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,3 +0,0 @@
1
- local _, ns = ...
2
- ns.ProbeDefinitions = {schema="lycheedev.queue.v1",entries={
3
- }}
@@ -1,44 +0,0 @@
1
- local ADDON_NAME, ns = ...
2
-
3
- local function restricted(value) return issecretvalue and issecretvalue(value) end
4
- local function requestKey(value)
5
- return not restricted(value) and type(value)=="string" and #value>0 and #value<=128
6
- and string.match(value,"^[%w_%-]+$")~=nil
7
- end
8
-
9
- ns.FaultRunner={
10
- Run=function(requestId,count)
11
- if not requestKey(requestId) or restricted(count) or type(count)~="number"
12
- or count%1~=0 or count<1 or count>100 then return nil,"fault_invalid_request" end
13
- local session,reason=ns.Session.Current()
14
- if not session then return nil,reason end
15
- local receipt,missing=ns.ReportStore.Read(requestId)
16
- if receipt or missing~="report_unavailable" then return nil,"fault_request_exists" end
17
- if type(ns.Diagnostics)~="table" or type(ns.Diagnostics.SnapshotRecentErrors)~="function" then
18
- return nil,"fault_diagnostics_unavailable"
19
- end
20
- local snapshot,failure=ns.Diagnostics.SnapshotRecentErrors(count,"provider_storage")
21
- local body={schema="lycheedev.bugs.v1",requestType="bugs",
22
- status=snapshot and "completed" or "unavailable",complete=snapshot~=nil,
23
- snapshot=snapshot,error=failure}
24
- return ns.ReportStore.Commit(requestId,"",body)
25
- end,
26
- Acknowledge=function(requestId,sequence)
27
- if not requestKey(requestId) or restricted(sequence) or type(sequence)~="number"
28
- or sequence%1~=0 or sequence<1 or sequence>9007199254740991 then
29
- return nil,"fault_invalid_acknowledgement"
30
- end
31
- local session,reason=ns.Session.Current()
32
- if not session then return nil,reason end
33
- local receipt,body=ns.ReportStore.Read(requestId)
34
- if not receipt then
35
- if body~="report_unavailable" then return nil,body end
36
- return ns.ReportStore.Acknowledged(requestId,sequence)
37
- end
38
- return ns.ReportStore.Acknowledge({schema="lycheedev.signal.v1",release=ns.Release,
39
- kind="reported",sessionNonce=session.sessionNonce,requestId=requestId,
40
- character=session.character,realm=session.realm,sequence=sequence,
41
- product=ns.Startup.identity.product,build=ns.Startup.identity.build,
42
- inputReady=false,reportBytes=#body,reportAdler32=ns.CaptureWriter.DigestBytes(body)})
43
- end,
44
- }
@@ -1,127 +0,0 @@
1
- local ADDON_NAME, ns = ...
2
-
3
- -- Identity markers answer "who is in this window" for one host trigger. They
4
- -- bind no session, write no SavedVariables, and grant no input authority. The
5
- -- module creates nothing until Trigger is called.
6
- local pending
7
- local focusEvent = "ChatFrame.OnEditBoxFocusLost"
8
-
9
- local function restricted(value)
10
- return issecretvalue and issecretvalue(value)
11
- end
12
-
13
- local function validNonce(nonce)
14
- return not restricted(nonce) and type(nonce) == "string"
15
- and #nonce == 32 and string.match(nonce, "^[0-9a-f]+$") ~= nil
16
- end
17
-
18
- local function cancelWait()
19
- local watch = pending
20
- pending = nil
21
- if watch then watch.registry:UnregisterCallback(focusEvent, watch) end
22
- end
23
-
24
- -- A request-scoped operation in flight owns this window's display. Scanning
25
- -- must never clobber another agent's receipt, so uncertainty fails closed.
26
- local function idle()
27
- if type(ns.ProbeQueue) == "table" and type(ns.ProbeQueue.Busy) == "function" then
28
- local busy, reason = ns.ProbeQueue.Busy()
29
- if busy == nil then return nil, reason end
30
- if busy then return nil, "identity_busy" end
31
- end
32
- if type(ns.Reentry) == "table" and type(ns.Reentry.Busy) == "function" then
33
- local busy, reason = ns.Reentry.Busy()
34
- if busy == nil then return nil, reason end
35
- if busy then return nil, "identity_busy" end
36
- end
37
- return true
38
- end
39
-
40
- local function observe(probeNonce)
41
- local build, buildFailure = ns.Platform.ObserveBuild()
42
- if not build then return nil, buildFailure end
43
- local actor, actorFailure = ns.Platform.ObserveActor()
44
- local actorState = "ok"
45
- if not actor then
46
- if actorFailure == "actor_restricted_identity" then
47
- actorState = "actor_restricted"
48
- else
49
- actorState = "no_actor"
50
- end
51
- end
52
- local inputReady, inputReason = true, nil
53
- if type(ns.Platform.ObserveInputState) == "function" then
54
- local eligible, reason = ns.Platform.ObserveInputState()
55
- if eligible == true then
56
- inputReady = true
57
- else
58
- inputReady = false
59
- if type(reason) == "string" and #reason > 0 and not restricted(reason) then
60
- inputReason = reason
61
- else
62
- inputReason = "input_observation_unavailable"
63
- end
64
- end
65
- else
66
- inputReady = false
67
- inputReason = "input_observation_unavailable"
68
- end
69
- local marker = {
70
- schema = "lycheedev.signal.v1", release = ns.Release, kind = "identity",
71
- probeNonce = probeNonce, actorState = actorState,
72
- sessionNonce = "", requestId = "",
73
- product = build.product, build = build.build,
74
- sequence = 0, inputReady = inputReady,
75
- }
76
- if inputReason then marker.inputReason = inputReason end
77
- if actorState == "ok" then
78
- marker.character = actor.character
79
- marker.realm = actor.realm
80
- marker.guid = actor.guid
81
- end
82
- return ns.CaptureWriter.EncodeSignal(marker, 4096)
83
- end
84
-
85
- ns.Identity = {
86
- CancelWait = cancelWait,
87
- -- Returns the encoded identity receipt; the caller displays it. Echoing the
88
- -- host probe nonce correlates exactly one trigger with one receipt.
89
- Trigger = function(nonce)
90
- if not validNonce(nonce) then return nil, "identity_invalid_nonce" end
91
- local ready, reason = idle()
92
- if not ready then return nil, reason end
93
- cancelWait()
94
- return observe(nonce)
95
- end,
96
- -- A fresh observation for the same trigger, used to replace the first
97
- -- display once keyboard focus has been released.
98
- Refresh = function(nonce)
99
- if not validNonce(nonce) then return nil, "identity_invalid_nonce" end
100
- local ready, reason = idle()
101
- if not ready then return nil, reason end
102
- return observe(nonce)
103
- end,
104
- -- One request-scoped callback, never a timer or permanent focus listener.
105
- -- It only prompts a fresh observation; it proves nothing by itself.
106
- WhenInputReady = function(callback)
107
- if type(callback) ~= "function" then return nil, "input_invalid_callback" end
108
- if pending then return nil, "input_wait_busy" end
109
- if type(ns.Platform.ObserveInputState) ~= "function" then return nil, "input_observation_unavailable" end
110
- local eligible, reason = ns.Platform.ObserveInputState()
111
- if eligible then callback(true); return true end
112
- if reason ~= "input_keyboard_focus" then return nil, reason or "input_observation_unavailable" end
113
- if type(EventRegistry) ~= "table" or type(EventRegistry.RegisterCallback) ~= "function"
114
- or type(EventRegistry.UnregisterCallback) ~= "function" then
115
- return nil, "input_events_unavailable"
116
- end
117
- local watch = { registry = EventRegistry }
118
- pending = watch
119
- watch.registry:RegisterCallback(focusEvent, function()
120
- if pending ~= watch then return end
121
- cancelWait()
122
- local now, observeFailure = ns.Platform.ObserveInputState()
123
- callback(now == true, observeFailure)
124
- end, watch)
125
- return true
126
- end,
127
- }
@@ -1,76 +0,0 @@
1
- local _, ns = ...
2
-
3
- -- Both frames are ASCII and anchored. The checksum covers every byte before
4
- -- the final colon; it detects accidental input pollution, not a secret actor.
5
- local function restricted(value) return issecretvalue and issecretvalue(value) end
6
- local function hex(value, length)
7
- return type(value) == "string" and #value == length and
8
- string.match(value, "^[0-9a-f]+$") ~= nil
9
- end
10
- local function request(value)
11
- return type(value) == "string" and #value >= 1 and #value <= 80 and
12
- string.match(value, "^[%w_%-]+$") ~= nil
13
- end
14
- local function actionArgument(action, requestId, argument)
15
- if action == "identify" or action == "reset" then
16
- return requestId == "-" and hex(argument, 32)
17
- elseif action == "connect" or action == "ready" or action == "hide" then
18
- return requestId == "-" and argument == "-"
19
- elseif action == "refresh" then
20
- return requestId == "-" and hex(argument, 32)
21
- elseif action == "load" or action == "run" or action == "reload" then
22
- return requestId ~= "-" and argument == "-"
23
- elseif action == "verify" or action == "prepare" or action == "clean" or action == "flush" or action == "observe" or action == "finish" then
24
- return requestId ~= "-" and hex(argument, 32)
25
- elseif action == "ack" or action == "bugs-ack" then
26
- return requestId ~= "-" and #argument <= 16 and string.match(argument, "^[1-9]%d*$") ~= nil
27
- elseif action == "bugs" then
28
- return requestId ~= "-" and #argument <= 3 and string.match(argument, "^%d+$") ~= nil
29
- end
30
- return false
31
- end
32
- local function checkedPrefix(text, marker)
33
- if restricted(text) or type(text) ~= "string" or #text > 256 then return nil, "receiver_capacity" end
34
- if not string.match(text, "^[A-Za-z0-9_:%-]+$") then return nil, "receiver_encoding" end
35
- local prefix, checksum = string.match(text, "^(.*):([0-9a-f]+)$")
36
- if not prefix or #checksum ~= 8 or string.sub(prefix, 1, #marker) ~= marker then
37
- return nil, "receiver_format"
38
- end
39
- if ns.CaptureWriter.DigestBytes(prefix) ~= checksum then return nil, "receiver_checksum" end
40
- return prefix
41
- end
42
-
43
- ns.InputProtocol = {
44
- MaxBytes = 256,
45
- Body = function(action, requestId, argument)
46
- return action .. "|" .. requestId .. "|" .. argument
47
- end,
48
- Stage = function(text, expectedNonce, expectedEpoch)
49
- local prefix, failure = checkedPrefix(text, "LDB1:")
50
- if not prefix then return nil, failure end
51
- local nonce, epoch, requestId, attempt, action, argument, length = string.match(prefix,
52
- "^LDB1:([0-9a-f]+):([0-9]+):([%w_%-]+):([0-9a-f]+):([a-z%-]+):([%w_%-]+):([0-9]+)$")
53
- if not nonce or not hex(nonce, 32) or not hex(attempt, 16) or not request(requestId)
54
- or not actionArgument(action, requestId, argument) then return nil, "receiver_format" end
55
- if expectedEpoch < 1 or expectedEpoch >= 9007199254740991 or
56
- nonce ~= expectedNonce or tonumber(epoch) ~= expectedEpoch or
57
- tostring(expectedEpoch) ~= epoch then return nil, "receiver_identity" end
58
- local body = ns.InputProtocol.Body(action, requestId, argument)
59
- if tonumber(length) ~= #body or tostring(#body) ~= length then return nil, "receiver_length" end
60
- return { receiverNonce = nonce, runtimeEpoch = expectedEpoch, requestId = requestId,
61
- attemptId = attempt, action = action, argument = argument,
62
- bodyBytes = #body, bodyAdler32 = ns.CaptureWriter.DigestBytes(body) }
63
- end,
64
- Commit = function(text, staged, challenge)
65
- local prefix, failure = checkedPrefix(text, "LDC1:")
66
- if not prefix then return nil, failure end
67
- local nonce, attempt, receivedChallenge, digest = string.match(prefix,
68
- "^LDC1:([0-9a-f]+):([0-9a-f]+):([0-9a-f]+):([0-9a-f]+)$")
69
- if not nonce or not hex(nonce, 32) or not hex(attempt, 16) or
70
- not hex(receivedChallenge, 16) or not hex(digest, 8) then return nil, "receiver_format" end
71
- if nonce ~= staged.receiverNonce or attempt ~= staged.attemptId or
72
- digest ~= staged.bodyAdler32 or receivedChallenge ~= challenge then
73
- return nil, "receiver_commit_mismatch" end
74
- return true
75
- end,
76
- }
@@ -1,36 +0,0 @@
1
- local _, ns = ...
2
-
3
- -- Three physical 2x2 cells. This display owns no input or independent clock.
4
- local frame,blocks,lastScale
5
- local colors={red={1,0,0},green={0,1,0},blue={0,0,1},black={0,0,0},white={1,1,1}}
6
- local codes={ready={"green","white"},input_keyboard_focus={"red","blue"},input_combat_lockdown={"blue","red"},unknown={"white","black"}}
7
- local function create()
8
- if frame then return frame end
9
- frame=CreateFrame("Frame",nil,UIParent)
10
- frame:Hide();frame:EnableMouse(false);frame:SetFrameStrata("TOOLTIP");frame:SetFrameLevel(10000)
11
- blocks={}
12
- for i=1,3 do blocks[i]=frame:CreateTexture(nil,"ARTWORK") end
13
- return frame
14
- end
15
- ns.InputSignal={
16
- Frame=create,
17
- Hide=function()if blocks then for _,block in ipairs(blocks) do block:Hide() end end end,
18
- Render=function(state,heartbeat)
19
- local code=codes[state]
20
- if not frame or not code then return nil end
21
- local px=ns.Compat.GetPhysicalPixelSize()
22
- if (issecretvalue and issecretvalue(px)) or type(px)~="number" or px~=px or px<=0 or px==math.huge then return nil end
23
- if px~=lastScale then
24
- frame:ClearAllPoints();frame:SetPoint("TOPLEFT",UIParent,"TOPLEFT",0,0);frame:SetSize(6*px,2*px)
25
- for i,block in ipairs(blocks) do
26
- block:SetPoint("TOPLEFT",frame,"TOPLEFT",(i-1)*2*px,0);block:SetSize(2*px,2*px)
27
- end
28
- lastScale=px
29
- end
30
- for i=1,2 do local c=colors[code[i]];blocks[i]:SetColorTexture(c[1],c[2],c[3],1) end
31
- local value=heartbeat and 1 or 0
32
- blocks[3]:SetColorTexture(value,value,value,1)
33
- for _,block in ipairs(blocks) do block:Show() end
34
- frame:Show();return true
35
- end,
36
- }
@@ -1,159 +0,0 @@
1
- local _, ns = ...
2
-
3
- -- Small character-owned execution facts. Slots are reserved before execution;
4
- -- only an acknowledged, finished slot may be reclaimed by a later admission.
5
- local LIMIT, SLOT_BYTES = 16, 2048
6
- local function secret(value) return issecretvalue and issecretvalue(value) end
7
- local function plain(value) return not secret(value) and type(value)=="table" and getmetatable(value)==nil end
8
- local function hex(value, size)
9
- return not secret(value) and type(value)=="string" and #value==size and value:match("^[0-9a-f]+$")~=nil
10
- end
11
- local phases={loaded=true,running=true,reported=true,report_error=true,acknowledged=true,finished=true}
12
- local fields={sessionNonce=true,guid=true,epoch=true,phase=true,codeSHA256=true,receipt=true}
13
- local function valid(item)
14
- if not plain(item) or not ns.CaptureWriter.Encode(item,SLOT_BYTES) then return false end
15
- for key in pairs(item) do if not fields[key] then return false end end
16
- return hex(item.sessionNonce,32) and hex(item.codeSHA256,64) and type(item.guid)=="string"
17
- and #item.guid>0 and #item.guid<=128 and type(item.epoch)=="number" and item.epoch>=1
18
- and item.epoch<9007199254740991 and item.epoch%1==0 and phases[item.phase]==true
19
- and (item.receipt==nil and (item.phase=="loaded" or item.phase=="running")
20
- or type(item.receipt)=="string" and #item.receipt>0 and #item.receipt<=1400)
21
- end
22
- local function context()
23
- local state, reason = ns.Persistence.Bridge()
24
- if not state then return nil, reason end
25
- local session, failure = ns.Session.Current()
26
- if not session then return nil, failure end
27
- if state.terminals == nil then state.terminals = {} end
28
- if not plain(state.terminals) then return nil, "terminal_invalid_store" end
29
- local count = 0
30
- for id, item in pairs(state.terminals) do
31
- count = count+1
32
- if count>LIMIT or secret(id) or type(id)~="string" or #id>80 or not id:match("^[%w_%-]+$")
33
- or not valid(item) then return nil,"terminal_invalid_store" end
34
- end
35
- return state.terminals, session
36
- end
37
- local function selected(requestId)
38
- if secret(requestId) or type(requestId)~="string" then return nil,"terminal_invalid_request" end
39
- local records, session = context()
40
- if not records then return nil, session end
41
- local item = records[requestId]
42
- if not plain(item) or item.sessionNonce~=session.sessionNonce or item.guid~=session.guid then
43
- return nil,"terminal_unavailable"
44
- end
45
- return item, session, records
46
- end
47
- local function store(records, requestId, item)
48
- if not valid(item) then return nil,"terminal_slot_limit" end
49
- records[requestId]=item
50
- return true
51
- end
52
- local function copy(item)
53
- local result={}
54
- for k,v in pairs(item) do result[k]=v end
55
- return result
56
- end
57
- local function released(requestId, item, session)
58
- -- A different validated Lua runtime has destroyed the previous managed
59
- -- timers/frames. Historical cleanup failures remain in the archived report.
60
- if item.epoch~=session.runtimeEpoch then return true end
61
- return ns.ProbeRunner.ResourcesReleased(requestId)==true
62
- end
63
- local function proof(requestId, nonce)
64
- if not hex(nonce,32) then return nil,"terminal_invalid_challenge" end
65
- local item, session = selected(requestId)
66
- if not item then return nil, session end
67
- local identity, reason=ns.Session.NextIdentity()
68
- if not identity then return nil,reason end
69
- return ns.CaptureWriter.EncodeSignal({
70
- schema="lycheedev.signal.v1",kind="checkpoint",release=ns.Release,
71
- product=ns.Startup.identity.product,build=ns.Startup.identity.build,
72
- sessionNonce=session.sessionNonce,requestId=requestId,probeNonce=nonce,
73
- character=session.character,realm=session.realm,guid=session.guid,
74
- sequence=identity.sequence,runtimeEpoch=session.runtimeEpoch,inputReady=false,
75
- workState=item.phase,codeSHA256=item.codeSHA256,receipt=item.receipt,
76
- resourcesReleased=released(requestId,item,session),
77
- },4096)
78
- end
79
-
80
- ns.Investigation = {
81
- ActivityRequest=function()
82
- local records,session=context()
83
- if not records then return nil end
84
- for id,item in pairs(records) do
85
- if item.guid==session.guid and item.sessionNonce==session.sessionNonce
86
- and (item.phase=="running" or item.phase=="reported" or item.phase=="acknowledged") then return id end
87
- end
88
- end,
89
- Tracked=function(requestId)
90
- local state=ns.Persistence.Bridge()
91
- return state and plain(state.terminals) and state.terminals[requestId]~=nil or false
92
- end,
93
- Reserve=function(requestId,entry)
94
- local records,session=context()
95
- if not records then return nil,session end
96
- local prior=records[requestId]
97
- if prior~=nil then return nil,"terminal_request_exists" end
98
- local count,retired=0,nil
99
- for id,item in pairs(records) do
100
- count=count+1
101
- if item.phase=="finished" and (not retired or id<retired) then retired=id end
102
- if item.guid==session.guid and item.epoch==session.runtimeEpoch and item.phase~="finished" then return nil,"investigation_busy" end
103
- end
104
- if count>=LIMIT and not retired then return nil,"terminal_capacity" end
105
- local item={sessionNonce=session.sessionNonce,guid=session.guid,epoch=session.runtimeEpoch,
106
- phase="loaded",codeSHA256=entry.codeSHA256}
107
- -- Leave bounded room for the longest minimal failure receipt.
108
- if not ns.CaptureWriter.Encode(item,512) then return nil,"terminal_identity_limit" end
109
- local capacity,reason=ns.ReportStore.Reserve(requestId)
110
- if not capacity then return nil,reason end
111
- if count>=LIMIT then records[retired]=nil end
112
- return store(records,requestId,item)
113
- end,
114
- Mark=function(requestId,phase,receipt)
115
- local item,session,records=selected(requestId)
116
- if not item then return nil,session end
117
- local nextItem=copy(item)
118
- if phase=="running" and item.phase~="loaded" then return nil,"terminal_already_dispatched" end
119
- if item.phase=="finished" then return nil,"terminal_finished" end
120
- nextItem.phase,nextItem.receipt=phase,receipt or item.receipt
121
- if phase=="acknowledged" then nextItem.epoch=session.runtimeEpoch end
122
- return store(records,requestId,nextItem)
123
- end,
124
- Busy=function()
125
- local state=ns.Persistence.Bridge()
126
- if not state then return nil,"terminal_state_unavailable" end
127
- if state.terminals==nil then return false end
128
- if not plain(state.terminals) then return nil,"terminal_invalid_store" end
129
- local actor,reason=ns.Platform.ObserveActor()
130
- if not actor then return nil,reason end
131
- local count=0
132
- for _,item in pairs(state.terminals) do
133
- count=count+1
134
- if count>LIMIT or not valid(item) then return nil,"terminal_invalid_store" end
135
- if item.guid==actor.guid and item.epoch==state.runtimeEpoch and item.phase~="finished" then return true end
136
- end
137
- return false
138
- end,
139
- Observe=proof,
140
- ReadyReceipt=function(requestId)
141
- local item,session=selected(requestId)
142
- if not item then return nil,session end
143
- if item.phase=="loaded" and item.epoch==session.runtimeEpoch then
144
- return ns.ProbeRunner.RefreshLoaded(requestId)
145
- end
146
- return ns.Session.ReadyReceipt()
147
- end,
148
- Finish=function(requestId,nonce)
149
- local item,session,records=selected(requestId)
150
- if not item then return nil,session end
151
- if not hex(nonce,32) then return nil,"terminal_invalid_challenge" end
152
- if item.phase~="acknowledged" and item.phase~="finished" then return nil,"terminal_ack_required" end
153
- if not released(requestId,item,session) then return nil,"probe_resources_pending" end
154
- local nextItem=copy(item); nextItem.phase="finished"
155
- if not store(records,requestId,nextItem) then return nil,"terminal_slot_limit" end
156
- if ns.ActivityView then ns.ActivityView.Finish(requestId) end
157
- return proof(requestId,nonce)
158
- end,
159
- }