lycheedev 1.0.0 → 1.0.2

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 (50) hide show
  1. package/bin/lycheedev.js +58 -8
  2. package/package.json +1 -1
  3. package/vendor/addon/Core/Bootstrap.lua +131 -131
  4. package/vendor/addon/Core/Clients/Mainline.lua +9 -9
  5. package/vendor/addon/Core/Clients/Mists.lua +9 -9
  6. package/vendor/addon/Core/Clients/Titan.lua +9 -9
  7. package/vendor/addon/Core/Compatibility.lua +43 -43
  8. package/vendor/addon/Core/Database.lua +859 -859
  9. package/vendor/addon/Core/Inspector.lua +647 -647
  10. package/vendor/addon/Core/Locale.lua +307 -307
  11. package/vendor/addon/Core/Locale_enUS.lua +318 -318
  12. package/vendor/addon/Core/Safety.lua +42 -42
  13. package/vendor/addon/Core/Serializer.lua +324 -324
  14. package/vendor/addon/Libs/AutomationQR.lua +1176 -1176
  15. package/vendor/addon/Lychee Dev_Mainline.toc +43 -43
  16. package/vendor/addon/Lychee Dev_Mists.toc +43 -43
  17. package/vendor/addon/Lychee Dev_Wrath.toc +43 -43
  18. package/vendor/addon/Modules/Automation/Controller.lua +757 -757
  19. package/vendor/addon/Modules/Automation/Report.lua +409 -409
  20. package/vendor/addon/Modules/Automation/auto/auto.lua +12 -12
  21. package/vendor/addon/Modules/Diagnostics.lua +238 -238
  22. package/vendor/addon/Modules/Events/Catalog.lua +184 -184
  23. package/vendor/addon/Modules/Events/CatalogData_Mainline.lua +1788 -1788
  24. package/vendor/addon/Modules/Events/CatalogData_Mists.lua +1489 -1489
  25. package/vendor/addon/Modules/Events/CatalogData_Titan.lua +1492 -1492
  26. package/vendor/addon/Modules/Events/Monitor.lua +181 -181
  27. package/vendor/addon/Modules/FunctionTrace.lua +85 -85
  28. package/vendor/addon/Modules/ObjectInspector.lua +329 -329
  29. package/vendor/addon/UI/AutomationOverlay.lua +183 -183
  30. package/vendor/addon/UI/Export.lua +140 -140
  31. package/vendor/addon/UI/Features.lua +890 -890
  32. package/vendor/addon/UI/MainWindow.lua +1145 -1145
  33. package/vendor/addon/UI/Pages/About.lua +223 -223
  34. package/vendor/addon/UI/Pages/Automation.lua +417 -417
  35. package/vendor/addon/UI/Pages/Diagnostics.lua +289 -289
  36. package/vendor/addon/UI/Pages/ExportRecords.lua +387 -387
  37. package/vendor/addon/UI/Pages/Object.lua +573 -573
  38. package/vendor/addon/UI/Pages/Trace.lua +165 -165
  39. package/vendor/skill/SKILL.md +94 -94
  40. package/vendor/skill/agents/openai.yaml +4 -4
  41. package/vendor/skill/references/automation.md +327 -327
  42. package/vendor/skill/references/runtime-investigations.md +97 -97
  43. package/vendor/skill/scripts/automation/__init__.py +1 -1
  44. package/vendor/skill/scripts/automation/registry.py +516 -516
  45. package/vendor/skill/scripts/automation/saved_variables.py +438 -438
  46. package/vendor/skill/scripts/automation/session.py +207 -207
  47. package/vendor/skill/scripts/automation/windows.py +573 -573
  48. package/vendor/skill/scripts/automation.py +865 -865
  49. package/vendor/skill/scripts/requirements.txt +13 -13
  50. package/vendor/skill/scripts/selftest_offline.py +981 -981
@@ -1,329 +1,329 @@
1
- local ADDON_NAME, ns = ...
2
-
3
- local inspector = {}
4
- local MAX_SEARCH_RESULTS = 200
5
- local MAX_SEARCH_SCANS = 10000
6
- local MAX_SEARCH_NODES = 2000
7
- local MAX_SEARCH_DEPTH = 6
8
- local MAX_PREVIEW_BYTES = 120
9
-
10
- local function IsSecret(value)
11
- return issecretvalue and issecretvalue(value)
12
- end
13
-
14
- local function Trim(text)
15
- return tostring(text or ""):match("^%s*(.-)%s*$")
16
- end
17
-
18
- local function ParsePath(path)
19
- path = Trim(path)
20
- if path == "" then
21
- return nil, ns.L.OBJECT_PATH_REQUIRED
22
- elseif path == "_G" then
23
- return {}
24
- elseif path:sub(1, 3) == "_G." then
25
- path = path:sub(4)
26
- end
27
-
28
- local tokens = {}
29
- local remaining = path
30
- while remaining ~= "" do
31
- if remaining:sub(1, 1) == "." then
32
- remaining = remaining:sub(2)
33
- end
34
- local identifier, tail = remaining:match("^([_%a][_%w]*)(.*)$")
35
- if identifier then
36
- tokens[#tokens + 1] = identifier
37
- remaining = tail
38
- else
39
- local numberKey
40
- numberKey, tail = remaining:match("^%[(-?%d+)%](.*)$")
41
- if numberKey then
42
- tokens[#tokens + 1] = tonumber(numberKey)
43
- remaining = tail
44
- else
45
- local stringKey
46
- stringKey, tail = remaining:match('^%["([^"%]]+)"%](.*)$')
47
- if not stringKey then
48
- stringKey, tail = remaining:match("^%['([^'%]]+)'%](.*)$")
49
- end
50
- if not stringKey then
51
- return nil, ns.L.OBJECT_PATH_INVALID
52
- end
53
- tokens[#tokens + 1] = stringKey
54
- remaining = tail
55
- end
56
- end
57
- if remaining ~= "" and remaining:sub(1, 1) ~= "." and remaining:sub(1, 1) ~= "[" then
58
- return nil, ns.L.OBJECT_PATH_INVALID
59
- end
60
- end
61
- return tokens
62
- end
63
-
64
- local function ReadMember(value, key)
65
- if IsSecret(value) or IsSecret(key) then
66
- return false, nil, ns.L.SECRET_VALUE_BLOCKED
67
- elseif type(value) == "table" then
68
- return true, rawget(value, key)
69
- end
70
- local succeeded, result = pcall(function() return value[key] end)
71
- if not succeeded then
72
- return false, nil, ns.L.OBJECT_PATH_UNREADABLE
73
- end
74
- return true, result
75
- end
76
-
77
- local function ResolveTokens(tokens, count)
78
- local value = _G
79
- for index = 1, count or #tokens do
80
- local succeeded, nextValue, errorMessage = ReadMember(value, tokens[index])
81
- if not succeeded then
82
- return false, nil, errorMessage
83
- elseif nextValue == nil then
84
- return false, nil, ns.L.OBJECT_NOT_FOUND
85
- end
86
- value = nextValue
87
- end
88
- return true, value
89
- end
90
-
91
- local function SafePreview(value)
92
- if IsSecret(value) then return "<secret>" end
93
- local valueType = type(value)
94
- local text
95
- if valueType == "string" then
96
- text = string.format("%q", value)
97
- elseif valueType == "number" or valueType == "boolean" or valueType == "nil" then
98
- text = tostring(value)
99
- elseif valueType == "table" then
100
- text = "table"
101
- else
102
- local succeeded, result = pcall(tostring, value)
103
- text = succeeded and result or ("<" .. valueType .. ">")
104
- end
105
- return #text > MAX_PREVIEW_BYTES and (text:sub(1, MAX_PREVIEW_BYTES) .. "...") or text
106
- end
107
-
108
- local function SafeMethod(value, methodName)
109
- if IsSecret(value) then return nil end
110
- local methodSucceeded, method = pcall(function() return value[methodName] end)
111
- if not methodSucceeded or type(method) ~= "function" then return nil end
112
- local succeeded, result = pcall(method, value)
113
- if not succeeded or IsSecret(result) then return nil end
114
- return result
115
- end
116
-
117
- local function SafeMethodResults(value, methodName)
118
- if IsSecret(value) then return nil end
119
- local methodSucceeded, method = pcall(function() return value[methodName] end)
120
- if not methodSucceeded or type(method) ~= "function" then return nil end
121
- local packed = { pcall(method, value) }
122
- if not packed[1] then return nil end
123
- local results = {}
124
- for index = 2, #packed do
125
- if packed[index] ~= nil and not IsSecret(packed[index]) then
126
- results[#results + 1] = packed[index]
127
- end
128
- end
129
- return results
130
- end
131
-
132
- local function IsScriptRegion(value)
133
- if IsSecret(value) then return false end
134
- local succeeded, method = pcall(function() return value.GetObjectType end)
135
- return succeeded and type(method) == "function"
136
- end
137
-
138
- local function BuildInspection(value, label)
139
- if IsSecret(value) then return nil, ns.L.SECRET_VALUE_BLOCKED end
140
- local isFrame = IsScriptRegion(value)
141
- local textStream = ns.CreateSerializationStream(value)
142
- local serialized = textStream:ReadChunk()
143
- return {
144
- label = label,
145
- valueType = type(value),
146
- value = value,
147
- preview = SafePreview(value),
148
- isFrame = isFrame,
149
- text = string.format(ns.L.OBJECT_TEXT_HEADER, label or "", type(value)) .. "\n" .. serialized,
150
- textStream = textStream,
151
- tree = ns.CreateValueTree({ n = 1, value }),
152
- }
153
- end
154
-
155
- function inspector.ResolvePath(path)
156
- local tokens, errorMessage = ParsePath(path)
157
- if not tokens then return false, nil, errorMessage end
158
- return ResolveTokens(tokens)
159
- end
160
-
161
- function inspector.ResolveFunctionTarget(path)
162
- local tokens, errorMessage = ParsePath(path)
163
- if not tokens then return false, nil, nil, errorMessage end
164
- if #tokens == 0 or type(tokens[#tokens]) ~= "string" then
165
- return false, nil, nil, ns.L.FUNCTION_PATH_INVALID
166
- end
167
- local key = tokens[#tokens]
168
- local succeeded, owner, resolveError = ResolveTokens(tokens, #tokens - 1)
169
- if not succeeded then return false, nil, nil, resolveError end
170
- return true, owner, key
171
- end
172
-
173
- function inspector.InspectPath(path)
174
- if ns.IsCombatBlocked() then return false, nil, ns.L.COMBAT_BLOCKED end
175
- local succeeded, value, errorMessage = inspector.ResolvePath(path)
176
- if not succeeded then return false, nil, errorMessage end
177
- local inspection, inspectError = BuildInspection(value, Trim(path))
178
- return inspection ~= nil, inspection, inspectError
179
- end
180
-
181
- function inspector.InspectValue(value, label)
182
- if ns.IsCombatBlocked() then return false, nil, ns.L.COMBAT_BLOCKED end
183
- local inspection, inspectError = BuildInspection(value, Trim(label))
184
- return inspection ~= nil, inspection, inspectError
185
- end
186
-
187
- function inspector.CaptureMouseFocus()
188
- if ns.IsCombatBlocked() then return false, nil, ns.L.COMBAT_BLOCKED end
189
- local focus = ns.Client.GetMouseFocus()
190
- if not focus then
191
- return false, nil, ns.L.NO_MOUSE_FOCUS
192
- end
193
- local inspection, errorMessage = BuildInspection(focus, SafeMethod(focus, "GetName") or SafePreview(focus))
194
- return inspection ~= nil, inspection, errorMessage
195
- end
196
-
197
- function inspector.GetMouseFocusLabel()
198
- if ns.IsCombatBlocked() then return false, nil, nil, ns.L.COMBAT_BLOCKED end
199
- local focus = ns.Client.GetMouseFocus()
200
- if not focus then return false, nil, nil, ns.L.NO_MOUSE_FOCUS end
201
- return true,
202
- SafeMethod(focus, "GetName") or SafePreview(focus),
203
- SafeMethod(focus, "GetObjectType") or type(focus)
204
- end
205
-
206
- function inspector.SearchValue(value, query, limit, maxDepth)
207
- if ns.IsCombatBlocked() then return false, nil, ns.L.COMBAT_BLOCKED end
208
- query = Trim(query):lower()
209
- if query == "" then return false, nil, ns.L.SEARCH_TERM_REQUIRED end
210
- if (type(value) ~= "table" and not IsScriptRegion(value)) or IsSecret(value) then
211
- return false, nil, ns.L.SEARCH_REQUIRES_TABLE
212
- end
213
-
214
- limit = math.max(1, math.floor(tonumber(limit) or MAX_SEARCH_RESULTS))
215
- maxDepth = math.max(0, math.floor(tonumber(maxDepth) or MAX_SEARCH_DEPTH))
216
- local exact, prefixes, contains = {}, {}, {}
217
- local matchCount = 0
218
- local scanned = 0
219
- local visitedCount = 0
220
- local seen = {}
221
- local stack = { { value = value, path = "", depth = 0 } }
222
-
223
- local function ChildPath(path, key)
224
- local segment
225
- if type(key) == "string" and key:match("^[_%a][_%w]*$") then
226
- segment = key
227
- return path == "" and segment or (path .. "." .. segment)
228
- end
229
- segment = "[" .. SafePreview(key) .. "]"
230
- return path .. segment
231
- end
232
-
233
- local function Push(childValue, path, depth)
234
- if depth <= maxDepth and (type(childValue) == "table" or IsScriptRegion(childValue))
235
- and not IsSecret(childValue) and not seen[childValue] then
236
- stack[#stack + 1] = { value = childValue, path = path, depth = depth }
237
- end
238
- end
239
-
240
- local function AddMatch(key, childValue, path)
241
- if type(key) ~= "string" or IsSecret(key) then return end
242
- local lowerKey = key:lower()
243
- local matchStart = lowerKey:find(query, 1, true)
244
- if not matchStart then return end
245
- matchCount = matchCount + 1
246
- local bucket = lowerKey == query and exact or (matchStart == 1 and prefixes or contains)
247
- if #exact + #prefixes + #contains < limit and not IsSecret(childValue) then
248
- bucket[#bucket + 1] = {
249
- key = key,
250
- path = path,
251
- value = childValue,
252
- valueType = type(childValue),
253
- preview = SafePreview(childValue),
254
- }
255
- end
256
- end
257
-
258
- while #stack > 0 and scanned < MAX_SEARCH_SCANS and visitedCount < MAX_SEARCH_NODES do
259
- local item = stack[#stack]
260
- stack[#stack] = nil
261
- local current = item.value
262
- if not seen[current] then
263
- seen[current] = true
264
- visitedCount = visitedCount + 1
265
-
266
- if type(current) == "table" then
267
- local cursor
268
- while scanned < MAX_SEARCH_SCANS do
269
- local succeeded, key, childValue = pcall(next, current, cursor)
270
- if not succeeded or key == nil then break end
271
- cursor = key
272
- scanned = scanned + 1
273
- if not IsSecret(key) then
274
- local path = ChildPath(item.path, key)
275
- AddMatch(key, childValue, path)
276
- Push(childValue, path, item.depth + 1)
277
- end
278
- end
279
- end
280
-
281
- if item.depth < maxDepth and IsScriptRegion(current) then
282
- local childFrames = SafeMethodResults(current, "GetChildren") or {}
283
- for index = 1, #childFrames do
284
- Push(childFrames[index], ChildPath(item.path, ns.L.FRAME_CHILDREN) .. "[" .. index .. "]", item.depth + 1)
285
- end
286
- local regions = SafeMethodResults(current, "GetRegions") or {}
287
- for index = 1, #regions do
288
- Push(regions[index], ChildPath(item.path, ns.L.FRAME_REGIONS) .. "[" .. index .. "]", item.depth + 1)
289
- end
290
- end
291
-
292
- local metaSucceeded, metatable = pcall(getmetatable, current)
293
- if metaSucceeded and type(metatable) == "table" then
294
- local indexTable = rawget(metatable, "__index")
295
- if type(indexTable) == "table" then
296
- Push(indexTable, item.path, item.depth + 1)
297
- end
298
- end
299
- end
300
- end
301
- table.sort(prefixes, function(left, right) return left.key < right.key end)
302
- table.sort(contains, function(left, right) return left.key < right.key end)
303
- local results = {}
304
- local function Append(bucket)
305
- for index = 1, #bucket do
306
- if #results >= limit then return end
307
- results[#results + 1] = bucket[index]
308
- end
309
- end
310
- Append(exact) Append(prefixes) Append(contains)
311
- return true, {
312
- results = results,
313
- totalMatches = matchCount,
314
- truncated = matchCount > #results or scanned >= MAX_SEARCH_SCANS or visitedCount >= MAX_SEARCH_NODES,
315
- }
316
- end
317
-
318
- function inspector.SearchGlobal(query, limit)
319
- return inspector.SearchValue(_G, query, limit, 0)
320
- end
321
-
322
- function inspector.SearchPath(path, query, limit)
323
- if ns.IsCombatBlocked() then return false, nil, ns.L.COMBAT_BLOCKED end
324
- local succeeded, value, errorMessage = inspector.ResolvePath(path)
325
- if not succeeded then return false, nil, errorMessage end
326
- return inspector.SearchValue(value, query, limit)
327
- end
328
-
329
- ns.ObjectInspector = inspector
1
+ local ADDON_NAME, ns = ...
2
+
3
+ local inspector = {}
4
+ local MAX_SEARCH_RESULTS = 200
5
+ local MAX_SEARCH_SCANS = 10000
6
+ local MAX_SEARCH_NODES = 2000
7
+ local MAX_SEARCH_DEPTH = 6
8
+ local MAX_PREVIEW_BYTES = 120
9
+
10
+ local function IsSecret(value)
11
+ return issecretvalue and issecretvalue(value)
12
+ end
13
+
14
+ local function Trim(text)
15
+ return tostring(text or ""):match("^%s*(.-)%s*$")
16
+ end
17
+
18
+ local function ParsePath(path)
19
+ path = Trim(path)
20
+ if path == "" then
21
+ return nil, ns.L.OBJECT_PATH_REQUIRED
22
+ elseif path == "_G" then
23
+ return {}
24
+ elseif path:sub(1, 3) == "_G." then
25
+ path = path:sub(4)
26
+ end
27
+
28
+ local tokens = {}
29
+ local remaining = path
30
+ while remaining ~= "" do
31
+ if remaining:sub(1, 1) == "." then
32
+ remaining = remaining:sub(2)
33
+ end
34
+ local identifier, tail = remaining:match("^([_%a][_%w]*)(.*)$")
35
+ if identifier then
36
+ tokens[#tokens + 1] = identifier
37
+ remaining = tail
38
+ else
39
+ local numberKey
40
+ numberKey, tail = remaining:match("^%[(-?%d+)%](.*)$")
41
+ if numberKey then
42
+ tokens[#tokens + 1] = tonumber(numberKey)
43
+ remaining = tail
44
+ else
45
+ local stringKey
46
+ stringKey, tail = remaining:match('^%["([^"%]]+)"%](.*)$')
47
+ if not stringKey then
48
+ stringKey, tail = remaining:match("^%['([^'%]]+)'%](.*)$")
49
+ end
50
+ if not stringKey then
51
+ return nil, ns.L.OBJECT_PATH_INVALID
52
+ end
53
+ tokens[#tokens + 1] = stringKey
54
+ remaining = tail
55
+ end
56
+ end
57
+ if remaining ~= "" and remaining:sub(1, 1) ~= "." and remaining:sub(1, 1) ~= "[" then
58
+ return nil, ns.L.OBJECT_PATH_INVALID
59
+ end
60
+ end
61
+ return tokens
62
+ end
63
+
64
+ local function ReadMember(value, key)
65
+ if IsSecret(value) or IsSecret(key) then
66
+ return false, nil, ns.L.SECRET_VALUE_BLOCKED
67
+ elseif type(value) == "table" then
68
+ return true, rawget(value, key)
69
+ end
70
+ local succeeded, result = pcall(function() return value[key] end)
71
+ if not succeeded then
72
+ return false, nil, ns.L.OBJECT_PATH_UNREADABLE
73
+ end
74
+ return true, result
75
+ end
76
+
77
+ local function ResolveTokens(tokens, count)
78
+ local value = _G
79
+ for index = 1, count or #tokens do
80
+ local succeeded, nextValue, errorMessage = ReadMember(value, tokens[index])
81
+ if not succeeded then
82
+ return false, nil, errorMessage
83
+ elseif nextValue == nil then
84
+ return false, nil, ns.L.OBJECT_NOT_FOUND
85
+ end
86
+ value = nextValue
87
+ end
88
+ return true, value
89
+ end
90
+
91
+ local function SafePreview(value)
92
+ if IsSecret(value) then return "<secret>" end
93
+ local valueType = type(value)
94
+ local text
95
+ if valueType == "string" then
96
+ text = string.format("%q", value)
97
+ elseif valueType == "number" or valueType == "boolean" or valueType == "nil" then
98
+ text = tostring(value)
99
+ elseif valueType == "table" then
100
+ text = "table"
101
+ else
102
+ local succeeded, result = pcall(tostring, value)
103
+ text = succeeded and result or ("<" .. valueType .. ">")
104
+ end
105
+ return #text > MAX_PREVIEW_BYTES and (text:sub(1, MAX_PREVIEW_BYTES) .. "...") or text
106
+ end
107
+
108
+ local function SafeMethod(value, methodName)
109
+ if IsSecret(value) then return nil end
110
+ local methodSucceeded, method = pcall(function() return value[methodName] end)
111
+ if not methodSucceeded or type(method) ~= "function" then return nil end
112
+ local succeeded, result = pcall(method, value)
113
+ if not succeeded or IsSecret(result) then return nil end
114
+ return result
115
+ end
116
+
117
+ local function SafeMethodResults(value, methodName)
118
+ if IsSecret(value) then return nil end
119
+ local methodSucceeded, method = pcall(function() return value[methodName] end)
120
+ if not methodSucceeded or type(method) ~= "function" then return nil end
121
+ local packed = { pcall(method, value) }
122
+ if not packed[1] then return nil end
123
+ local results = {}
124
+ for index = 2, #packed do
125
+ if packed[index] ~= nil and not IsSecret(packed[index]) then
126
+ results[#results + 1] = packed[index]
127
+ end
128
+ end
129
+ return results
130
+ end
131
+
132
+ local function IsScriptRegion(value)
133
+ if IsSecret(value) then return false end
134
+ local succeeded, method = pcall(function() return value.GetObjectType end)
135
+ return succeeded and type(method) == "function"
136
+ end
137
+
138
+ local function BuildInspection(value, label)
139
+ if IsSecret(value) then return nil, ns.L.SECRET_VALUE_BLOCKED end
140
+ local isFrame = IsScriptRegion(value)
141
+ local textStream = ns.CreateSerializationStream(value)
142
+ local serialized = textStream:ReadChunk()
143
+ return {
144
+ label = label,
145
+ valueType = type(value),
146
+ value = value,
147
+ preview = SafePreview(value),
148
+ isFrame = isFrame,
149
+ text = string.format(ns.L.OBJECT_TEXT_HEADER, label or "", type(value)) .. "\n" .. serialized,
150
+ textStream = textStream,
151
+ tree = ns.CreateValueTree({ n = 1, value }),
152
+ }
153
+ end
154
+
155
+ function inspector.ResolvePath(path)
156
+ local tokens, errorMessage = ParsePath(path)
157
+ if not tokens then return false, nil, errorMessage end
158
+ return ResolveTokens(tokens)
159
+ end
160
+
161
+ function inspector.ResolveFunctionTarget(path)
162
+ local tokens, errorMessage = ParsePath(path)
163
+ if not tokens then return false, nil, nil, errorMessage end
164
+ if #tokens == 0 or type(tokens[#tokens]) ~= "string" then
165
+ return false, nil, nil, ns.L.FUNCTION_PATH_INVALID
166
+ end
167
+ local key = tokens[#tokens]
168
+ local succeeded, owner, resolveError = ResolveTokens(tokens, #tokens - 1)
169
+ if not succeeded then return false, nil, nil, resolveError end
170
+ return true, owner, key
171
+ end
172
+
173
+ function inspector.InspectPath(path)
174
+ if ns.IsCombatBlocked() then return false, nil, ns.L.COMBAT_BLOCKED end
175
+ local succeeded, value, errorMessage = inspector.ResolvePath(path)
176
+ if not succeeded then return false, nil, errorMessage end
177
+ local inspection, inspectError = BuildInspection(value, Trim(path))
178
+ return inspection ~= nil, inspection, inspectError
179
+ end
180
+
181
+ function inspector.InspectValue(value, label)
182
+ if ns.IsCombatBlocked() then return false, nil, ns.L.COMBAT_BLOCKED end
183
+ local inspection, inspectError = BuildInspection(value, Trim(label))
184
+ return inspection ~= nil, inspection, inspectError
185
+ end
186
+
187
+ function inspector.CaptureMouseFocus()
188
+ if ns.IsCombatBlocked() then return false, nil, ns.L.COMBAT_BLOCKED end
189
+ local focus = ns.Client.GetMouseFocus()
190
+ if not focus then
191
+ return false, nil, ns.L.NO_MOUSE_FOCUS
192
+ end
193
+ local inspection, errorMessage = BuildInspection(focus, SafeMethod(focus, "GetName") or SafePreview(focus))
194
+ return inspection ~= nil, inspection, errorMessage
195
+ end
196
+
197
+ function inspector.GetMouseFocusLabel()
198
+ if ns.IsCombatBlocked() then return false, nil, nil, ns.L.COMBAT_BLOCKED end
199
+ local focus = ns.Client.GetMouseFocus()
200
+ if not focus then return false, nil, nil, ns.L.NO_MOUSE_FOCUS end
201
+ return true,
202
+ SafeMethod(focus, "GetName") or SafePreview(focus),
203
+ SafeMethod(focus, "GetObjectType") or type(focus)
204
+ end
205
+
206
+ function inspector.SearchValue(value, query, limit, maxDepth)
207
+ if ns.IsCombatBlocked() then return false, nil, ns.L.COMBAT_BLOCKED end
208
+ query = Trim(query):lower()
209
+ if query == "" then return false, nil, ns.L.SEARCH_TERM_REQUIRED end
210
+ if (type(value) ~= "table" and not IsScriptRegion(value)) or IsSecret(value) then
211
+ return false, nil, ns.L.SEARCH_REQUIRES_TABLE
212
+ end
213
+
214
+ limit = math.max(1, math.floor(tonumber(limit) or MAX_SEARCH_RESULTS))
215
+ maxDepth = math.max(0, math.floor(tonumber(maxDepth) or MAX_SEARCH_DEPTH))
216
+ local exact, prefixes, contains = {}, {}, {}
217
+ local matchCount = 0
218
+ local scanned = 0
219
+ local visitedCount = 0
220
+ local seen = {}
221
+ local stack = { { value = value, path = "", depth = 0 } }
222
+
223
+ local function ChildPath(path, key)
224
+ local segment
225
+ if type(key) == "string" and key:match("^[_%a][_%w]*$") then
226
+ segment = key
227
+ return path == "" and segment or (path .. "." .. segment)
228
+ end
229
+ segment = "[" .. SafePreview(key) .. "]"
230
+ return path .. segment
231
+ end
232
+
233
+ local function Push(childValue, path, depth)
234
+ if depth <= maxDepth and (type(childValue) == "table" or IsScriptRegion(childValue))
235
+ and not IsSecret(childValue) and not seen[childValue] then
236
+ stack[#stack + 1] = { value = childValue, path = path, depth = depth }
237
+ end
238
+ end
239
+
240
+ local function AddMatch(key, childValue, path)
241
+ if type(key) ~= "string" or IsSecret(key) then return end
242
+ local lowerKey = key:lower()
243
+ local matchStart = lowerKey:find(query, 1, true)
244
+ if not matchStart then return end
245
+ matchCount = matchCount + 1
246
+ local bucket = lowerKey == query and exact or (matchStart == 1 and prefixes or contains)
247
+ if #exact + #prefixes + #contains < limit and not IsSecret(childValue) then
248
+ bucket[#bucket + 1] = {
249
+ key = key,
250
+ path = path,
251
+ value = childValue,
252
+ valueType = type(childValue),
253
+ preview = SafePreview(childValue),
254
+ }
255
+ end
256
+ end
257
+
258
+ while #stack > 0 and scanned < MAX_SEARCH_SCANS and visitedCount < MAX_SEARCH_NODES do
259
+ local item = stack[#stack]
260
+ stack[#stack] = nil
261
+ local current = item.value
262
+ if not seen[current] then
263
+ seen[current] = true
264
+ visitedCount = visitedCount + 1
265
+
266
+ if type(current) == "table" then
267
+ local cursor
268
+ while scanned < MAX_SEARCH_SCANS do
269
+ local succeeded, key, childValue = pcall(next, current, cursor)
270
+ if not succeeded or key == nil then break end
271
+ cursor = key
272
+ scanned = scanned + 1
273
+ if not IsSecret(key) then
274
+ local path = ChildPath(item.path, key)
275
+ AddMatch(key, childValue, path)
276
+ Push(childValue, path, item.depth + 1)
277
+ end
278
+ end
279
+ end
280
+
281
+ if item.depth < maxDepth and IsScriptRegion(current) then
282
+ local childFrames = SafeMethodResults(current, "GetChildren") or {}
283
+ for index = 1, #childFrames do
284
+ Push(childFrames[index], ChildPath(item.path, ns.L.FRAME_CHILDREN) .. "[" .. index .. "]", item.depth + 1)
285
+ end
286
+ local regions = SafeMethodResults(current, "GetRegions") or {}
287
+ for index = 1, #regions do
288
+ Push(regions[index], ChildPath(item.path, ns.L.FRAME_REGIONS) .. "[" .. index .. "]", item.depth + 1)
289
+ end
290
+ end
291
+
292
+ local metaSucceeded, metatable = pcall(getmetatable, current)
293
+ if metaSucceeded and type(metatable) == "table" then
294
+ local indexTable = rawget(metatable, "__index")
295
+ if type(indexTable) == "table" then
296
+ Push(indexTable, item.path, item.depth + 1)
297
+ end
298
+ end
299
+ end
300
+ end
301
+ table.sort(prefixes, function(left, right) return left.key < right.key end)
302
+ table.sort(contains, function(left, right) return left.key < right.key end)
303
+ local results = {}
304
+ local function Append(bucket)
305
+ for index = 1, #bucket do
306
+ if #results >= limit then return end
307
+ results[#results + 1] = bucket[index]
308
+ end
309
+ end
310
+ Append(exact) Append(prefixes) Append(contains)
311
+ return true, {
312
+ results = results,
313
+ totalMatches = matchCount,
314
+ truncated = matchCount > #results or scanned >= MAX_SEARCH_SCANS or visitedCount >= MAX_SEARCH_NODES,
315
+ }
316
+ end
317
+
318
+ function inspector.SearchGlobal(query, limit)
319
+ return inspector.SearchValue(_G, query, limit, 0)
320
+ end
321
+
322
+ function inspector.SearchPath(path, query, limit)
323
+ if ns.IsCombatBlocked() then return false, nil, ns.L.COMBAT_BLOCKED end
324
+ local succeeded, value, errorMessage = inspector.ResolvePath(path)
325
+ if not succeeded then return false, nil, errorMessage end
326
+ return inspector.SearchValue(value, query, limit)
327
+ end
328
+
329
+ ns.ObjectInspector = inspector