lycheedev 1.2.0 → 2.0.1

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 (118) hide show
  1. package/LICENSE +49 -0
  2. package/README.md +45 -0
  3. package/THIRD_PARTY_NOTICES +812 -0
  4. package/bin/lycheedev.mjs +56 -0
  5. package/native/windows-amd64/lycheedev.exe +0 -0
  6. package/package.json +12 -33
  7. package/payload/addon/Bridge/CaptureWriter.lua +154 -0
  8. package/payload/addon/Bridge/Definitions.lua +3 -0
  9. package/payload/addon/Bridge/Identity.lua +127 -0
  10. package/{vendor/addon/Libs/AutomationQR.lua → payload/addon/Bridge/MatrixSymbol.lua} +23 -30
  11. package/payload/addon/Bridge/ProbeQueue.lua +136 -0
  12. package/payload/addon/Bridge/ProbeRunner.lua +128 -0
  13. package/payload/addon/Bridge/ReceiptView.lua +160 -0
  14. package/payload/addon/Bridge/Reentry.lua +192 -0
  15. package/payload/addon/Bridge/ReportStore.lua +153 -0
  16. package/payload/addon/Bridge/Session.lua +163 -0
  17. package/payload/addon/Clients/Evergreen.lua +2 -0
  18. package/payload/addon/Clients/Live.lua +2 -0
  19. package/payload/addon/Clients/Pandaria.lua +2 -0
  20. package/payload/addon/Clients/Titan.lua +2 -0
  21. package/payload/addon/Core/Compat.lua +59 -0
  22. package/payload/addon/Core/Controls.lua +168 -0
  23. package/{vendor/addon/Core/Bootstrap.lua → payload/addon/Core/Execute.lua} +12 -23
  24. package/{vendor → payload}/addon/Core/Inspector.lua +19 -235
  25. package/{vendor → payload}/addon/Core/Locale.lua +128 -93
  26. package/{vendor → payload}/addon/Core/Locale_enUS.lua +128 -95
  27. package/payload/addon/Core/Persistence.lua +58 -0
  28. package/payload/addon/Core/Platform.lua +58 -0
  29. package/payload/addon/Core/Runtime.lua +25 -0
  30. package/payload/addon/Core/Safety.lua +56 -0
  31. package/{vendor → payload}/addon/Core/Serializer.lua +18 -6
  32. package/payload/addon/Core/Stores.lua +611 -0
  33. package/payload/addon/Lychee Dev_Forever.toc +52 -0
  34. package/payload/addon/Lychee Dev_Mainline.toc +52 -0
  35. package/payload/addon/Lychee Dev_Mists.toc +52 -0
  36. package/payload/addon/Lychee Dev_Wrath.toc +52 -0
  37. package/payload/addon/Modules/AutomationView.lua +393 -0
  38. package/{vendor → payload}/addon/Modules/Diagnostics.lua +92 -36
  39. package/{vendor → payload}/addon/Modules/Events/Catalog.lua +9 -0
  40. package/{vendor → payload}/addon/Modules/Events/Monitor.lua +45 -5
  41. package/payload/addon/Modules/FunctionTrace.lua +150 -0
  42. package/{vendor → payload}/addon/Modules/ObjectInspector.lua +105 -31
  43. package/{vendor → payload}/addon/UI/Export.lua +64 -34
  44. package/{vendor → payload}/addon/UI/Pages/About.lua +26 -14
  45. package/payload/addon/UI/Pages/Automation.lua +446 -0
  46. package/payload/addon/UI/Pages/Diagnostics.lua +402 -0
  47. package/{vendor/addon/UI/Features.lua → payload/addon/UI/Pages/Events.lua} +192 -302
  48. package/{vendor → payload}/addon/UI/Pages/ExportRecords.lua +213 -132
  49. package/{vendor → payload}/addon/UI/Pages/Object.lua +229 -121
  50. package/payload/addon/UI/Pages/Run.lua +423 -0
  51. package/payload/addon/UI/Pages/Trace.lua +314 -0
  52. package/payload/addon/UI/TreeView.lua +246 -0
  53. package/{vendor/addon/UI/MainWindow.lua → payload/addon/UI/Widgets.lua} +89 -529
  54. package/payload/addon/UI/Window.lua +425 -0
  55. package/payload/skill/SKILL.md +87 -0
  56. package/payload/skill/agents/openai.yaml +7 -0
  57. package/payload/skill/references/addon-validation.md +42 -0
  58. package/payload/skill/references/asset-export.md +109 -0
  59. package/payload/skill/references/commands.md +169 -0
  60. package/payload/skill/references/data-investigation.md +242 -0
  61. package/payload/skill/references/error-diagnosis.md +41 -0
  62. package/payload/skill/references/installation.md +18 -0
  63. package/payload/skill/references/live-investigation.md +129 -0
  64. package/payload/skill/references/source-research.md +82 -0
  65. package/payload/skill/scripts/lycheedev.mjs +59 -0
  66. package/release.json +346 -0
  67. package/bin/lycheedev.js +0 -746
  68. package/src/addon.js +0 -95
  69. package/src/config.js +0 -68
  70. package/src/doctor.js +0 -126
  71. package/src/install.js +0 -145
  72. package/src/paths.js +0 -93
  73. package/src/py/instances.py +0 -165
  74. package/src/python.js +0 -111
  75. package/src/skill.js +0 -48
  76. package/src/wow.js +0 -541
  77. package/vendor/addon/Core/Clients/Forever.lua +0 -9
  78. package/vendor/addon/Core/Clients/Mainline.lua +0 -9
  79. package/vendor/addon/Core/Clients/Mists.lua +0 -9
  80. package/vendor/addon/Core/Clients/Titan.lua +0 -9
  81. package/vendor/addon/Core/Compatibility.lua +0 -43
  82. package/vendor/addon/Core/Database.lua +0 -859
  83. package/vendor/addon/Core/Safety.lua +0 -42
  84. package/vendor/addon/Lychee Dev_Forever.toc +0 -44
  85. package/vendor/addon/Lychee Dev_Mainline.toc +0 -44
  86. package/vendor/addon/Lychee Dev_Mists.toc +0 -44
  87. package/vendor/addon/Lychee Dev_Wrath.toc +0 -44
  88. package/vendor/addon/Modules/Automation/Controller.lua +0 -896
  89. package/vendor/addon/Modules/Automation/Reload.lua +0 -101
  90. package/vendor/addon/Modules/Automation/Report.lua +0 -409
  91. package/vendor/addon/Modules/Automation/auto/auto.lua +0 -12
  92. package/vendor/addon/Modules/FunctionTrace.lua +0 -85
  93. package/vendor/addon/UI/AutomationOverlay.lua +0 -253
  94. package/vendor/addon/UI/Pages/Automation.lua +0 -417
  95. package/vendor/addon/UI/Pages/Diagnostics.lua +0 -289
  96. package/vendor/addon/UI/Pages/Trace.lua +0 -165
  97. package/vendor/skill/SKILL.md +0 -44
  98. package/vendor/skill/agents/openai.yaml +0 -4
  99. package/vendor/skill/references/automation.md +0 -130
  100. package/vendor/skill/references/clients.md +0 -51
  101. package/vendor/skill/references/runtime-investigations.md +0 -104
  102. package/vendor/skill/scripts/automation/__init__.py +0 -1
  103. package/vendor/skill/scripts/automation/registry.py +0 -516
  104. package/vendor/skill/scripts/automation/reload.py +0 -121
  105. package/vendor/skill/scripts/automation/saved_variables.py +0 -438
  106. package/vendor/skill/scripts/automation/session.py +0 -207
  107. package/vendor/skill/scripts/automation/windows.py +0 -792
  108. package/vendor/skill/scripts/automation.py +0 -1067
  109. package/vendor/skill/scripts/requirements.txt +0 -13
  110. package/vendor/skill/scripts/selftest_offline.py +0 -1061
  111. package/vendor/skill/scripts/test_input_safety.py +0 -132
  112. package/vendor/skill/scripts/test_reload.py +0 -120
  113. /package/{vendor → payload}/addon/Media/GitHub.png +0 -0
  114. /package/{vendor → payload}/addon/Media/Logo.png +0 -0
  115. /package/{vendor → payload}/addon/Modules/Events/CatalogData_Forever.lua +0 -0
  116. /package/{vendor → payload}/addon/Modules/Events/CatalogData_Mainline.lua +0 -0
  117. /package/{vendor → payload}/addon/Modules/Events/CatalogData_Mists.lua +0 -0
  118. /package/{vendor → payload}/addon/Modules/Events/CatalogData_Titan.lua +0 -0
@@ -0,0 +1,128 @@
1
+ local ADDON_NAME, ns = ...
2
+
3
+ local requests, owner, count, bytes
4
+ local function restricted(value)
5
+ return issecretvalue and issecretvalue(value)
6
+ end
7
+ local function context()
8
+ local session, failure = ns.Session.Current()
9
+ if not session then
10
+ requests, owner, count, bytes = nil, nil, nil, nil
11
+ return nil, failure
12
+ end
13
+ if owner ~= session.generation then
14
+ requests, owner, count, bytes = {}, session.generation, 0, 0
15
+ end
16
+ return session
17
+ end
18
+ local function key(value)
19
+ return not restricted(value) and type(value) == "string" and #value > 0
20
+ and #value <= 128 and string.match(value, "^[%w_%-]+$") ~= nil
21
+ end
22
+ local function loadedSignal(requestId, code, reloadNonce, ready)
23
+ local identity, failure = ns.Session.NextIdentity()
24
+ if not identity then return nil, failure end
25
+ return ns.CaptureWriter.Encode({
26
+ schema = "lycheedev.signal.v1", release = ns.Release, kind = "loaded",
27
+ sessionNonce = identity.sessionNonce, requestId = requestId, reloadNonce = reloadNonce,
28
+ character = identity.character, realm = identity.realm, sequence = identity.sequence,
29
+ product = ns.Startup.identity.product, build = ns.Startup.identity.build,
30
+ inputReady = ready, codeBytes = #code, codeAdler32 = ns.CaptureWriter.DigestBytes(code),
31
+ }, 4096)
32
+ end
33
+
34
+ ns.ProbeRunner = {
35
+ Reported = function(requestId)
36
+ local session, failure = context()
37
+ if not session then return nil, failure end
38
+ if not key(requestId) then return nil, "probe_invalid_request" end
39
+ local request = requests[requestId]
40
+ if not request or request.state ~= "reported" then return nil, "probe_not_reported" end
41
+ local receipt, body = ns.ReportStore.Read(requestId)
42
+ if not receipt then return nil, body end
43
+ if receipt ~= request.report or body ~= request.reportBody then return nil, "probe_report_changed" end
44
+ return receipt, body, request.code
45
+ end,
46
+ VerifyAbsent = function(requestId)
47
+ local session, failure = context()
48
+ if not session then return nil, failure end
49
+ if not key(requestId) then return nil, "probe_invalid_request" end
50
+ if requests[requestId] ~= nil then return nil, "probe_still_retained" end
51
+ return true
52
+ end,
53
+ Load = function(requestId, code, reloadNonce)
54
+ local session, failure = context()
55
+ if not session then return nil, failure end
56
+ if not key(requestId) then return nil, "probe_invalid_request" end
57
+ if restricted(reloadNonce) or (reloadNonce ~= nil and (type(reloadNonce) ~= "string"
58
+ or #reloadNonce ~= 32 or not string.match(reloadNonce, "^[0-9a-f]+$"))) then
59
+ return nil, "probe_invalid_reload_nonce"
60
+ end
61
+ if restricted(code) or type(code) ~= "string" or #code == 0 or #code > 256 * 1024
62
+ or string.byte(code, 1) == 27 then return nil, "probe_invalid_code" end
63
+ if requests[requestId] then return nil, "probe_request_exists" end
64
+ local receipt, reason = ns.ReportStore.Read(requestId)
65
+ if receipt then return nil, "probe_report_exists" end
66
+ if reason ~= "report_unavailable" then return nil, reason end
67
+ if count >= 16 or bytes + #code > 1024 * 1024 then return nil, "probe_queue_limit" end
68
+ -- Compile text only. Loading definitions never invokes their code.
69
+ local executable = loadstring(code, "=LycheeProbe:" .. requestId)
70
+ if not executable then return nil, "probe_syntax_error" end
71
+ local signal, encodeFailure = loadedSignal(requestId, code, reloadNonce, false)
72
+ if not signal then return nil, encodeFailure end
73
+ requests[requestId] = { code = code, executable = executable, state = "loaded", reloadNonce = reloadNonce }
74
+ count, bytes = count + 1, bytes + #code
75
+ return signal
76
+ end,
77
+ RefreshLoaded = function(requestId)
78
+ local session, failure = context()
79
+ if not session then return nil, failure end
80
+ if not key(requestId) then return nil, "probe_invalid_request" end
81
+ local request = requests[requestId]
82
+ if not request then return nil, "probe_not_loaded" end
83
+ if request.state ~= "loaded" then return nil, "probe_already_dispatched" end
84
+ local ready, reason = ns.Platform.ObserveInputState()
85
+ if ready ~= true then return nil, reason end
86
+ return loadedSignal(requestId, request.code, request.reloadNonce, true)
87
+ end,
88
+ Dispatch = function(requestId)
89
+ local session, failure = context()
90
+ if not session then return nil, failure end
91
+ if not key(requestId) then return nil, "probe_invalid_request" end
92
+ local request = requests[requestId]
93
+ if not request then return nil, "probe_not_loaded" end
94
+ if request.state ~= "loaded" then return nil, "probe_already_dispatched" end
95
+ local receipt, reason = ns.ReportStore.Read(requestId)
96
+ if receipt then return nil, "probe_report_exists" end
97
+ if reason ~= "report_unavailable" then return nil, reason end
98
+ -- Consume before calling user code, including recursive dispatch. pcall
99
+ -- contains Lua errors; it is not a sandbox or a synchronous time limit.
100
+ request.state = "running"
101
+ local executable = request.executable
102
+ request.executable = nil
103
+ local ok, result = pcall(executable)
104
+ local active = ns.Session.Current()
105
+ if not active or active.generation ~= session.generation then
106
+ request.state = "unresolved"
107
+ return nil, "probe_session_changed"
108
+ end
109
+ local body
110
+ if ok then
111
+ body = { probeStatus = "completed", result = result }
112
+ else
113
+ -- Never stringify an arbitrary error object or restricted value.
114
+ local message = "probe_runtime_error"
115
+ if not restricted(result) and type(result) == "string" and #result <= 4096 then message = result end
116
+ body = { probeStatus = "failed", error = message }
117
+ end
118
+ local report, reportFailure = ns.ReportStore.Commit(requestId, request.code, body)
119
+ request.state = report and "reported" or "unresolved"
120
+ request.report = report
121
+ if report then
122
+ local _, storedBody = ns.ReportStore.Read(requestId)
123
+ request.reportBody = storedBody
124
+ end
125
+ -- An executed probe whose result could not be stored must not run again.
126
+ return report, reportFailure
127
+ end,
128
+ }
@@ -0,0 +1,160 @@
1
+ local ADDON_NAME, ns = ...
2
+
3
+ local frame, strips, lastBytes, lastReady, lastGeneration, lastScale
4
+ local focusWatch
5
+ local focusEvent = "ChatFrame.OnEditBoxFocusGained"
6
+ -- The white receipt card matches the legacy automation notice: anchored to the
7
+ -- top-left corner, at most 480 UI units on a side, with module size derived
8
+ -- from physical pixels so high-resolution screens do not grow giant symbols.
9
+ local MAX_CARD_UI_SIZE = 480
10
+ local function restricted(value)
11
+ return issecretvalue and issecretvalue(value)
12
+ end
13
+ local function stopFocusWatch()
14
+ local watch = focusWatch
15
+ focusWatch = nil
16
+ if watch then watch.registry:UnregisterCallback(focusEvent, watch) end
17
+ end
18
+ local function hide()
19
+ stopFocusWatch()
20
+ if ns.Session and type(ns.Session.CancelInputWait) == "function" then ns.Session.CancelInputWait() end
21
+ if ns.Identity and type(ns.Identity.CancelWait) == "function" then ns.Identity.CancelWait() end
22
+ lastBytes, lastReady, lastGeneration, lastScale = nil, nil, nil, nil
23
+ if frame then
24
+ frame:Hide()
25
+ frame:UnregisterAllEvents()
26
+ frame:SetScript("OnEvent", nil)
27
+ end
28
+ end
29
+ local function create()
30
+ frame = CreateFrame("Frame", nil, UIParent)
31
+ frame:Hide()
32
+ frame:EnableMouse(false)
33
+ frame:SetFrameStrata("DIALOG")
34
+ frame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 16, -16)
35
+ local background = frame:CreateTexture(nil, "BACKGROUND")
36
+ background:SetAllPoints(frame)
37
+ background:SetColorTexture(1, 1, 1, 1)
38
+ strips = {}
39
+ end
40
+ local function payload(value)
41
+ if restricted(value) or type(value) ~= "string" or #value == 0 or #value > 2048 then
42
+ return nil, "receipt_invalid_payload"
43
+ end
44
+ return value
45
+ end
46
+ -- One visual system for every receipt kind. The generation key only memoizes
47
+ -- identical redisplays; it is never an identity or an input permission.
48
+ -- Module size is max(2, ceil(3 * physical pixel)) UI units, every symbol keeps
49
+ -- a 4-module quiet zone, and the whole card is clamped to MAX_CARD_UI_SIZE.
50
+ local function cardGeometry(sizes)
51
+ local unit = 1
52
+ if ns.Compat and type(ns.Compat.GetPhysicalPixelSize) == "function" then
53
+ local measured = ns.Compat.GetPhysicalPixelSize()
54
+ if not (issecretvalue and issecretvalue(measured)) and type(measured) == "number"
55
+ and measured == measured and measured > 0 and measured < math.huge then
56
+ unit = measured
57
+ end
58
+ end
59
+ local across, tall = 8, 8
60
+ for index, size in ipairs(sizes) do
61
+ across = across + size
62
+ if index > 1 then across = across + 8 end
63
+ if size + 8 > tall then tall = size + 8 end
64
+ end
65
+ local modules = math.max(2, math.ceil(3 * unit))
66
+ modules = math.min(modules,
67
+ math.max(1, math.floor(MAX_CARD_UI_SIZE / across)),
68
+ math.max(1, math.floor(MAX_CARD_UI_SIZE / tall)))
69
+ return modules, across, tall
70
+ end
71
+
72
+ local function display(receipt, readiness, generation)
73
+ local valid, failure = payload(receipt)
74
+ if not valid then hide(); return nil, failure end
75
+ if readiness ~= nil then
76
+ local auxiliary, auxiliaryFailure = payload(readiness)
77
+ if not auxiliary then hide(); return nil, auxiliaryFailure end
78
+ end
79
+ if restricted(EventRegistry) or type(EventRegistry) ~= "table"
80
+ or type(EventRegistry.RegisterCallback) ~= "function"
81
+ or type(EventRegistry.UnregisterCallback) ~= "function" then
82
+ hide(); return nil, "receipt_events_unavailable"
83
+ end
84
+ local scale = UIParent:GetEffectiveScale()
85
+ if restricted(scale) or type(scale) ~= "number" or scale ~= scale or scale <= 0 or scale == math.huge then
86
+ hide(); return nil, "receipt_invalid_scale"
87
+ end
88
+ if lastBytes == receipt and lastReady == readiness and lastGeneration == generation and lastScale == scale then return true end
89
+ -- Merge horizontal black runs instead of allocating a texture per cell.
90
+ -- Matrix coordinates are [x][y]. Every symbol owns a 4-module quiet zone;
91
+ -- both share invalidation and one frame.
92
+ local runs, sizes = {}, {}
93
+ local origin = 4
94
+ for _, bytes in ipairs({receipt, readiness}) do
95
+ local matrix, reason = ns.MatrixSymbol.Encode(bytes)
96
+ if not matrix then hide(); return nil, reason end
97
+ local size = #matrix
98
+ if size < 21 or size > 177 then hide(); return nil, "receipt_invalid_symbol" end
99
+ sizes[#sizes + 1] = size
100
+ local count = 0
101
+ for y = 1, size do
102
+ local x = 1
103
+ while x <= size do
104
+ if matrix[x][y] > 0 then
105
+ local start = x
106
+ repeat x = x + 1 until x > size or matrix[x][y] <= 0
107
+ runs[#runs + 1] = { origin + start, y, x - start }
108
+ count = count + 1
109
+ if count > 8192 then hide(); return nil, "receipt_texture_limit" end
110
+ else x = x + 1 end
111
+ end
112
+ end
113
+ origin = origin + size + 8
114
+ end
115
+ local modules, across, tall = cardGeometry(sizes)
116
+ if not frame then create() end
117
+ frame:Hide()
118
+ frame:SetSize(across * modules, tall * modules)
119
+ for index, run in ipairs(runs) do
120
+ local texture = strips[index]
121
+ if not texture then
122
+ texture = frame:CreateTexture(nil, "ARTWORK")
123
+ texture:SetColorTexture(0, 0, 0, 1)
124
+ strips[index] = texture
125
+ end
126
+ texture:ClearAllPoints()
127
+ texture:SetPoint("TOPLEFT", frame, "TOPLEFT", (run[1] - 1) * modules, -(run[2] + 3) * modules)
128
+ texture:SetSize(run[3] * modules, modules)
129
+ texture:Show()
130
+ end
131
+ for index = #runs + 1, #strips do strips[index]:Hide() end
132
+ frame:SetScript("OnEvent", hide)
133
+ frame:RegisterEvent("PLAYER_LEAVING_WORLD")
134
+ frame:RegisterEvent("PLAYER_REGEN_DISABLED")
135
+ -- Visible receipts are point-in-time observations, not latched input
136
+ -- permission. Invalidate on known focus/combat changes without polling.
137
+ stopFocusWatch()
138
+ local watch = { registry = EventRegistry }
139
+ focusWatch = watch
140
+ watch.registry:RegisterCallback(focusEvent, function()
141
+ if focusWatch == watch then hide() end
142
+ end, watch)
143
+ lastBytes, lastReady, lastGeneration, lastScale = receipt, readiness, generation, scale
144
+ frame:Show()
145
+ return true
146
+ end
147
+
148
+ ns.ReceiptView = {
149
+ Hide = hide,
150
+ Show = function(receipt, readiness)
151
+ local session, failure = ns.Session.Current()
152
+ if not session then hide(); return nil, failure end
153
+ return display(receipt, readiness, session.generation)
154
+ end,
155
+ -- Identity markers bind no session. They share the exact display,
156
+ -- invalidation and focus/combat rules; only the memo key differs.
157
+ ShowIdentity = function(receipt)
158
+ return display(receipt, nil, 0)
159
+ end,
160
+ }
@@ -0,0 +1,192 @@
1
+ local ADDON_NAME, ns = ...
2
+
3
+ local waiting, ownedTicket, ownedRoot, ownedBytes, submitted
4
+ local function restricted(value) return issecretvalue and issecretvalue(value) end
5
+ local function plain(value)
6
+ return not restricted(value) and type(value) == "table" and getmetatable(value) == nil
7
+ end
8
+ local fields = { schema=true, requestId=true, sessionNonce=true, reloadNonce=true,
9
+ release=true, product=true, build=true, character=true, realm=true, guid=true,
10
+ runtimeEpoch=true, receipt=true, bodyBytes=true, bodyAdler32=true,
11
+ codeSHA256=true, codeAdler32=true, codeBytes=true, cleanupNonce=true, queueReload=true }
12
+ local function valid(ticket)
13
+ if not plain(ticket) then return false end
14
+ -- Encoding traverses all values before comparisons, rejecting secrets,
15
+ -- cycles and metatables. Do not interpret unknown/newer ticket formats.
16
+ if not ns.CaptureWriter.Encode(ticket, 8192) or ticket.schema ~= "lycheedev.reentry.v1" then return false end
17
+ for field in pairs(ticket) do if not fields[field] then return false end end
18
+ for _, field in ipairs({"requestId","release","product","build","character","realm","guid"}) do
19
+ local value=ticket[field]
20
+ if type(value)~="string" or #value==0 or #value>128 or string.find(value,"[%z\1-\31\127]") then return false end
21
+ end
22
+ if not string.match(ticket.requestId,"^[%w_%-]+$") then return false end
23
+ for _, field in ipairs({"sessionNonce","reloadNonce"}) do
24
+ local value=ticket[field]
25
+ if type(value)~="string" or #value~=32 or not string.match(value,"^[0-9a-f]+$") then return false end
26
+ end
27
+ if type(ticket.runtimeEpoch)~="number" or ticket.runtimeEpoch<1
28
+ or ticket.runtimeEpoch>=9007199254740991 or ticket.runtimeEpoch%1~=0 then return false end
29
+ if ticket.queueReload~=nil then
30
+ return ticket.queueReload==true and ticket.receipt==nil and ticket.bodyBytes==nil
31
+ and ticket.bodyAdler32==nil and ticket.codeSHA256==nil and ticket.codeAdler32==nil
32
+ and ticket.codeBytes==nil and ticket.cleanupNonce==nil
33
+ end
34
+ for field,size in pairs({codeSHA256=64,codeAdler32=8}) do
35
+ local value=ticket[field]
36
+ if type(value)~="string" or #value~=size or not string.match(value,"^[0-9a-f]+$") then return false end
37
+ end
38
+ if ticket.cleanupNonce~=nil then
39
+ if type(ticket.cleanupNonce)~="string" or #ticket.cleanupNonce~=32
40
+ or not string.match(ticket.cleanupNonce,"^[0-9a-f]+$")
41
+ or ticket.bodyBytes~=nil or ticket.bodyAdler32~=nil then return false end
42
+ elseif not (type(ticket.bodyBytes)=="number" and ticket.bodyBytes>=1 and ticket.bodyBytes<=512*1024 and ticket.bodyBytes%1==0
43
+ and type(ticket.bodyAdler32)=="string" and #ticket.bodyAdler32==8 and string.match(ticket.bodyAdler32,"^[0-9a-f]+$")~=nil) then return false end
44
+ return type(ticket.receipt)=="string" and #ticket.receipt>0 and #ticket.receipt<=4096
45
+ and type(ticket.codeBytes)=="number" and ticket.codeBytes>=1 and ticket.codeBytes<=256*1024 and ticket.codeBytes%1==0
46
+ end
47
+ local function cancel(discard)
48
+ if waiting then waiting:UnregisterAllEvents(); waiting:SetScript("OnEvent",nil); waiting=nil end
49
+ local state=ns.Persistence.Current()
50
+ if state and ((discard and valid(state.reentry)) or (state==ownedRoot and rawequal(state.reentry,ownedTicket)
51
+ and ns.CaptureWriter.Encode(state.reentry,8192)==ownedBytes)) then state.reentry=nil end
52
+ ownedTicket,ownedRoot,ownedBytes=nil,nil,nil
53
+ end
54
+ local function show(ticket)
55
+ if ticket.cleanupNonce then
56
+ local receipt,reason=ns.ProbeQueue.VerifyRetired(ticket.requestId,ticket.cleanupNonce)
57
+ if not receipt then return nil,reason end
58
+ return ns.ReceiptView.Show(receipt)
59
+ end
60
+ local identity,reason=ns.Session.NextIdentity()
61
+ if not identity then return nil,reason end
62
+ local ready=ns.Platform.ObserveInputState()==true
63
+ local receipt,failure=ns.CaptureWriter.Encode({
64
+ schema="lycheedev.signal.v1",kind="ready",release=ns.Release,
65
+ sessionNonce=identity.sessionNonce,requestId=ticket.requestId,reloadNonce=ticket.reloadNonce,
66
+ character=identity.character,realm=identity.realm,guid=identity.guid,
67
+ product=ns.Startup.identity.product,build=ns.Startup.identity.build,
68
+ sequence=identity.sequence,runtimeEpoch=identity.runtimeEpoch,inputReady=ready,
69
+ },2048)
70
+ if not receipt then return nil,failure end
71
+ return ns.ReceiptView.Show(receipt)
72
+ end
73
+ local function submit(state,ticket)
74
+ if not valid(ticket) then return nil,"reload_invalid_ticket" end
75
+ if type(C_UI)~="table" or type(C_UI.Reload)~="function" or type(InCombatLockdown)~="function" then return nil,"reload_unavailable" end
76
+ local ok,combat=pcall(InCombatLockdown)
77
+ if not ok or restricted(combat) or combat~=false then return nil,"reload_combat_unavailable" end
78
+ ns.Session.CancelInputWait(); ns.ReceiptView.Hide()
79
+ -- Publish before the one-shot effect. An exception is unresolved, never
80
+ -- permission to retry; opt-out can explicitly discard our own ticket.
81
+ state.reentry=ticket
82
+ ownedTicket,ownedRoot,ownedBytes,submitted=ticket,state,ns.CaptureWriter.Encode(ticket,8192),true
83
+ if not pcall(C_UI.Reload) then return nil,"reload_submission_failed" end
84
+ return "reload_requested"
85
+ end
86
+ ns.Reentry={
87
+ Cancel=cancel,
88
+ -- A pending, submitted or persisted reload ticket means a request-scoped
89
+ -- operation is mid-flight and owns the displayed receipt.
90
+ Busy=function()
91
+ if waiting or submitted then return true end
92
+ local state,failure=ns.Persistence.Current()
93
+ if not state then return nil,failure end
94
+ if restricted(state.reentry) then return nil,"reload_invalid_ticket" end
95
+ return state.reentry~=nil
96
+ end,
97
+ LoadQueue=function(requestId,reloadNonce)
98
+ if submitted then return nil,"reload_already_submitted" end
99
+ local session,reason=ns.Session.Current()
100
+ if not session then return nil,reason end
101
+ local state,failure=ns.Persistence.Current()
102
+ if not state then return nil,failure end
103
+ if restricted(state.reentry) or state.reentry~=nil then return nil,"reload_ticket_exists" end
104
+ local ticket={schema="lycheedev.reentry.v1",queueReload=true,requestId=requestId,
105
+ sessionNonce=session.sessionNonce,reloadNonce=reloadNonce,runtimeEpoch=session.runtimeEpoch,
106
+ character=session.character,realm=session.realm,guid=session.guid,
107
+ release=ns.Release,product=ns.Startup.identity.product,build=ns.Startup.identity.build}
108
+ if not valid(ticket) then return nil,"reload_invalid_ticket" end
109
+ local receipt,reportFailure=ns.ReportStore.Read(requestId)
110
+ if receipt or reportFailure~="report_unavailable" then return nil,"report_still_retained" end
111
+ local absent,probeFailure=ns.ProbeRunner.VerifyAbsent(requestId)
112
+ if not absent then return nil,probeFailure end
113
+ return submit(state,ticket)
114
+ end,
115
+ Reload=function(requestId,cleanupNonce)
116
+ if submitted then return nil,"reload_already_submitted" end
117
+ local session,reason=ns.Session.Current()
118
+ if not session then return nil,reason end
119
+ local state,failure=ns.Persistence.Current()
120
+ if not state then return nil,failure end
121
+ if restricted(state.reentry) or state.reentry~=nil then return nil,"reload_ticket_exists" end
122
+ local ticket,scopeFailure=ns.ProbeQueue.ReloadScope(requestId)
123
+ if not ticket then return nil,scopeFailure end
124
+ local receipt,body,code
125
+ if cleanupNonce~=nil then
126
+ receipt,body=ns.ReportStore.Acknowledged(requestId)
127
+ ticket.cleanupNonce=cleanupNonce
128
+ else
129
+ receipt,body,code=ns.ProbeRunner.Reported(requestId)
130
+ if receipt then
131
+ if #code~=ticket.codeBytes or ns.CaptureWriter.DigestBytes(code)~=ticket.codeAdler32 then return nil,"reload_code_changed" end
132
+ ticket.bodyBytes,ticket.bodyAdler32=#body,ns.CaptureWriter.DigestBytes(body)
133
+ end
134
+ end
135
+ if not receipt then return nil,body end
136
+ ticket.schema,ticket.runtimeEpoch,ticket.receipt="lycheedev.reentry.v1",session.runtimeEpoch,receipt
137
+ return submit(state,ticket)
138
+ end,
139
+ Start=function(frame)
140
+ local state=ns.Persistence.Current()
141
+ if not state or not state.options or state.options.bridgeEnabled~=true then return true end
142
+ if restricted(state.reentry) then return nil,"reload_invalid_ticket" end
143
+ if state.reentry==nil then return true end
144
+ local ticket=state.reentry
145
+ if not valid(ticket) then return nil,"reload_invalid_ticket" end
146
+ if waiting or submitted then return nil,"reload_already_submitted" end
147
+ ownedTicket,ownedRoot,ownedBytes=ticket,state,ns.CaptureWriter.Encode(ticket,8192)
148
+ local copy={}
149
+ for key,value in pairs(ticket) do copy[key]=value end
150
+ ticket=copy
151
+ waiting=frame
152
+ frame:RegisterEvent("PLAYER_ENTERING_WORLD")
153
+ frame:SetScript("OnEvent",function(_,event,initialLogin,reloading)
154
+ if event~="PLAYER_ENTERING_WORLD" or waiting~=frame then return end
155
+ local unchanged=rawequal(state.reentry,ownedTicket) and ns.CaptureWriter.Encode(state.reentry,8192)==ownedBytes
156
+ cancel()
157
+ if not unchanged then return end
158
+ local current=ns.Persistence.Current()
159
+ if current~=state or not current.options or current.options.bridgeEnabled~=true then return end
160
+ if restricted(initialLogin) or restricted(reloading) or initialLogin~=false or reloading~=true then return end
161
+ if restricted(state.runtimeEpoch) or state.runtimeEpoch~=ticket.runtimeEpoch then return end
162
+ local actor=ns.Platform.ObserveActor()
163
+ if not actor or actor.character~=ticket.character or actor.realm~=ticket.realm or actor.guid~=ticket.guid
164
+ or ns.Release~=ticket.release or ns.Startup.identity.product~=ticket.product or ns.Startup.identity.build~=ticket.build then return end
165
+ local receipt,body=ns.ReportStore.Read(ticket.requestId)
166
+ if ticket.cleanupNonce or ticket.queueReload then
167
+ if receipt~=nil or body~="report_unavailable" then return end
168
+ elseif receipt~=ticket.receipt or type(body)~="string" or #body~=ticket.bodyBytes or ns.CaptureWriter.DigestBytes(body)~=ticket.bodyAdler32 then return end
169
+ local bound=ns.Session.Bind(ticket.sessionNonce)
170
+ if not bound then return end
171
+ if bound.runtimeEpoch~=ticket.runtimeEpoch+1 then ns.Session.Release(); return end
172
+ if not ticket.cleanupNonce then
173
+ local scope=ns.ProbeQueue.ReloadScope(ticket.requestId)
174
+ if not scope then ns.Session.Release(); return end
175
+ for key,value in pairs(scope) do
176
+ if not (ticket.queueReload and (key=="codeSHA256" or key=="codeAdler32" or key=="codeBytes"))
177
+ and ticket[key]~=value then ns.Session.Release(); return end
178
+ end
179
+ end
180
+ local visible=show(ticket)
181
+ if not visible then ns.Session.Release(); ns.ReceiptView.Hide(); return end
182
+ if ticket.cleanupNonce then return end
183
+ ns.Session.WhenInputReady(function(ready)
184
+ if ready then
185
+ local shown=show(ticket)
186
+ if not shown then ns.ReceiptView.Hide() end
187
+ end
188
+ end)
189
+ end)
190
+ return true
191
+ end,
192
+ }
@@ -0,0 +1,153 @@
1
+ local ADDON_NAME, ns = ...
2
+
3
+ local MAX_RECORDS, MAX_BYTES = 100, 16 * 1024 * 1024
4
+ local lastAcknowledgement
5
+ local function restricted(value)
6
+ return issecretvalue and issecretvalue(value)
7
+ end
8
+ local function plain(value)
9
+ return not restricted(value) and type(value) == "table" and getmetatable(value) == nil
10
+ end
11
+ local function label(value, limit)
12
+ return not restricted(value) and type(value) == "string" and #value > 0
13
+ and #value <= limit and not string.find(value, "[%z\1-\31\127]")
14
+ end
15
+ local function requestKey(value)
16
+ return label(value, 128) and string.match(value, "^[%w_%-]+$") ~= nil
17
+ end
18
+
19
+ ns.ReportStore = {
20
+ Acknowledged = function(requestId)
21
+ if not requestKey(requestId) then return nil, "report_invalid_request" end
22
+ local state = ns.Persistence.Current()
23
+ local session = ns.Session.Current()
24
+ local ack = lastAcknowledgement
25
+ if not ack or not session or ack.root ~= state or ack.requestId ~= requestId
26
+ or ack.sessionNonce ~= session.sessionNonce or ack.guid ~= session.guid
27
+ or ack.generation ~= session.generation then
28
+ return nil, "report_acknowledgement_unavailable"
29
+ end
30
+ local receipt, reason = ns.ReportStore.Read(requestId)
31
+ if receipt or reason ~= "report_unavailable" then return nil, "report_still_retained" end
32
+ return ack.receipt
33
+ end,
34
+ Commit = function(requestId, code, value)
35
+ local state, failure = ns.Persistence.Current()
36
+ if not state then return nil, failure end
37
+ if not ns.Startup.ready or not state.options or state.options.bridgeEnabled ~= true then
38
+ return nil, "bridge_disabled"
39
+ end
40
+ if not requestKey(requestId) then return nil, "report_invalid_request" end
41
+ local session, sessionFailure = ns.Session.Current()
42
+ if not session then return nil, sessionFailure end
43
+ if restricted(code) or type(code) ~= "string" or #code > 256 * 1024 then
44
+ return nil, "report_invalid_code"
45
+ end
46
+ if not plain(state.reports) then return nil, "report_invalid_store" end
47
+ local previous = state.reports[requestId]
48
+ if restricted(previous) or previous ~= nil then return nil, "report_request_exists" end
49
+ local body, reason = ns.CaptureWriter.Encode(value)
50
+ if not body then return nil, reason end
51
+ local identity, identityFailure = ns.Session.NextIdentity()
52
+ if not identity then return nil, identityFailure end
53
+ local signal = {
54
+ schema = "lycheedev.signal.v1", release = ns.Release, kind = "reported",
55
+ sessionNonce = identity.sessionNonce, requestId = requestId,
56
+ character = identity.character, realm = identity.realm, sequence = identity.sequence,
57
+ product = ns.Startup.identity.product, build = ns.Startup.identity.build,
58
+ inputReady = false, reportBytes = #body,
59
+ reportAdler32 = ns.CaptureWriter.DigestBytes(body),
60
+ }
61
+ if #code > 0 then
62
+ signal.codeBytes = #code
63
+ signal.codeAdler32 = ns.CaptureWriter.DigestBytes(code)
64
+ end
65
+ local receipt, encodeFailure = ns.CaptureWriter.Encode(signal, 4096)
66
+ if not receipt then return nil, encodeFailure end
67
+ local count, bytes = 0, #receipt + #body
68
+ for key, record in pairs(state.reports) do
69
+ count = count + 1
70
+ if count >= MAX_RECORDS then return nil, "report_count_limit" end
71
+ if not requestKey(key) or not plain(record) or restricted(record.receipt)
72
+ or restricted(record.body) or type(record.receipt) ~= "string"
73
+ or type(record.body) ~= "string" then return nil, "report_invalid_store" end
74
+ if #record.receipt == 0 or #record.receipt > 4096 or #record.body == 0
75
+ or #record.body > 512 * 1024 then return nil, "report_invalid_store" end
76
+ for field in pairs(record) do
77
+ if restricted(field) or (field ~= "receipt" and field ~= "body") then
78
+ return nil, "report_invalid_store"
79
+ end
80
+ end
81
+ bytes = bytes + #record.receipt + #record.body
82
+ if bytes > MAX_BYTES then return nil, "report_store_limit" end
83
+ end
84
+ if bytes > MAX_BYTES then return nil, "report_store_limit" end
85
+ -- No pruning or replacement of unacknowledged reports. One final write
86
+ -- makes failures leave the previous store intact. Disk flush is separate.
87
+ state.reports[requestId] = { receipt = receipt, body = body }
88
+ return receipt
89
+ end,
90
+ Read = function(requestId)
91
+ if not requestKey(requestId) then return nil, "report_invalid_request" end
92
+ local state, failure = ns.Persistence.Current()
93
+ if not state then return nil, failure end
94
+ if not plain(state.reports) then return nil, "report_invalid_store" end
95
+ local record = state.reports[requestId]
96
+ if not restricted(record) and record == nil then return nil, "report_unavailable" end
97
+ if not plain(record) or restricted(record.receipt) or restricted(record.body)
98
+ or type(record.receipt) ~= "string" or type(record.body) ~= "string" then
99
+ return nil, "report_invalid_store"
100
+ end
101
+ return record.receipt, record.body
102
+ end,
103
+ Acknowledge = function(reported)
104
+ local state, failure = ns.Persistence.Current()
105
+ if not state then return nil, failure end
106
+ if not ns.Startup.ready or not state.options or state.options.bridgeEnabled ~= true then
107
+ return nil, "bridge_disabled"
108
+ end
109
+ if not plain(reported) then return nil, "report_invalid_acknowledgement" end
110
+ -- Encoding rejects restricted values, metatables and cycles before any
111
+ -- field comparisons. The host returns the archived original fields.
112
+ local receipt, encodeFailure = ns.CaptureWriter.Encode(reported, 4096)
113
+ if not receipt then return nil, encodeFailure end
114
+ local requestId, bodyBytes, bodyAdler32 = reported.requestId, reported.reportBytes, reported.reportAdler32
115
+ if not requestKey(requestId) or reported.schema ~= "lycheedev.signal.v1" or reported.kind ~= "reported"
116
+ or type(reported.sequence) ~= "number" or reported.sequence < 1 or reported.sequence > 9007199254740991
117
+ or reported.sequence % 1 ~= 0 or type(bodyBytes) ~= "number" or bodyBytes < 1 or bodyBytes > 512 * 1024
118
+ or bodyBytes % 1 ~= 0 or type(bodyAdler32) ~= "string" or #bodyAdler32 ~= 8
119
+ or not string.match(bodyAdler32, "^[0-9a-f]+$") then
120
+ return nil, "report_invalid_acknowledgement"
121
+ end
122
+ local session, sessionFailure = ns.Session.Current()
123
+ if not session then return nil, sessionFailure end
124
+ if reported.sessionNonce ~= session.sessionNonce or reported.character ~= session.character
125
+ or reported.realm ~= session.realm or reported.release ~= ns.Release
126
+ or reported.product ~= ns.Startup.identity.product or reported.build ~= ns.Startup.identity.build then
127
+ return nil, "report_acknowledgement_identity"
128
+ end
129
+ local storedReceipt, body = ns.ReportStore.Read(requestId)
130
+ if not storedReceipt then return nil, body end
131
+ if storedReceipt ~= receipt or #body ~= bodyBytes
132
+ or ns.CaptureWriter.DigestBytes(body) ~= bodyAdler32 then
133
+ return nil, "report_acknowledgement_mismatch"
134
+ end
135
+ -- After a reload the private counter starts again. A validated original
136
+ -- receipt provides a floor, never an arbitrary caller-supplied sequence.
137
+ local identity, identityFailure = ns.Session.NextIdentity(reported.sequence)
138
+ if not identity then return nil, identityFailure end
139
+ local signal = {}
140
+ for key, value in pairs(reported) do signal[key] = value end
141
+ signal.kind, signal.sequence, signal.inputReady = "acknowledged", identity.sequence, false
142
+ local acknowledgement, signalFailure = ns.CaptureWriter.Encode(signal, 2048)
143
+ if not acknowledgement then return nil, signalFailure end
144
+ -- Prepare the bounded optical receipt before deletion. The executor must
145
+ -- have archived and verified the full original report before this call.
146
+ -- This proves only in-memory cleanup, not a SavedVariables disk flush.
147
+ state.reports[requestId] = nil
148
+ -- One bounded runtime-only handoff, never inherited across reload/login.
149
+ lastAcknowledgement = { root=state, requestId=requestId, receipt=acknowledgement,
150
+ sessionNonce=session.sessionNonce, guid=session.guid, generation=session.generation }
151
+ return acknowledgement
152
+ end,
153
+ }