lycheedev 1.1.1 → 2.0.0
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.
- package/LICENSE +49 -0
- package/README.md +45 -0
- package/THIRD_PARTY_NOTICES +812 -0
- package/bin/lycheedev.mjs +56 -0
- package/native/windows-amd64/lycheedev.exe +0 -0
- package/package.json +12 -33
- package/payload/addon/Bridge/CaptureWriter.lua +154 -0
- package/payload/addon/Bridge/Definitions.lua +3 -0
- package/payload/addon/Bridge/Identity.lua +127 -0
- package/{vendor/addon/Libs/AutomationQR.lua → payload/addon/Bridge/MatrixSymbol.lua} +23 -30
- package/payload/addon/Bridge/ProbeQueue.lua +136 -0
- package/payload/addon/Bridge/ProbeRunner.lua +128 -0
- package/payload/addon/Bridge/ReceiptView.lua +160 -0
- package/payload/addon/Bridge/Reentry.lua +192 -0
- package/payload/addon/Bridge/ReportStore.lua +153 -0
- package/payload/addon/Bridge/Session.lua +163 -0
- package/payload/addon/Clients/Evergreen.lua +2 -0
- package/payload/addon/Clients/Live.lua +2 -0
- package/payload/addon/Clients/Pandaria.lua +2 -0
- package/payload/addon/Clients/Titan.lua +2 -0
- package/payload/addon/Core/Compat.lua +59 -0
- package/payload/addon/Core/Controls.lua +168 -0
- package/{vendor/addon/Core/Bootstrap.lua → payload/addon/Core/Execute.lua} +12 -23
- package/{vendor → payload}/addon/Core/Inspector.lua +19 -235
- package/{vendor → payload}/addon/Core/Locale.lua +129 -94
- package/{vendor → payload}/addon/Core/Locale_enUS.lua +129 -96
- package/payload/addon/Core/Persistence.lua +58 -0
- package/payload/addon/Core/Platform.lua +58 -0
- package/payload/addon/Core/Runtime.lua +25 -0
- package/payload/addon/Core/Safety.lua +56 -0
- package/{vendor → payload}/addon/Core/Serializer.lua +18 -6
- package/payload/addon/Core/Stores.lua +611 -0
- package/payload/addon/Lychee Dev_Forever.toc +52 -0
- package/payload/addon/Lychee Dev_Mainline.toc +52 -0
- package/payload/addon/Lychee Dev_Mists.toc +52 -0
- package/payload/addon/Lychee Dev_Wrath.toc +52 -0
- package/payload/addon/Modules/AutomationView.lua +393 -0
- package/{vendor → payload}/addon/Modules/Diagnostics.lua +92 -36
- package/{vendor → payload}/addon/Modules/Events/Catalog.lua +9 -0
- package/{vendor → payload}/addon/Modules/Events/Monitor.lua +45 -5
- package/payload/addon/Modules/FunctionTrace.lua +150 -0
- package/{vendor → payload}/addon/Modules/ObjectInspector.lua +105 -31
- package/{vendor → payload}/addon/UI/Export.lua +64 -34
- package/{vendor → payload}/addon/UI/Pages/About.lua +26 -14
- package/payload/addon/UI/Pages/Automation.lua +446 -0
- package/payload/addon/UI/Pages/Diagnostics.lua +402 -0
- package/{vendor/addon/UI/Features.lua → payload/addon/UI/Pages/Events.lua} +192 -302
- package/{vendor → payload}/addon/UI/Pages/ExportRecords.lua +213 -132
- package/{vendor → payload}/addon/UI/Pages/Object.lua +229 -121
- package/payload/addon/UI/Pages/Run.lua +423 -0
- package/payload/addon/UI/Pages/Trace.lua +314 -0
- package/payload/addon/UI/TreeView.lua +246 -0
- package/{vendor/addon/UI/MainWindow.lua → payload/addon/UI/Widgets.lua} +89 -529
- package/payload/addon/UI/Window.lua +425 -0
- package/payload/skill/SKILL.md +87 -0
- package/payload/skill/agents/openai.yaml +7 -0
- package/payload/skill/references/addon-validation.md +42 -0
- package/payload/skill/references/asset-export.md +109 -0
- package/payload/skill/references/commands.md +169 -0
- package/payload/skill/references/data-investigation.md +242 -0
- package/payload/skill/references/error-diagnosis.md +41 -0
- package/payload/skill/references/installation.md +18 -0
- package/payload/skill/references/live-investigation.md +129 -0
- package/payload/skill/references/source-research.md +82 -0
- package/payload/skill/scripts/lycheedev.mjs +59 -0
- package/release.json +346 -0
- package/bin/lycheedev.js +0 -742
- package/src/addon.js +0 -95
- package/src/config.js +0 -68
- package/src/doctor.js +0 -126
- package/src/install.js +0 -145
- package/src/paths.js +0 -93
- package/src/py/instances.py +0 -165
- package/src/python.js +0 -111
- package/src/skill.js +0 -48
- package/src/wow.js +0 -541
- package/vendor/addon/Core/Clients/Forever.lua +0 -9
- package/vendor/addon/Core/Clients/Mainline.lua +0 -9
- package/vendor/addon/Core/Clients/Mists.lua +0 -9
- package/vendor/addon/Core/Clients/Titan.lua +0 -9
- package/vendor/addon/Core/Compatibility.lua +0 -43
- package/vendor/addon/Core/Database.lua +0 -859
- package/vendor/addon/Core/Safety.lua +0 -42
- package/vendor/addon/Lychee Dev_Forever.toc +0 -43
- package/vendor/addon/Lychee Dev_Mainline.toc +0 -43
- package/vendor/addon/Lychee Dev_Mists.toc +0 -43
- package/vendor/addon/Lychee Dev_Wrath.toc +0 -43
- package/vendor/addon/Modules/Automation/Controller.lua +0 -884
- package/vendor/addon/Modules/Automation/Report.lua +0 -409
- package/vendor/addon/Modules/Automation/auto/auto.lua +0 -12
- package/vendor/addon/Modules/FunctionTrace.lua +0 -85
- package/vendor/addon/UI/AutomationOverlay.lua +0 -253
- package/vendor/addon/UI/Pages/Automation.lua +0 -417
- package/vendor/addon/UI/Pages/Diagnostics.lua +0 -289
- package/vendor/addon/UI/Pages/Trace.lua +0 -165
- package/vendor/skill/SKILL.md +0 -42
- package/vendor/skill/agents/openai.yaml +0 -4
- package/vendor/skill/references/automation.md +0 -128
- package/vendor/skill/references/clients.md +0 -51
- package/vendor/skill/references/runtime-investigations.md +0 -104
- package/vendor/skill/scripts/automation/__init__.py +0 -1
- package/vendor/skill/scripts/automation/registry.py +0 -516
- package/vendor/skill/scripts/automation/saved_variables.py +0 -438
- package/vendor/skill/scripts/automation/session.py +0 -207
- package/vendor/skill/scripts/automation/windows.py +0 -792
- package/vendor/skill/scripts/automation.py +0 -1034
- package/vendor/skill/scripts/requirements.txt +0 -13
- package/vendor/skill/scripts/selftest_offline.py +0 -1061
- package/vendor/skill/scripts/test_input_safety.py +0 -132
- /package/{vendor → payload}/addon/Media/GitHub.png +0 -0
- /package/{vendor → payload}/addon/Media/Logo.png +0 -0
- /package/{vendor → payload}/addon/Modules/Events/CatalogData_Forever.lua +0 -0
- /package/{vendor → payload}/addon/Modules/Events/CatalogData_Mainline.lua +0 -0
- /package/{vendor → payload}/addon/Modules/Events/CatalogData_Mists.lua +0 -0
- /package/{vendor → payload}/addon/Modules/Events/CatalogData_Titan.lua +0 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
local ADDON_NAME, ns = ...
|
|
2
2
|
|
|
3
|
+
-- Error diagnostics over the !BugGrabber error provider. The integration is
|
|
4
|
+
-- SOFT: no TOC dependency, the provider is read under pcall at use time, and a
|
|
5
|
+
-- missing provider is an explicit state, never fabricated errors.
|
|
3
6
|
local diagnostics = {}
|
|
4
7
|
local MAX_REPORT_BYTES = 48000
|
|
5
8
|
local SNAPSHOT_MAX_ERRORS = 100
|
|
@@ -11,13 +14,32 @@ local SNAPSHOT_ERROR_COUNT = "invalid_count"
|
|
|
11
14
|
local SNAPSHOT_ERROR_PROVIDER = "provider_unavailable"
|
|
12
15
|
local SNAPSHOT_ERROR_PROVIDER_CALL = "provider_error"
|
|
13
16
|
|
|
17
|
+
diagnostics.SNAPSHOT_ERROR_COMBAT = SNAPSHOT_ERROR_COMBAT
|
|
18
|
+
diagnostics.SNAPSHOT_ERROR_COUNT = SNAPSHOT_ERROR_COUNT
|
|
19
|
+
diagnostics.SNAPSHOT_ERROR_PROVIDER = SNAPSHOT_ERROR_PROVIDER
|
|
20
|
+
diagnostics.SNAPSHOT_ERROR_PROVIDER_CALL = SNAPSHOT_ERROR_PROVIDER_CALL
|
|
21
|
+
|
|
14
22
|
local function IsSecret(value)
|
|
15
23
|
return issecretvalue and issecretvalue(value)
|
|
16
24
|
end
|
|
17
25
|
|
|
26
|
+
-- Numeric provider fields are converted only after a secrecy check.
|
|
27
|
+
local function SafeNumber(value)
|
|
28
|
+
if value == nil or IsSecret(value) then
|
|
29
|
+
return nil
|
|
30
|
+
end
|
|
31
|
+
return tonumber(value)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
-- Every report field passes here: secrets render as <secret>, everything else
|
|
35
|
+
-- is capped at 48 KB with a visible truncation marker.
|
|
18
36
|
local function SafeText(value)
|
|
19
|
-
if value == nil then
|
|
20
|
-
|
|
37
|
+
if value == nil then
|
|
38
|
+
return ""
|
|
39
|
+
end
|
|
40
|
+
if IsSecret(value) then
|
|
41
|
+
return "<secret>"
|
|
42
|
+
end
|
|
21
43
|
local text = type(value) == "string" and value or tostring(value)
|
|
22
44
|
if #text > MAX_REPORT_BYTES then
|
|
23
45
|
return text:sub(1, MAX_REPORT_BYTES) .. "\n... <truncated>"
|
|
@@ -34,14 +56,20 @@ local function GetGrabber()
|
|
|
34
56
|
end
|
|
35
57
|
|
|
36
58
|
local function GetSessionId(grabber)
|
|
37
|
-
if type(grabber.GetSessionId) ~= "function" then
|
|
59
|
+
if type(grabber.GetSessionId) ~= "function" then
|
|
60
|
+
return -1
|
|
61
|
+
end
|
|
38
62
|
local succeeded, session = pcall(grabber.GetSessionId, grabber)
|
|
39
|
-
if not succeeded or IsSecret(session) then
|
|
63
|
+
if not succeeded or IsSecret(session) then
|
|
64
|
+
return -1
|
|
65
|
+
end
|
|
40
66
|
return tonumber(session) or -1
|
|
41
67
|
end
|
|
42
68
|
|
|
43
69
|
local function MatchesQuery(entry, query)
|
|
44
|
-
if query == "" then
|
|
70
|
+
if query == "" then
|
|
71
|
+
return true
|
|
72
|
+
end
|
|
45
73
|
local searchable = table.concat({
|
|
46
74
|
SafeText(entry.message),
|
|
47
75
|
SafeText(entry.stack),
|
|
@@ -50,11 +78,17 @@ local function MatchesQuery(entry, query)
|
|
|
50
78
|
return searchable:find(query, 1, true) ~= nil
|
|
51
79
|
end
|
|
52
80
|
|
|
81
|
+
-- Newest first (reverse provider-storage order). scope "current" keeps only
|
|
82
|
+
-- entries recorded in the active capture session.
|
|
53
83
|
local function CollectErrors(scope, query)
|
|
54
84
|
local grabber = GetGrabber()
|
|
55
|
-
if not grabber then
|
|
85
|
+
if not grabber then
|
|
86
|
+
return {}, -1, false
|
|
87
|
+
end
|
|
56
88
|
local succeeded, database = pcall(grabber.GetDB, grabber)
|
|
57
|
-
if not succeeded or type(database) ~= "table" then
|
|
89
|
+
if not succeeded or type(database) ~= "table" then
|
|
90
|
+
return {}, -1, false
|
|
91
|
+
end
|
|
58
92
|
|
|
59
93
|
local session = GetSessionId(grabber)
|
|
60
94
|
query = SafeText(query):match("^%s*(.-)%s*$"):lower()
|
|
@@ -62,7 +96,7 @@ local function CollectErrors(scope, query)
|
|
|
62
96
|
for index = #database, 1, -1 do
|
|
63
97
|
local entry = database[index]
|
|
64
98
|
if type(entry) == "table"
|
|
65
|
-
and (scope == "all" or
|
|
99
|
+
and (scope == "all" or SafeNumber(entry.session) == session)
|
|
66
100
|
and MatchesQuery(entry, query) then
|
|
67
101
|
errors[#errors + 1] = entry
|
|
68
102
|
end
|
|
@@ -72,30 +106,43 @@ end
|
|
|
72
106
|
|
|
73
107
|
local function DetectSource(entry)
|
|
74
108
|
local source = SafeText(entry.source)
|
|
75
|
-
if source ~= "" then
|
|
109
|
+
if source ~= "" then
|
|
110
|
+
return source
|
|
111
|
+
end
|
|
76
112
|
local combined = (SafeText(entry.message) .. "\n" .. SafeText(entry.stack)):gsub("\\", "/")
|
|
77
113
|
return combined:match("[Aa]dd[Oo]ns/([^/%s]+)") or ns.L.UNKNOWN_SOURCE
|
|
78
114
|
end
|
|
79
115
|
|
|
116
|
+
diagnostics.DetectSource = DetectSource
|
|
117
|
+
diagnostics.SafeText = SafeText
|
|
118
|
+
|
|
80
119
|
function diagnostics.GetErrors(scope, query)
|
|
81
|
-
if ns.IsCombatBlocked() then
|
|
120
|
+
if ns.Safety.IsCombatBlocked() then
|
|
121
|
+
return false, nil, ns.L.COMBAT_BLOCKED
|
|
122
|
+
end
|
|
82
123
|
local errors, session, available = CollectErrors(scope, query)
|
|
83
|
-
if not available then
|
|
124
|
+
if not available then
|
|
125
|
+
return false, nil, ns.L.BUGGRABBER_UNAVAILABLE
|
|
126
|
+
end
|
|
84
127
|
return true, { errors = errors, session = session }
|
|
85
128
|
end
|
|
86
129
|
|
|
130
|
+
-- Human-readable agent report: title, context, environment, error, stack (or
|
|
131
|
+
-- REPORT_NOT_AVAILABLE) and optional locals. Every field is SafeText-capped.
|
|
87
132
|
function diagnostics.FormatAgentReport(entry)
|
|
88
|
-
if type(entry) ~= "table" then
|
|
133
|
+
if type(entry) ~= "table" then
|
|
134
|
+
return ns.L.SELECT_ERROR_DETAIL
|
|
135
|
+
end
|
|
89
136
|
local version, build, buildDate = GetBuildInfo()
|
|
90
|
-
local timestamp =
|
|
137
|
+
local timestamp = SafeNumber(entry.time) and date("%Y-%m-%d %H:%M:%S", SafeNumber(entry.time)) or ns.L.UNKNOWN_TIME
|
|
91
138
|
local sections = {
|
|
92
139
|
ns.L.AGENT_REPORT_TITLE,
|
|
93
140
|
"",
|
|
94
141
|
ns.L.REPORT_CONTEXT,
|
|
95
142
|
string.format(ns.L.REPORT_TIME, timestamp),
|
|
96
143
|
string.format(ns.L.REPORT_SOURCE, DetectSource(entry)),
|
|
97
|
-
string.format(ns.L.REPORT_COUNT,
|
|
98
|
-
string.format(ns.L.REPORT_SESSION,
|
|
144
|
+
string.format(ns.L.REPORT_COUNT, SafeNumber(entry.counter) or 1),
|
|
145
|
+
string.format(ns.L.REPORT_SESSION, SafeNumber(entry.session) or -1),
|
|
99
146
|
"",
|
|
100
147
|
ns.L.REPORT_ENVIRONMENT,
|
|
101
148
|
string.format(ns.L.REPORT_CLIENT, SafeText(version)),
|
|
@@ -122,7 +169,9 @@ function diagnostics.FormatError(entry)
|
|
|
122
169
|
end
|
|
123
170
|
|
|
124
171
|
function diagnostics.ResetErrors()
|
|
125
|
-
if ns.IsCombatBlocked() then
|
|
172
|
+
if ns.Safety.IsCombatBlocked() then
|
|
173
|
+
return false, ns.L.COMBAT_BLOCKED
|
|
174
|
+
end
|
|
126
175
|
local grabber = GetGrabber()
|
|
127
176
|
if not grabber or type(grabber.Reset) ~= "function" then
|
|
128
177
|
return false, ns.L.BUGGRABBER_UNAVAILABLE
|
|
@@ -132,20 +181,19 @@ function diagnostics.ResetErrors()
|
|
|
132
181
|
end
|
|
133
182
|
|
|
134
183
|
local function GetProviderVersion(grabber)
|
|
135
|
-
if type(grabber.version) == "string" and grabber.version ~= "" then
|
|
184
|
+
if type(grabber.version) == "string" and grabber.version ~= "" and not IsSecret(grabber.version) then
|
|
136
185
|
return grabber.version
|
|
137
186
|
end
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
local succeeded, version = pcall(metadata, "!BugGrabber", "Version")
|
|
141
|
-
if succeeded and type(version) == "string" and not IsSecret(version) then
|
|
142
|
-
return version
|
|
143
|
-
end
|
|
187
|
+
if ns.Compat and ns.Compat.GetAddOnMetadata then
|
|
188
|
+
return ns.Compat.GetAddOnMetadata("!BugGrabber", "Version")
|
|
144
189
|
end
|
|
145
190
|
return nil
|
|
146
191
|
end
|
|
147
192
|
|
|
148
|
-
-- Copy one error entry immediately so later BugGrabber updates cannot change
|
|
193
|
+
-- Copy one error entry immediately so later BugGrabber updates cannot change
|
|
194
|
+
-- it. Absent, secret or non-string text fields land in missingFields instead of
|
|
195
|
+
-- being tostring-substituted; source is optional, the other text fields make
|
|
196
|
+
-- the copy incomplete.
|
|
149
197
|
local function CopyErrorEntry(entry)
|
|
150
198
|
local missing = {}
|
|
151
199
|
local copy = {}
|
|
@@ -153,25 +201,29 @@ local function CopyErrorEntry(entry)
|
|
|
153
201
|
local field = SNAPSHOT_TEXT_FIELDS[index]
|
|
154
202
|
local value = entry[field]
|
|
155
203
|
if value == nil then
|
|
156
|
-
-- source is optional; message/stack/locals are reported missing when absent.
|
|
157
204
|
if field ~= "source" then
|
|
158
205
|
missing[#missing + 1] = field
|
|
159
206
|
end
|
|
160
207
|
elseif IsSecret(value) then
|
|
161
208
|
missing[#missing + 1] = field
|
|
162
209
|
elseif type(value) ~= "string" then
|
|
163
|
-
-- Never substitute tostring(table) for real content.
|
|
164
210
|
missing[#missing + 1] = field
|
|
165
211
|
else
|
|
166
212
|
copy[field] = value
|
|
167
213
|
end
|
|
168
214
|
end
|
|
169
|
-
local timeValue =
|
|
170
|
-
local sessionValue =
|
|
171
|
-
local counterValue =
|
|
172
|
-
if not timeValue
|
|
173
|
-
|
|
174
|
-
|
|
215
|
+
local timeValue = SafeNumber(entry.time)
|
|
216
|
+
local sessionValue = SafeNumber(entry.session)
|
|
217
|
+
local counterValue = SafeNumber(entry.counter)
|
|
218
|
+
if not timeValue then
|
|
219
|
+
missing[#missing + 1] = "time"
|
|
220
|
+
end
|
|
221
|
+
if not sessionValue then
|
|
222
|
+
missing[#missing + 1] = "session"
|
|
223
|
+
end
|
|
224
|
+
if not counterValue then
|
|
225
|
+
missing[#missing + 1] = "counter"
|
|
226
|
+
end
|
|
175
227
|
copy.time = timeValue
|
|
176
228
|
copy.session = sessionValue
|
|
177
229
|
copy.counter = counterValue
|
|
@@ -179,10 +231,14 @@ local function CopyErrorEntry(entry)
|
|
|
179
231
|
return copy
|
|
180
232
|
end
|
|
181
233
|
|
|
182
|
-
|
|
183
|
-
|
|
234
|
+
diagnostics.CopyErrorEntry = CopyErrorEntry
|
|
235
|
+
|
|
236
|
+
-- Machine snapshot for the future host "live bugs" entry and automation
|
|
237
|
+
-- exports. Never calls FormatAgentReport and never truncates fields silently.
|
|
238
|
+
-- Returns nil plus a stable error code on failure: combat_blocked,
|
|
239
|
+
-- invalid_count, provider_unavailable, provider_error.
|
|
184
240
|
function diagnostics.SnapshotRecentErrors(count, scope)
|
|
185
|
-
if ns.IsCombatBlocked() then
|
|
241
|
+
if ns.Safety.IsCombatBlocked() then
|
|
186
242
|
return nil, SNAPSHOT_ERROR_COMBAT
|
|
187
243
|
end
|
|
188
244
|
if type(count) ~= "number" or count ~= math.floor(count)
|
|
@@ -206,7 +262,7 @@ function diagnostics.SnapshotRecentErrors(count, scope)
|
|
|
206
262
|
for index = #database, 1, -1 do
|
|
207
263
|
local entry = database[index]
|
|
208
264
|
if type(entry) == "table" then
|
|
209
|
-
if allSessions or
|
|
265
|
+
if allSessions or SafeNumber(entry.session) == session then
|
|
210
266
|
availableCount = availableCount + 1
|
|
211
267
|
if #errors < count then
|
|
212
268
|
local copy = CopyErrorEntry(entry)
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
local ADDON_NAME, ns = ...
|
|
2
2
|
|
|
3
|
+
-- Event catalog lookup and selection over the flat per-client data table
|
|
4
|
+
-- (ns.EventCatalogData: alternating name, payloadSignature strings). Data is
|
|
5
|
+
-- sorted by literal event name, so Find is a binary search. No frames, events
|
|
6
|
+
-- or hooks are created here; selection editing stays pure Lua state.
|
|
3
7
|
local data = ns.EventCatalogData
|
|
4
8
|
local L = ns.L
|
|
5
9
|
local ALL_INDEX = 0
|
|
@@ -10,6 +14,7 @@ Selection.__index = Selection
|
|
|
10
14
|
local function NormalizeQuery(query)
|
|
11
15
|
query = type(query) == "string" and query or ""
|
|
12
16
|
query = query:match("^%s*(.-)%s*$"):upper()
|
|
17
|
+
-- "quan bu" / "quan bu shi jian" (Chinese for "all"/"all events").
|
|
13
18
|
if query == "\229\133\168\233\131\168" or query == "\229\133\168\233\131\168\228\186\139\228\187\182" then
|
|
14
19
|
return "ALL"
|
|
15
20
|
end
|
|
@@ -52,6 +57,8 @@ function catalog.Find(eventName)
|
|
|
52
57
|
return nil
|
|
53
58
|
end
|
|
54
59
|
|
|
60
|
+
-- Ranked results: exact match first, then prefix matches, then substring
|
|
61
|
+
-- matches, bounded by limit. The results table is reused when supplied.
|
|
55
62
|
function catalog.Search(query, limit, results)
|
|
56
63
|
query = NormalizeQuery(query)
|
|
57
64
|
results = results or {}
|
|
@@ -96,6 +103,8 @@ function catalog.Search(query, limit, results)
|
|
|
96
103
|
return results
|
|
97
104
|
end
|
|
98
105
|
|
|
106
|
+
-- Selection semantics: unlimited count, de-duplicated by event name. ALL
|
|
107
|
+
-- replaces the whole selection; picking any individual event removes ALL.
|
|
99
108
|
function Selection:Add(catalogIndex)
|
|
100
109
|
local eventName = catalog.Get(catalogIndex)
|
|
101
110
|
if not eventName then
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
local ADDON_NAME, ns = ...
|
|
2
|
+
|
|
3
|
+
-- Bounded event monitor. One lazy driver frame (created on the first Start),
|
|
4
|
+
-- per-event RegisterEvent + IsEventRegistered verification with atomic
|
|
5
|
+
-- failure, and a fixed-size record ring. Stop unregisters everything; the
|
|
6
|
+
-- combat shutdown callback tears the driver down with it.
|
|
2
7
|
local L = ns.L
|
|
3
8
|
|
|
4
9
|
local MAX_RECORDS = 500
|
|
@@ -15,11 +20,22 @@ local running = false
|
|
|
15
20
|
local activeEventCount = 0
|
|
16
21
|
local monitoringAllEvents = false
|
|
17
22
|
local startedAt = 0
|
|
23
|
+
local combatShutdownRegistered = false
|
|
18
24
|
|
|
19
25
|
local function IsSecret(value)
|
|
20
26
|
return issecretvalue and issecretvalue(value)
|
|
21
27
|
end
|
|
22
28
|
|
|
29
|
+
-- GetTime may be restricted in combat; a secret clock degrades to a zero
|
|
30
|
+
-- elapsed time instead of throwing on arithmetic.
|
|
31
|
+
local function SafeTime()
|
|
32
|
+
local now = GetTime()
|
|
33
|
+
if IsSecret(now) or type(now) ~= "number" then
|
|
34
|
+
return nil
|
|
35
|
+
end
|
|
36
|
+
return now
|
|
37
|
+
end
|
|
38
|
+
|
|
23
39
|
local function FormatArgument(value)
|
|
24
40
|
if IsSecret(value) then
|
|
25
41
|
return "<secret>"
|
|
@@ -54,9 +70,15 @@ local function AddRecord(event, ...)
|
|
|
54
70
|
arguments[#arguments + 1] = "<" .. (suppliedCount - MAX_ARGUMENTS) .. " more arguments>"
|
|
55
71
|
end
|
|
56
72
|
|
|
73
|
+
local now = SafeTime()
|
|
74
|
+
local elapsed = 0
|
|
75
|
+
if now then
|
|
76
|
+
elapsed = math.max(0, now - startedAt)
|
|
77
|
+
end
|
|
78
|
+
|
|
57
79
|
head = head % MAX_RECORDS + 1
|
|
58
80
|
records[head] = {
|
|
59
|
-
elapsed =
|
|
81
|
+
elapsed = elapsed,
|
|
60
82
|
event = event,
|
|
61
83
|
arguments = arguments,
|
|
62
84
|
summary = table.concat(arguments, ", "),
|
|
@@ -80,6 +102,18 @@ local function EnsureDriver()
|
|
|
80
102
|
return driver
|
|
81
103
|
end
|
|
82
104
|
|
|
105
|
+
-- Registered once on the first Start so a session that never monitors never
|
|
106
|
+
-- creates the combat shutdown driver frame.
|
|
107
|
+
local function EnsureCombatShutdown()
|
|
108
|
+
if combatShutdownRegistered then
|
|
109
|
+
return
|
|
110
|
+
end
|
|
111
|
+
combatShutdownRegistered = true
|
|
112
|
+
if type(ns.RegisterCombatShutdown) == "function" then
|
|
113
|
+
ns.RegisterCombatShutdown(monitor.Stop)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
83
117
|
function monitor.Start(eventNames, callback)
|
|
84
118
|
if ns.IsCombatBlocked() then
|
|
85
119
|
return false, L.COMBAT_BLOCKED
|
|
@@ -93,7 +127,8 @@ function monitor.Start(eventNames, callback)
|
|
|
93
127
|
for index = 1, #eventNames do
|
|
94
128
|
local eventName = eventNames[index]
|
|
95
129
|
if type(eventName) ~= "string" or not eventName:match("^[A-Z][A-Z0-9_]*$") then
|
|
96
|
-
|
|
130
|
+
local shown = IsSecret(eventName) and "<secret>" or tostring(eventName)
|
|
131
|
+
return false, L.INVALID_EVENT .. shown
|
|
97
132
|
elseif not uniqueNames[eventName] then
|
|
98
133
|
uniqueNames[eventName] = true
|
|
99
134
|
names[#names + 1] = eventName
|
|
@@ -116,7 +151,9 @@ function monitor.Start(eventNames, callback)
|
|
|
116
151
|
running = true
|
|
117
152
|
monitoringAllEvents = true
|
|
118
153
|
activeEventCount = 1
|
|
119
|
-
|
|
154
|
+
local now = SafeTime()
|
|
155
|
+
startedAt = now or 0
|
|
156
|
+
EnsureCombatShutdown()
|
|
120
157
|
return true
|
|
121
158
|
end
|
|
122
159
|
|
|
@@ -133,7 +170,9 @@ function monitor.Start(eventNames, callback)
|
|
|
133
170
|
changedCallback = callback
|
|
134
171
|
running = true
|
|
135
172
|
activeEventCount = #names
|
|
136
|
-
|
|
173
|
+
local now = SafeTime()
|
|
174
|
+
startedAt = now or 0
|
|
175
|
+
EnsureCombatShutdown()
|
|
137
176
|
return true
|
|
138
177
|
end
|
|
139
178
|
|
|
@@ -157,6 +196,8 @@ function monitor.GetCount()
|
|
|
157
196
|
return count
|
|
158
197
|
end
|
|
159
198
|
|
|
199
|
+
-- newestIndex 1 is the newest record. The ring keeps MAX_RECORDS entries and
|
|
200
|
+
-- always retains the newest record.
|
|
160
201
|
function monitor.GetRecord(newestIndex)
|
|
161
202
|
if type(newestIndex) ~= "number" or newestIndex < 1 or newestIndex > count then
|
|
162
203
|
return nil
|
|
@@ -178,4 +219,3 @@ function monitor.IsMonitoringAllEvents()
|
|
|
178
219
|
end
|
|
179
220
|
|
|
180
221
|
ns.EventMonitor = monitor
|
|
181
|
-
ns.RegisterCombatShutdown(monitor.Stop)
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
local ADDON_NAME, ns = ...
|
|
2
|
+
|
|
3
|
+
-- Bounded function-call tracing. One hooksecurefunc hook is installed per path
|
|
4
|
+
-- and never removed; Stop only disables recording so the hook degrades to a
|
|
5
|
+
-- constant-time guard. Records live in a 300-entry ring buffer.
|
|
6
|
+
local trace = {}
|
|
7
|
+
local MAX_RECORDS = 300
|
|
8
|
+
local MAX_ARGUMENTS = 16
|
|
9
|
+
local MAX_ARGUMENT_BYTES = 180
|
|
10
|
+
local hooks = {}
|
|
11
|
+
local records = {}
|
|
12
|
+
local head, count = 0, 0
|
|
13
|
+
local activePath
|
|
14
|
+
local enabled = false
|
|
15
|
+
local changedCallback
|
|
16
|
+
local startedAt = 0
|
|
17
|
+
local combatShutdownRegistered = false
|
|
18
|
+
|
|
19
|
+
local function IsSecret(value)
|
|
20
|
+
return issecretvalue and issecretvalue(value)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
local function Trim(text)
|
|
24
|
+
if IsSecret(text) then
|
|
25
|
+
return ""
|
|
26
|
+
end
|
|
27
|
+
return tostring(text or ""):match("^%s*(.-)%s*$")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
local function Wipe(target)
|
|
31
|
+
if wipe then
|
|
32
|
+
wipe(target)
|
|
33
|
+
return
|
|
34
|
+
end
|
|
35
|
+
for key in pairs(target) do
|
|
36
|
+
target[key] = nil
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
-- Strings are %q-quoted, tables collapse to <table>, secrets to <secret>, and
|
|
41
|
+
-- every argument text is capped at 180 bytes with a visible "..." suffix.
|
|
42
|
+
local function FormatArgument(value)
|
|
43
|
+
if IsSecret(value) then
|
|
44
|
+
return "<secret>"
|
|
45
|
+
end
|
|
46
|
+
local valueType = type(value)
|
|
47
|
+
local text
|
|
48
|
+
if valueType == "string" then
|
|
49
|
+
text = string.format("%q", value)
|
|
50
|
+
elseif valueType == "number" or valueType == "boolean" or valueType == "nil" then
|
|
51
|
+
text = tostring(value)
|
|
52
|
+
elseif valueType == "table" then
|
|
53
|
+
text = "<table>"
|
|
54
|
+
else
|
|
55
|
+
text = "<" .. valueType .. ">"
|
|
56
|
+
end
|
|
57
|
+
return #text > MAX_ARGUMENT_BYTES and (text:sub(1, MAX_ARGUMENT_BYTES) .. "...") or text
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
local function OnCall(path, ...)
|
|
61
|
+
if not enabled or activePath ~= path or ns.Safety.IsCombatBlocked() then
|
|
62
|
+
return
|
|
63
|
+
end
|
|
64
|
+
local suppliedCount = select("#", ...)
|
|
65
|
+
local arguments = {}
|
|
66
|
+
for index = 1, math.min(suppliedCount, MAX_ARGUMENTS) do
|
|
67
|
+
arguments[index] = FormatArgument(select(index, ...))
|
|
68
|
+
end
|
|
69
|
+
if suppliedCount > MAX_ARGUMENTS then
|
|
70
|
+
arguments[#arguments + 1] = "<" .. (suppliedCount - MAX_ARGUMENTS) .. " more arguments>"
|
|
71
|
+
end
|
|
72
|
+
head = head % MAX_RECORDS + 1
|
|
73
|
+
records[head] = {
|
|
74
|
+
elapsed = math.max(0, GetTime() - startedAt),
|
|
75
|
+
path = path,
|
|
76
|
+
arguments = arguments,
|
|
77
|
+
summary = table.concat(arguments, ", "),
|
|
78
|
+
}
|
|
79
|
+
count = math.min(count + 1, MAX_RECORDS)
|
|
80
|
+
if changedCallback then
|
|
81
|
+
changedCallback(records[head])
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
function trace.Start(path, callback)
|
|
86
|
+
if ns.Safety.IsCombatBlocked() then
|
|
87
|
+
return false, ns.L.COMBAT_BLOCKED
|
|
88
|
+
end
|
|
89
|
+
if IsSecret(path) then
|
|
90
|
+
return false, ns.L.FUNCTION_PATH_INVALID
|
|
91
|
+
end
|
|
92
|
+
path = Trim(path)
|
|
93
|
+
local succeeded, owner, functionName, errorMessage = ns.ObjectInspector.ResolveFunctionTarget(path)
|
|
94
|
+
if not succeeded then
|
|
95
|
+
return false, errorMessage
|
|
96
|
+
end
|
|
97
|
+
local target = owner[functionName]
|
|
98
|
+
if IsSecret(target) or type(target) ~= "function" then
|
|
99
|
+
return false, ns.L.FUNCTION_NOT_FOUND
|
|
100
|
+
end
|
|
101
|
+
-- Install once per path. A failed install leaves no partial state behind.
|
|
102
|
+
if not hooks[path] then
|
|
103
|
+
local hooked = pcall(hooksecurefunc, owner, functionName, function(...) OnCall(path, ...) end)
|
|
104
|
+
if not hooked then
|
|
105
|
+
return false, ns.L.FUNCTION_HOOK_FAILED
|
|
106
|
+
end
|
|
107
|
+
hooks[path] = true
|
|
108
|
+
end
|
|
109
|
+
-- The combat shutdown driver is registered lazily on the first trace so an
|
|
110
|
+
-- addon session that never traces creates no frame.
|
|
111
|
+
if not combatShutdownRegistered then
|
|
112
|
+
combatShutdownRegistered = true
|
|
113
|
+
ns.Safety.RegisterCombatShutdown(trace.Stop)
|
|
114
|
+
end
|
|
115
|
+
activePath, enabled, changedCallback, startedAt = path, true, callback, GetTime()
|
|
116
|
+
return true
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
-- Hooks are never removed: Stop only disables recording and the hook stays a
|
|
120
|
+
-- constant-time guard for the rest of the session.
|
|
121
|
+
function trace.Stop()
|
|
122
|
+
enabled, activePath, changedCallback = false, nil, nil
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
function trace.Clear()
|
|
126
|
+
Wipe(records)
|
|
127
|
+
head, count = 0, 0
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
function trace.GetCount()
|
|
131
|
+
return count
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
-- newestIndex 1 is the newest record.
|
|
135
|
+
function trace.GetRecord(newestIndex)
|
|
136
|
+
if type(newestIndex) ~= "number" or newestIndex < 1 or newestIndex > count then
|
|
137
|
+
return nil
|
|
138
|
+
end
|
|
139
|
+
return records[(head - newestIndex) % MAX_RECORDS + 1]
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
function trace.IsRunning()
|
|
143
|
+
return enabled
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
function trace.GetActivePath()
|
|
147
|
+
return activePath
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
ns.FunctionTrace = trace
|