skill-seekers 2.7.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. skill_seekers/__init__.py +22 -0
  2. skill_seekers/cli/__init__.py +39 -0
  3. skill_seekers/cli/adaptors/__init__.py +120 -0
  4. skill_seekers/cli/adaptors/base.py +221 -0
  5. skill_seekers/cli/adaptors/claude.py +485 -0
  6. skill_seekers/cli/adaptors/gemini.py +453 -0
  7. skill_seekers/cli/adaptors/markdown.py +269 -0
  8. skill_seekers/cli/adaptors/openai.py +503 -0
  9. skill_seekers/cli/ai_enhancer.py +310 -0
  10. skill_seekers/cli/api_reference_builder.py +373 -0
  11. skill_seekers/cli/architectural_pattern_detector.py +525 -0
  12. skill_seekers/cli/code_analyzer.py +1462 -0
  13. skill_seekers/cli/codebase_scraper.py +1225 -0
  14. skill_seekers/cli/config_command.py +563 -0
  15. skill_seekers/cli/config_enhancer.py +431 -0
  16. skill_seekers/cli/config_extractor.py +871 -0
  17. skill_seekers/cli/config_manager.py +452 -0
  18. skill_seekers/cli/config_validator.py +394 -0
  19. skill_seekers/cli/conflict_detector.py +528 -0
  20. skill_seekers/cli/constants.py +72 -0
  21. skill_seekers/cli/dependency_analyzer.py +757 -0
  22. skill_seekers/cli/doc_scraper.py +2332 -0
  23. skill_seekers/cli/enhance_skill.py +488 -0
  24. skill_seekers/cli/enhance_skill_local.py +1096 -0
  25. skill_seekers/cli/enhance_status.py +194 -0
  26. skill_seekers/cli/estimate_pages.py +433 -0
  27. skill_seekers/cli/generate_router.py +1209 -0
  28. skill_seekers/cli/github_fetcher.py +534 -0
  29. skill_seekers/cli/github_scraper.py +1466 -0
  30. skill_seekers/cli/guide_enhancer.py +723 -0
  31. skill_seekers/cli/how_to_guide_builder.py +1267 -0
  32. skill_seekers/cli/install_agent.py +461 -0
  33. skill_seekers/cli/install_skill.py +178 -0
  34. skill_seekers/cli/language_detector.py +614 -0
  35. skill_seekers/cli/llms_txt_detector.py +60 -0
  36. skill_seekers/cli/llms_txt_downloader.py +104 -0
  37. skill_seekers/cli/llms_txt_parser.py +150 -0
  38. skill_seekers/cli/main.py +558 -0
  39. skill_seekers/cli/markdown_cleaner.py +132 -0
  40. skill_seekers/cli/merge_sources.py +806 -0
  41. skill_seekers/cli/package_multi.py +77 -0
  42. skill_seekers/cli/package_skill.py +241 -0
  43. skill_seekers/cli/pattern_recognizer.py +1825 -0
  44. skill_seekers/cli/pdf_extractor_poc.py +1166 -0
  45. skill_seekers/cli/pdf_scraper.py +617 -0
  46. skill_seekers/cli/quality_checker.py +519 -0
  47. skill_seekers/cli/rate_limit_handler.py +438 -0
  48. skill_seekers/cli/resume_command.py +160 -0
  49. skill_seekers/cli/run_tests.py +230 -0
  50. skill_seekers/cli/setup_wizard.py +93 -0
  51. skill_seekers/cli/split_config.py +390 -0
  52. skill_seekers/cli/swift_patterns.py +560 -0
  53. skill_seekers/cli/test_example_extractor.py +1081 -0
  54. skill_seekers/cli/test_unified_simple.py +179 -0
  55. skill_seekers/cli/unified_codebase_analyzer.py +572 -0
  56. skill_seekers/cli/unified_scraper.py +932 -0
  57. skill_seekers/cli/unified_skill_builder.py +1605 -0
  58. skill_seekers/cli/upload_skill.py +162 -0
  59. skill_seekers/cli/utils.py +432 -0
  60. skill_seekers/mcp/__init__.py +33 -0
  61. skill_seekers/mcp/agent_detector.py +316 -0
  62. skill_seekers/mcp/git_repo.py +273 -0
  63. skill_seekers/mcp/server.py +231 -0
  64. skill_seekers/mcp/server_fastmcp.py +1249 -0
  65. skill_seekers/mcp/server_legacy.py +2302 -0
  66. skill_seekers/mcp/source_manager.py +285 -0
  67. skill_seekers/mcp/tools/__init__.py +115 -0
  68. skill_seekers/mcp/tools/config_tools.py +251 -0
  69. skill_seekers/mcp/tools/packaging_tools.py +826 -0
  70. skill_seekers/mcp/tools/scraping_tools.py +842 -0
  71. skill_seekers/mcp/tools/source_tools.py +828 -0
  72. skill_seekers/mcp/tools/splitting_tools.py +212 -0
  73. skill_seekers/py.typed +0 -0
  74. skill_seekers-2.7.3.dist-info/METADATA +2027 -0
  75. skill_seekers-2.7.3.dist-info/RECORD +79 -0
  76. skill_seekers-2.7.3.dist-info/WHEEL +5 -0
  77. skill_seekers-2.7.3.dist-info/entry_points.txt +19 -0
  78. skill_seekers-2.7.3.dist-info/licenses/LICENSE +21 -0
  79. skill_seekers-2.7.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,560 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Swift Language Detection Patterns
4
+
5
+ Comprehensive regex patterns for detecting Swift code including:
6
+ - Pure Swift syntax (structs, protocols, extensions, optionals, generics)
7
+ - iOS/UIKit patterns (UIViewController, IBOutlet, lifecycle methods)
8
+ - macOS/AppKit patterns (NSViewController, NSWindow, AppKit classes)
9
+ - SwiftUI patterns (@State, @Binding, View protocol, modifiers)
10
+ - Combine framework patterns (Publishers, Subscribers)
11
+ - Swift Concurrency (async/await, actors, Tasks)
12
+ - Foundation Models (iOS/macOS 26+: @Generable, LanguageModelSession, SystemLanguageModel)
13
+
14
+ Weight Scale:
15
+ - 5: Unique to Swift (no other language uses this)
16
+ - 4: Strong Swift indicator (rarely seen elsewhere)
17
+ - 3: Common Swift pattern (moderate indicator)
18
+ - 2: Moderate indicator (seen in some other languages)
19
+ - 1: Weak indicator (commonly seen elsewhere)
20
+
21
+ Author: iLearn Project (Swift Support Extension)
22
+ """
23
+
24
+ import logging
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+ SWIFT_PATTERNS: dict[str, list[tuple[str, int]]] = {
29
+ "swift": [
30
+ # ===== PURE SWIFT SYNTAX (Weight 4-5) =====
31
+ # Function declarations with return type arrow (Swift-specific syntax)
32
+ (r"\bfunc\s+\w+\s*\([^)]*\)\s*->", 5), # func foo() -> ReturnType
33
+ (r"\bfunc\s+\w+\s*\([^)]*\)\s*\{", 4), # func foo() {
34
+ # Struct/class/enum declarations
35
+ (r"\bstruct\s+\w+\s*:", 5), # struct Foo: Protocol
36
+ (r"\bstruct\s+\w+\s*\{", 4), # struct Foo {
37
+ (r"\bclass\s+\w+\s*:\s*\w+", 4), # class Foo: SuperClass
38
+ (r"\benum\s+\w+\s*:\s*\w+", 4), # enum Foo: String
39
+ (r"\benum\s+\w+\s*\{", 3), # enum Foo {
40
+ # Protocol declarations (weight 5 - Swift-specific in this context)
41
+ (r"\bprotocol\s+\w+\s*\{", 5), # protocol Foo {
42
+ (r"\bprotocol\s+\w+\s*:\s*\w+", 5), # protocol Foo: AnotherProtocol
43
+ # Extension (weight 5 - very Swift-specific syntax)
44
+ (r"\bextension\s+\w+\s*:", 5), # extension Foo: Protocol
45
+ (r"\bextension\s+\w+\s*\{", 5), # extension Foo {
46
+ (r"\bextension\s+\w+\s*where\s+", 5), # extension Foo where T: Equatable
47
+ # Property wrappers (weight 5 - unique to Swift)
48
+ (r"@\w+\s+var\s+\w+", 4), # @Something var foo
49
+ (r"@propertyWrapper", 5), # @propertyWrapper attribute
50
+ # Optionals and unwrapping (weight 5 - unique to Swift)
51
+ (r"\bguard\s+let\s+\w+\s*=", 5), # guard let foo =
52
+ (r"\bguard\s+var\s+\w+\s*=", 5), # guard var foo =
53
+ (r"\bif\s+let\s+\w+\s*=", 5), # if let foo =
54
+ (r"\bif\s+var\s+\w+\s*=", 5), # if var foo =
55
+ (r"\bguard\s+.*\s+else\s*\{", 4), # guard ... else {
56
+ (r"\w+\?\.", 4), # foo?.bar (optional chaining)
57
+ (r"\w+!\.\w+", 4), # foo!.bar (forced unwrap)
58
+ (r"\?\?", 4), # nil coalescing ??
59
+ # Closures (weight 4-5 - Swift closure syntax)
60
+ (r"\{\s*\([^)]*\)\s*in\b", 5), # { (params) in
61
+ (r"\{\s*\$0", 4), # { $0 (shorthand argument)
62
+ (r"\$[0-9]+", 3), # $0, $1, etc.
63
+ # Type annotations (weight 3-4)
64
+ (r":\s*\[\w+\]", 4), # : [Type] (array type)
65
+ (r":\s*\[\w+\s*:\s*\w+\]", 4), # : [Key: Value] (dictionary type)
66
+ (r":\s*\w+\?", 4), # : Type? (optional type)
67
+ (r"->\s*\w+\?", 4), # -> Type? (optional return)
68
+ # Keywords (weight 2-4)
69
+ (r"\blet\s+\w+\s*:", 3), # let foo: Type
70
+ (r"\bvar\s+\w+\s*:", 3), # var foo: Type
71
+ (r"\blet\s+\w+\s*=", 2), # let foo = (also JS const)
72
+ (r"\bself\.\w+", 3), # self.property (also Python)
73
+ (r"\bSelf\b", 4), # Self (Swift-specific)
74
+ # Imports (weight 2-5 based on specificity)
75
+ (r"\bimport\s+Foundation", 4), # import Foundation
76
+ (r"\bimport\s+\w+", 2), # import Something
77
+ # Access modifiers (weight 3-5)
78
+ (r"\bprivate\s*\(set\)", 5), # private(set) - Swift-specific
79
+ (r"\bfileprivate\s+", 5), # fileprivate - Swift-only keyword
80
+ (r"\binternal\s+", 2), # internal (also C#)
81
+ (r"\bopen\s+class", 4), # open class (Swift-specific)
82
+ # Error handling (weight 4-5)
83
+ (r"\bthrows\s*->", 5), # throws -> ReturnType
84
+ (r"\bthrows\s*\{", 4), # func foo() throws {
85
+ (r"\brethrows\b", 5), # rethrows keyword (Swift-only)
86
+ (r"\btry\?\s+", 5), # try? (optional try - Swift)
87
+ (r"\btry!\s+", 5), # try! (forced try - Swift)
88
+ (r"\bdo\s*\{", 3), # do { (try block)
89
+ (r"\bcatch\s+\w+", 3), # catch error
90
+ # Generics (weight 3-4)
91
+ (r"<\w+:\s*\w+>", 4), # <T: Protocol>
92
+ (r"\bwhere\s+\w+\s*:", 4), # where T: Protocol
93
+ # NOTE: 'some' and 'any' require capitalized type names to avoid matching
94
+ # English prose ("some example", "any variable"). Swift types are capitalized
95
+ # by convention (View, Protocol, etc.). The (?-i:[A-Z]) syntax enforces
96
+ # case-sensitive matching for the first letter despite global IGNORECASE flag.
97
+ (r"\bsome\s+(?-i:[A-Z])\w+", 5), # some Protocol (opaque type - Swift 5.1+)
98
+ (r"\bany\s+(?-i:[A-Z])\w+", 4), # any Protocol (existential type - Swift 5.6+)
99
+ # Actors and concurrency (weight 5 - Swift 5.5+)
100
+ (r"\bactor\s+\w+", 5), # actor MyActor
101
+ (r"\basync\s+throws", 5), # async throws (Swift-specific combo)
102
+ (r"\basync\s+func", 5), # async func
103
+ (r"\bawait\s+\w+", 3), # await (also JS/Python/C#)
104
+ (r"\bTask\s*\{", 4), # Task { (Swift concurrency)
105
+ (r"\bTask\.\w+", 4), # Task.detached, Task.sleep
106
+ (r"@MainActor", 5), # @MainActor attribute
107
+ (r"@Sendable", 5), # @Sendable attribute
108
+ (r"\bnonisolated\b", 5), # nonisolated keyword
109
+ # Result builders (weight 5)
110
+ (r"@resultBuilder", 5), # @resultBuilder attribute
111
+ # Type aliases and associated types (weight 5)
112
+ (r"\btypealias\s+\w+\s*=", 5), # typealias Foo = Bar
113
+ (r"\bassociatedtype\s+\w+", 5), # associatedtype Element
114
+ # Print function
115
+ (r"\bprint\s*\(", 2), # print() (also Python)
116
+ # String interpolation (weight 4)
117
+ (r"\\\(\w+", 4), # \(variable) interpolation
118
+ # Memory management (weight 4-5)
119
+ (r"\bweak\s+var", 5), # weak var
120
+ (r"\bunowned\s+", 5), # unowned (Swift-specific)
121
+ (r"\[weak\s+self\]", 5), # [weak self] capture list
122
+ (r"\[unowned\s+self\]", 5), # [unowned self] capture list
123
+ (r"\blazy\s+var", 4), # lazy var
124
+ # ===== iOS/UIKit PATTERNS (Weight 4-5) =====
125
+ (r"\bimport\s+UIKit", 5), # import UIKit
126
+ (r"\bUIViewController\b", 5), # UIViewController class
127
+ (r"\bUIView\b", 4), # UIView class
128
+ (r"\bUITableView\b", 5), # UITableView
129
+ (r"\bUICollectionView\b", 5), # UICollectionView
130
+ (r"\bUINavigationController\b", 5), # UINavigationController
131
+ (r"\bUITabBarController\b", 5), # UITabBarController
132
+ (r"\bUIButton\b", 4), # UIButton
133
+ (r"\bUILabel\b", 4), # UILabel
134
+ (r"\bUIImageView\b", 4), # UIImageView
135
+ (r"\bUITextField\b", 4), # UITextField
136
+ (r"\bUITextView\b", 4), # UITextView
137
+ (r"\bUIStackView\b", 4), # UIStackView
138
+ (r"\bUIScrollView\b", 4), # UIScrollView
139
+ (r"\bUIAlertController\b", 5), # UIAlertController
140
+ (r"\bUIApplication\b", 5), # UIApplication
141
+ (r"\bUIWindow\b", 4), # UIWindow
142
+ (r"\bUIScreen\b", 4), # UIScreen
143
+ (r"\bUIDevice\b", 5), # UIDevice
144
+ # UIKit Lifecycle methods (weight 5)
145
+ (r"\bviewDidLoad\s*\(\s*\)", 5), # viewDidLoad()
146
+ (r"\bviewWillAppear\s*\(", 5), # viewWillAppear(_:)
147
+ (r"\bviewDidAppear\s*\(", 5), # viewDidAppear(_:)
148
+ (r"\bviewWillDisappear\s*\(", 5), # viewWillDisappear(_:)
149
+ (r"\bviewDidDisappear\s*\(", 5), # viewDidDisappear(_:)
150
+ (r"\bviewWillLayoutSubviews\s*\(\)", 5), # viewWillLayoutSubviews()
151
+ (r"\bviewDidLayoutSubviews\s*\(\)", 5), # viewDidLayoutSubviews()
152
+ # Interface Builder outlets/actions (weight 5)
153
+ (r"@IBOutlet", 5), # @IBOutlet
154
+ (r"@IBAction", 5), # @IBAction
155
+ (r"@IBDesignable", 5), # @IBDesignable
156
+ (r"@IBInspectable", 5), # @IBInspectable
157
+ # UIKit delegates and datasources (weight 5)
158
+ (r"\bUITableViewDelegate\b", 5),
159
+ (r"\bUITableViewDataSource\b", 5),
160
+ (r"\bUICollectionViewDelegate\b", 5),
161
+ (r"\bUICollectionViewDataSource\b", 5),
162
+ (r"\bUITextFieldDelegate\b", 5),
163
+ (r"\bUIScrollViewDelegate\b", 5),
164
+ # Auto Layout (weight 4-5)
165
+ (r"\bNSLayoutConstraint\b", 5), # NSLayoutConstraint
166
+ (r"\.constraint\(", 4), # constraint methods
167
+ (r"\btranslatesAutoresizingMaskIntoConstraints", 5),
168
+ (r"NSLayoutConstraint\.activate", 5),
169
+ # GCD / DispatchQueue (weight 5)
170
+ (r"\bDispatchQueue\b", 5), # DispatchQueue
171
+ (r"\bDispatchQueue\.main", 5), # DispatchQueue.main
172
+ (r"\bDispatchQueue\.global", 5), # DispatchQueue.global
173
+ (r"\.async\s*\{", 4), # .async {
174
+ (r"\.sync\s*\{", 4), # .sync {
175
+ # ===== macOS/AppKit PATTERNS (Weight 4-5) =====
176
+ (r"\bimport\s+AppKit", 5), # import AppKit
177
+ (r"\bimport\s+Cocoa", 5), # import Cocoa
178
+ (r"\bNSViewController\b", 5), # NSViewController
179
+ (r"\bNSView\b", 4), # NSView
180
+ (r"\bNSWindow\b", 5), # NSWindow
181
+ (r"\bNSWindowController\b", 5), # NSWindowController
182
+ (r"\bNSApplication\b", 5), # NSApplication
183
+ (r"\bNSTableView\b", 5), # NSTableView
184
+ (r"\bNSOutlineView\b", 5), # NSOutlineView
185
+ (r"\bNSCollectionView\b", 5), # NSCollectionView
186
+ (r"\bNSButton\b", 4), # NSButton
187
+ (r"\bNSTextField\b", 4), # NSTextField
188
+ (r"\bNSTextView\b", 4), # NSTextView
189
+ (r"\bNSImageView\b", 4), # NSImageView
190
+ (r"\bNSStackView\b", 4), # NSStackView
191
+ (r"\bNSScrollView\b", 4), # NSScrollView
192
+ (r"\bNSSplitView\b", 5), # NSSplitView
193
+ (r"\bNSTabView\b", 5), # NSTabView
194
+ (r"\bNSMenu\b", 5), # NSMenu
195
+ (r"\bNSMenuItem\b", 5), # NSMenuItem
196
+ (r"\bNSToolbar\b", 5), # NSToolbar
197
+ (r"\bNSAlert\b", 5), # NSAlert
198
+ (r"\bNSPanel\b", 5), # NSPanel
199
+ (r"\bNSOpenPanel\b", 5), # NSOpenPanel
200
+ (r"\bNSSavePanel\b", 5), # NSSavePanel
201
+ (r"\bNSWorkspace\b", 5), # NSWorkspace
202
+ (r"\bNSRunningApplication\b", 5), # NSRunningApplication
203
+ (r"\bNSScreen\b", 4), # NSScreen
204
+ (r"\bNSColor\b", 4), # NSColor
205
+ (r"\bNSFont\b", 4), # NSFont
206
+ (r"\bNSImage\b", 4), # NSImage
207
+ (r"\bNSBezierPath\b", 5), # NSBezierPath
208
+ (r"\bNSSound\b", 5), # NSSound
209
+ (r"\bNSEvent\b", 5), # NSEvent
210
+ (r"\bNSResponder\b", 5), # NSResponder
211
+ (r"\bNSPasteboard\b", 5), # NSPasteboard
212
+ (r"\bNSStatusBar\b", 5), # NSStatusBar
213
+ (r"\bNSStatusItem\b", 5), # NSStatusItem
214
+ # macOS Lifecycle methods (weight 5)
215
+ # Note: viewDidLoad() is defined in the UIKit section above since it's shared
216
+ # between iOS (UIViewController) and macOS (NSViewController)
217
+ (r"\bviewWillAppear\s*\(\)", 5), # NSViewController viewWillAppear
218
+ (r"\bviewDidAppear\s*\(\)", 5), # NSViewController viewDidAppear
219
+ (r"\bawakeFromNib\s*\(\)", 5), # awakeFromNib()
220
+ (r"\bapplicationDidFinishLaunching", 5), # NSApplicationDelegate
221
+ (r"\bapplicationWillTerminate", 5), # NSApplicationDelegate
222
+ (r"\bwindowDidLoad\s*\(\)", 5), # NSWindowController
223
+ # macOS delegates (weight 5)
224
+ (r"\bNSTableViewDelegate\b", 5),
225
+ (r"\bNSTableViewDataSource\b", 5),
226
+ (r"\bNSOutlineViewDelegate\b", 5),
227
+ (r"\bNSOutlineViewDataSource\b", 5),
228
+ (r"\bNSWindowDelegate\b", 5),
229
+ (r"\bNSApplicationDelegate\b", 5),
230
+ (r"\bNSTextFieldDelegate\b", 5),
231
+ (r"\bNSTextViewDelegate\b", 5),
232
+ # ===== SwiftUI PATTERNS (Weight 5) =====
233
+ (r"\bimport\s+SwiftUI", 5), # import SwiftUI
234
+ (r"\bstruct\s+\w+\s*:\s*View", 5), # struct Foo: View
235
+ (r"\bvar\s+body\s*:\s*some\s+View", 5), # var body: some View
236
+ (r":\s*some\s+View", 5), # : some View
237
+ # SwiftUI property wrappers (weight 5 - unique to SwiftUI)
238
+ (r"@State\s+", 5), # @State var
239
+ (r"@Binding\s+", 5), # @Binding var
240
+ (r"@Published\s+", 5), # @Published var
241
+ (r"@ObservedObject\s+", 5), # @ObservedObject var
242
+ (r"@StateObject\s+", 5), # @StateObject var
243
+ (r"@EnvironmentObject\s+", 5), # @EnvironmentObject var
244
+ (r"@Environment\s*\(", 5), # @Environment(\.keyPath)
245
+ (r"@FetchRequest\s*\(", 5), # @FetchRequest (Core Data)
246
+ (r"@AppStorage\s*\(", 5), # @AppStorage
247
+ (r"@SceneStorage\s*\(", 5), # @SceneStorage
248
+ (r"@FocusState\s+", 5), # @FocusState
249
+ (r"@FocusedBinding\s*\(", 5), # @FocusedBinding
250
+ (r"@Observable\b", 5), # @Observable (Swift 5.9+)
251
+ (r"@Bindable\s+", 5), # @Bindable (Swift 5.9+)
252
+ (r"@Query\s*\(", 5), # @Query (SwiftData)
253
+ (r"@Model\b", 5), # @Model (SwiftData)
254
+ (r"@ViewBuilder", 5), # @ViewBuilder
255
+ # SwiftUI Views (weight 4-5)
256
+ (r"\bText\s*\(", 4), # Text("Hello")
257
+ (r"\bImage\s*\(", 3), # Image(systemName:)
258
+ (r"\bButton\s*\(", 3), # Button("Label") { }
259
+ (r"\bVStack\s*[\(\{]", 5), # VStack { } or VStack(alignment:)
260
+ (r"\bHStack\s*[\(\{]", 5), # HStack { }
261
+ (r"\bZStack\s*[\(\{]", 5), # ZStack { }
262
+ (r"\bList\s*[\(\{]", 4), # List { }
263
+ (r"\bForEach\s*\(", 4), # ForEach(items) { }
264
+ (r"\bNavigationView\s*\{", 5), # NavigationView { }
265
+ (r"\bNavigationStack\s*[\(\{]", 5), # NavigationStack { } (iOS 16+)
266
+ (r"\bNavigationSplitView\s*[\(\{]", 5), # NavigationSplitView (macOS/iPad)
267
+ (r"\bNavigationLink\s*\(", 5), # NavigationLink
268
+ (r"\bTabView\s*[\(\{]", 5), # TabView { }
269
+ (r"\bScrollView\s*[\(\{]", 5), # ScrollView { }
270
+ (r"\bLazyVStack\s*[\(\{]", 5), # LazyVStack { }
271
+ (r"\bLazyHStack\s*[\(\{]", 5), # LazyHStack { }
272
+ (r"\bLazyVGrid\s*\(", 5), # LazyVGrid
273
+ (r"\bLazyHGrid\s*\(", 5), # LazyHGrid
274
+ (r"\bGrid\s*[\(\{]", 4), # Grid { } (iOS 16+)
275
+ (r"\bGridRow\s*[\(\{]", 5), # GridRow { }
276
+ (r"\bGeometryReader\s*\{", 5), # GeometryReader { }
277
+ (r"\bSpacer\s*\(\)", 5), # Spacer()
278
+ (r"\bDivider\s*\(\)", 5), # Divider()
279
+ (r"\bForm\s*\{", 4), # Form { }
280
+ (r"\bSection\s*[\(\{]", 4), # Section { }
281
+ (r"\bGroup\s*\{", 4), # Group { }
282
+ (r"\bGroupBox\s*[\(\{]", 5), # GroupBox { }
283
+ (r"\bDisclosureGroup\s*\(", 5), # DisclosureGroup
284
+ (r"\bOutlineGroup\s*\(", 5), # OutlineGroup
285
+ (r"\bToggle\s*\(", 4), # Toggle
286
+ (r"\bPicker\s*\(", 4), # Picker
287
+ (r"\bSlider\s*\(", 4), # Slider
288
+ (r"\bStepper\s*\(", 4), # Stepper
289
+ (r"\bDatePicker\s*\(", 5), # DatePicker
290
+ (r"\bColorPicker\s*\(", 5), # ColorPicker
291
+ (r"\bProgressView\s*[\(\{]", 5), # ProgressView
292
+ (r"\bLabel\s*\(", 4), # Label
293
+ (r"\bLink\s*\(", 4), # Link
294
+ (r"\bMenu\s*[\(\{]", 4), # Menu
295
+ (r"\bContextMenu\s*\{", 5), # ContextMenu
296
+ (r"\bToolbar\s*\{", 5), # Toolbar
297
+ (r"\bToolbarItem\s*\(", 5), # ToolbarItem
298
+ (r"\bCanvas\s*\{", 5), # Canvas
299
+ (r"\bTimelineView\s*\(", 5), # TimelineView
300
+ (r"\bShareLink\s*\(", 5), # ShareLink (iOS 16+)
301
+ (r"\bPhotosPicker\s*\(", 5), # PhotosPicker
302
+ (r"\bTextField\s*\(", 4), # TextField
303
+ (r"\bSecureField\s*\(", 5), # SecureField
304
+ (r"\bTextEditor\s*\(", 5), # TextEditor
305
+ # SwiftUI Modifiers (weight 4-5)
306
+ (r"\.padding\s*\(", 4), # .padding()
307
+ (r"\.frame\s*\(", 4), # .frame(width:height:)
308
+ (r"\.foregroundColor\s*\(", 5), # .foregroundColor(.red)
309
+ (r"\.foregroundStyle\s*\(", 5), # .foregroundStyle (iOS 15+)
310
+ (r"\.background\s*\(", 3), # .background()
311
+ (r"\.cornerRadius\s*\(", 4), # .cornerRadius()
312
+ (r"\.clipShape\s*\(", 5), # .clipShape()
313
+ (r"\.shadow\s*\(", 3), # .shadow()
314
+ (r"\.font\s*\(", 3), # .font(.title)
315
+ (r"\.fontWeight\s*\(", 4), # .fontWeight()
316
+ (r"\.bold\s*\(\)", 4), # .bold()
317
+ (r"\.italic\s*\(\)", 4), # .italic()
318
+ (r"\.onAppear\s*\{", 5), # .onAppear { }
319
+ (r"\.onDisappear\s*\{", 5), # .onDisappear { }
320
+ (r"\.onTapGesture\s*\{", 5), # .onTapGesture { }
321
+ (r"\.gesture\s*\(", 4), # .gesture()
322
+ (r"\.sheet\s*\(", 5), # .sheet(isPresented:)
323
+ (r"\.fullScreenCover\s*\(", 5), # .fullScreenCover()
324
+ (r"\.popover\s*\(", 5), # .popover()
325
+ (r"\.alert\s*\(", 4), # .alert()
326
+ (r"\.confirmationDialog\s*\(", 5), # .confirmationDialog()
327
+ (r"\.navigationTitle\s*\(", 5), # .navigationTitle()
328
+ (r"\.navigationBarTitleDisplayMode", 5), # .navigationBarTitleDisplayMode
329
+ (r"\.toolbar\s*\{", 5), # .toolbar { }
330
+ (r"\.toolbarBackground\s*\(", 5), # .toolbarBackground()
331
+ (r"\.environmentObject\s*\(", 5), # .environmentObject()
332
+ (r"\.environment\s*\(", 4), # .environment()
333
+ (r"\.task\s*\{", 5), # .task { } (async)
334
+ (r"\.refreshable\s*\{", 5), # .refreshable { }
335
+ (r"\.searchable\s*\(", 5), # .searchable()
336
+ (r"\.onChange\s*\(", 5), # .onChange(of:)
337
+ (r"\.onSubmit\s*\{", 5), # .onSubmit { }
338
+ (r"\.focused\s*\(", 5), # .focused()
339
+ (r"\.disabled\s*\(", 4), # .disabled()
340
+ (r"\.opacity\s*\(", 3), # .opacity()
341
+ (r"\.offset\s*\(", 4), # .offset()
342
+ (r"\.rotationEffect\s*\(", 5), # .rotationEffect()
343
+ (r"\.scaleEffect\s*\(", 5), # .scaleEffect()
344
+ (r"\.animation\s*\(", 4), # .animation()
345
+ (r"\.transition\s*\(", 5), # .transition()
346
+ (r"\.withAnimation\s*\{", 5), # withAnimation { }
347
+ (r"\.matchedGeometryEffect\s*\(", 5), # .matchedGeometryEffect()
348
+ (r"\.contentShape\s*\(", 5), # .contentShape()
349
+ (r"\.allowsHitTesting\s*\(", 5), # .allowsHitTesting()
350
+ (r"\.overlay\s*\(", 4), # .overlay()
351
+ (r"\.mask\s*\(", 4), # .mask()
352
+ (r"\.zIndex\s*\(", 4), # .zIndex()
353
+ (r"\.layoutPriority\s*\(", 5), # .layoutPriority()
354
+ (r"\.preference\s*\(", 5), # .preference()
355
+ (r"\.onPreferenceChange\s*\(", 5), # .onPreferenceChange()
356
+ (r"\.coordinateSpace\s*\(", 5), # .coordinateSpace()
357
+ (r"\.ignoresSafeArea\s*\(", 5), # .ignoresSafeArea()
358
+ (r"\.safeAreaInset\s*\(", 5), # .safeAreaInset()
359
+ (r"\.listStyle\s*\(", 5), # .listStyle()
360
+ (r"\.buttonStyle\s*\(", 5), # .buttonStyle()
361
+ (r"\.textFieldStyle\s*\(", 5), # .textFieldStyle()
362
+ (r"\.pickerStyle\s*\(", 5), # .pickerStyle()
363
+ (r"\.labelStyle\s*\(", 5), # .labelStyle()
364
+ (r"\.toggleStyle\s*\(", 5), # .toggleStyle()
365
+ (r"\.presentationDetents\s*\(", 5), # .presentationDetents() (iOS 16+)
366
+ (r"\.interactiveDismissDisabled\s*\(", 5), # .interactiveDismissDisabled()
367
+ # SwiftUI Scene types (macOS/multi-window)
368
+ (r"\bWindowGroup\s*\{", 5), # WindowGroup { }
369
+ (r"\bWindow\s*\(", 5), # Window (macOS)
370
+ (r"\bSettings\s*\{", 5), # Settings { } (macOS)
371
+ (r"\bMenuBarExtra\s*\(", 5), # MenuBarExtra (macOS)
372
+ (r"\bDocumentGroup\s*\(", 5), # DocumentGroup
373
+ (r":\s*App\s*\{", 5), # : App {
374
+ (r"@main\b", 5), # @main
375
+ (r"var\s+body:\s*some\s+Scene", 5), # var body: some Scene
376
+ # ===== Combine Framework (Weight 5) =====
377
+ (r"\bimport\s+Combine", 5), # import Combine
378
+ (r"\bAnyPublisher\b", 5), # AnyPublisher
379
+ (r"\bPassthroughSubject\b", 5), # PassthroughSubject
380
+ (r"\bCurrentValueSubject\b", 5), # CurrentValueSubject
381
+ (r"\bPublisher\b", 4), # Publisher protocol
382
+ (r"\bSubscriber\b", 4), # Subscriber protocol
383
+ (r"\.sink\s*\{", 5), # .sink { }
384
+ (r"\.receive\s*\(on:\s*", 5), # .receive(on: RunLoop.main)
385
+ (r"\bAnyCancellable\b", 5), # AnyCancellable
386
+ (r"\.store\s*\(in:\s*&", 5), # .store(in: &cancellables)
387
+ (r"\.eraseToAnyPublisher\s*\(\)", 5), # .eraseToAnyPublisher()
388
+ (r"\.map\s*\{\s*\$0", 5), # .map { $0 (Combine map)
389
+ (r"\.flatMap\s*\{", 4), # .flatMap {
390
+ (r"\.compactMap\s*\{", 4), # .compactMap {
391
+ (r"\.filter\s*\{", 3), # .filter {
392
+ (r"\.debounce\s*\(", 5), # .debounce()
393
+ (r"\.throttle\s*\(", 5), # .throttle()
394
+ (r"\.removeDuplicates\s*\(", 5), # .removeDuplicates()
395
+ (r"\.combineLatest\s*\(", 5), # .combineLatest()
396
+ (r"\.merge\s*\(", 4), # .merge()
397
+ (r"\.zip\s*\(", 3), # .zip()
398
+ (r"@Published\s+var", 5), # @Published var
399
+ # ===== Codable/JSON (Weight 5) =====
400
+ (r"\bCodable\b", 5), # Codable protocol
401
+ (r"\bEncodable\b", 4), # Encodable protocol
402
+ (r"\bDecodable\b", 4), # Decodable protocol
403
+ (r"\bJSONDecoder\s*\(\)", 5), # JSONDecoder()
404
+ (r"\bJSONEncoder\s*\(\)", 5), # JSONEncoder()
405
+ (r"\bCodingKeys\b", 5), # CodingKeys enum
406
+ (r"\bPropertyListDecoder\b", 5), # PropertyListDecoder
407
+ (r"\bPropertyListEncoder\b", 5), # PropertyListEncoder
408
+ # ===== Core Data (Weight 5) =====
409
+ (r"\bimport\s+CoreData", 5), # import CoreData
410
+ (r"\bNSManagedObject\b", 5), # NSManagedObject
411
+ (r"\bNSManagedObjectContext\b", 5), # NSManagedObjectContext
412
+ (r"\bNSPersistentContainer\b", 5), # NSPersistentContainer
413
+ (r"\bNSFetchRequest\b", 5), # NSFetchRequest
414
+ (r"\b@FetchRequest\b", 5), # @FetchRequest property wrapper
415
+ (r"\bNSPredicate\b", 5), # NSPredicate
416
+ (r"\bNSSortDescriptor\b", 5), # NSSortDescriptor
417
+ # ===== SwiftData (Weight 5 - iOS 17+) =====
418
+ (r"\bimport\s+SwiftData", 5), # import SwiftData
419
+ (r"@Model\s+", 5), # @Model class
420
+ (r"@Attribute\s*\(", 5), # @Attribute
421
+ (r"@Relationship\s*\(", 5), # @Relationship
422
+ (r"\bModelContext\b", 5), # ModelContext
423
+ (r"\bModelContainer\b", 5), # ModelContainer
424
+ # ===== Common Apple Frameworks (Weight 4-5) =====
425
+ (r"\bimport\s+MapKit", 5), # import MapKit
426
+ (r"\bimport\s+CoreLocation", 5), # import CoreLocation
427
+ (r"\bimport\s+AVFoundation", 5), # import AVFoundation
428
+ (r"\bimport\s+Photos", 5), # import Photos
429
+ (r"\bimport\s+PhotosUI", 5), # import PhotosUI
430
+ (r"\bimport\s+HealthKit", 5), # import HealthKit
431
+ (r"\bimport\s+StoreKit", 5), # import StoreKit
432
+ (r"\bimport\s+CloudKit", 5), # import CloudKit
433
+ (r"\bimport\s+UserNotifications", 5), # import UserNotifications
434
+ (r"\bimport\s+EventKit", 5), # import EventKit
435
+ (r"\bimport\s+Contacts", 5), # import Contacts
436
+ (r"\bimport\s+MessageUI", 5), # import MessageUI
437
+ (r"\bimport\s+SafariServices", 5), # import SafariServices
438
+ (r"\bimport\s+WebKit", 5), # import WebKit
439
+ (r"\bimport\s+PDFKit", 5), # import PDFKit
440
+ (r"\bimport\s+QuickLook", 5), # import QuickLook
441
+ (r"\bimport\s+AuthenticationServices", 5), # import AuthenticationServices
442
+ (r"\bimport\s+LocalAuthentication", 5), # import LocalAuthentication
443
+ (r"\bimport\s+GameKit", 5), # import GameKit
444
+ (r"\bimport\s+SpriteKit", 5), # import SpriteKit
445
+ (r"\bimport\s+SceneKit", 5), # import SceneKit
446
+ (r"\bimport\s+RealityKit", 5), # import RealityKit
447
+ (r"\bimport\s+ARKit", 5), # import ARKit
448
+ (r"\bimport\s+Metal", 5), # import Metal
449
+ (r"\bimport\s+CoreML", 5), # import CoreML
450
+ (r"\bimport\s+Vision", 5), # import Vision
451
+ (r"\bimport\s+NaturalLanguage", 5), # import NaturalLanguage
452
+ (r"\bimport\s+Speech", 5), # import Speech
453
+ (r"\bimport\s+CoreBluetooth", 5), # import CoreBluetooth
454
+ (r"\bimport\s+NetworkExtension", 5), # import NetworkExtension
455
+ (r"\bimport\s+WidgetKit", 5), # import WidgetKit
456
+ (r"\bimport\s+ActivityKit", 5), # import ActivityKit
457
+ (r"\bimport\s+AppIntents", 5), # import AppIntents
458
+ # ===== Foundation Models Framework (iOS/macOS/visionOS 26+) =====
459
+ # Apple's on-device AI/ML framework for language model interactions
460
+ # Import statement
461
+ (r"\bimport\s+FoundationModels", 5), # import FoundationModels
462
+ # Core classes
463
+ (r"\bSystemLanguageModel\b", 5), # Main model class
464
+ (r"\bLanguageModelSession\b", 5), # Session for interactions
465
+ (r"\bLanguageModelFeedback\b", 5), # Feedback reporting
466
+ # Key structs
467
+ (r"\bInstructionsBuilder\b", 5), # Result builder for instructions
468
+ (r"\bPromptBuilder\b", 5), # Result builder for prompts
469
+ (r"\bGenerationOptions\b", 5), # Controls generation behavior
470
+ (r"\bGeneratedContent\b", 5), # Structured output type
471
+ (r"\bGenerationID\b", 5), # Unique generation identifier
472
+ (r"\bGenerationSchema\b", 5), # Schema for guided generation
473
+ (r"\bDynamicGenerationSchema\b", 5), # Runtime schema definition
474
+ (r"\bGenerationGuide\b", 5), # Value constraint guides
475
+ # Macros (unique to FoundationModels)
476
+ (r"@Generable\b", 5), # Guided generation macro
477
+ (r"@Generable\s*\(\s*description:", 5), # @Generable with description
478
+ (r"@Guide\b", 5), # Property constraint macro
479
+ (r"@Guide\s*\(\s*description:", 5), # @Guide with description
480
+ # Key protocols
481
+ (r"\bGenerable\b", 4), # Core protocol (also common word)
482
+ (r"\bInstructionsRepresentable\b", 5), # Instructions protocol
483
+ (r"\bPromptRepresentable\b", 5), # Prompt protocol
484
+ (r"\bConvertibleFromGeneratedContent\b", 5), # Content conversion
485
+ (r"\bConvertibleToGeneratedContent\b", 5), # Content conversion
486
+ # Nested types (SystemLanguageModel.*)
487
+ (r"\bSystemLanguageModel\.default\b", 5), # Default model access
488
+ (r"\bSystemLanguageModel\.UseCase\b", 5), # Use case type
489
+ (r"\bSystemLanguageModel\.Guardrails\b", 5), # Safety guardrails
490
+ (r"\bSystemLanguageModel\.Adapter\b", 5), # Custom adapters
491
+ (r"\bSystemLanguageModel\.Availability\b", 5), # Availability enum
492
+ # Key methods
493
+ (r"\.respond\s*\(to:", 4), # Primary response method
494
+ (r"\.respond\s*\([^)]*generating:", 5), # Guided generation response
495
+ (r"\.streamResponse\s*\(", 4), # Streaming response
496
+ (r"\.prewarm\s*\(", 5), # Session prewarming
497
+ (r"\.logFeedbackAttachment\s*\(", 5), # Feedback logging
498
+ # Transcript types
499
+ (r"\bTranscript\.Entry\b", 5), # Transcript entry
500
+ (r"\bTranscript\.Segment\b", 5), # Transcript segment
501
+ (r"\bTranscript\.ToolCall\b", 5), # Tool call record
502
+ (r"\bTranscript\.ToolOutput\b", 5), # Tool output record
503
+ (r"\bTranscript\.Response\b", 5), # Response record
504
+ # Error types and availability
505
+ (r"\bGenerationError\b", 4), # Generation error type
506
+ (r"\bToolCallError\b", 5), # Tool execution error
507
+ (r"\.exceededContextWindowSize\b", 5), # Context window error
508
+ (r"\.guardrailViolation\b", 5), # Safety guardrail error
509
+ (r"\.appleIntelligenceNotEnabled\b", 5), # Availability reason
510
+ (r"\.deviceNotEligible\b", 5), # Device eligibility
511
+ (r"\.modelNotReady\b", 5), # Model readiness
512
+ # Use cases and guardrails
513
+ (r"\.contentTagging\b", 5), # Content tagging use case
514
+ (r"\.permissiveContentTransformations\b", 5), # Guardrail setting
515
+ # Common usage patterns
516
+ (r"LanguageModelSession\s*\(\s*instructions:", 5), # Session init
517
+ (r"for\s+try\s+await.*streamResponse", 5), # Streaming iteration
518
+ (r"\.PartiallyGenerated\b", 5), # Partial generation type
519
+ ],
520
+ }
521
+
522
+
523
+ def _validate_patterns(patterns: dict[str, list[tuple[str, int]]]) -> None:
524
+ """
525
+ Validate pattern structure at module load time.
526
+
527
+ Ensures all patterns follow the expected format:
528
+ - Each pattern is a (regex_string, weight) tuple
529
+ - Weight is an integer between 1 and 5
530
+ - Regex string is a valid string
531
+
532
+ Raises:
533
+ ValueError: If any pattern is malformed
534
+ """
535
+ for lang, pattern_list in patterns.items():
536
+ for i, item in enumerate(pattern_list):
537
+ if not isinstance(item, tuple) or len(item) != 2:
538
+ raise ValueError(f"Pattern {i} for '{lang}' is not a (regex, weight) tuple: {item}")
539
+ pattern, weight = item
540
+ if not isinstance(pattern, str):
541
+ raise ValueError(
542
+ f"Pattern {i} for '{lang}': regex must be a string, got {type(pattern).__name__}"
543
+ )
544
+ if not isinstance(weight, int) or weight < 1 or weight > 5:
545
+ raise ValueError(
546
+ f"Pattern {i} for '{lang}': weight must be int 1-5, got {weight!r}"
547
+ )
548
+
549
+
550
+ # Validate patterns at module load time
551
+ try:
552
+ _validate_patterns(SWIFT_PATTERNS)
553
+ except ValueError as e:
554
+ logger.error(
555
+ "Swift pattern validation failed: %s. Swift detection will be disabled. "
556
+ "This indicates a bug in swift_patterns.py - please file an issue.",
557
+ e,
558
+ )
559
+ # Clear patterns to prevent broken detection with invalid data
560
+ SWIFT_PATTERNS = {}