lycheedev 2.5.1 → 3.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/native/windows-amd64/lycheedev.exe +0 -0
- package/package.json +1 -1
- package/payload/addon/Bridge/ActivityView.lua +26 -12
- package/payload/addon/Bridge/InputProtection.lua +63 -0
- package/payload/addon/Bridge/InputState.lua +45 -0
- package/payload/addon/Bridge/MemoryProtocol.lua +31 -0
- package/payload/addon/Bridge/ProbeExecution.lua +147 -0
- package/payload/addon/Bridge/ReceiverBindings.lua +6 -0
- package/payload/addon/Bridge/SlotProtocol.lua +165 -0
- package/payload/addon/Bridge/SlotRuntime.lua +106 -0
- package/payload/addon/Bridge/StartupBeacon.lua +8 -11
- package/payload/addon/Core/Compat.lua +7 -0
- package/payload/addon/Core/Controls.lua +16 -0
- package/payload/addon/Core/Locale.lua +6 -4
- package/payload/addon/Core/Locale_enUS.lua +4 -2
- package/payload/addon/Core/Platform.lua +4 -2
- package/payload/addon/Core/Runtime.lua +17 -6
- package/payload/addon/Lychee Dev.toc +8 -2
- package/payload/addon/Modules/AutomationHistory.lua +119 -0
- package/payload/addon/Modules/AutomationView.lua +26 -6
- package/payload/addon/UI/Pages/About.lua +0 -3
- package/payload/addon/UI/Pages/Automation.lua +40 -27
- package/payload/addon/UI/Pages/Diagnostics.lua +2 -4
- package/payload/addon/UI/Pages/Object.lua +0 -1
- package/payload/addon/UI/Pages/Run.lua +2 -1
- package/payload/addon/UI/Pages/Trace.lua +0 -1
- package/payload/addon/UI/Theme.lua +3 -2
- package/payload/addon/UI/Widgets.lua +32 -22
- package/payload/addon/UI/Window.lua +3 -35
- package/payload/skill/SKILL.md +39 -53
- package/payload/skill/references/commands.md +17 -15
- package/payload/skill/references/error-diagnosis.md +7 -11
- package/payload/skill/references/installation.md +6 -13
- package/payload/skill/references/live-investigation.md +193 -255
- package/payload/skill/references/live-startup.md +62 -130
- package/release.json +95 -65
- package/payload/addon/UI/Pages/Settings.lua +0 -82
|
Binary file
|
package/package.json
CHANGED
|
@@ -2,14 +2,17 @@ local _, ns = ...
|
|
|
2
2
|
|
|
3
3
|
-- Presentation has no input authority. The receiver owns the short input
|
|
4
4
|
-- shield; this independent, click-through companion owns only task feedback.
|
|
5
|
-
local frame, receiving, requestId, startedAt, failed
|
|
5
|
+
local frame, receiving, requestId, startedAt, failed, collecting, collectionTimer
|
|
6
|
+
local function clearTimer()
|
|
7
|
+
if collectionTimer then collectionTimer:Cancel();collectionTimer=nil end
|
|
8
|
+
end
|
|
6
9
|
local function create()
|
|
7
10
|
frame = CreateFrame("Frame", nil, UIParent)
|
|
8
11
|
frame:Hide()
|
|
9
|
-
frame:SetSize(120,
|
|
12
|
+
frame:SetSize(120, 120)
|
|
10
13
|
frame:SetFrameStrata("DIALOG")
|
|
11
14
|
frame:EnableMouse(false)
|
|
12
|
-
frame:SetPoint("TOPLEFT", UIParent, "TOPLEFT",
|
|
15
|
+
frame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 8, -8)
|
|
13
16
|
local anchor = CreateFrame("Frame", nil, frame)
|
|
14
17
|
anchor:SetSize(96, 96)
|
|
15
18
|
anchor:SetPoint("TOP", frame, "TOP", 0, 0)
|
|
@@ -19,13 +22,11 @@ local function create()
|
|
|
19
22
|
frame.logo:SetTexture(ns.Widgets.LOGO_TEXTURE)
|
|
20
23
|
frame.logo:SetTexCoord(0, 1, 0, 1)
|
|
21
24
|
frame.label = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
|
|
22
|
-
ns.Theme.SetFont(frame.label,
|
|
25
|
+
ns.Theme.SetFont(frame.label, 14, ns.Theme.text)
|
|
23
26
|
frame.label:SetPoint("TOP", anchor, "BOTTOM", 0, 0)
|
|
24
27
|
frame:SetScript("OnHide", function(self) self:SetScript("OnUpdate", nil) end)
|
|
25
28
|
end
|
|
26
|
-
local function anchor()
|
|
27
|
-
if frame and not failed then ns.ReceiptView.AnchorCompanion(frame) end
|
|
28
|
-
end
|
|
29
|
+
local function anchor() end -- Position belongs to this view, never a receipt.
|
|
29
30
|
local function render()
|
|
30
31
|
if not receiving and not requestId then
|
|
31
32
|
if frame then frame:SetScript("OnUpdate", nil); frame:Hide() end
|
|
@@ -34,7 +35,7 @@ local function render()
|
|
|
34
35
|
end
|
|
35
36
|
if not frame then create() end
|
|
36
37
|
startedAt = startedAt or GetTime()
|
|
37
|
-
frame.label:SetText(receiving and ns.L.ACTIVITY_CONNECTING or ns.L.ACTIVITY_PROBE)
|
|
38
|
+
frame.label:SetText(receiving and ns.L.ACTIVITY_CONNECTING or collecting and ns.L.ACTIVITY_COLLECTING or ns.L.ACTIVITY_PROBE)
|
|
38
39
|
anchor()
|
|
39
40
|
local current = ns.Persistence.Current()
|
|
40
41
|
local reduced = current and current.options and current.options.reducedMotion == true
|
|
@@ -51,6 +52,7 @@ local function update()
|
|
|
51
52
|
-- Cosmetic failure cannot interrupt execution or retain an input
|
|
52
53
|
-- shield. Fence repeated construction attempts for this runtime.
|
|
53
54
|
failed = true
|
|
55
|
+
clearTimer()
|
|
54
56
|
if frame then
|
|
55
57
|
if frame.SetScript then pcall(frame.SetScript,frame,"OnUpdate",nil) end
|
|
56
58
|
if frame.Hide then pcall(frame.Hide,frame) end
|
|
@@ -59,12 +61,24 @@ local function update()
|
|
|
59
61
|
end
|
|
60
62
|
ns.ActivityView = {
|
|
61
63
|
Receiving = function(value) receiving = value == true; update() end,
|
|
62
|
-
Begin = function(id) requestId = id; update() end,
|
|
64
|
+
Begin = function(id) clearTimer();collecting=false;requestId = id; update() end,
|
|
65
|
+
Collecting = function(id)
|
|
66
|
+
clearTimer();requestId=id;collecting=true;update()
|
|
67
|
+
if C_Timer and C_Timer.NewTimer then collectionTimer=C_Timer.NewTimer(20,function()
|
|
68
|
+
collectionTimer=nil
|
|
69
|
+
if requestId~=id or not collecting then return end
|
|
70
|
+
if frame then frame:SetScript("OnUpdate",nil) end
|
|
71
|
+
collectionTimer=C_Timer.NewTimer(5,function()
|
|
72
|
+
collectionTimer=nil
|
|
73
|
+
if requestId==id and collecting then requestId=nil;collecting=false;update() end
|
|
74
|
+
end)
|
|
75
|
+
end) end
|
|
76
|
+
end,
|
|
63
77
|
Finish = function(id)
|
|
64
|
-
if requestId == id then requestId = nil; update() end
|
|
78
|
+
if requestId == id then clearTimer();requestId = nil;collecting=false; update() end
|
|
65
79
|
end,
|
|
66
|
-
Stop = function() receiving, requestId = false, nil; update() end,
|
|
80
|
+
Stop = function() clearTimer();receiving, requestId, collecting = false, nil, false; update() end,
|
|
67
81
|
Refresh = update,
|
|
68
82
|
Anchor = anchor,
|
|
69
|
-
Current = function() return receiving and "connecting" or requestId and "probe" or nil, requestId end,
|
|
83
|
+
Current = function() return receiving and "connecting" or collecting and "collecting" or requestId and "probe" or nil, requestId end,
|
|
70
84
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
local _, ns = ...
|
|
2
|
+
|
|
3
|
+
-- One short, runtime-local lease. No UI or event work until explicitly acquired.
|
|
4
|
+
-- This shields this game's UI; it is not a system-wide keyboard/mouse lock.
|
|
5
|
+
local frame, active, unavailable
|
|
6
|
+
local function release(token, reason)
|
|
7
|
+
if not active or active ~= token then return false end
|
|
8
|
+
local prior=active;active=nil
|
|
9
|
+
if prior.timer then pcall(prior.timer.Cancel,prior.timer) end
|
|
10
|
+
frame:Hide();frame:UnregisterAllEvents();frame:SetScript("OnEvent",nil)
|
|
11
|
+
if ns.ActivityView then pcall(ns.ActivityView.Receiving,false) end
|
|
12
|
+
if reason and prior.interrupted then prior.interrupted(reason) end
|
|
13
|
+
return true
|
|
14
|
+
end
|
|
15
|
+
ns.InputProtection={
|
|
16
|
+
Acquire=function(seconds, interrupted, transport)
|
|
17
|
+
if unavailable then return nil,"input_protection_unavailable" end
|
|
18
|
+
if active then return nil,"input_protection_busy" end
|
|
19
|
+
if (issecretvalue and issecretvalue(seconds)) or type(seconds)~="number"
|
|
20
|
+
or seconds~=seconds or seconds<=0 or seconds==math.huge then return nil,"input_protection_invalid_budget" end
|
|
21
|
+
if ns.Platform.ObserveInputState(transport==true)~=true then return nil,"input_protection_not_ready" end
|
|
22
|
+
if not C_Timer or type(C_Timer.NewTimer)~="function" then return nil,"input_protection_timer_unavailable" end
|
|
23
|
+
if not frame then
|
|
24
|
+
local candidate
|
|
25
|
+
local created=pcall(function()
|
|
26
|
+
candidate=CreateFrame("Frame",nil,UIParent)
|
|
27
|
+
candidate:Hide();candidate:SetAllPoints(UIParent);candidate:SetFrameStrata("TOOLTIP")
|
|
28
|
+
candidate:EnableMouse(true);candidate:EnableMouseWheel(true);candidate:EnableKeyboard(true)
|
|
29
|
+
candidate:SetScript("OnKeyDown",function(self,key)
|
|
30
|
+
local chord=ns.Compat.ReceiverChord(key)
|
|
31
|
+
local token=active
|
|
32
|
+
self:SetPropagateKeyboardInput(false)
|
|
33
|
+
if chord=="ALT-CTRL-[" then release(token,"input_protection_cancelled");return end
|
|
34
|
+
if token and token.transport then
|
|
35
|
+
self:SetPropagateKeyboardInput(chord=="ALT-CTRL-F12" or chord=="ALT-CTRL-SHIFT-F12")
|
|
36
|
+
end
|
|
37
|
+
end)
|
|
38
|
+
end)
|
|
39
|
+
if not created then
|
|
40
|
+
unavailable=true
|
|
41
|
+
if candidate then pcall(candidate.Hide,candidate) end
|
|
42
|
+
return nil,"input_protection_unavailable"
|
|
43
|
+
end
|
|
44
|
+
frame=candidate
|
|
45
|
+
end
|
|
46
|
+
local token={interrupted=interrupted,transport=transport==true}
|
|
47
|
+
active=token
|
|
48
|
+
local ok=pcall(function()
|
|
49
|
+
token.timer=C_Timer.NewTimer(seconds,function()release(token,"input_protection_timeout")end)
|
|
50
|
+
assert(token.timer,"input_protection_timer_unavailable")
|
|
51
|
+
frame:RegisterEvent("PLAYER_REGEN_DISABLED");frame:RegisterEvent("PLAYER_LEAVING_WORLD")
|
|
52
|
+
frame:SetScript("OnEvent",function(_,event)release(token,event=="PLAYER_REGEN_DISABLED"
|
|
53
|
+
and "input_protection_combat" or "input_protection_world_changed")end)
|
|
54
|
+
frame:Show()
|
|
55
|
+
if ns.ActivityView then ns.ActivityView.Receiving(true) end
|
|
56
|
+
end)
|
|
57
|
+
if not ok then release(token);return nil,"input_protection_unavailable" end
|
|
58
|
+
return token
|
|
59
|
+
end,
|
|
60
|
+
Release=function(token)return release(token)end,
|
|
61
|
+
Cancel=function()return release(active,"input_protection_cancelled")end,
|
|
62
|
+
IsActive=function()return active~=nil end,
|
|
63
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
local _, ns = ...
|
|
2
|
+
|
|
3
|
+
-- Owner-approved native transport telemetry. One invisible sampler, no input
|
|
4
|
+
-- hooks or focus mutation. Explicit bridge-off removes all recurring work.
|
|
5
|
+
local frame, provider, record, last, sequence
|
|
6
|
+
local zero=string.rep("0",32)
|
|
7
|
+
local function sample()
|
|
8
|
+
local identity=provider and provider()
|
|
9
|
+
if not identity then record=nil;return end
|
|
10
|
+
local tick=ns.Compat.MonotonicSeconds()
|
|
11
|
+
if not tick then record=nil;return end
|
|
12
|
+
local ready,reason=ns.Platform.ObserveInputState()
|
|
13
|
+
sequence=sequence+1
|
|
14
|
+
if sequence>=4294967295 then ns.InputState.Stop();return end
|
|
15
|
+
identity.schema="lycheedev.input.v1"
|
|
16
|
+
identity.sampleMillis=math.floor(tick*1000)
|
|
17
|
+
identity.inputBlocked=ready~=true
|
|
18
|
+
identity.reason=reason or ""
|
|
19
|
+
local text=ns.CaptureWriter.Encode(identity,2048)
|
|
20
|
+
if not text then record=nil;return end
|
|
21
|
+
record=ns.MemoryProtocol.Encode(identity.runtime,identity.runtime,zero,5,1,sequence,text)
|
|
22
|
+
end
|
|
23
|
+
ns.InputState={
|
|
24
|
+
Start=function(observe)
|
|
25
|
+
provider=observe
|
|
26
|
+
if frame and frame:GetScript("OnUpdate") then return true end
|
|
27
|
+
sequence,last=sequence or 0,0
|
|
28
|
+
if not frame then frame=CreateFrame("Frame") end
|
|
29
|
+
frame:SetScript("OnUpdate",function(_,elapsed)
|
|
30
|
+
last=last+elapsed
|
|
31
|
+
if last<0.1 then return end
|
|
32
|
+
last=0
|
|
33
|
+
local ok=pcall(sample)
|
|
34
|
+
if not ok then record=nil end
|
|
35
|
+
end)
|
|
36
|
+
local ok=pcall(sample)
|
|
37
|
+
if not ok then record=nil end
|
|
38
|
+
return true
|
|
39
|
+
end,
|
|
40
|
+
Stop=function()
|
|
41
|
+
if frame then frame:SetScript("OnUpdate",nil) end
|
|
42
|
+
provider,record=nil,nil
|
|
43
|
+
end,
|
|
44
|
+
Snapshot=function()return record end,
|
|
45
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
local _, ns = ...
|
|
2
|
+
|
|
3
|
+
-- Immutable binary strings are retained by the transport. Finding one is not
|
|
4
|
+
-- publication proof: the host must request a fresh confirmation of live state.
|
|
5
|
+
local function u32(n)
|
|
6
|
+
return string.char(n%256,math.floor(n/256)%256,math.floor(n/65536)%256,math.floor(n/16777216)%256)
|
|
7
|
+
end
|
|
8
|
+
local function token(value)
|
|
9
|
+
return not (issecretvalue and issecretvalue(value)) and type(value)=="string"
|
|
10
|
+
and #value==32 and value:match("^[0-9a-f]+$")~=nil
|
|
11
|
+
end
|
|
12
|
+
local function raw(hex)
|
|
13
|
+
return (hex:gsub("..",function(pair)return string.char(tonumber(pair,16))end))
|
|
14
|
+
end
|
|
15
|
+
local function checksum(value)
|
|
16
|
+
return tonumber(ns.CaptureWriter.DigestBytes(value),16)
|
|
17
|
+
end
|
|
18
|
+
ns.MemoryProtocol = {
|
|
19
|
+
Token=token, Checksum=checksum,
|
|
20
|
+
Encode=function(nonce,runtime,ticket,kind,state,sequence,payload)
|
|
21
|
+
if not token(nonce) or not token(runtime) or not token(ticket)
|
|
22
|
+
or type(payload)~="string" or #payload>524288
|
|
23
|
+
or kind<1 or kind>5 or state<1 or state>255
|
|
24
|
+
or type(sequence)~="number" or sequence<0 or sequence>=4294967296 or sequence%1~=0 then
|
|
25
|
+
return nil,"memory_record_invalid"
|
|
26
|
+
end
|
|
27
|
+
local header="LYCMEM05"..raw(nonce)..raw(runtime)..raw(ticket)
|
|
28
|
+
..string.char(kind,state,0,0)..u32(sequence)..u32(#payload)..u32(checksum(payload))..u32(80)
|
|
29
|
+
return header..u32(checksum(header))..payload.."LYCEND05"..raw(nonce)..raw(runtime)
|
|
30
|
+
end,
|
|
31
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
local _, ns = ...
|
|
2
|
+
|
|
3
|
+
-- Runtime-local execution, independent of transport, display and persistence.
|
|
4
|
+
-- Async callbacks are bounded; Lua pcall is not a synchronous CPU sandbox.
|
|
5
|
+
ns.ProbeExecution={Run=function(fn,budget,done)
|
|
6
|
+
local live,async,depth=true,false,0
|
|
7
|
+
local started=ns.Compat.MonotonicSeconds()
|
|
8
|
+
local timer,pending
|
|
9
|
+
local cleanups,logs={},{}
|
|
10
|
+
local callbacks,logBytes=0,0
|
|
11
|
+
local protection,protectionUsed,guardFrame
|
|
12
|
+
local guards,events={},{}
|
|
13
|
+
local api={}
|
|
14
|
+
local function finish()
|
|
15
|
+
if not live or not pending or depth>0 then return end
|
|
16
|
+
live=false
|
|
17
|
+
local outcome=pending;pending=nil
|
|
18
|
+
if timer then pcall(timer.Cancel,timer);timer=nil end
|
|
19
|
+
local clean=true
|
|
20
|
+
-- Release our lease before user cleanup, even if that cleanup throws.
|
|
21
|
+
if protection then
|
|
22
|
+
if not pcall(ns.InputProtection.Release,protection) then clean=false end
|
|
23
|
+
protection=nil
|
|
24
|
+
end
|
|
25
|
+
if guardFrame then
|
|
26
|
+
if not pcall(function()guardFrame:UnregisterAllEvents();guardFrame:SetScript("OnEvent",nil)end) then clean=false end
|
|
27
|
+
end
|
|
28
|
+
for i=#cleanups,1,-1 do if not pcall(cleanups[i]) then clean=false end end
|
|
29
|
+
cleanups={}
|
|
30
|
+
done(outcome.ok,outcome.value,{resourcesReleased=clean,logs=logs})
|
|
31
|
+
end
|
|
32
|
+
local function settle(ok,value)
|
|
33
|
+
if not live then return nil,"probe_not_running" end
|
|
34
|
+
if not pending or not ok then pending={ok=ok,value=value} end
|
|
35
|
+
finish();return true
|
|
36
|
+
end
|
|
37
|
+
local function checkGuards()
|
|
38
|
+
for _,guard in ipairs(guards) do
|
|
39
|
+
local ok,value=pcall(guard.check)
|
|
40
|
+
if not ok or (issecretvalue and issecretvalue(value)) or value~=true then
|
|
41
|
+
settle(false,guard.reason);return nil,guard.reason
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
return true
|
|
45
|
+
end
|
|
46
|
+
function api:Guard(check, watchedEvents, reason)
|
|
47
|
+
if not live or pending or type(check)~="function" or #guards>=8
|
|
48
|
+
or (issecretvalue and issecretvalue(reason)) or type(reason)~="string" or #reason==0 or #reason>128
|
|
49
|
+
or type(watchedEvents)~="table" or getmetatable(watchedEvents) then return nil,"probe_invalid_guard" end
|
|
50
|
+
local newEvents={}
|
|
51
|
+
for i,event in ipairs(watchedEvents) do
|
|
52
|
+
if i>8 or (issecretvalue and issecretvalue(event)) or type(event)~="string"
|
|
53
|
+
or #event>80 or not event:match("^[A-Z][A-Z0-9_]+$") then return nil,"probe_invalid_guard_event" end
|
|
54
|
+
newEvents[event]=true
|
|
55
|
+
end
|
|
56
|
+
local count=0
|
|
57
|
+
for _ in pairs(events) do count=count+1 end
|
|
58
|
+
for event in pairs(newEvents) do if not events[event] then count=count+1 end end
|
|
59
|
+
if count>8 then return nil,"probe_guard_event_limit" end
|
|
60
|
+
guards[#guards+1]={check=check,reason=reason}
|
|
61
|
+
local ok,failure=checkGuards();if not ok then return nil,failure end
|
|
62
|
+
if next(newEvents) then
|
|
63
|
+
local registered=pcall(function()
|
|
64
|
+
if not guardFrame then
|
|
65
|
+
guardFrame=CreateFrame("Frame")
|
|
66
|
+
guardFrame:SetScript("OnEvent",function()if live and not pending then checkGuards() end end)
|
|
67
|
+
end
|
|
68
|
+
for event in pairs(newEvents) do guardFrame:RegisterEvent(event);events[event]=true end
|
|
69
|
+
end)
|
|
70
|
+
if not registered then settle(false,"probe_guard_event_unavailable");return nil,"probe_guard_event_unavailable" end
|
|
71
|
+
end
|
|
72
|
+
return true
|
|
73
|
+
end
|
|
74
|
+
function api:ProtectInput(seconds)
|
|
75
|
+
if not live or pending or protectionUsed then return nil,"probe_input_protection_used" end
|
|
76
|
+
if (issecretvalue and issecretvalue(seconds)) or type(seconds)~="number" or seconds~=seconds
|
|
77
|
+
or seconds<=0 or seconds==math.huge or not started then return nil,"probe_invalid_protection_budget" end
|
|
78
|
+
local remaining=budget-(ns.Compat.MonotonicSeconds()-started)
|
|
79
|
+
if seconds>remaining then return nil,"probe_budget_exhausted" end
|
|
80
|
+
local ok,reason=checkGuards();if not ok then return nil,reason end
|
|
81
|
+
if not ns.InputProtection then return nil,"probe_input_protection_unavailable" end
|
|
82
|
+
protection,reason=ns.InputProtection.Acquire(seconds,function(failure)
|
|
83
|
+
protection=nil;settle(false,failure)
|
|
84
|
+
end)
|
|
85
|
+
if not protection then return nil,reason end
|
|
86
|
+
protectionUsed=true;return true
|
|
87
|
+
end
|
|
88
|
+
function api:ReleaseInput()
|
|
89
|
+
if not protection then return false end
|
|
90
|
+
local token=protection;protection=nil
|
|
91
|
+
return ns.InputProtection.Release(token)
|
|
92
|
+
end
|
|
93
|
+
function api:IsInputProtected()return protection~=nil end
|
|
94
|
+
function api:Async(seconds)
|
|
95
|
+
if not live or async or not started or type(seconds)~="number" or seconds<1 or seconds>budget then return nil,"probe_invalid_async_budget" end
|
|
96
|
+
if type(C_Timer)~="table" or type(C_Timer.NewTimer)~="function" then return nil,"probe_async_unavailable" end
|
|
97
|
+
local remaining=seconds-(ns.Compat.MonotonicSeconds()-started)
|
|
98
|
+
if remaining<=0 then return nil,"probe_budget_exhausted" end
|
|
99
|
+
timer=C_Timer.NewTimer(remaining,function()settle(false,"probe_timeout")end)
|
|
100
|
+
if not timer then return nil,"probe_async_unavailable" end
|
|
101
|
+
async=true;return true
|
|
102
|
+
end
|
|
103
|
+
function api:Finish(value)
|
|
104
|
+
if not live then return nil,"probe_not_running" end
|
|
105
|
+
local valid,reason=checkGuards();if not valid then return nil,reason end
|
|
106
|
+
return settle(true,value)
|
|
107
|
+
end
|
|
108
|
+
function api:Fail(value)
|
|
109
|
+
if (issecretvalue and issecretvalue(value)) or type(value)~="string" or #value>4096 then value="probe_runtime_error" end
|
|
110
|
+
return settle(false,value)
|
|
111
|
+
end
|
|
112
|
+
function api:Callback(callback)
|
|
113
|
+
if not live or type(callback)~="function" or callbacks>=16 then return nil,"probe_callback_limit" end
|
|
114
|
+
callbacks=callbacks+1
|
|
115
|
+
return function(...)
|
|
116
|
+
if not live or pending then return nil,"probe_callback_inactive" end
|
|
117
|
+
local valid,reason=checkGuards();if not valid then return nil,reason end
|
|
118
|
+
depth=depth+1;local ok,result=pcall(callback,...);depth=depth-1
|
|
119
|
+
if not ok then api:Fail(result) else finish() end
|
|
120
|
+
return ok,result
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
function api:OnCleanup(callback)
|
|
124
|
+
if not live or type(callback)~="function" or #cleanups>=16 then return nil,"probe_cleanup_limit" end
|
|
125
|
+
cleanups[#cleanups+1]=callback;return true
|
|
126
|
+
end
|
|
127
|
+
function api:Log(...)
|
|
128
|
+
if not live or #logs>=100 or logBytes>=32768 then return nil,"probe_log_limit" end
|
|
129
|
+
local parts={}
|
|
130
|
+
for i=1,select("#",...) do
|
|
131
|
+
local value=select(i,...)
|
|
132
|
+
if issecretvalue and issecretvalue(value) then parts[i]="<secret>"
|
|
133
|
+
elseif type(value)=="string" or type(value)=="number" or type(value)=="boolean" then parts[i]=tostring(value)
|
|
134
|
+
else parts[i]="<unsupported>" end
|
|
135
|
+
end
|
|
136
|
+
local line=table.concat(parts," "):sub(1,32768-logBytes)
|
|
137
|
+
logs[#logs+1]=line;logBytes=logBytes+#line;return true
|
|
138
|
+
end
|
|
139
|
+
function api:IsCancelled()return not live end
|
|
140
|
+
depth=1;local ok,result=pcall(fn,api);depth=0
|
|
141
|
+
if not ok then api:Fail(result)
|
|
142
|
+
elseif pending then finish()
|
|
143
|
+
elseif not async then
|
|
144
|
+
local valid=checkGuards();if valid then settle(true,result) end
|
|
145
|
+
end
|
|
146
|
+
return api
|
|
147
|
+
end}
|
|
@@ -126,6 +126,7 @@ local function apply(profile)
|
|
|
126
126
|
return copy(valid)
|
|
127
127
|
end
|
|
128
128
|
local function stored()
|
|
129
|
+
if ns.SlotRuntime then return copy(defaults) end
|
|
129
130
|
local state, failure = ns.Persistence.Current()
|
|
130
131
|
if not state then return nil, failure end
|
|
131
132
|
local profile = state.options and state.options.receiverBindings
|
|
@@ -172,6 +173,7 @@ ns.ReceiverBindings = {
|
|
|
172
173
|
return key == terminal(effective[action])
|
|
173
174
|
end,
|
|
174
175
|
ConfigureProfile = function(profile)
|
|
176
|
+
if ns.SlotRuntime then return nil,"receiver_bindings_fixed" end
|
|
175
177
|
if ns.Receiver and ns.Receiver.IsActive and ns.Receiver.IsActive() then return nil,"receiver_active" end
|
|
176
178
|
if not owner then return nil,"receiver_bindings_unavailable" end
|
|
177
179
|
local state,failure=ns.Persistence.Current()
|
|
@@ -183,6 +185,7 @@ ns.ReceiverBindings = {
|
|
|
183
185
|
return copy(applied)
|
|
184
186
|
end,
|
|
185
187
|
Configure = function(action, chord)
|
|
188
|
+
if ns.SlotRuntime then return nil,"receiver_bindings_fixed" end
|
|
186
189
|
if action ~= "wake" and action ~= "submit" and action ~= "close" then return nil, "receiver_binding_action_invalid" end
|
|
187
190
|
if ns.Receiver and type(ns.Receiver.IsActive) == "function" and ns.Receiver.IsActive() then
|
|
188
191
|
return nil, "receiver_active"
|
|
@@ -223,6 +226,9 @@ ns.ReceiverBindings = {
|
|
|
223
226
|
if type(SetOverrideBindingClick) ~= "function" or type(CreateFrame) ~= "function" then
|
|
224
227
|
return nil, "receiver_bindings_unavailable"
|
|
225
228
|
end
|
|
229
|
+
if ns.SlotRuntime then
|
|
230
|
+
defaults = {wake="ALT-CTRL-F12",submit="ALT-CTRL-SHIFT-F12",close="ALT-CTRL-["}
|
|
231
|
+
end
|
|
226
232
|
handlers = callbacks
|
|
227
233
|
owner = CreateFrame("Frame", nil, UIParent)
|
|
228
234
|
local loggedIn = true
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
local _, ns = ...
|
|
2
|
+
|
|
3
|
+
-- Pure bounded protocol engine. Host input, frames, file loading and async
|
|
4
|
+
-- execution are adapters; there is only one owner and one active business job.
|
|
5
|
+
local ZERO=string.rep("0",32)
|
|
6
|
+
local LIMIT=64
|
|
7
|
+
local function plain(v)return not (issecretvalue and issecretvalue(v)) and type(v)=="table" and getmetatable(v)==nil end
|
|
8
|
+
local function safe(v)return not (issecretvalue and issecretvalue(v))end
|
|
9
|
+
|
|
10
|
+
ns.SlotProtocol = { Count=LIMIT, Create=function(adapter)
|
|
11
|
+
assert(plain(adapter) and ns.MemoryProtocol.Token(adapter.runtime),"invalid slot adapter")
|
|
12
|
+
local wire=ns.MemoryProtocol
|
|
13
|
+
local owner,fence,active,pending
|
|
14
|
+
local sequence,count=0,0
|
|
15
|
+
local consumed,operations,receipts={},{},{}
|
|
16
|
+
local descriptor
|
|
17
|
+
local api={}
|
|
18
|
+
local function observe(op)
|
|
19
|
+
if adapter.observe then
|
|
20
|
+
local ok,result,reason=pcall(adapter.observe,op)
|
|
21
|
+
op.historyError=not ok and "automation_history_failed" or (not result and reason or nil)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
local function nextSlot()
|
|
25
|
+
for i=1,LIMIT do if not consumed[i] then return i end end
|
|
26
|
+
return LIMIT+1
|
|
27
|
+
end
|
|
28
|
+
local function actor()
|
|
29
|
+
local value=adapter.actor()
|
|
30
|
+
if not plain(value) or not safe(value.guid) or not safe(value.character) or not safe(value.realm)
|
|
31
|
+
or type(value.guid)~="string" or type(value.character)~="string" or type(value.realm)~="string" then return nil end
|
|
32
|
+
return value
|
|
33
|
+
end
|
|
34
|
+
local function encode(value,limit)
|
|
35
|
+
local text,reason=adapter.encode(value,limit)
|
|
36
|
+
if not text then return nil,reason end
|
|
37
|
+
return text
|
|
38
|
+
end
|
|
39
|
+
local function publish(e,state,extra,kind)
|
|
40
|
+
if sequence>=4294967295 then return nil,"slot_sequence_exhausted" end
|
|
41
|
+
local a=actor();if not a then return nil,"slot_actor_unavailable" end
|
|
42
|
+
sequence=sequence+1
|
|
43
|
+
local value={schema="lycheedev.slot.v1",runtime=adapter.runtime,owner=owner or "",fence=fence or 0,
|
|
44
|
+
nonce=e.nonce,ticket=e.ticket or ZERO,action=e.action,state=state,sequence=sequence,
|
|
45
|
+
nextSlot=nextSlot(),slots=LIMIT,character=a.character,realm=a.realm,guid=a.guid,
|
|
46
|
+
build=adapter.build,product=adapter.product,release=adapter.release,inventory=adapter.inventory,inputState=adapter.inputState}
|
|
47
|
+
for k,v in pairs(extra or {}) do value[k]=v end
|
|
48
|
+
local text,reason=encode(value,16384);if not text then return nil,reason end
|
|
49
|
+
local record;record,reason=wire.Encode(e.nonce,adapter.runtime,e.ticket or ZERO,kind or 2,1,sequence,text)
|
|
50
|
+
if not record then return nil,reason end
|
|
51
|
+
receipts[e.nonce]=record
|
|
52
|
+
return record,value
|
|
53
|
+
end
|
|
54
|
+
function api.Describe()
|
|
55
|
+
local a=actor();if not a then return nil,"slot_actor_unavailable" end
|
|
56
|
+
local text=encode({schema="lycheedev.slot.identity.v1",runtime=adapter.runtime,owner=owner or "",fence=fence or 0,
|
|
57
|
+
nextSlot=nextSlot(),slots=LIMIT,character=a.character,realm=a.realm,guid=a.guid,
|
|
58
|
+
build=adapter.build,product=adapter.product,release=adapter.release,inventory=adapter.inventory,inputState=adapter.inputState},16384)
|
|
59
|
+
if not text then return nil,"slot_identity_encoding" end
|
|
60
|
+
descriptor=wire.Encode(ZERO,adapter.runtime,ZERO,1,1,sequence,text)
|
|
61
|
+
return descriptor
|
|
62
|
+
end
|
|
63
|
+
local function finish(op,ok,value,metadata)
|
|
64
|
+
if op.state~="running" then return nil,"slot_not_running" end
|
|
65
|
+
op.resourcesReleased=not metadata or metadata.resourcesReleased~=false
|
|
66
|
+
local text,reason=encode({ok=ok,result=ok and value or nil,error=not ok and value or nil,
|
|
67
|
+
resourcesReleased=op.resourcesReleased,logs=metadata and metadata.logs or nil},524288)
|
|
68
|
+
if not text then ok=false;text=assert(encode({ok=false,error=type(reason)=="string" and reason or "report_encoding_failed"},16384)) end
|
|
69
|
+
-- Store body and outcome before constructing its public response.
|
|
70
|
+
op.payload=text;op.bytes=#text;op.checksum=wire.Checksum(text)
|
|
71
|
+
op.body=assert(wire.Encode(op.envelope.nonce,adapter.runtime,op.envelope.ticket,3,3,op.sequence,text))
|
|
72
|
+
op.state="reported";op.ok=ok
|
|
73
|
+
observe(op)
|
|
74
|
+
local record,value=publish(op.envelope,"reported",{reportBytes=op.bytes,reportChecksum=op.checksum,challenge=op.challenge})
|
|
75
|
+
if adapter.activity then adapter.activity("collecting",op.envelope.ticket) end
|
|
76
|
+
return record,value
|
|
77
|
+
end
|
|
78
|
+
local function reject(e,reason)
|
|
79
|
+
if plain(e) and wire.Token(e.nonce) and (e.ticket==nil or wire.Token(e.ticket)) then return publish(e,"rejected",{reason=reason}) end
|
|
80
|
+
return nil,reason
|
|
81
|
+
end
|
|
82
|
+
function api.Receive(index,e)
|
|
83
|
+
if type(index)~="number" or index%1~=0 or index<1 or index>LIMIT then return nil,"slot_index_invalid" end
|
|
84
|
+
if consumed[index] then return nil,"slot_already_consumed" end
|
|
85
|
+
consumed[index]=true -- Load-on-demand is consumed even by invalid data.
|
|
86
|
+
if not plain(e) then return nil,"slot_envelope_invalid" end
|
|
87
|
+
-- Never inspect or execute encoded business code before these checks.
|
|
88
|
+
for _,key in ipairs({"schema","index","runtime","owner","fence","nonce","ticket","action","guid","build","challenge","preparedNonce","reportBytes","reportChecksum"}) do if not safe(e[key]) then return nil,"slot_secret_envelope" end end
|
|
89
|
+
if e.schema~="lycheedev.slot.v1" or e.index~=index or not wire.Token(e.nonce)
|
|
90
|
+
or not wire.Token(e.ticket) or not wire.Token(e.owner) then return nil,"slot_envelope_invalid" end
|
|
91
|
+
if receipts[e.nonce] then return receipts[e.nonce],"slot_nonce_reused" end
|
|
92
|
+
if e.runtime~=adapter.runtime then return reject(e,"slot_runtime_changed") end
|
|
93
|
+
local a=actor();if not a or a.guid~=e.guid or e.build~=adapter.build then return reject(e,"slot_target_changed") end
|
|
94
|
+
if type(e.fence)~="number" or e.fence<1 or e.fence%1~=0 or e.fence>9007199254740991 then return reject(e,"slot_fence_invalid") end
|
|
95
|
+
if e.action=="bind" then
|
|
96
|
+
if owner and owner~=e.owner then return reject(e,"slot_owner_busy") end
|
|
97
|
+
if fence and e.fence<fence then return reject(e,"slot_stale_driver") end
|
|
98
|
+
owner,fence=e.owner,e.fence
|
|
99
|
+
api.Describe()
|
|
100
|
+
return publish(e,"bound")
|
|
101
|
+
end
|
|
102
|
+
if owner~=e.owner or fence~=e.fence then return reject(e,"slot_owner_mismatch") end
|
|
103
|
+
if e.action=="prepare" then
|
|
104
|
+
if active or pending then return reject(e,"slot_busy") end
|
|
105
|
+
if operations[e.ticket] then return reject(e,"slot_operation_exists") end
|
|
106
|
+
if nextSlot()>LIMIT-3 or count>=12 then return reject(e,"slot_capacity") end
|
|
107
|
+
if not safe(e.code) or type(e.code)~="string" or #e.code<1 or #e.code>262144 or e.code:byte(1)==27
|
|
108
|
+
or not safe(e.codeBytes) or e.codeBytes~=#e.code or not safe(e.codeChecksum) or e.codeChecksum~=wire.Checksum(e.code)
|
|
109
|
+
or not safe(e.budget) or type(e.budget)~="number" or e.budget%1~=0 or e.budget<1 or e.budget>120 then return reject(e,"slot_code_invalid") end
|
|
110
|
+
local fn,reason=adapter.compile(e.code)
|
|
111
|
+
local challenge=adapter.runtime:sub(1,24)..string.format("%08x",sequence+1)
|
|
112
|
+
if not fn then
|
|
113
|
+
local op={envelope=e,challenge=challenge,sequence=sequence+1,state="running"}
|
|
114
|
+
operations[e.ticket]=op;active=op;count=count+1
|
|
115
|
+
if adapter.releaseInput then adapter.releaseInput() end
|
|
116
|
+
return finish(op,false,{kind="compile_error",message=reason or "slot_compile_failed"})
|
|
117
|
+
end
|
|
118
|
+
pending={envelope=e,fn=fn,challenge=challenge,sequence=sequence+1,state="prepared"}
|
|
119
|
+
operations[e.ticket]=pending;count=count+1
|
|
120
|
+
observe(pending)
|
|
121
|
+
return publish(e,"prepared",{challenge=challenge})
|
|
122
|
+
elseif e.action=="commit" then
|
|
123
|
+
if not pending or pending.envelope.ticket~=e.ticket or pending.challenge~=e.challenge
|
|
124
|
+
or pending.envelope.nonce~=e.preparedNonce then return reject(e,"slot_commit_mismatch") end
|
|
125
|
+
active=pending;pending=nil;active.state="running"
|
|
126
|
+
local op=active
|
|
127
|
+
observe(op)
|
|
128
|
+
local record,value=publish(e,"accepted")
|
|
129
|
+
if adapter.releaseInput then adapter.releaseInput() end
|
|
130
|
+
if adapter.activity then adapter.activity("running",e.ticket) end
|
|
131
|
+
local ok,reason=pcall(adapter.execute,op.fn,op.envelope.budget,function(ok,result,metadata)return finish(op,ok,result,metadata)end)
|
|
132
|
+
if not ok and op.state=="running" then finish(op,false,"probe_executor_error") end
|
|
133
|
+
return record,value
|
|
134
|
+
elseif e.action=="confirm" then
|
|
135
|
+
local op=operations[e.ticket]
|
|
136
|
+
if not op then return publish(e,"absent",nil,4) end
|
|
137
|
+
return publish(e,op.state,{preparedNonce=op.envelope.nonce,reportBytes=op.bytes,reportChecksum=op.checksum,challenge=op.challenge},4)
|
|
138
|
+
elseif e.action=="release" then
|
|
139
|
+
local op=operations[e.ticket]
|
|
140
|
+
if not op or (op.state~="reported" and op.state~="released")
|
|
141
|
+
or e.reportBytes~=op.bytes or e.reportChecksum~=op.checksum then return reject(e,"slot_release_mismatch") end
|
|
142
|
+
if op.resourcesReleased==false then return reject(e,"slot_resources_pending") end
|
|
143
|
+
op.payload=nil;op.body=nil;op.fn=nil;op.state="released"
|
|
144
|
+
-- Retain identity/digest tombstone; never re-admit its ticket.
|
|
145
|
+
op.envelope.code=nil
|
|
146
|
+
observe(op)
|
|
147
|
+
if active==op then active=nil end
|
|
148
|
+
if adapter.activity then adapter.activity("idle",e.ticket) end
|
|
149
|
+
return publish(e,"released")
|
|
150
|
+
elseif e.action=="unbind" then
|
|
151
|
+
if active or pending then return reject(e,"slot_busy") end
|
|
152
|
+
local record,value=publish(e,"unbound")
|
|
153
|
+
owner,fence=nil,nil;api.Describe();return record,value
|
|
154
|
+
end
|
|
155
|
+
return reject(e,"slot_action_invalid")
|
|
156
|
+
end
|
|
157
|
+
function api.NextSlot()return nextSlot()end
|
|
158
|
+
function api.InputIdentity()
|
|
159
|
+
local a=actor();if not a then return nil end
|
|
160
|
+
return {runtime=adapter.runtime,owner=owner or "",fence=fence or 0,nextSlot=nextSlot(),
|
|
161
|
+
guid=a.guid,build=adapter.build,character=a.character,realm=a.realm}
|
|
162
|
+
end
|
|
163
|
+
function api.Snapshot()return {descriptor=descriptor,receipts=receipts,operations=operations,owner=owner,fence=fence,consumed=consumed}end
|
|
164
|
+
return api
|
|
165
|
+
end }
|