lycheedev 3.1.2 → 3.2.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.
Files changed (77) hide show
  1. package/README.md +16 -38
  2. package/THIRD_PARTY_NOTICES +4 -314
  3. package/bin/lycheedev.mjs +1 -1
  4. package/bin/update.mjs +26 -32
  5. package/native/windows-amd64/lycheedev.exe +0 -0
  6. package/package.json +1 -1
  7. package/payload/addon/Bindings.xml +12 -0
  8. package/payload/addon/Bridge/ActivityView.lua +2 -5
  9. package/payload/addon/Bridge/CaptureWriter.lua +9 -115
  10. package/payload/addon/Bridge/FocusBindings.lua +71 -0
  11. package/payload/addon/Bridge/InputProtection.lua +2 -9
  12. package/payload/addon/Bridge/InputState.lua +15 -19
  13. package/payload/addon/Bridge/MemoryProtocol.lua +1 -1
  14. package/payload/addon/Bridge/ProbeExecution.lua +1 -0
  15. package/payload/addon/Bridge/ReceiverBindings.lua +73 -279
  16. package/payload/addon/Bridge/SlotProtocol.lua +30 -12
  17. package/payload/addon/Bridge/SlotRuntime.lua +9 -12
  18. package/payload/addon/Core/ClientGate.lua +2 -0
  19. package/payload/addon/Core/Compat.lua +25 -24
  20. package/payload/addon/Core/Controls.lua +27 -248
  21. package/payload/addon/Core/Execute.lua +22 -19
  22. package/payload/addon/Core/Locale.lua +4 -116
  23. package/payload/addon/Core/Locale_enUS.lua +4 -116
  24. package/payload/addon/Core/Persistence.lua +2 -2
  25. package/payload/addon/Core/Runtime.lua +46 -64
  26. package/payload/addon/Core/Serializer.lua +9 -1
  27. package/payload/addon/Core/Startup.lua +20 -0
  28. package/payload/addon/Core/Stores.lua +63 -95
  29. package/payload/addon/LICENSE +21 -0
  30. package/payload/addon/Lychee Dev.toc +10 -21
  31. package/payload/addon/Modules/AutomationView.lua +47 -383
  32. package/payload/addon/Modules/Diagnostics.lua +0 -4
  33. package/payload/addon/Modules/Events/Catalog.lua +1 -1
  34. package/payload/addon/Modules/Events/CatalogData_Anniversary.lua +1489 -0
  35. package/payload/addon/Modules/Events/CatalogData_Era.lua +1489 -0
  36. package/payload/addon/Modules/FunctionTrace.lua +17 -6
  37. package/payload/addon/Modules/ObjectInspector.lua +27 -25
  38. package/payload/addon/THIRD_PARTY_NOTICES +483 -0
  39. package/payload/addon/UI/Pages/Automation.lua +7 -64
  40. package/payload/addon/UI/Pages/Events.lua +0 -4
  41. package/payload/addon/UI/Pages/ExportRecords.lua +1 -1
  42. package/payload/addon/UI/Pages/Object.lua +5 -4
  43. package/payload/addon/UI/Pages/Run.lua +7 -1
  44. package/payload/addon/UI/TreeView.lua +0 -11
  45. package/payload/addon/UI/Widgets.lua +0 -102
  46. package/payload/addon/UI/Window.lua +0 -6
  47. package/payload/skill/SKILL.md +11 -2
  48. package/payload/skill/references/commands.md +17 -27
  49. package/payload/skill/references/data-hotfix.md +6 -3
  50. package/payload/skill/references/data-investigation.md +5 -2
  51. package/payload/skill/references/data-tables.md +4 -0
  52. package/payload/skill/references/data-targets.md +4 -2
  53. package/payload/skill/references/installation.md +9 -3
  54. package/payload/skill/references/live-investigation.md +14 -6
  55. package/payload/skill/references/live-probes.md +9 -8
  56. package/payload/skill/references/live-recovery.md +67 -43
  57. package/payload/skill/references/live-startup.md +97 -76
  58. package/payload/skill/references/runtime-investigations.md +10 -8
  59. package/payload/skill/references/source-preparation.md +23 -2
  60. package/payload/skill/references/source-research.md +58 -5
  61. package/payload/skill/scripts/lycheedev.mjs +16 -12
  62. package/release.json +136 -176
  63. package/payload/addon/Bridge/Definitions.lua +0 -3
  64. package/payload/addon/Bridge/FaultRunner.lua +0 -44
  65. package/payload/addon/Bridge/Identity.lua +0 -127
  66. package/payload/addon/Bridge/InputProtocol.lua +0 -76
  67. package/payload/addon/Bridge/InputSignal.lua +0 -36
  68. package/payload/addon/Bridge/Investigation.lua +0 -159
  69. package/payload/addon/Bridge/MatrixSymbol.lua +0 -1169
  70. package/payload/addon/Bridge/ProbeQueue.lua +0 -205
  71. package/payload/addon/Bridge/ProbeRunner.lua +0 -349
  72. package/payload/addon/Bridge/ReceiptView.lua +0 -316
  73. package/payload/addon/Bridge/Receiver.lua +0 -326
  74. package/payload/addon/Bridge/Reentry.lua +0 -261
  75. package/payload/addon/Bridge/ReportStore.lua +0 -224
  76. package/payload/addon/Bridge/Session.lua +0 -173
  77. package/payload/addon/Bridge/StartupBeacon.lua +0 -63
@@ -1,205 +0,0 @@
1
- local ADDON_NAME, ns = ...
2
-
3
- local definitions = ns.ProbeDefinitions
4
- -- Bounded by the loaded queue (at most 16 entries). Keep definitions for the
5
- -- retained cleanup protocol, but acknowledged source no longer owns the UI
6
- -- and cannot be loaded again in this runtime. Disk retirement stays host-owned.
7
- local acknowledged = {}
8
- ns.ProbeDefinitions = nil
9
- local function restricted(value)
10
- return issecretvalue and issecretvalue(value)
11
- end
12
- local function plain(value)
13
- return not restricted(value) and type(value) == "table" and getmetatable(value) == nil
14
- end
15
- local function label(value)
16
- return not restricted(value) and type(value) == "string" and #value > 0
17
- and #value <= 128 and not string.find(value, "[%z\1-\31\127]")
18
- end
19
- local function hex(value, size)
20
- return not restricted(value) and type(value) == "string" and #value == size
21
- and string.match(value, "^[0-9a-f]+$") ~= nil
22
- end
23
- local fields = { release = true, sessionNonce = true, reloadNonce = true, character = true,
24
- realm = true, guid = true, product = true, build = true, code = true,
25
- codeSHA256 = true, codeAdler32 = true, codeBytes = true, budgetSeconds = true, goal = true }
26
- local function validate()
27
- if not plain(definitions) or restricted(definitions.schema) or definitions.schema ~= "lycheedev.queue.v1"
28
- or not plain(definitions.entries) then return nil, "queue_invalid_format" end
29
- for field in pairs(definitions) do
30
- if restricted(field) or (field ~= "schema" and field ~= "entries") then return nil, "queue_invalid_format" end
31
- end
32
- local count, bytes = 0, 0
33
- for id, entry in pairs(definitions.entries) do
34
- count = count + 1
35
- if count > 16 then return nil, "queue_limit" end
36
- if not label(id) or not string.match(id, "^[%w_%-]+$") or not plain(entry) then return nil, "queue_invalid_entry" end
37
- for field in pairs(entry) do
38
- if restricted(field) or not fields[field] then return nil, "queue_invalid_entry" end
39
- end
40
- for _, field in ipairs({ "release", "character", "realm", "guid", "product", "build" }) do
41
- if not label(entry[field]) then return nil, "queue_invalid_identity" end
42
- end
43
- if not hex(entry.sessionNonce, 32) or not hex(entry.reloadNonce, 32)
44
- or not hex(entry.codeSHA256, 64) or not hex(entry.codeAdler32, 8) then return nil, "queue_invalid_digest" end
45
- if entry.budgetSeconds ~= nil and (restricted(entry.budgetSeconds) or
46
- type(entry.budgetSeconds) ~= "number" or entry.budgetSeconds % 1 ~= 0 or
47
- entry.budgetSeconds < 1 or entry.budgetSeconds > 120) then return nil, "queue_invalid_budget" end
48
- if restricted(entry.goal) or entry.goal~=nil and entry.goal~="finished" then return nil,"queue_invalid_goal" end
49
- if restricted(entry.code) or type(entry.code) ~= "string" or #entry.code == 0 or #entry.code > 256 * 1024
50
- or string.byte(entry.code, 1) == 27 or string.find(entry.code, "%z")
51
- or restricted(entry.codeBytes) or entry.codeBytes ~= #entry.code
52
- or ns.CaptureWriter.DigestBytes(entry.code) ~= entry.codeAdler32 then return nil, "queue_code_mismatch" end
53
- bytes = bytes + #entry.code
54
- if bytes > 1024 * 1024 then return nil, "queue_limit" end
55
- end
56
- return true
57
- end
58
-
59
- local function selectEntry(requestId)
60
- local session, failure = ns.Session.Current()
61
- if not session then return nil, failure end
62
- if not label(requestId) then return nil, "queue_invalid_request" end
63
- local valid, reason = validate()
64
- if not valid then return nil, reason end
65
- local entry = definitions.entries[requestId]
66
- if not entry then return nil, "queue_request_missing" end
67
- local identity = ns.Startup.identity
68
- if entry.release ~= ns.Release or entry.product ~= identity.product or entry.build ~= identity.build
69
- or entry.character ~= session.character or entry.realm ~= session.realm or entry.guid ~= session.guid
70
- or entry.sessionNonce ~= session.sessionNonce then return nil, "queue_identity_mismatch" end
71
- return entry
72
- end
73
-
74
- ns.ProbeQueue = {
75
- -- Registered entries mean a request-scoped operation still owns this
76
- -- window's queue and display. Unreadable definitions fail closed.
77
- Busy = function()
78
- if ns.ProbeRunner.Busy() then return true end
79
- if ns.Investigation then
80
- local busy,reason=ns.Investigation.Busy()
81
- if busy~=false then return busy,reason end
82
- end
83
- if definitions == nil then return false end
84
- local valid, reason = validate()
85
- if not valid then return nil, reason end
86
- if next(definitions.entries) == nil then return false end
87
- local actor, failure = ns.Platform.ObserveActor()
88
- if not actor then return nil, failure end
89
- -- The installation queue is shared by windows; another character
90
- -- cannot own this window merely because its definition is loaded here.
91
- for id, entry in pairs(definitions.entries) do
92
- if not acknowledged[id] and entry.character == actor.character
93
- and entry.realm == actor.realm and entry.guid == actor.guid then return true end
94
- end
95
- return false
96
- end,
97
- ReloadScope = function(requestId)
98
- local entry, reason = selectEntry(requestId)
99
- if not entry then return nil, reason end
100
- return { requestId = requestId, sessionNonce = entry.sessionNonce, reloadNonce = entry.reloadNonce,
101
- release = entry.release, product = entry.product, build = entry.build,
102
- character = entry.character, realm = entry.realm, guid = entry.guid,
103
- codeSHA256 = entry.codeSHA256, codeAdler32 = entry.codeAdler32, codeBytes = entry.codeBytes }
104
- end,
105
- VerifyRetired = function(requestId, nonce)
106
- local session, failure = ns.Session.Current()
107
- if not session then return nil, failure end
108
- if not label(requestId) or not string.match(requestId, "^[%w_%-]+$") then
109
- return nil, "queue_invalid_request"
110
- end
111
- if not hex(nonce, 32) then return nil, "queue_invalid_cleanup_nonce" end
112
- local valid, reason = validate()
113
- if not valid then return nil, reason end
114
- if definitions.entries[requestId] ~= nil then return nil, "queue_request_retained" end
115
- local receipt, reportFailure = ns.ReportStore.Read(requestId)
116
- if receipt ~= nil then return nil, "report_still_retained" end
117
- if reportFailure ~= "report_unavailable" then return nil, reportFailure end
118
- local absent, probeFailure = ns.ProbeRunner.VerifyAbsent(requestId)
119
- if not absent then return nil, probeFailure end
120
- local identity, identityFailure = ns.Session.NextIdentity()
121
- if not identity then return nil, identityFailure end
122
- -- This observes loaded memory, never disk or host ownership. No report,
123
- -- queue entry or executable is removed to manufacture a success receipt.
124
- return ns.CaptureWriter.EncodeSignal({
125
- schema = "lycheedev.signal.v1", release = ns.Release, kind = "cleared",
126
- sessionNonce = identity.sessionNonce, requestId = requestId, cleanupNonce = nonce,
127
- character = identity.character, realm = identity.realm, guid = identity.guid,
128
- product = ns.Startup.identity.product, build = ns.Startup.identity.build,
129
- sequence = identity.sequence, runtimeEpoch = identity.runtimeEpoch, inputReady = false,
130
- }, 4096)
131
- end,
132
- Load = function(requestId)
133
- local entry, reason = selectEntry(requestId)
134
- if not entry then return nil, reason end
135
- if acknowledged[requestId] then return nil, "queue_request_acknowledged" end
136
- if entry.goal=="finished" then
137
- local reserved,failure=ns.Investigation.Reserve(requestId,entry)
138
- if not reserved then return nil,failure end
139
- end
140
- -- SHA-256 is checked by the host. The game checks actual code bytes and
141
- -- Adler-32; neither a carried digest nor loading is execution permission.
142
- return ns.ProbeRunner.Load(requestId, entry.code, entry.reloadNonce, entry.budgetSeconds or 120, entry.goal)
143
- end,
144
- Acknowledge = function(requestId, sequence)
145
- local entry, reason = selectEntry(requestId)
146
- if not entry then return nil, reason end
147
- if restricted(sequence) or type(sequence) ~= "number" or sequence < 1
148
- or sequence > 9007199254740991 or sequence % 1 ~= 0 then return nil, "report_invalid_sequence" end
149
- local receipt, body = ns.ReportStore.Read(requestId)
150
- if not receipt then
151
- if body ~= "report_unavailable" then return nil, body end
152
- -- Re-display only this runtime's exact ACK. The original report
153
- -- sequence is checked; source is never loaded or executed again.
154
- return ns.ReportStore.Acknowledged(requestId, sequence)
155
- end
156
- -- Reconstruct only the canonical receipt format generated by Commit.
157
- -- The store compares its exact bytes before deletion, so neither an
158
- -- arbitrary sequence nor changed code/body can authorize another report.
159
- local acknowledgement, failure = ns.ReportStore.Acknowledge({
160
- schema = "lycheedev.signal.v1", release = entry.release, kind = "reported",
161
- sessionNonce = entry.sessionNonce, requestId = requestId,
162
- character = entry.character, realm = entry.realm, sequence = sequence,
163
- product = entry.product, build = entry.build, inputReady = false,
164
- codeBytes = entry.codeBytes, codeAdler32 = entry.codeAdler32,
165
- reportBytes = #body, reportAdler32 = ns.CaptureWriter.DigestBytes(body),
166
- })
167
- if acknowledgement then
168
- acknowledged[requestId] = true
169
- if ns.AutomationView and ns.AutomationView.Changed then ns.AutomationView.Changed() end
170
- end
171
- return acknowledgement, failure
172
- end,
173
- -- Host-side recovery for a stuck runtime whose queue blocks identity after
174
- -- its disk entry was retired (abandon) or its receipt was lost. Session
175
- -- free and actor scoped exactly like Busy: entries of other characters on
176
- -- a shared installation are never touched. A pending reentry ticket is
177
- -- stale residue here by definition; the caller verified no disk owner.
178
- Reset = function(nonce)
179
- if not hex(nonce, 32) then return nil, "reset_invalid_nonce" end
180
- if ns.ProbeRunner.Busy() then return nil,"probe_runtime_busy" end
181
- local valid, reason = validate()
182
- if not valid then return nil, reason end
183
- local actor, actorFailure = ns.Platform.ObserveActor()
184
- if not actor then return nil, actorFailure or "no_actor" end
185
- if ns.Reentry and type(ns.Reentry.Cancel) == "function" then ns.Reentry.Cancel(true) end
186
- local reset = 0
187
- for id, entry in pairs(definitions.entries) do
188
- if not acknowledged[id] and entry.character == actor.character
189
- and entry.realm == actor.realm and entry.guid == actor.guid then
190
- acknowledged[id] = true
191
- reset = reset + 1
192
- end
193
- end
194
- local identity, identityFailure = ns.Platform.ObserveBuild()
195
- if not identity then return nil, identityFailure end
196
- return ns.CaptureWriter.EncodeSignal({
197
- schema = "lycheedev.signal.v1", release = ns.Release, kind = "reset",
198
- sessionNonce = "", probeNonce = nonce,
199
- requestId = "", character = actor.character, realm = actor.realm,
200
- guid = actor.guid, product = identity.product,
201
- build = identity.build, sequence = 0,
202
- inputReady = false,
203
- }, 4096)
204
- end,
205
- }
@@ -1,349 +0,0 @@
1
- local ADDON_NAME, ns = ...
2
-
3
- local requests, owner, count, bytes
4
- local MAX_ASYNC_SECONDS,MAX_LOG_BYTES,MAX_LOG_ENTRIES,MAX_CLEANUPS=120,32768,100,16
5
- local function notify()
6
- if ns.AutomationView and ns.AutomationView.Changed then ns.AutomationView.Changed() end
7
- end
8
- local function restricted(value)
9
- return issecretvalue and issecretvalue(value)
10
- end
11
- local function busy(except)
12
- for id, request in pairs(requests or {}) do
13
- if id ~= except and (request.state == "running" or request.state == "settling"
14
- or request.state == "quarantined" or request.cleanupFailed) then return true end
15
- end
16
- return false
17
- end
18
- local function context()
19
- local session, failure = ns.Session.Current()
20
- if not session then
21
- return nil, failure
22
- end
23
- if owner ~= session.generation then
24
- -- Input sessions are replaceable; live work is not. Only a verified
25
- -- new Lua runtime can discard an unresolved old executor.
26
- if busy() then return nil, "probe_runtime_busy" end
27
- requests, owner, count, bytes = {}, session.generation, 0, 0
28
- end
29
- return session
30
- end
31
- local function key(value)
32
- return not restricted(value) and type(value) == "string" and #value > 0
33
- and #value <= 128 and string.match(value, "^[%w_%-]+$") ~= nil
34
- end
35
- local function loadedSignal(requestId, code, reloadNonce, ready)
36
- local identity, failure = ns.Session.NextIdentity()
37
- if not identity then return nil, failure end
38
- return ns.CaptureWriter.EncodeSignal({
39
- schema = "lycheedev.signal.v1", release = ns.Release, kind = "loaded",
40
- sessionNonce = identity.sessionNonce, requestId = requestId, reloadNonce = reloadNonce,
41
- character = identity.character, realm = identity.realm, sequence = identity.sequence,
42
- product = ns.Startup.identity.product, build = ns.Startup.identity.build,
43
- inputReady = ready, codeBytes = #code, codeAdler32 = ns.CaptureWriter.DigestBytes(code),
44
- }, 4096)
45
- end
46
- local function safeMessage(value,fallback)
47
- if restricted(value) or type(value)~="string" or #value==0 or #value>4096 then return fallback end
48
- return value
49
- end
50
- local REPORT_ERROR_CODES = { report_byte_limit=true, report_secret_value=true,
51
- report_invalid_utf8=true, report_depth_limit=true, report_entry_limit=true,
52
- report_cycle=true, report_metatable=true, report_nonfinite_number=true,
53
- report_unsupported_value=true, report_nonstring_key=true,
54
- report_count_limit=true, report_store_limit=true,
55
- report_invalid_store=true, report_invalid_document=true }
56
- local function minimalFailure(request, reason)
57
- local identity = ns.Session.NextIdentity()
58
- if not identity then return nil end
59
- local code = not restricted(reason) and REPORT_ERROR_CODES[reason] and reason or "report_encoding_failed"
60
- return ns.CaptureWriter.EncodeSignal({
61
- schema="lycheedev.signal.v1", release=ns.Release, kind="report_error",
62
- sessionNonce=identity.sessionNonce, requestId=request.requestId,
63
- character=identity.character, realm=identity.realm, guid=identity.guid,
64
- product=ns.Startup.identity.product, build=ns.Startup.identity.build,
65
- sequence=identity.sequence, inputReady=false, errorCode=code,
66
- }, 2048)
67
- end
68
- local function cleanup(request)
69
- local failures = {}
70
- local function attempt(callback, ...)
71
- local ok, reason = pcall(callback, ...)
72
- if not ok then failures[#failures+1] = safeMessage(reason,"probe_cleanup_error") end
73
- end
74
- if request.timer and type(request.timer.Cancel)=="function" then attempt(request.timer.Cancel,request.timer) end
75
- request.timer=nil
76
- local callbacks=request.cleanups or {}
77
- request.cleanups={}
78
- for index=#callbacks,1,-1 do attempt(callbacks[index]) end
79
- request.cleanupFailed = #failures > 0
80
- return request.cleanupFailed and {state="pending",errors=failures} or nil
81
- end
82
- local function publish(request,receipt)
83
- local function refresh()
84
- local session=ns.Session.Current()
85
- if not session or session.generation~=request.generation then return nil end
86
- if request.state=="unresolved" and request.failureReceipt==receipt then
87
- -- A terminal encoding failure has no full SavedVariables report.
88
- -- Refresh the exact failure marker without dispatching again.
89
- return receipt
90
- end
91
- if request.state~="reported" or request.report~=receipt then return nil end
92
- local current,_,signal=ns.Session.ReadyReceipt()
93
- if current then return receipt,current,signal end
94
- end
95
- local visible=ns.ReceiptView.Show(receipt,nil,refresh)
96
- if not visible then return end
97
- if request.state~="reported" then return end
98
- ns.Session.WhenInputReady(function(ready)
99
- if not ready or request.state~="reported" then return end
100
- local current,_,signal=ns.Session.ReadyReceipt()
101
- if current then ns.ReceiptView.Show(receipt,current,refresh,signal) end
102
- end)
103
- end
104
- local function seal(request,status,value,display)
105
- if request.state~="running" then return nil,"probe_not_running" end
106
- local active=ns.Session.Current()
107
- if not active or active.generation~=request.generation then
108
- request.state="quarantined";cleanup(request);return nil,"probe_session_changed"
109
- end
110
- -- Close callback admission before invoking cleanup. Neither a recursive
111
- -- Finish nor a cleanup exception can change the chosen execution result.
112
- request.state="settling"
113
- local resources=cleanup(request)
114
- local body={probeStatus=status,acceptedBudgetSeconds=request.budgetSeconds,
115
- result=status=="completed" and value or nil,
116
- error=status=="failed" and safeMessage(value,"probe_runtime_error") or nil,
117
- logs=#request.logs>0 and request.logs or nil,logsTruncated=request.logsTruncated or nil,
118
- resources=resources}
119
- local report,failure=ns.ReportStore.Commit(request.requestId,request.code,body)
120
- if not report and request.goal=="finished" and REPORT_ERROR_CODES[failure] then
121
- -- Encoding user values may fail (including secret values). Preserve the
122
- -- known execution outcome as a small ordinary report without echoing it.
123
- report=ns.ReportStore.Commit(request.requestId,request.code,{
124
- probeStatus="failed",acceptedBudgetSeconds=request.budgetSeconds,
125
- error=failure,resources=resources and {state="pending",errors={"probe_cleanup_error"}} or nil})
126
- end
127
- request.state=report and "reported" or "unresolved"
128
- request.report=report
129
- if report then
130
- local _,storedBody=ns.ReportStore.Read(request.requestId)
131
- request.reportBody=storedBody
132
- end
133
- if not report then
134
- report = minimalFailure(request, failure)
135
- request.failureReceipt = report
136
- end
137
- if request.goal=="finished" then
138
- local retained,retainFailure=ns.Investigation.Mark(request.requestId,request.report and "reported" or "report_error",report)
139
- if not retained then return nil,retainFailure end
140
- end
141
- if report and display then publish(request,report) end
142
- if request.goal ~= "finished" and ns.ActivityView then ns.ActivityView.Finish(request.requestId) end
143
- notify()
144
- return report,failure
145
- end
146
- local function complete(request,status,value,display)
147
- if request.state~="running" then return nil,"probe_not_running" end
148
- if request.pending then return nil,"probe_completion_requested" end
149
- if (request.depth or 0)>0 then
150
- request.pending={status=status,value=value,display=display}
151
- return true
152
- end
153
- return seal(request,status,value,display)
154
- end
155
- local function settle(request,ok,result,display)
156
- if not ok then request.pending={status="failed",value=result,display=display} end
157
- local pending=request.pending
158
- if pending and request.depth==0 then
159
- request.pending=nil
160
- return seal(request,pending.status,pending.value,pending.display)
161
- end
162
- end
163
- local function probeAPI(request)
164
- local api={}
165
- function api.Async(_,seconds)
166
- if request.state~="running" or request.async then return nil,"probe_async_state" end
167
- if restricted(seconds) or type(seconds)~="number" or seconds%1~=0 or seconds<1 or seconds>request.budgetSeconds
168
- or type(C_Timer)~="table" or type(C_Timer.NewTimer)~="function" then return nil,"probe_async_unavailable" end
169
- local now=ns.Compat and ns.Compat.MonotonicSeconds()
170
- if not now or not request.startedAt then return nil,"probe_clock_unavailable" end
171
- local remaining=seconds-(now-request.startedAt)
172
- if remaining<=0 then return nil,"probe_budget_exhausted" end
173
- request.async=true
174
- request.timer=C_Timer.NewTimer(remaining,function()
175
- if request.state=="running" then complete(request,"failed","probe_timeout",true) end
176
- end)
177
- if not request.timer then request.async=false;return nil,"probe_async_unavailable" end
178
- return true
179
- end
180
- function api.Finish(_,value) return complete(request,"completed",value,true) end
181
- function api.Fail(_,message) return complete(request,"failed",message,true) end
182
- function api.Callback(_,callback)
183
- if request.state~="running" or type(callback)~="function" or request.callbackCount>=16 then
184
- return nil,"probe_callback_limit"
185
- end
186
- request.callbackCount=request.callbackCount+1
187
- return function(...)
188
- local active=ns.Session.Current()
189
- if request.state~="running" or request.pending or not active
190
- or active.generation~=request.generation then return nil,"probe_callback_inactive" end
191
- request.depth=request.depth+1
192
- local ok,result=pcall(callback,...)
193
- request.depth=request.depth-1
194
- local receipt,failure=settle(request,ok,result,true)
195
- if receipt or failure then return receipt,failure end
196
- return ok and true or nil,result
197
- end
198
- end
199
- function api.OnCleanup(_,callback)
200
- if request.state~="running" or type(callback)~="function" or #request.cleanups>=MAX_CLEANUPS then
201
- return nil,"probe_cleanup_limit"
202
- end
203
- request.cleanups[#request.cleanups+1]=callback
204
- return true
205
- end
206
- function api.Log(_,...)
207
- if request.state~="running" then return nil,"probe_not_running" end
208
- if #request.logs>=MAX_LOG_ENTRIES or request.logBytes>=MAX_LOG_BYTES then request.logsTruncated=true;return nil,"probe_log_limit" end
209
- local values={n=select("#",...),...}
210
- local parts={}
211
- for index=1,values.n do
212
- local value=values[index]
213
- if restricted(value) then parts[index]="<secret>"
214
- elseif type(value)=="string" or type(value)=="number" or type(value)=="boolean" then parts[index]=tostring(value)
215
- else parts[index]="<unsupported>" end
216
- end
217
- local line=table.concat(parts," ")
218
- local remaining=MAX_LOG_BYTES-request.logBytes
219
- if #line>remaining then line=line:sub(1,remaining);request.logsTruncated=true end
220
- request.logs[#request.logs+1]=line;request.logBytes=request.logBytes+#line
221
- return not request.logsTruncated
222
- end
223
- function api.IsCancelled() local active=ns.Session.Current();return request.state~="running" or not active or active.generation~=request.generation end
224
- return api
225
- end
226
-
227
- ns.ProbeRunner = {
228
- State = function(requestId)
229
- local session,failure=context()
230
- if not session then return nil,failure end
231
- if not key(requestId) then return nil,"probe_invalid_request" end
232
- return requests[requestId] and requests[requestId].state or nil
233
- end,
234
- Busy = function() return busy() end,
235
- ResourcesReleased = function(requestId)
236
- local request=requests and requests[requestId]
237
- if request and (request.cleanupFailed or request.state=="running"
238
- or request.state=="settling" or request.state=="quarantined") then
239
- return nil,"probe_resources_pending"
240
- end
241
- return true
242
- end,
243
- Reported = function(requestId)
244
- local session, failure = context()
245
- if not session then return nil, failure end
246
- if not key(requestId) then return nil, "probe_invalid_request" end
247
- local request = requests[requestId]
248
- if not request or request.state ~= "reported" then return nil, "probe_not_reported" end
249
- local receipt, body = ns.ReportStore.Read(requestId)
250
- if not receipt then return nil, body end
251
- if receipt ~= request.report or body ~= request.reportBody then return nil, "probe_report_changed" end
252
- return receipt, body, request.code
253
- end,
254
- VerifyAbsent = function(requestId)
255
- local session, failure = context()
256
- if not session then return nil, failure end
257
- if not key(requestId) then return nil, "probe_invalid_request" end
258
- if requests[requestId] ~= nil then return nil, "probe_still_retained" end
259
- return true
260
- end,
261
- Load = function(requestId, code, reloadNonce, budgetSeconds, goal)
262
- local session, failure = context()
263
- if not session then return nil, failure end
264
- if not key(requestId) then return nil, "probe_invalid_request" end
265
- if restricted(reloadNonce) or (reloadNonce ~= nil and (type(reloadNonce) ~= "string"
266
- or #reloadNonce ~= 32 or not string.match(reloadNonce, "^[0-9a-f]+$"))) then
267
- return nil, "probe_invalid_reload_nonce"
268
- end
269
- if restricted(code) or type(code) ~= "string" or #code == 0 or #code > 256 * 1024
270
- or string.byte(code, 1) == 27 then return nil, "probe_invalid_code" end
271
- if budgetSeconds == nil then budgetSeconds = MAX_ASYNC_SECONDS end
272
- if restricted(budgetSeconds) or type(budgetSeconds) ~= "number" or
273
- budgetSeconds % 1 ~= 0 or budgetSeconds < 1 or budgetSeconds > MAX_ASYNC_SECONDS then
274
- return nil, "probe_invalid_budget"
275
- end
276
- if requests[requestId] then return nil, "probe_request_exists" end
277
- local receipt, reason = ns.ReportStore.Read(requestId)
278
- if receipt then return nil, "probe_report_exists" end
279
- if reason ~= "report_unavailable" then return nil, reason end
280
- if count >= 16 or bytes + #code > 1024 * 1024 then return nil, "probe_queue_limit" end
281
- -- Compile text only. Loading definitions never invokes their code.
282
- local executable = loadstring(code, "=LycheeProbe:" .. requestId)
283
- if not executable then
284
- if goal~="finished" then return nil, "probe_syntax_error" end
285
- executable=function() error("probe_syntax_error",0) end
286
- end
287
- local signal, encodeFailure = loadedSignal(requestId, code, reloadNonce, false)
288
- if not signal then return nil, encodeFailure end
289
- requests[requestId] = { requestId=requestId,code = code, executable = executable,
290
- state = "loaded", reloadNonce = reloadNonce, budgetSeconds = budgetSeconds, goal=goal }
291
- count, bytes = count + 1, bytes + #code
292
- notify()
293
- return signal
294
- end,
295
- RefreshLoaded = function(requestId)
296
- local session, failure = context()
297
- if not session then return nil, failure end
298
- if not key(requestId) then return nil, "probe_invalid_request" end
299
- local request = requests[requestId]
300
- if not request then return nil, "probe_not_loaded" end
301
- if request.state ~= "loaded" then return nil, "probe_already_dispatched" end
302
- local ready, reason = ns.Platform.ObserveInputState()
303
- if ready ~= true then return nil, reason end
304
- return loadedSignal(requestId, request.code, request.reloadNonce, true)
305
- end,
306
- Dispatch = function(requestId)
307
- local session, failure = context()
308
- if not session then return nil, failure end
309
- if not key(requestId) then return nil, "probe_invalid_request" end
310
- local request = requests[requestId]
311
- if not request then return nil, "probe_not_loaded" end
312
- if request.state ~= "loaded" then return nil, "probe_already_dispatched" end
313
- if busy(requestId) then return nil,"probe_runtime_busy" end
314
- local receipt, reason = ns.ReportStore.Read(requestId)
315
- if receipt then return nil, "probe_report_exists" end
316
- if reason ~= "report_unavailable" then return nil, reason end
317
- if request.goal=="finished" then
318
- local started,startFailure=ns.Investigation.Mark(requestId,"running")
319
- if not started then return nil,startFailure end
320
- end
321
- -- Consume before calling user code, including recursive dispatch. pcall
322
- -- contains Lua errors; it is not a sandbox or a synchronous time limit.
323
- request.state = "running"
324
- if ns.ActivityView then ns.ActivityView.Begin(requestId) end
325
- notify()
326
- local executable = request.executable
327
- request.executable = nil
328
- request.generation=session.generation
329
- request.startedAt=ns.Compat and ns.Compat.MonotonicSeconds()
330
- request.logs,request.logBytes,request.cleanups={},0,{}
331
- request.depth,request.callbackCount=1,0
332
- local ok, result = pcall(executable,probeAPI(request))
333
- request.depth=0
334
- local active = ns.Session.Current()
335
- if not active or active.generation ~= session.generation then
336
- request.state = "quarantined";cleanup(request)
337
- return nil, "probe_session_changed"
338
- end
339
- if not ok or request.pending then return settle(request,ok,result,false) end
340
- if request.async then
341
- if request.state=="reported" then return request.report end
342
- if request.state~="running" then return nil,"probe_async_unresolved" end
343
- -- Accepted asynchronous work has no terminal receipt yet. Keep
344
- -- the scene clear until seal publishes its actual result.
345
- return true
346
- end
347
- return complete(request,"completed",result,false)
348
- end,
349
- }