Skip to content

armgit / chops

Public Imported from GitHub
0

Your AI agent skills, finally organized. A macOS app to browse, edit, and manage skills across Claude Code, Cursor, Codex, Windsurf, and Amp.

feat: Organize skills rules agents (#72)

Miguel Zavalab3fb43e7b6d4
diff --git a/Chops.xcodeproj/project.pbxproj b/Chops.xcodeproj/project.pbxproj
index 09d3445..799f970 100644
--- a/Chops.xcodeproj/project.pbxproj
+++ b/Chops.xcodeproj/project.pbxproj
@@ -8,7 +8,6 @@
/* Begin PBXBuildFile section */
038F5975DA97A3211EF4D448 /* ThinkingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D07C2CD05E172DB71F63033 /* ThinkingView.swift */; };
- 08B4E2A065E192F17F2568B6 /* TemplateDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E792EE2E83B2068F8C5305F /* TemplateDetailView.swift */; };
09D3F065191A83BDEE922789 /* SkillDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 168E103488DEA623E712852B /* SkillDetailView.swift */; };
0DC3536F86CAA3C4680958AF /* ACPModel in Frameworks */ = {isa = PBXBuildFile; productRef = 86292938A0949F325E358FA5 /* ACPModel */; };
1BBEBC85C24BBC4E08AA1821 /* ACPLogViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F236C158C893B626A51E385 /* ACPLogViewer.swift */; };
@@ -42,6 +41,8 @@
95163AEB7980654C901EC693 /* Skill.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27D6ED655F951177D2152351 /* Skill.swift */; };
98434D3DDFEEC7239F6F7B79 /* RegistrySheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FCD6C2A8BE68F553A9CA392 /* RegistrySheet.swift */; };
99EE8F6124FE91AC9576D6FD /* FileWatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAD26AA4787A2E0CDC86AADC /* FileWatcher.swift */; };
+ A0862ECC573FDC0AA7CB9950 /* LibrarySettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AA4FA049E1DADB40552060 /* LibrarySettingsView.swift */; };
+ A500A6E37C3F2BF5B4428959 /* ChopsSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D9B5801101BA69BB84EE28D /* ChopsSettings.swift */; };
A99BA179E0520DCDC98E1382 /* AppLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = F45D5C8E8C732B2F4A867E43 /* AppLogger.swift */; };
AAC4A3CBF2A9B4DF50608948 /* SSHService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6797D4AC1970DB9ACB5ACA73 /* SSHService.swift */; };
AFDC3DAB708B352A7606F119 /* DiagnosticExporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5D3C2567FBF8DBA4DE957B3 /* DiagnosticExporter.swift */; };
@@ -70,6 +71,7 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
+ 03AA4FA049E1DADB40552060 /* LibrarySettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibrarySettingsView.swift; sourceTree = "<group>"; };
04C3C644B72DD508A7CBC403 /* ChopsIcon.icon */ = {isa = PBXFileReference; lastKnownFileType = wrapper.icon; path = ChopsIcon.icon; sourceTree = "<group>"; };
07899C351E63B32277272A59 /* CursorACPAgent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CursorACPAgent.swift; sourceTree = "<group>"; };
12C5CD1627D4EFF58AEF4F71 /* TemplateManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateManager.swift; sourceTree = "<group>"; };
@@ -82,6 +84,7 @@
27D6ED655F951177D2152351 /* Skill.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Skill.swift; sourceTree = "<group>"; };
2CF7822031FD82A28978D9C5 /* SidebarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarView.swift; sourceTree = "<group>"; };
2D07C2CD05E172DB71F63033 /* ThinkingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThinkingView.swift; sourceTree = "<group>"; };
+ 2D9B5801101BA69BB84EE28D /* ChopsSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChopsSettings.swift; sourceTree = "<group>"; };
31B4DB87833D5160A11E39C9 /* SkillEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkillEditorView.swift; sourceTree = "<group>"; };
3314080A44DEB895223E36D5 /* RemoteServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteServer.swift; sourceTree = "<group>"; };
372FA72F2C179B79470DF86A /* MarkdownRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkdownRenderer.swift; sourceTree = "<group>"; };
@@ -95,7 +98,6 @@
5F236C158C893B626A51E385 /* ACPLogViewer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ACPLogViewer.swift; sourceTree = "<group>"; };
60E0F71982C4AF0045962380 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
6797D4AC1970DB9ACB5ACA73 /* SSHService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHService.swift; sourceTree = "<group>"; };
- 6E792EE2E83B2068F8C5305F /* TemplateDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateDetailView.swift; sourceTree = "<group>"; };
77E332B9970E6E3D00DCFBA3 /* SkillPreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkillPreviewView.swift; sourceTree = "<group>"; };
7C77C5B30E6C885B39444E5B /* FrontmatterParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FrontmatterParser.swift; sourceTree = "<group>"; };
7FCD6C2A8BE68F553A9CA392 /* RegistrySheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegistrySheet.swift; sourceTree = "<group>"; };
@@ -208,6 +210,7 @@
children = (
9C052B94D025127C9823E7BC /* ACPSettingsView.swift */,
D5D3C2567FBF8DBA4DE957B3 /* DiagnosticExporter.swift */,
+ 03AA4FA049E1DADB40552060 /* LibrarySettingsView.swift */,
E684304D1723CA691F40335B /* RemoteServersSettingsView.swift */,
A924245DDDA4C6A59BE15567 /* SettingsView.swift */,
);
@@ -256,6 +259,7 @@
children = (
D946A13468984E6DEBC20B9A /* ACPConfiguration.swift */,
907E59B064AB8366B60BF611 /* AgentTarget.swift */,
+ 2D9B5801101BA69BB84EE28D /* ChopsSettings.swift */,
C9AFE1AF02B0F8057791C2A9 /* Collection.swift */,
3314080A44DEB895223E36D5 /* RemoteServer.swift */,
B1F8AA042D5D8A9F92F35CA3 /* SchemaVersions.swift */,
@@ -296,7 +300,6 @@
31B4DB87833D5160A11E39C9 /* SkillEditorView.swift */,
8C812515FD8DC222B89745F2 /* SkillMetadataBar.swift */,
77E332B9970E6E3D00DCFBA3 /* SkillPreviewView.swift */,
- 6E792EE2E83B2068F8C5305F /* TemplateDetailView.swift */,
);
path = Detail;
sourceTree = "<group>";
@@ -408,6 +411,7 @@
A99BA179E0520DCDC98E1382 /* AppLogger.swift in Sources */,
25A4FB387DB5BD96DB630C14 /* AppState.swift in Sources */,
309B12E0B72A22C9772BBC99 /* ChopsApp.swift in Sources */,
+ A500A6E37C3F2BF5B4428959 /* ChopsSettings.swift in Sources */,
91EA572FCA75A2EA848C3429 /* ChopsTextView.swift in Sources */,
62C6C8687D8A1E3C1EBBBC8C /* ClaudeACPAgent.swift in Sources */,
7A17C99C5EFAE3AA9E788D50 /* Collection.swift in Sources */,
@@ -421,6 +425,7 @@
B4526ECE136AC044CD3C7603 /* EditorTheme.swift in Sources */,
99EE8F6124FE91AC9576D6FD /* FileWatcher.swift in Sources */,
CBD8FECF1C5A453C8B021665 /* FrontmatterParser.swift in Sources */,
+ A0862ECC573FDC0AA7CB9950 /* LibrarySettingsView.swift in Sources */,
7FD1DE6640F9339D5E97E09A /* MDCParser.swift in Sources */,
322C22C23073C29FC0C6098D /* MarkdownMessageView.swift in Sources */,
E7ED248D6F94C1B1DEF1E8BA /* MarkdownRenderer.swift in Sources */,
@@ -443,7 +448,6 @@
E6F4E1CF50F2F78F5BA9BAC9 /* SkillPreviewView.swift in Sources */,
846B58F3B105D1734DC6FA75 /* SkillRegistry.swift in Sources */,
6A8E0927D95BB14C9F377F4E /* SkillScanner.swift in Sources */,
- 08B4E2A065E192F17F2568B6 /* TemplateDetailView.swift in Sources */,
3F0ED402E77D8D25C600BAED /* TemplateManager.swift in Sources */,
038F5975DA97A3211EF4D448 /* ThinkingView.swift in Sources */,
53C393C13E30EC439317509F /* ToolBadge.swift in Sources */,
diff --git a/Chops/App/AppState.swift b/Chops/App/AppState.swift
index e1164f9..57763e6 100644
--- a/Chops/App/AppState.swift
+++ b/Chops/App/AppState.swift
@@ -9,14 +9,16 @@ final class AppState {
var showingRegistrySheet: Bool = false
var newItemKind: ItemKind = .skill
var sidebarFilter: SidebarFilter = .allSkills
+ /// Filter by item kind within a tool view (nil = show all)
+ var toolKindFilter: ItemKind?
}
enum SidebarFilter: Hashable {
case allSkills
case allAgents
+ case allRules
case favorites
case tool(ToolSource)
case collection(String)
case server(String)
- case wizardTemplate(WizardTemplateType)
}
diff --git a/Chops/App/ContentView.swift b/Chops/App/ContentView.swift
index b526380..a1ec7d1 100644
--- a/Chops/App/ContentView.swift
+++ b/Chops/App/ContentView.swift
@@ -17,9 +17,7 @@ struct ContentView: View {
} content: {
SkillListView()
} detail: {
- if case .wizardTemplate(let templateType) = appState.sidebarFilter {
- TemplateDetailView(templateType: templateType)
- } else if let skill = appState.selectedSkill {
+ if let skill = appState.selectedSkill {
SkillDetailView(skill: skill)
} else {
ContentUnavailableView(
@@ -39,26 +37,8 @@ struct ContentView: View {
.sheet(isPresented: $appState.showingRegistrySheet) {
RegistrySheet()
}
- .toolbar {
- ToolbarItem(placement: .primaryAction) {
- Menu {
- Button {
- appState.newItemKind = .skill
- appState.showingNewSkillSheet = true
- } label: {
- Label("New Skill", systemImage: "doc.text")
- }
- Divider()
- Button {
- appState.showingRegistrySheet = true
- } label: {
- Label("Browse Registry", systemImage: "globe")
- }
- } label: {
- Label("Add", systemImage: "plus")
- }
- .menuIndicator(.hidden)
- }
+ .onChange(of: appState.sidebarFilter) {
+ appState.toolKindFilter = nil
}
.frame(minWidth: 900, minHeight: 500)
.onReceive(NotificationCenter.default.publisher(for: .customScanPathsChanged)) { _ in
diff --git a/Chops/Models/ChopsSettings.swift b/Chops/Models/ChopsSettings.swift
new file mode 100644
index 0000000..cea7101
--- /dev/null
+++ b/Chops/Models/ChopsSettings.swift
@@ -0,0 +1,24 @@
+import Foundation
+
+/// User-configurable source-of-truth root directory.
+/// Sub-directories for skills, agents, and rules are derived from the root.
+struct ChopsSettings {
+ private init() {}
+
+ private static let home = FileManager.default.homeDirectoryForCurrentUser.path
+
+ static var sotDir: String {
+ get { UserDefaults.standard.string(forKey: "sotDir") ?? "\(home)/.chops" }
+ set { UserDefaults.standard.set(newValue, forKey: "sotDir") }
+ }
+
+ static var sotSkillsDir: String { "\(sotDir)/skills" }
+ static var sotAgentsDir: String { "\(sotDir)/agents" }
+ static var sotRulesDir: String { "\(sotDir)/rules" }
+
+ /// When false (default), skills installed by CLI and Desktop plugins are excluded from the library.
+ static var includePluginSkills: Bool {
+ get { UserDefaults.standard.bool(forKey: "includePluginSkills") }
+ set { UserDefaults.standard.set(newValue, forKey: "includePluginSkills") }
+ }
+}
diff --git a/Chops/Models/Skill.swift b/Chops/Models/Skill.swift
index 0f9e791..c37d6b7 100644
--- a/Chops/Models/Skill.swift
+++ b/Chops/Models/Skill.swift
@@ -4,6 +4,31 @@ import Foundation
enum ItemKind: String, Codable, CaseIterable {
case skill
case agent
+ case rule
+
+ var displayName: String {
+ switch self {
+ case .skill: "Skills"
+ case .agent: "Agents"
+ case .rule: "Rules"
+ }
+ }
+
+ var singularName: String {
+ switch self {
+ case .skill: "Skill"
+ case .agent: "Agent"
+ case .rule: "Rule"
+ }
+ }
+
+ var icon: String {
+ switch self {
+ case .skill: "doc.text"
+ case .agent: "person.crop.rectangle"
+ case .rule: "list.bullet.rectangle"
+ }
+ }
}
@Model
@@ -28,13 +53,19 @@ final class Skill {
var isRemote: Bool { remoteServer != nil }
+ var isPlugin: Bool {
+ filePath.contains("/.claude/plugins/") ||
+ filePath.contains("/local-agent-mode-sessions/") ||
+ toolSources.contains(.claudeDesktop)
+ }
+
/// Comma-separated tool raw values (e.g. "claude,cursor,codex")
var toolSourcesRaw: String
/// All file paths where this skill is installed (JSON-encoded array)
var installedPathsData: Data?
- /// Discriminator: "skill" or "agent"
+ /// Raw `ItemKind` value. Defaults to `"skill"` for lightweight migration compatibility.
var kind: String = ItemKind.skill.rawValue
// MARK: - Computed
@@ -45,7 +76,11 @@ final class Skill {
}
var displayTypeName: String {
- itemKind == .agent ? "Agent" : "Skill"
+ switch itemKind {
+ case .agent: "Agent"
+ case .rule: "Rule"
+ case .skill: "Skill"
+ }
}
var toolSources: [ToolSource] {
@@ -71,7 +106,11 @@ final class Skill {
return (try? JSONDecoder().decode([String].self, from: data)) ?? [filePath]
}
set {
- installedPathsData = try? JSONEncoder().encode(Array(Set(newValue)))
+ do {
+ installedPathsData = try JSONEncoder().encode(Array(Set(newValue)))
+ } catch {
+ AppLogger.fileIO.fault("Failed to encode installedPaths: \(error.localizedDescription)")
+ }
}
}
@@ -81,7 +120,11 @@ final class Skill {
return (try? JSONDecoder().decode([String: String].self, from: data)) ?? [:]
}
set {
- frontmatterData = try? JSONEncoder().encode(newValue)
+ do {
+ frontmatterData = try JSONEncoder().encode(newValue)
+ } catch {
+ AppLogger.fileIO.fault("Failed to encode frontmatter: \(error.localizedDescription)")
+ }
}
}
@@ -125,12 +168,12 @@ final class Skill {
self.resolvedPath = resolvedPath.isEmpty ? filePath : resolvedPath
self.filePath = filePath
self.toolSourcesRaw = toolSource.rawValue
- self.installedPathsData = try? JSONEncoder().encode([filePath])
+ self.installedPathsData = try? JSONEncoder().encode([filePath]) // [String] encode never throws
self.isDirectory = isDirectory
self.name = name
self.skillDescription = skillDescription
self.content = content
- self.frontmatterData = try? JSONEncoder().encode(frontmatter)
+ self.frontmatterData = try? JSONEncoder().encode(frontmatter) // [String: String] encode never throws
self.collections = collections
self.isFavorite = isFavorite
diff --git a/Chops/Models/ToolSource.swift b/Chops/Models/ToolSource.swift
index 31171c9..be6b0c2 100644
--- a/Chops/Models/ToolSource.swift
+++ b/Chops/Models/ToolSource.swift
@@ -128,8 +128,8 @@ enum ToolSource: String, Codable, CaseIterable, Identifiable {
switch self {
case .augment: return ["\(home)/.augment/skills"]
case .claude: return ["\(home)/.claude/skills"]
- case .cursor: return ["\(home)/.cursor/skills", "\(home)/.cursor/rules"]
- case .windsurf: return ["\(home)/.codeium/windsurf/memories", "\(home)/.windsurf/rules"]
+ case .cursor: return ["\(home)/.cursor/skills"]
+ case .windsurf: return []
case .codex: return ["\(home)/.codex/skills"]
case .copilot: return ["\(home)/.copilot/skills"]
case .aider: return []
@@ -144,6 +144,15 @@ enum ToolSource: String, Codable, CaseIterable, Identifiable {
}
}
+ var globalRulePaths: [String] {
+ let home = FileManager.default.homeDirectoryForCurrentUser.path
+ switch self {
+ case .cursor: return ["\(home)/.cursor/rules"]
+ case .windsurf: return ["\(home)/.codeium/windsurf/memories", "\(home)/.windsurf/rules"]
+ default: return []
+ }
+ }
+
/// Whether the tool is actually installed on this machine.
/// Checks for app bundles, CLI binaries, tool-specific config files,
/// or known global skill locations that imply a real setup is present.
@@ -166,6 +175,7 @@ enum ToolSource: String, Codable, CaseIterable, Identifiable {
return fm.fileExists(atPath: "/Applications/Windsurf.app")
|| fm.fileExists(atPath: "\(home)/.codeium/windsurf/argv.json")
|| globalPaths.contains { fm.fileExists(atPath: $0) }
+ || globalRulePaths.contains { fm.fileExists(atPath: $0) }
case .codex:
return fm.fileExists(atPath: "\(home)/.codex/config.toml")
|| fm.fileExists(atPath: "\(home)/.codex/auth.json")
diff --git a/Chops/Models/WizardTemplate.swift b/Chops/Models/WizardTemplate.swift
index a49c667..663a0dc 100644
--- a/Chops/Models/WizardTemplate.swift
+++ b/Chops/Models/WizardTemplate.swift
@@ -5,11 +5,17 @@ import Foundation
/// Types of wizard templates for AI-assisted composition
enum WizardTemplateType: String, CaseIterable, Codable, Identifiable {
case skill = "skill"
+ case agent = "agent"
+ case rule = "rule"
var id: String { rawValue }
var displayName: String {
- "Skill Composer"
+ switch self {
+ case .skill: "Skills"
+ case .agent: "Agents"
+ case .rule: "Rules"
+ }
}
var fileName: String {
@@ -17,7 +23,11 @@ enum WizardTemplateType: String, CaseIterable, Codable, Identifiable {
}
var icon: String {
- "doc.text.fill"
+ switch self {
+ case .skill: "doc.text"
+ case .agent: "person.crop.rectangle"
+ case .rule: "list.bullet.rectangle"
+ }
}
}
diff --git a/Chops/Services/ACP/ACPClient.swift b/Chops/Services/ACP/ACPClient.swift
index 585c6e5..4c47df6 100644
--- a/Chops/Services/ACP/ACPClient.swift
+++ b/Chops/Services/ACP/ACPClient.swift
@@ -276,12 +276,18 @@ open class BaseACPAgent: ClientDelegate {
if !alreadyCaptured {
let snapshot = await Task.detached {
let existedBefore = FileManager.default.fileExists(atPath: path)
- let originalData = existedBefore ? try? Data(contentsOf: URL(fileURLWithPath: path)) : nil
- return (
- existedBefore,
- originalData,
- Self.decodeText(from: originalData)
- )
+ let originalData: Data?
+ if existedBefore {
+ do {
+ originalData = try Data(contentsOf: URL(fileURLWithPath: path))
+ } catch {
+ acpLog.error("Failed to read original for diff revert (\(path)): \(error.localizedDescription)")
+ originalData = nil
+ }
+ } else {
+ originalData = nil
+ }
+ return (existedBefore, originalData, Self.decodeText(from: originalData))
}.value
pendingWrites.append(
PendingWrite(
diff --git a/Chops/Services/ACP/ACPLogger.swift b/Chops/Services/ACP/ACPLogger.swift
index 85d23ff..6c79c8d 100644
--- a/Chops/Services/ACP/ACPLogger.swift
+++ b/Chops/Services/ACP/ACPLogger.swift
@@ -23,7 +23,8 @@ final class ACPLogger: @unchecked Sendable {
}
private init() {
- let appSupport = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
+ let appSupport = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first
+ ?? FileManager.default.temporaryDirectory
let logsDir = appSupport.appendingPathComponent("Chops/Logs", isDirectory: true)
try? FileManager.default.createDirectory(at: logsDir, withIntermediateDirectories: true)
@@ -71,18 +72,6 @@ final class ACPLogger: @unchecked Sendable {
}
}
- /// Log send payload (only in debug mode)
- func logSend(_ payload: String) {
- guard debugEnabled else { return }
- log(level: .debug, message: ">>> SEND: \(payload)")
- }
-
- /// Log receive payload (only in debug mode)
- func logReceive(_ payload: String) {
- guard debugEnabled else { return }
- log(level: .debug, message: "<<< RECV: \(payload)")
- }
-
/// Get the log file URL for viewing
var logURL: URL { logFileURL }
diff --git a/Chops/Services/ACP/Agents/ClaudeACPAgent.swift b/Chops/Services/ACP/Agents/ClaudeACPAgent.swift
index 815d5ff..f788881 100644
--- a/Chops/Services/ACP/Agents/ClaudeACPAgent.swift
+++ b/Chops/Services/ACP/Agents/ClaudeACPAgent.swift
@@ -140,14 +140,20 @@ final class ClaudeACPAgent: BaseACPAgent {
for prefix in ["</\(tag)", "<\(tag)"] {
var i = result.startIndex
while i < result.endIndex,
- let open = result.range(of: prefix, range: i ..< result.endIndex),
- let close = result.range(of: ">", range: open.lowerBound ..< result.endIndex) {
+ let open = result.range(of: prefix, range: i ..< result.endIndex) {
+ // Search for closing '>' starting after the tag prefix, not from its start.
+ guard let close = result.range(of: ">", range: open.upperBound ..< result.endIndex) else {
+ // No closing '>' — malformed tag, advance past prefix to avoid infinite loop.
+ i = open.upperBound
+ continue
+ }
result.removeSubrange(open.lowerBound ... close.lowerBound)
i = open.lowerBound
}
}
}
- while result.contains("\n\n\n") { result = result.replacingOccurrences(of: "\n\n\n", with: "\n\n") }
+ // Collapse runs of 3+ consecutive newlines down to 2.
+ result = result.replacingOccurrences(of: "\n{3,}", with: "\n\n", options: .regularExpression)
return result.trimmingCharacters(in: .whitespacesAndNewlines)
}
diff --git a/Chops/Services/SkillScanner.swift b/Chops/Services/SkillScanner.swift
index aa194f0..9f71deb 100644
--- a/Chops/Services/SkillScanner.swift
+++ b/Chops/Services/SkillScanner.swift
@@ -52,11 +52,11 @@ final class SkillScanner {
(".claude/skills", .claude, .skill),
(".claude/agents", .claude, .agent),
(".cursor/skills", .cursor, .skill),
- (".cursor/rules", .cursor, .skill),
+ (".cursor/rules", .cursor, .rule),
(".cursor/agents", .cursor, .agent),
(".codex/skills", .codex, .skill),
(".codex/agents", .codex, .agent),
- (".windsurf/rules", .windsurf, .skill),
+ (".windsurf/rules", .windsurf, .rule),
(".github", .copilot, .skill),
(".github/agents", .copilot, .agent),
(".config/amp/skills", .amp, .skill),
@@ -71,8 +71,9 @@ final class SkillScanner {
scanGeneration += 1
let generation = scanGeneration
let customPaths = UserDefaults.standard.stringArray(forKey: "customScanPaths") ?? []
+ let includePlugins = ChopsSettings.includePluginSkills
scanTask = Task.detached { [weak self] in
- let results = Self.collectAllSkills(customPaths: customPaths)
+ let results = Self.collectAllSkills(customPaths: customPaths, includePlugins: includePlugins)
guard !Task.isCancelled else { return }
let elapsed = CFAbsoluteTimeGetCurrent() - start
AppLogger.scanning.notice("File collection done: \(results.count) skills in \(String(format: "%.2f", elapsed))s")
@@ -87,7 +88,7 @@ final class SkillScanner {
}
/// Pure filesystem I/O — safe to run off main thread.
- private static func collectAllSkills(customPaths: [String]) -> [ScannedSkillData] {
+ private static func collectAllSkills(customPaths: [String], includePlugins: Bool) -> [ScannedSkillData] {
var results: [ScannedSkillData] = []
for tool in ToolSource.allCases where tool != .custom {
@@ -103,16 +104,21 @@ final class SkillScanner {
let url = URL(fileURLWithPath: path)
collectFromDirectory(url, toolSource: tool, isGlobal: true, kind: .agent, into: &results)
}
+ for path in tool.globalRulePaths {
+ let url = URL(fileURLWithPath: path)
+ collectFromDirectory(url, toolSource: tool, isGlobal: true, kind: .rule, into: &results)
+ }
}
- // CLI plugins (installed_plugins.json)
- if ToolSource.claude.isInstalled {
- collectFromCLIPlugins(into: &results)
- }
-
- // Claude Desktop/Cowork plugin skills
- if ToolSource.claudeDesktop.isInstalled {
- collectClaudeDesktopSkills(into: &results)
+ if includePlugins {
+ // CLI plugins (installed_plugins.json)
+ if ToolSource.claude.isInstalled {
+ collectFromCLIPlugins(into: &results)
+ }
+ // Claude Desktop/Cowork plugin skills
+ if ToolSource.claudeDesktop.isInstalled {
+ collectClaudeDesktopSkills(into: &results)
+ }
}
for path in customPaths {
@@ -472,11 +478,14 @@ final class SkillScanner {
modelContext.delete(skill)
}
- try? modelContext.save()
+ do { try modelContext.save() } catch {
+ AppLogger.scanning.error("SwiftData save failed: \(error.localizedDescription)")
+ }
}
// MARK: - Remote Server Scanning
+ @MainActor
func syncAllRemoteServers() async {
let descriptor = FetchDescriptor<RemoteServer>()
guard let servers = try? modelContext.fetch(descriptor) else { return }
@@ -486,6 +495,7 @@ final class SkillScanner {
}
/// Scans a remote server for skills. Sets lastSyncError on failure.
+ @MainActor
func scanRemoteServer(_ server: RemoteServer) async {
do {
let remoteSkills = try await SSHService.findSkills(server)
@@ -502,8 +512,11 @@ final class SkillScanner {
} else {
// Derive name from parent directory
let components = path.components(separatedBy: "/")
- let skillDirIndex = components.lastIndex(of: "SKILL.md").map { components.index(before: $0) }
- name = skillDirIndex.map { components[$0] } ?? "Unknown"
+ if let fileIndex = components.lastIndex(of: "SKILL.md"), fileIndex > 0 {
+ name = components[fileIndex - 1]
+ } else {
+ name = "Unknown"
+ }
}
let predicate = #Predicate<Skill> { $0.resolvedPath == resolvedPath }
@@ -546,13 +559,18 @@ final class SkillScanner {
server.lastSyncDate = .now
server.lastSyncError = nil
- try? modelContext.save()
+ do { try modelContext.save() } catch {
+ AppLogger.scanning.error("SwiftData save failed after sync: \(error.localizedDescription)")
+ }
} catch {
server.lastSyncError = error.localizedDescription
- try? modelContext.save()
+ do { try modelContext.save() } catch {
+ AppLogger.scanning.error("SwiftData save failed after sync error: \(error.localizedDescription)")
+ }
}
}
+ @MainActor
func removeDeletedSkills() {
let descriptor = FetchDescriptor<Skill>()
guard let skills = try? modelContext.fetch(descriptor) else { return }
@@ -589,7 +607,9 @@ final class SkillScanner {
}
}
}
- try? modelContext.save()
+ do { try modelContext.save() } catch {
+ AppLogger.scanning.error("SwiftData save failed: \(error.localizedDescription)")
+ }
}
deinit {
diff --git a/Chops/Services/TemplateManager.swift b/Chops/Services/TemplateManager.swift
index a59908e..fc0d439 100644
--- a/Chops/Services/TemplateManager.swift
+++ b/Chops/Services/TemplateManager.swift
@@ -13,7 +13,8 @@ final class TemplateManager {
private let fileManager = FileManager.default
private var templatesDirectory: URL {
- let appSupport = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
+ let appSupport = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask).first
+ ?? fileManager.temporaryDirectory
return appSupport.appendingPathComponent("Chops/templates", isDirectory: true)
}
@@ -53,7 +54,11 @@ final class TemplateManager {
}
private func systemPromptContent(for type: WizardTemplateType) -> String {
- Self.defaultSkillSystemPrompt
+ switch type {
+ case .skill: Self.defaultSkillSystemPrompt
+ case .agent: Self.defaultAgentSystemPrompt
+ case .rule: Self.defaultRuleSystemPrompt
+ }
}
/// Save updated template content
@@ -91,8 +96,10 @@ final class TemplateManager {
// MARK: - Private
private func ensureTemplatesExist() {
- if !fileManager.fileExists(atPath: templatesDirectory.path) {
- try? fileManager.createDirectory(at: templatesDirectory, withIntermediateDirectories: true)
+ do {
+ try fileManager.createDirectory(at: templatesDirectory, withIntermediateDirectories: true)
+ } catch {
+ AppLogger.fileIO.error("Failed to create templates dir: \(error.localizedDescription)")
}
// Write bundled templates on first run; overwrite outdated stored versions.
@@ -100,11 +107,21 @@ final class TemplateManager {
let destURL = templatesDirectory.appendingPathComponent(type.fileName)
guard let bundled = loadBundledTemplate(type) else { continue }
+ let needsWrite: Bool
if !fileManager.fileExists(atPath: destURL.path) {
- try? bundled.write(to: destURL, atomically: true, encoding: .utf8)
- } else if let stored = try? String(contentsOf: destURL, encoding: .utf8),
- templateNeedsUpdate(stored: stored, bundled: bundled) {
- try? bundled.write(to: destURL, atomically: true, encoding: .utf8)
+ needsWrite = true
+ } else if let stored = try? String(contentsOf: destURL, encoding: .utf8) {
+ needsWrite = templateNeedsUpdate(stored: stored, bundled: bundled)
+ } else {
+ needsWrite = false
+ }
+
+ if needsWrite {
+ do {
+ try bundled.write(to: destURL, atomically: true, encoding: .utf8)
+ } catch {
+ AppLogger.fileIO.error("Failed to write template \(type.rawValue): \(error.localizedDescription)")
+ }
}
}
}
@@ -161,7 +178,11 @@ final class TemplateManager {
}
private func defaultTemplateContent(for type: WizardTemplateType) -> String {
- Self.defaultSkillTemplate
+ switch type {
+ case .skill: Self.defaultSkillTemplate
+ case .agent: Self.defaultAgentTemplate
+ case .rule: Self.defaultRuleTemplate
+ }
}
// MARK: - Default Templates
@@ -190,6 +211,54 @@ final class TemplateManager {
"""
+ // MARK: - Default Agent / Rule Templates
+
+ private static let defaultAgentTemplate = """
+ <!-- chops-template-version: 1 -->
+ # Agent Composer
+
+ You are helping create or improve an agent definition.
+
+ ## Context
+ - File type: Agent
+ - Agents are specialized AI assistants with a defined role, tools, and behavior
+
+ ## Current Content
+ {{file_content}}
+
+ ## User Instructions
+ {{user_instructions}}
+
+ ## Guidelines
+ 1. Use YAML frontmatter for metadata (name, description)
+ 2. Define a clear, focused role for the agent
+ 3. Specify which tools and capabilities the agent should use
+ 4. Keep instructions concise and unambiguous
+ """
+
+ private static let defaultRuleTemplate = """
+ <!-- chops-template-version: 1 -->
+ # Rule Composer
+
+ You are helping create or improve a rule definition.
+
+ ## Context
+ - File type: Rule
+ - Rules are persistent instructions applied across all interactions in a tool
+
+ ## Current Content
+ {{file_content}}
+
+ ## User Instructions
+ {{user_instructions}}
+
+ ## Guidelines
+ 1. Use YAML frontmatter for metadata (name, description)
+ 2. Write rules as clear, imperative directives
+ 3. Keep scope narrow — one concern per rule
+ 4. Avoid contradictions with other rules
+ """
+
// MARK: - Default System Prompts
private static let defaultSkillSystemPrompt = """
@@ -208,5 +277,37 @@ final class TemplateManager {
Always write the full file, including YAML frontmatter.
"""
+ private static let defaultAgentSystemPrompt = """
+ You are an expert in writing agent definitions for AI coding assistants.
+
+ ## Current agent context
+ - Name: {{skill_name}}
+ - Description: {{skill_description}}
+ - File: {{file_path}}
+ - Frontmatter:
+ {{frontmatter}}
+
+ ## Your role
+ When the user asks you to create or update this agent, use the ACP `write_text_file` tool to write the complete updated file content directly to the file path shown above.
+ Do not show the content in a code block or ask for confirmation — write it directly via `write_text_file`.
+ Always write the full file, including YAML frontmatter.
+ """
+
+ private static let defaultRuleSystemPrompt = """
+ You are an expert in writing rules for AI coding assistants.
+
+ ## Current rule context
+ - Name: {{skill_name}}
+ - Description: {{skill_description}}
+ - File: {{file_path}}
+ - Frontmatter:
+ {{frontmatter}}
+
+ ## Your role
+ When the user asks you to create or update this rule, use the ACP `write_text_file` tool to write the complete updated file content directly to the file path shown above.
+ Do not show the content in a code block or ask for confirmation — write it directly via `write_text_file`.
+ Always write the full file, including YAML frontmatter.
+ """
+
}
diff --git a/Chops/Views/Detail/SkillDetailView.swift b/Chops/Views/Detail/SkillDetailView.swift
index f43be22..a0ddb7f 100644
--- a/Chops/Views/Detail/SkillDetailView.swift
+++ b/Chops/Views/Detail/SkillDetailView.swift
@@ -91,10 +91,10 @@ struct SkillDetailView: View {
if preferPreview {
SkillPreviewView(content: document.editorContent)
} else {
- SkillEditorView(document: document)
+ SkillEditorView(document: document, isEditable: !skill.isPlugin)
}
- if !showingComposePanel {
+ if !showingComposePanel && !skill.isPlugin {
composeFloatingButton
}
}
@@ -109,7 +109,7 @@ struct SkillDetailView: View {
frontmatter: skill.frontmatter,
filePath: skill.filePath,
workingDirectory: URL(fileURLWithPath: skill.filePath).deletingLastPathComponent(),
- templateType: .skill,
+ templateType: WizardTemplateType(rawValue: skill.itemKind.rawValue) ?? .skill,
onAccept: { document.save(to: skill) }
)
.id(skill.filePath)
@@ -128,6 +128,7 @@ struct SkillDetailView: View {
document.load(from: skill)
}
.onChange(of: document.editorContent) {
+ guard !skill.isPlugin else { return }
autoSaveTask?.cancel()
autoSaveTask = Task {
try? await Task.sleep(for: .seconds(1))
@@ -147,16 +148,6 @@ struct SkillDetailView: View {
Text(document.saveErrorMessage)
}
.toolbar {
- ToolbarItem {
- Button {
- document.save(to: skill)
- } label: {
- Label("Save", systemImage: "square.and.arrow.down")
- }
- .buttonStyle(.bordered)
- .disabled(!document.hasUnsavedChanges)
- .help("Save (⌘S)")
- }
ToolbarItem {
Picker("Mode", selection: $preferPreview) {
Image(systemName: "pencil").tag(false)
diff --git a/Chops/Views/Detail/SkillEditorView.swift b/Chops/Views/Detail/SkillEditorView.swift
index db1e707..1ea16d8 100644
--- a/Chops/Views/Detail/SkillEditorView.swift
+++ b/Chops/Views/Detail/SkillEditorView.swift
@@ -189,6 +189,7 @@ final class SkillEditorDocument {
struct SkillEditorView: View {
@Bindable var document: SkillEditorDocument
+ var isEditable: Bool = true
var body: some View {
ZStack(alignment: .topTrailing) {
@@ -199,7 +200,7 @@ struct SkillEditorView: View {
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
- HighlightedTextEditor(text: $document.editorContent)
+ HighlightedTextEditor(text: $document.editorContent, isEditable: isEditable)
}
HStack(spacing: 6) {
@@ -227,6 +228,7 @@ extension Notification.Name {
struct HighlightedTextEditor: NSViewRepresentable {
@Binding var text: String
+ var isEditable: Bool = true
@Environment(\.colorScheme) private var colorScheme
func makeCoordinator() -> Coordinator {
@@ -241,6 +243,7 @@ struct HighlightedTextEditor: NSViewRepresentable {
scrollView.autohidesScrollers = true
let textView = ChopsTextView()
+ textView.isEditable = isEditable
textView.isRichText = false
textView.allowsUndo = true
textView.usesFindPanel = true
@@ -300,6 +303,7 @@ struct HighlightedTextEditor: NSViewRepresentable {
guard let textView = scrollView.documentView as? ChopsTextView else { return }
context.coordinator.parent = self
+ textView.isEditable = isEditable
// Re-highlight on appearance change
let currentScheme = colorScheme
diff --git a/Chops/Views/Detail/TemplateDetailView.swift b/Chops/Views/Detail/TemplateDetailView.swift
deleted file mode 100644
index f9c23cd..0000000
--- a/Chops/Views/Detail/TemplateDetailView.swift
+++ /dev/null
@@ -1,100 +0,0 @@
-import SwiftUI
-
-struct TemplateDetailView: View {
- let templateType: WizardTemplateType
- @State private var templateManager = TemplateManager.shared
- @State private var content: String = ""
- @State private var hasChanges = false
- @State private var showingResetConfirm = false
-
- var body: some View {
- VStack(spacing: 0) {
- // Editor
- TextEditor(text: $content)
- .font(.system(.body, design: .monospaced))
- .scrollContentBackground(.hidden)
- .padding(12)
- .onChange(of: content) { _, _ in
- hasChanges = true
- }
-
- Divider()
-
- // Footer
- HStack {
- Text("Template for \(templateType.displayName.lowercased())")
- .font(.caption)
- .foregroundStyle(.secondary)
-
- Spacer()
-
- if hasChanges {
- Text("Unsaved changes")
- .font(.caption)
- .foregroundStyle(.orange)
- }
-
- Button("Reset to Default") {
- showingResetConfirm = true
- }
- .buttonStyle(.plain)
- .foregroundStyle(.red)
- .font(.caption)
-
- Button("Save") {
- save()
- }
- .buttonStyle(.borderedProminent)
- .controlSize(.small)
- .disabled(!hasChanges)
- .keyboardShortcut("s", modifiers: .command)
- }
- .padding(.horizontal, 12)
- .padding(.vertical, 8)
- .background(Color(NSColor.controlBackgroundColor))
- }
- .onAppear {
- loadTemplate()
- }
- .onChange(of: templateType) { _, _ in
- loadTemplate()
- }
- .confirmationDialog(
- "Reset Template?",
- isPresented: $showingResetConfirm,
- titleVisibility: .visible
- ) {
- Button("Reset to Default", role: .destructive) {
- templateManager.resetToDefault(templateType)
- loadTemplate()
- }
- Button("Cancel", role: .cancel) {}
- } message: {
- Text("This will replace your custom template with the default version.")
- }
- .navigationTitle(templateType.displayName)
- }
-
- private func loadTemplate() {
- if let template = templateManager.template(for: templateType) {
- content = template.content
- hasChanges = false
- }
- }
-
- private func save() {
- let template = WizardTemplate(
- type: templateType,
- content: content,
- lastModified: Date()
- )
- templateManager.save(template)
- hasChanges = false
- }
-}
-
-#Preview {
- TemplateDetailView(templateType: .skill)
- .frame(width: 600, height: 400)
-}
-
diff --git a/Chops/Views/Settings/ACPSettingsView.swift b/Chops/Views/Settings/ACPSettingsView.swift
index 3f10e9e..5397a54 100644
--- a/Chops/Views/Settings/ACPSettingsView.swift
+++ b/Chops/Views/Settings/ACPSettingsView.swift
@@ -3,34 +3,47 @@ import SwiftUI
struct ACPSettingsView: View {
@State private var configuration = ACPConfiguration.shared
+ @State private var templateManager = TemplateManager.shared
+ @State private var templateContents: [WizardTemplateType: String] = [:]
+ @State private var templateChanges: Set<WizardTemplateType> = []
+ @State private var showingResetConfirm: WizardTemplateType?
+ @State private var expandedTemplates: Set<WizardTemplateType> = []
var body: some View {
- Form {
- Section {
+ ScrollView {
+ VStack(alignment: .leading, spacing: 16) {
Text("Enable AI assistants to help compose and improve skills, agents, and rules.")
.font(.callout)
.foregroundStyle(.secondary)
- }
- agentListSection
+ agentListSection
- Section {
- Button("Refresh Registry") {
- Task { await configuration.refreshRegistry() }
+ HStack {
+ Button("Refresh Registry") {
+ Task { await configuration.refreshRegistry() }
+ }
+ .disabled(configuration.isLoadingRegistry)
}
- .disabled(configuration.isLoadingRegistry)
+
+ Divider()
+
+ templateSection
}
+ .padding()
}
- .formStyle(.grouped)
- .padding()
+ .frame(maxHeight: 550)
.task { await configuration.loadRegistryIfNeeded() }
+ .onAppear { loadAllTemplates() }
}
// MARK: - Agent List
@ViewBuilder
private var agentListSection: some View {
- Section {
+ VStack(alignment: .leading, spacing: 8) {
+ Text("Agents")
+ .font(.headline)
+
if configuration.isLoadingRegistry {
HStack {
ProgressView()
@@ -50,14 +63,157 @@ struct ACPSettingsView: View {
Text("No agents found.")
.foregroundStyle(.secondary)
} else {
- ForEach(configuration.registryAgents) { agent in
- AgentRow(agent: agent, configuration: configuration)
+ VStack(spacing: 0) {
+ ForEach(configuration.registryAgents) { agent in
+ AgentRow(agent: agent, configuration: configuration)
+ if agent.id != configuration.registryAgents.last?.id {
+ Divider()
+ }
+ }
}
+ .padding(8)
+ .background(Color(NSColor.controlBackgroundColor))
+ .clipShape(RoundedRectangle(cornerRadius: 6))
}
- } header: {
- Text("Agents")
}
}
+
+ // MARK: - Wizard Templates
+
+ private var templateSection: some View {
+ VStack(alignment: .leading, spacing: 8) {
+ Text("Chat Rules")
+ .font(.headline)
+
+ VStack(spacing: 0) {
+ ForEach(WizardTemplateType.allCases) { type in
+ VStack(spacing: 0) {
+ Button {
+ withAnimation(.easeInOut(duration: 0.15)) {
+ if expandedTemplates.contains(type) {
+ expandedTemplates.remove(type)
+ } else {
+ expandedTemplates.insert(type)
+ }
+ }
+ } label: {
+ HStack {
+ Image(systemName: "chevron.right")
+ .font(.caption2)
+ .rotationEffect(expandedTemplates.contains(type) ? .degrees(90) : .zero)
+ Label(type.displayName, systemImage: type.icon)
+ Spacer()
+ }
+ .padding(.horizontal, 8)
+ .padding(.vertical, 8)
+ .contentShape(Rectangle())
+ }
+ .buttonStyle(.plain)
+
+ if expandedTemplates.contains(type) {
+ templateEditor(for: type)
+ .padding(.horizontal, 8)
+ .padding(.bottom, 8)
+ }
+ }
+
+ if type != WizardTemplateType.allCases.last {
+ Divider()
+ }
+ }
+ }
+ .padding(4)
+ .background(Color(NSColor.controlBackgroundColor))
+ .clipShape(RoundedRectangle(cornerRadius: 6))
+ }
+ }
+
+ @ViewBuilder
+ private func templateEditor(for type: WizardTemplateType) -> some View {
+ let binding = Binding<String>(
+ get: { templateContents[type] ?? "" },
+ set: {
+ templateContents[type] = $0
+ templateChanges.insert(type)
+ }
+ )
+
+ VStack(alignment: .leading, spacing: 8) {
+ TextEditor(text: binding)
+ .font(.system(.caption, design: .monospaced))
+ .scrollContentBackground(.hidden)
+ .frame(height: 200)
+ .padding(6)
+ .background(Color(NSColor.textBackgroundColor))
+ .clipShape(RoundedRectangle(cornerRadius: 4))
+
+ HStack {
+ if templateChanges.contains(type) {
+ Text("Unsaved changes")
+ .font(.caption)
+ .foregroundStyle(.orange)
+ }
+
+ Spacer()
+
+ Button("Reset to Default") {
+ showingResetConfirm = type
+ }
+ .buttonStyle(.plain)
+ .foregroundStyle(.red)
+ .font(.caption)
+
+ Button("Save") {
+ saveTemplate(type)
+ }
+ .buttonStyle(.borderedProminent)
+ .controlSize(.small)
+ .disabled(!templateChanges.contains(type))
+ }
+ }
+ .confirmationDialog(
+ "Reset Template?",
+ isPresented: Binding(
+ get: { showingResetConfirm == type },
+ set: { if !$0 { showingResetConfirm = nil } }
+ ),
+ titleVisibility: .visible
+ ) {
+ Button("Reset to Default", role: .destructive) {
+ templateManager.resetToDefault(type)
+ loadTemplate(type)
+ }
+ Button("Cancel", role: .cancel) {}
+ } message: {
+ Text("This will replace your custom template with the default version.")
+ }
+ }
+
+ // MARK: - Template Helpers
+
+ private func loadAllTemplates() {
+ for type in WizardTemplateType.allCases {
+ loadTemplate(type)
+ }
+ }
+
+ private func loadTemplate(_ type: WizardTemplateType) {
+ if let template = templateManager.template(for: type) {
+ templateContents[type] = template.content
+ }
+ templateChanges.remove(type)
+ }
+
+ private func saveTemplate(_ type: WizardTemplateType) {
+ guard let content = templateContents[type] else { return }
+ let template = WizardTemplate(
+ type: type,
+ content: content,
+ lastModified: Date()
+ )
+ templateManager.save(template)
+ templateChanges.remove(type)
+ }
}
// MARK: - Agent Row
@@ -86,7 +242,7 @@ private struct AgentRow: View {
))
.labelsHidden()
}
- .padding(.vertical, 2)
+ .padding(.vertical, 4)
}
}
@@ -94,5 +250,5 @@ private struct AgentRow: View {
#Preview {
ACPSettingsView()
- .frame(width: 500, height: 500)
+ .frame(width: 480)
}
diff --git a/Chops/Views/Settings/LibrarySettingsView.swift b/Chops/Views/Settings/LibrarySettingsView.swift
new file mode 100644
index 0000000..00af6f1
--- /dev/null
+++ b/Chops/Views/Settings/LibrarySettingsView.swift
@@ -0,0 +1,68 @@
+import SwiftUI
+
+/// Settings for the source-of-truth directory used when symlinking library items.
+struct LibrarySettingsView: View {
+ @AppStorage("sotDir") private var sotDir = FileManager.default.homeDirectoryForCurrentUser.path + "/.chops"
+ @AppStorage("includePluginSkills") private var includePluginSkills = false
+
+ var body: some View {
+ VStack(alignment: .leading, spacing: 16) {
+ VStack(alignment: .leading, spacing: 4) {
+ Toggle("Include plugin skills", isOn: $includePluginSkills)
+ .onChange(of: includePluginSkills) {
+ NotificationCenter.default.post(name: .customScanPathsChanged, object: nil)
+ }
+ Text("When enabled, skills installed by Claude CLI and Claude Desktop plugins are listed in the library. These are read-only and managed by the plugin.")
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ }
+ }
+ .padding()
+ }
+
+ private var displayPath: String {
+ let home = FileManager.default.homeDirectoryForCurrentUser.path
+ return sotDir.hasPrefix(home) ? "~" + sotDir.dropFirst(home.count) : sotDir
+ }
+}
+
+private struct DirectoryPickerRow: View {
+ let label: String
+ @Binding var path: String
+
+ var body: some View {
+ HStack {
+ VStack(alignment: .leading, spacing: 2) {
+ Text(label)
+ Text(displayPath)
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ .lineLimit(1)
+ .truncationMode(.middle)
+ }
+
+ Spacer()
+
+ Button("Choose...") {
+ pickDirectory()
+ }
+ }
+ }
+
+ private var displayPath: String {
+ let home = FileManager.default.homeDirectoryForCurrentUser.path
+ return path.hasPrefix(home) ? "~" + path.dropFirst(home.count) : path
+ }
+
+ private func pickDirectory() {
+ let panel = NSOpenPanel()
+ panel.canChooseFiles = false
+ panel.canChooseDirectories = true
+ panel.allowsMultipleSelection = false
+ panel.showsHiddenFiles = true
+ panel.prompt = "Select"
+ panel.directoryURL = URL(fileURLWithPath: (path as NSString).expandingTildeInPath)
+ guard panel.runModal() == .OK, let url = panel.url else { return }
+ path = url.path
+ }
+}
diff --git a/Chops/Views/Settings/SettingsView.swift b/Chops/Views/Settings/SettingsView.swift
index 1ec04b0..ae19559 100644
--- a/Chops/Views/Settings/SettingsView.swift
+++ b/Chops/Views/Settings/SettingsView.swift
@@ -5,55 +5,103 @@ extension Notification.Name {
static let customScanPathsChanged = Notification.Name("customScanPathsChanged")
}
+// MARK: - Settings Tab Definition
+
+enum SettingsTab: String, CaseIterable, Identifiable {
+ case general, library, aiAssist, scanDirs, servers, about
+
+ var id: String { rawValue }
+
+ var title: String {
+ switch self {
+ case .general: "General"
+ case .library: "Library"
+ case .aiAssist: "AI Assist"
+ case .scanDirs: "Scan Directories"
+ case .servers: "Servers"
+ case .about: "About"
+ }
+ }
+
+ var icon: String {
+ switch self {
+ case .general: "gearshape"
+ case .library: "books.vertical"
+ case .aiAssist: "sparkles"
+ case .scanDirs: "folder.badge.gearshape"
+ case .servers: "server.rack"
+ case .about: "info.circle"
+ }
+ }
+}
+
+// MARK: - Settings View
+
struct SettingsView: View {
private static let logger = AppLogger.settings
let updater: SPUUpdater
+ @State private var selectedTab: SettingsTab = .general
@State private var customPaths: [String] = []
- @State private var defaultTool: ToolSource = .claude
+ @AppStorage("defaultTool") private var defaultTool: ToolSource = .claude
var body: some View {
- TabView {
- generalSettings
- .tabItem {
- Label("General", systemImage: "gearshape")
- }
-
- ACPSettingsView()
- .tabItem {
- Label("AI Assist", systemImage: "sparkles")
- }
-
- scanSettings
- .tabItem {
- Label("Scan Directories", systemImage: "folder.badge.gearshape")
+ VStack(spacing: 0) {
+ // Tab bar
+ HStack(spacing: 1) {
+ ForEach(SettingsTab.allCases) { tab in
+ SettingsTabButton(tab: tab, isSelected: selectedTab == tab) {
+ selectedTab = tab
+ }
}
+ }
+ .padding(.horizontal, 12)
+ .padding(.top, 8)
+ .padding(.bottom, 4)
- RemoteServersSettingsView()
- .tabItem {
- Label("Servers", systemImage: "server.rack")
- }
+ Divider()
- aboutView
- .tabItem {
- Label("About", systemImage: "info.circle")
- }
+ // Tab content — each pane sizes itself, no outer ScrollView
+ tabContent
+ .frame(maxWidth: .infinity, alignment: .leading)
}
- .frame(minWidth: 480, maxWidth: 480, minHeight: 300)
+ .frame(width: 520)
+ .fixedSize(horizontal: false, vertical: true)
.onAppear {
loadCustomPaths()
}
}
+ @ViewBuilder
+ private var tabContent: some View {
+ switch selectedTab {
+ case .general:
+ generalSettings
+ case .library:
+ LibrarySettingsView()
+ case .aiAssist:
+ ACPSettingsView()
+ case .scanDirs:
+ scanSettings
+ case .servers:
+ RemoteServersSettingsView()
+ case .about:
+ aboutView
+ }
+ }
+
private var generalSettings: some View {
- Form {
+ VStack(alignment: .leading, spacing: 12) {
+ Text("General")
+ .font(.headline)
+
Picker("Default tool", selection: $defaultTool) {
ForEach(ToolSource.allCases) { tool in
Text(tool.displayName).tag(tool)
}
}
+ .frame(maxWidth: 300)
}
- .formStyle(.grouped)
.padding()
}
@@ -66,27 +114,40 @@ struct SettingsView: View {
.font(.caption)
.foregroundStyle(.secondary)
- List {
- ForEach(customPaths, id: \.self) { path in
- HStack {
- Image(systemName: "folder")
- Text(path)
- .font(.system(.body, design: .monospaced))
- .lineLimit(1)
- .truncationMode(.middle)
- Spacer()
- Button {
- customPaths.removeAll { $0 == path }
- saveCustomPaths()
- } label: {
- Image(systemName: "minus.circle.fill")
- .foregroundStyle(.red)
+ if !customPaths.isEmpty {
+ VStack(spacing: 0) {
+ ForEach(customPaths, id: \.self) { path in
+ HStack {
+ Image(systemName: "folder")
+ Text(path)
+ .font(.system(.body, design: .monospaced))
+ .lineLimit(1)
+ .truncationMode(.middle)
+ Spacer()
+ Button {
+ customPaths.removeAll { $0 == path }
+ saveCustomPaths()
+ } label: {
+ Image(systemName: "minus.circle.fill")
+ .foregroundStyle(.red)
+ }
+ .buttonStyle(.plain)
+ }
+ .padding(.vertical, 6)
+ .padding(.horizontal, 8)
+
+ if path != customPaths.last {
+ Divider()
}
- .buttonStyle(.plain)
}
}
+ .background(Color(NSColor.controlBackgroundColor))
+ .clipShape(RoundedRectangle(cornerRadius: 6))
+ } else {
+ Text("No custom directories added.")
+ .foregroundStyle(.secondary)
+ .font(.callout)
}
- .frame(minHeight: 120)
HStack {
Spacer()
@@ -110,19 +171,12 @@ struct SettingsView: View {
private var aboutView: some View {
VStack(spacing: 16) {
- Image("tool-claude") // App icon from asset catalog
- .resizable()
- .aspectRatio(contentMode: .fit)
- .frame(width: 80, height: 80)
- .opacity(0) // Hidden — use the actual app icon instead
- .overlay {
- if let icon = NSApp.applicationIconImage {
- Image(nsImage: icon)
- .resizable()
- .aspectRatio(contentMode: .fit)
- .frame(width: 80, height: 80)
- }
- }
+ if let icon = NSApp.applicationIconImage {
+ Image(nsImage: icon)
+ .resizable()
+ .aspectRatio(contentMode: .fit)
+ .frame(width: 80, height: 80)
+ }
Text("Chops")
.font(.title)
@@ -142,15 +196,15 @@ struct SettingsView: View {
}
Button("Website") {
- NSWorkspace.shared.open(URL(string: "https://chops.md")!)
+ if let url = URL(string: "https://chops.md") { NSWorkspace.shared.open(url) }
}
Button("@Shpigford") {
- NSWorkspace.shared.open(URL(string: "https://x.com/Shpigford")!)
+ if let url = URL(string: "https://x.com/Shpigford") { NSWorkspace.shared.open(url) }
}
Button("GitHub") {
- NSWorkspace.shared.open(URL(string: "https://github.com/Shpigford/chops")!)
+ if let url = URL(string: "https://github.com/Shpigford/chops") { NSWorkspace.shared.open(url) }
}
}
@@ -158,7 +212,8 @@ struct SettingsView: View {
.font(.caption)
.foregroundStyle(.tertiary)
}
- .frame(maxWidth: .infinity, maxHeight: .infinity)
+ .frame(maxWidth: .infinity)
+ .padding(.vertical, 30)
}
private var appVersion: String {
@@ -176,3 +231,32 @@ struct SettingsView: View {
NotificationCenter.default.post(name: .customScanPathsChanged, object: nil)
}
}
+
+// MARK: - Tab Button
+
+private struct SettingsTabButton: View {
+ let tab: SettingsTab
+ let isSelected: Bool
+ let action: () -> Void
+
+ var body: some View {
+ Button(action: action) {
+ VStack(spacing: 2) {
+ Image(systemName: tab.icon)
+ .font(.system(size: 16))
+ .frame(height: 20)
+ Text(tab.title)
+ .font(.caption2)
+ .lineLimit(1)
+ }
+ .frame(maxWidth: .infinity)
+ .padding(.vertical, 6)
+ .padding(.horizontal, 4)
+ .background(isSelected ? Color.accentColor.opacity(0.15) : Color.clear)
+ .clipShape(RoundedRectangle(cornerRadius: 6))
+ .contentShape(Rectangle())
+ }
+ .buttonStyle(.plain)
+ .foregroundStyle(isSelected ? .primary : .secondary)
+ }
+}
diff --git a/Chops/Views/Shared/ComposePanel.swift b/Chops/Views/Shared/ComposePanel.swift
index d920076..119c7a1 100644
--- a/Chops/Views/Shared/ComposePanel.swift
+++ b/Chops/Views/Shared/ComposePanel.swift
@@ -193,7 +193,7 @@ struct ComposePanel: View {
}
}
- @State private var configuration = ACPConfiguration.shared
+ private let configuration = ACPConfiguration.shared
private var noToolsConfiguredView: some View {
ZStack(alignment: .topTrailing) {
@@ -279,7 +279,7 @@ struct ComposePanel: View {
.frame(maxWidth: 200)
}
- // RIGHT: Config options (when connected) + close
+ // RIGHT: config options (when connected) + close
HStack(spacing: 8) {
inlineConfigOptions
closeButton
@@ -890,15 +890,23 @@ struct ComposePanel: View {
nonisolated private static func revertDiffOnDisk(_ diff: ChatDiff) {
let url = URL(fileURLWithPath: diff.path)
if diff.existedBefore {
- if let originalData = diff.originalData {
- try? originalData.write(to: url)
- } else if let original = diff.original {
- try? original.write(to: url, atomically: true, encoding: .utf8)
- } else {
- acpLog.error("Reject failed: missing original snapshot for \(diff.path)")
+ do {
+ if let originalData = diff.originalData {
+ try originalData.write(to: url)
+ } else if let original = diff.original {
+ try original.write(to: url, atomically: true, encoding: .utf8)
+ } else {
+ acpLog.error("Reject failed: missing original snapshot for \(diff.path)")
+ }
+ } catch {
+ acpLog.error("Reject failed writing \(diff.path): \(error.localizedDescription)")
}
} else {
- try? FileManager.default.removeItem(at: url)
+ do {
+ try FileManager.default.removeItem(at: url)
+ } catch {
+ acpLog.error("Reject failed removing \(diff.path): \(error.localizedDescription)")
+ }
}
}
diff --git a/Chops/Views/Shared/NewSkillSheet.swift b/Chops/Views/Shared/NewSkillSheet.swift
index 782607d..037946e 100644
--- a/Chops/Views/Shared/NewSkillSheet.swift
+++ b/Chops/Views/Shared/NewSkillSheet.swift
@@ -9,24 +9,27 @@ struct NewSkillSheet: View {
@State private var selectedTool: ToolSource = .claude
@State private var errorMessage: String?
- private let skillCreatableTools: [ToolSource] = [.claude, .agents, .cursor, .codex, .amp, .opencode, .pi, .antigravity]
- private let agentCreatableTools: [ToolSource] = [.claude, .cursor, .codex]
-
private var itemKind: ItemKind { appState.newItemKind }
- private var isAgent: Bool { itemKind == .agent }
private var creatableTools: [ToolSource] {
- isAgent ? agentCreatableTools : skillCreatableTools
+ switch itemKind {
+ case .skill:
+ return [.claude, .agents, .cursor, .codex, .amp, .opencode, .pi, .antigravity]
+ case .agent:
+ return ToolSource.allCases.filter { !$0.globalAgentPaths.isEmpty }
+ case .rule:
+ return ToolSource.allCases.filter { !$0.globalRulePaths.isEmpty }
+ }
}
var body: some View {
VStack(spacing: 20) {
- Text(isAgent ? "New Agent" : "New Skill")
+ Text("New \(itemKind.singularName)")
.font(.title2)
.fontWeight(.bold)
Form {
- TextField(isAgent ? "Agent name" : "Skill name", text: $skillName)
+ TextField("\(itemKind.singularName) name", text: $skillName)
.textFieldStyle(.roundedBorder)
Picker("Tool", selection: $selectedTool) {
@@ -90,46 +93,28 @@ struct NewSkillSheet: View {
let basePath: String
let fileName: String
- if isAgent {
- // Agents go into the tool's agents/ directory
- guard let agentDir = selectedTool.globalAgentPaths.first else {
+ switch itemKind {
+ case .agent:
+ guard let dir = selectedTool.globalAgentPaths.first else {
errorMessage = "This tool doesn't support agents"
return
}
- basePath = "\(agentDir)/\(sanitizedName)"
+ basePath = "\(dir)/\(sanitizedName)"
fileName = "\(sanitizedName).md"
- } else {
- // Skills use existing path logic
- switch selectedTool {
- case .claude:
- basePath = "\(fm.homeDirectoryForCurrentUser.path)/.claude/skills/\(sanitizedName)"
- fileName = "SKILL.md"
- case .agents:
- basePath = "\(fm.homeDirectoryForCurrentUser.path)/.agents/skills/\(sanitizedName)"
- fileName = "SKILL.md"
- case .cursor:
- basePath = "\(fm.homeDirectoryForCurrentUser.path)/.cursor/skills/\(sanitizedName)"
- fileName = "SKILL.md"
- case .codex:
- basePath = "\(fm.homeDirectoryForCurrentUser.path)/.codex/skills/\(sanitizedName)"
- fileName = "SKILL.md"
- case .amp:
- basePath = "\(configHome)/amp/skills/\(sanitizedName)"
- fileName = "SKILL.md"
- case .opencode:
- basePath = "\(configHome)/opencode/skills/\(sanitizedName)"
- fileName = "SKILL.md"
- case .pi:
- basePath = "\(fm.homeDirectoryForCurrentUser.path)/.pi/agent/skills/\(sanitizedName)"
- fileName = "SKILL.md"
- case .antigravity:
- basePath = "\(fm.homeDirectoryForCurrentUser.path)/.gemini/antigravity/skills/\(sanitizedName)"
- fileName = "SKILL.md"
- default:
- let firstPath = selectedTool.globalPaths.first ?? "\(fm.homeDirectoryForCurrentUser.path)/.claude/skills/\(sanitizedName)"
- basePath = firstPath
- fileName = "SKILL.md"
+ case .rule:
+ guard let dir = selectedTool.globalRulePaths.first else {
+ errorMessage = "This tool doesn't support rules"
+ return
}
+ basePath = dir
+ fileName = "\(sanitizedName).md"
+ case .skill:
+ guard let dir = selectedTool.globalPaths.first else {
+ errorMessage = "This tool doesn't support skills"
+ return
+ }
+ basePath = "\(dir)/\(sanitizedName)"
+ fileName = "SKILL.md"
}
do {
@@ -138,7 +123,7 @@ struct NewSkillSheet: View {
let filePath = "\(basePath)/\(fileName)"
guard !fm.fileExists(atPath: filePath) else {
- errorMessage = isAgent ? "An agent with this name already exists" : "A skill with this name already exists"
+ errorMessage = "A \(itemKind.singularName.lowercased()) with this name already exists"
return
}
@@ -149,7 +134,7 @@ struct NewSkillSheet: View {
let skill = Skill(
filePath: filePath,
toolSource: selectedTool,
- isDirectory: true,
+ isDirectory: itemKind != .rule,
name: skillName,
skillDescription: parsed.description,
content: parsed.content,
@@ -163,6 +148,11 @@ struct NewSkillSheet: View {
modelContext.insert(skill)
try modelContext.save()
+ switch itemKind {
+ case .skill: appState.sidebarFilter = .allSkills
+ case .agent: appState.sidebarFilter = .allAgents
+ case .rule: appState.sidebarFilter = .allRules
+ }
appState.selectedSkill = skill
dismiss()
} catch {
@@ -171,7 +161,8 @@ struct NewSkillSheet: View {
}
private func generateBoilerplate(name: String, skillID: String, tool: ToolSource) -> String {
- if isAgent {
+ switch itemKind {
+ case .agent:
return """
---
name: \(skillID)
@@ -184,50 +175,45 @@ struct NewSkillSheet: View {
Add your agent instructions here.
"""
- }
-
- switch tool {
- case .claude, .cursor:
+ case .rule:
return """
- ---
- name: \(skillID)
- description: \(name)
- ---
-
# \(name)
- ## When to Use
+ Add your rule content here.
+ """
+ case .skill:
+ switch tool {
+ case .claude, .cursor:
+ return """
+ ---
+ name: \(skillID)
+ description: \(name)
+ ---
- - Describe when this skill should be activated
+ # \(name)
- ## Instructions
+ ## When to Use
- Add your skill instructions here.
- """
- case .codex, .amp, .opencode, .pi, .agents, .antigravity:
- return """
- ---
- name: \(skillID)
- description: \(name)
- ---
+ - Describe when this skill should be activated
- # \(name)
+ ## Instructions
- ## Instructions
+ Add your skill instructions here.
+ """
+ default:
+ return """
+ ---
+ name: \(skillID)
+ description: \(name)
+ ---
- Add your skill instructions here.
- """
- default:
- return """
- ---
- name: \(skillID)
- description: \(name)
- ---
+ # \(name)
- # \(name)
+ ## Instructions
- Add your skill instructions here.
- """
+ Add your skill instructions here.
+ """
+ }
}
}
}
diff --git a/Chops/Views/Sidebar/SidebarView.swift b/Chops/Views/Sidebar/SidebarView.swift
index 4818745..45181d0 100644
--- a/Chops/Views/Sidebar/SidebarView.swift
+++ b/Chops/Views/Sidebar/SidebarView.swift
@@ -26,10 +26,18 @@ struct SidebarView: View {
List(selection: $appState.sidebarFilter) {
Section("Library") {
- Label("All Skills", systemImage: "doc.text")
- .badge(allSkills.count)
+ Label("Skills", systemImage: "doc.text")
+ .badge(allSkills.filter { $0.itemKind == .skill }.count)
.tag(SidebarFilter.allSkills)
+ Label("Agents", systemImage: "person.crop.rectangle")
+ .badge(allSkills.filter { $0.itemKind == .agent }.count)
+ .tag(SidebarFilter.allAgents)
+
+ Label("Rules", systemImage: "list.bullet.rectangle")
+ .badge(allSkills.filter { $0.itemKind == .rule }.count)
+ .tag(SidebarFilter.allRules)
+
Label("Favorites", systemImage: "star")
.badge(allSkills.filter(\.isFavorite).count)
.tag(SidebarFilter.favorites)
@@ -47,13 +55,6 @@ struct SidebarView: View {
}
}
- Section("Wizard Templates") {
- ForEach(WizardTemplateType.allCases) { templateType in
- Label(templateType.displayName, systemImage: templateType.icon)
- .tag(SidebarFilter.wizardTemplate(templateType))
- }
- }
-
if !servers.isEmpty {
Section("Servers") {
ForEach(servers) { server in
@@ -119,7 +120,7 @@ struct SidebarView: View {
syncingServerIDs.insert(server.id)
serverErrors.removeValue(forKey: server.id)
let context = modelContext
- Task { @MainActor in
+ Task {
let scanner = SkillScanner(modelContext: context)
await scanner.scanRemoteServer(server)
syncingServerIDs.remove(server.id)
diff --git a/Chops/Views/Sidebar/SkillListView.swift b/Chops/Views/Sidebar/SkillListView.swift
index ee7a05d..88b7702 100644
--- a/Chops/Views/Sidebar/SkillListView.swift
+++ b/Chops/Views/Sidebar/SkillListView.swift
@@ -30,18 +30,21 @@ struct SkillListView: View {
result = result.filter { $0.itemKind == .skill }
case .allAgents:
result = result.filter { $0.itemKind == .agent }
+ case .allRules:
+ result = result.filter { $0.itemKind == .rule }
case .favorites:
result = result.filter { $0.isFavorite }
case .tool(let tool):
result = result.filter { $0.toolSources.contains(tool) }
+ if let kind = appState.toolKindFilter {
+ result = result.filter { $0.itemKind == kind }
+ }
case .collection(let collName):
result = result.filter { skill in
skill.collections.contains { $0.name == collName }
}
case .server(let serverID):
result = result.filter { $0.remoteServer?.id == serverID }
- case .wizardTemplate:
- result = []
}
if !appState.searchText.isEmpty {
@@ -57,25 +60,92 @@ struct SkillListView: View {
private var title: String {
switch appState.sidebarFilter {
- case .allSkills: "All Skills"
- case .allAgents: "All Agents"
+ case .allSkills: "Skills"
+ case .allAgents: "Agents"
+ case .allRules: "Rules"
case .favorites: "Favorites"
case .tool(let tool): tool.displayName
case .collection(let name): name
case .server(let id):
allSkills.first(where: { $0.remoteServer?.id == id })?.remoteServer?.label ?? "Remote"
- case .wizardTemplate(let templateType): templateType.displayName
}
}
/// Whether the current filter shows mixed item types (skills and agents together)
private var showsTypeBadge: Bool {
switch appState.sidebarFilter {
- case .allSkills, .allAgents: false
+ case .allSkills, .allAgents, .allRules: false
+ case .tool: appState.toolKindFilter == nil
default: true
}
}
+ private var availableKinds: [ItemKind] {
+ guard case .tool(let tool) = appState.sidebarFilter else { return [] }
+ let kinds = Set(allSkills.filter { $0.toolSources.contains(tool) }.map(\.itemKind))
+ return ItemKind.allCases.filter { kinds.contains($0) }
+ }
+
+ @ViewBuilder
+ private var emptyStateView: some View {
+ if let kind = appState.toolKindFilter {
+ ContentUnavailableView(
+ "No \(kind.displayName)",
+ systemImage: kind.icon,
+ description: Text("No \(kind.displayName.lowercased()) match the current filter.")
+ )
+ } else {
+ switch appState.sidebarFilter {
+ case .allAgents:
+ ContentUnavailableView("No Agents", systemImage: "person.crop.rectangle",
+ description: Text("No agents match the current filter."))
+ case .allRules:
+ ContentUnavailableView("No Rules", systemImage: "list.bullet.rectangle",
+ description: Text("No rules match the current filter."))
+ default:
+ ContentUnavailableView("No Skills", systemImage: "doc.text",
+ description: Text("No skills match the current filter."))
+ }
+ }
+ }
+
+ @ViewBuilder
+ private func contextMenu(for skill: Skill) -> some View {
+ Button(skill.isFavorite ? "Unfavorite" : "Favorite") {
+ skill.isFavorite.toggle()
+ try? modelContext.save()
+ }
+ if !allCollections.isEmpty {
+ Menu("Collections") {
+ ForEach(allCollections) { collection in
+ let isAssigned = skill.collections.contains(where: { $0.name == collection.name })
+ Button {
+ if isAssigned {
+ skill.collections.removeAll { $0.name == collection.name }
+ } else {
+ skill.collections.append(collection)
+ }
+ try? modelContext.save()
+ } label: {
+ Toggle(isOn: .constant(isAssigned)) {
+ Label(collection.name, systemImage: collection.icon)
+ }
+ }
+ }
+ }
+ }
+ if !skill.isRemote {
+ Divider()
+ Button("Show in Finder") {
+ NSWorkspace.shared.selectFile(skill.filePath, inFileViewerRootedAtPath: "")
+ }
+ }
+ Divider()
+ Button("Delete", role: .destructive) {
+ activeAlert = .confirmDelete(skill)
+ }
+ }
+
private func deleteSkill(_ skill: Skill) {
do {
try skill.deleteFromDisk()
@@ -97,44 +167,72 @@ struct SkillListView: View {
SkillRow(skill: skill, showTypeBadge: showsTypeBadge)
.tag(skill)
.draggable(skill.resolvedPath)
- .contextMenu {
- Button(skill.isFavorite ? "Unfavorite" : "Favorite") {
- skill.isFavorite.toggle()
- try? modelContext.save()
- }
- if !allCollections.isEmpty {
- Menu("Collections") {
- ForEach(allCollections) { collection in
- let isAssigned = skill.collections.contains(where: { $0.name == collection.name })
- Button {
- if isAssigned {
- skill.collections.removeAll { $0.name == collection.name }
- } else {
- skill.collections.append(collection)
- }
- try? modelContext.save()
- } label: {
- Toggle(isOn: .constant(isAssigned)) {
- Label(collection.name, systemImage: collection.icon)
- }
- }
+ .contextMenu { contextMenu(for: skill) }
+ }
+ }
+ .navigationTitle(title)
+ .toolbar {
+ ToolbarItem(placement: .primaryAction) {
+ HStack(spacing: 4) {
+ if case .tool = appState.sidebarFilter, availableKinds.count > 1 {
+ Menu {
+ Button {
+ appState.toolKindFilter = nil
+ } label: {
+ if appState.toolKindFilter == nil {
+ Label("All", systemImage: "checkmark")
+ } else {
+ Text("All")
}
}
- }
- if !skill.isRemote {
Divider()
- Button("Show in Finder") {
- NSWorkspace.shared.selectFile(skill.filePath, inFileViewerRootedAtPath: "")
+ ForEach(availableKinds, id: \.self) { kind in
+ Button {
+ appState.toolKindFilter = kind
+ } label: {
+ if appState.toolKindFilter == kind {
+ Label(kind.displayName, systemImage: "checkmark")
+ } else {
+ Text(kind.displayName)
+ }
+ }
}
+ } label: {
+ Image(systemName: appState.toolKindFilter != nil ? "ellipsis.circle.fill" : "ellipsis.circle")
+ }
+ }
+ Menu {
+ Button {
+ appState.newItemKind = .skill
+ appState.showingNewSkillSheet = true
+ } label: {
+ Label("New Skill", systemImage: "doc.text")
+ }
+ Button {
+ appState.newItemKind = .agent
+ appState.showingNewSkillSheet = true
+ } label: {
+ Label("New Agent", systemImage: "person.crop.rectangle")
+ }
+ Button {
+ appState.newItemKind = .rule
+ appState.showingNewSkillSheet = true
+ } label: {
+ Label("New Rule", systemImage: "list.bullet.rectangle")
}
Divider()
- Button("Delete", role: .destructive) {
- activeAlert = .confirmDelete(skill)
+ Button {
+ appState.showingRegistrySheet = true
+ } label: {
+ Label("Browse Registry", systemImage: "globe")
}
+ } label: {
+ Image(systemName: "square.and.pencil")
}
+ .menuIndicator(.hidden)
+ }
}
}
- .navigationTitle(title)
.alert(item: $activeAlert) { alert in
switch alert {
case .confirmDelete(let skill):
@@ -155,14 +253,13 @@ struct SkillListView: View {
}
}
.overlay {
- if filteredSkills.isEmpty {
- ContentUnavailableView(
- appState.sidebarFilter == .allAgents ? "No Agents" : "No Skills",
- systemImage: appState.sidebarFilter == .allAgents ? "person.crop.rectangle" : "doc.text",
- description: Text(appState.sidebarFilter == .allAgents
- ? "No agents match the current filter."
- : "No skills match the current filter.")
- )
+ if filteredSkills.isEmpty { emptyStateView }
+ }
+ .onChange(of: appState.sidebarFilter) {
+ if let selected = appState.selectedSkill, filteredSkills.contains(selected) {
+ // Already selected something valid in this filter
+ } else {
+ appState.selectedSkill = filteredSkills.first
}
}
}
@@ -175,7 +272,12 @@ struct SkillRow: View {
var body: some View {
HStack(spacing: 6) {
if showTypeBadge {
- Image(systemName: skill.itemKind == .agent ? "person.crop.rectangle" : "doc.text")
+ let kindIcon: String = switch skill.itemKind {
+ case .agent: "person.crop.rectangle"
+ case .rule: "list.bullet.rectangle"
+ case .skill: "doc.text"
+ }
+ Image(systemName: kindIcon)
.font(.caption2)
.foregroundStyle(.secondary)
}