lycheedev 1.1.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +49 -0
- package/README.md +45 -0
- package/THIRD_PARTY_NOTICES +812 -0
- package/bin/lycheedev.mjs +56 -0
- package/native/windows-amd64/lycheedev.exe +0 -0
- package/package.json +12 -33
- package/payload/addon/Bridge/CaptureWriter.lua +154 -0
- package/payload/addon/Bridge/Definitions.lua +3 -0
- package/payload/addon/Bridge/Identity.lua +127 -0
- package/{vendor/addon/Libs/AutomationQR.lua → payload/addon/Bridge/MatrixSymbol.lua} +23 -30
- package/payload/addon/Bridge/ProbeQueue.lua +136 -0
- package/payload/addon/Bridge/ProbeRunner.lua +128 -0
- package/payload/addon/Bridge/ReceiptView.lua +160 -0
- package/payload/addon/Bridge/Reentry.lua +192 -0
- package/payload/addon/Bridge/ReportStore.lua +153 -0
- package/payload/addon/Bridge/Session.lua +163 -0
- package/payload/addon/Clients/Evergreen.lua +2 -0
- package/payload/addon/Clients/Live.lua +2 -0
- package/payload/addon/Clients/Pandaria.lua +2 -0
- package/payload/addon/Clients/Titan.lua +2 -0
- package/payload/addon/Core/Compat.lua +59 -0
- package/payload/addon/Core/Controls.lua +168 -0
- package/{vendor/addon/Core/Bootstrap.lua → payload/addon/Core/Execute.lua} +12 -23
- package/{vendor → payload}/addon/Core/Inspector.lua +19 -235
- package/{vendor → payload}/addon/Core/Locale.lua +129 -94
- package/{vendor → payload}/addon/Core/Locale_enUS.lua +129 -96
- package/payload/addon/Core/Persistence.lua +58 -0
- package/payload/addon/Core/Platform.lua +58 -0
- package/payload/addon/Core/Runtime.lua +25 -0
- package/payload/addon/Core/Safety.lua +56 -0
- package/{vendor → payload}/addon/Core/Serializer.lua +18 -6
- package/payload/addon/Core/Stores.lua +611 -0
- package/payload/addon/Lychee Dev_Forever.toc +52 -0
- package/payload/addon/Lychee Dev_Mainline.toc +52 -0
- package/payload/addon/Lychee Dev_Mists.toc +52 -0
- package/payload/addon/Lychee Dev_Wrath.toc +52 -0
- package/payload/addon/Modules/AutomationView.lua +393 -0
- package/{vendor → payload}/addon/Modules/Diagnostics.lua +92 -36
- package/{vendor → payload}/addon/Modules/Events/Catalog.lua +9 -0
- package/{vendor → payload}/addon/Modules/Events/Monitor.lua +45 -5
- package/payload/addon/Modules/FunctionTrace.lua +150 -0
- package/{vendor → payload}/addon/Modules/ObjectInspector.lua +105 -31
- package/{vendor → payload}/addon/UI/Export.lua +64 -34
- package/{vendor → payload}/addon/UI/Pages/About.lua +26 -14
- package/payload/addon/UI/Pages/Automation.lua +446 -0
- package/payload/addon/UI/Pages/Diagnostics.lua +402 -0
- package/{vendor/addon/UI/Features.lua → payload/addon/UI/Pages/Events.lua} +192 -302
- package/{vendor → payload}/addon/UI/Pages/ExportRecords.lua +213 -132
- package/{vendor → payload}/addon/UI/Pages/Object.lua +229 -121
- package/payload/addon/UI/Pages/Run.lua +423 -0
- package/payload/addon/UI/Pages/Trace.lua +314 -0
- package/payload/addon/UI/TreeView.lua +246 -0
- package/{vendor/addon/UI/MainWindow.lua → payload/addon/UI/Widgets.lua} +89 -529
- package/payload/addon/UI/Window.lua +425 -0
- package/payload/skill/SKILL.md +87 -0
- package/payload/skill/agents/openai.yaml +7 -0
- package/payload/skill/references/addon-validation.md +42 -0
- package/payload/skill/references/asset-export.md +109 -0
- package/payload/skill/references/commands.md +169 -0
- package/payload/skill/references/data-investigation.md +242 -0
- package/payload/skill/references/error-diagnosis.md +41 -0
- package/payload/skill/references/installation.md +18 -0
- package/payload/skill/references/live-investigation.md +129 -0
- package/payload/skill/references/source-research.md +82 -0
- package/payload/skill/scripts/lycheedev.mjs +59 -0
- package/release.json +346 -0
- package/bin/lycheedev.js +0 -742
- package/src/addon.js +0 -95
- package/src/config.js +0 -68
- package/src/doctor.js +0 -126
- package/src/install.js +0 -145
- package/src/paths.js +0 -93
- package/src/py/instances.py +0 -165
- package/src/python.js +0 -111
- package/src/skill.js +0 -48
- package/src/wow.js +0 -541
- package/vendor/addon/Core/Clients/Forever.lua +0 -9
- package/vendor/addon/Core/Clients/Mainline.lua +0 -9
- package/vendor/addon/Core/Clients/Mists.lua +0 -9
- package/vendor/addon/Core/Clients/Titan.lua +0 -9
- package/vendor/addon/Core/Compatibility.lua +0 -43
- package/vendor/addon/Core/Database.lua +0 -859
- package/vendor/addon/Core/Safety.lua +0 -42
- package/vendor/addon/Lychee Dev_Forever.toc +0 -43
- package/vendor/addon/Lychee Dev_Mainline.toc +0 -43
- package/vendor/addon/Lychee Dev_Mists.toc +0 -43
- package/vendor/addon/Lychee Dev_Wrath.toc +0 -43
- package/vendor/addon/Modules/Automation/Controller.lua +0 -884
- package/vendor/addon/Modules/Automation/Report.lua +0 -409
- package/vendor/addon/Modules/Automation/auto/auto.lua +0 -12
- package/vendor/addon/Modules/FunctionTrace.lua +0 -85
- package/vendor/addon/UI/AutomationOverlay.lua +0 -253
- package/vendor/addon/UI/Pages/Automation.lua +0 -417
- package/vendor/addon/UI/Pages/Diagnostics.lua +0 -289
- package/vendor/addon/UI/Pages/Trace.lua +0 -165
- package/vendor/skill/SKILL.md +0 -42
- package/vendor/skill/agents/openai.yaml +0 -4
- package/vendor/skill/references/automation.md +0 -128
- package/vendor/skill/references/clients.md +0 -51
- package/vendor/skill/references/runtime-investigations.md +0 -104
- package/vendor/skill/scripts/automation/__init__.py +0 -1
- package/vendor/skill/scripts/automation/registry.py +0 -516
- package/vendor/skill/scripts/automation/saved_variables.py +0 -438
- package/vendor/skill/scripts/automation/session.py +0 -207
- package/vendor/skill/scripts/automation/windows.py +0 -792
- package/vendor/skill/scripts/automation.py +0 -1034
- package/vendor/skill/scripts/requirements.txt +0 -13
- package/vendor/skill/scripts/selftest_offline.py +0 -1061
- package/vendor/skill/scripts/test_input_safety.py +0 -132
- /package/{vendor → payload}/addon/Media/GitHub.png +0 -0
- /package/{vendor → payload}/addon/Media/Logo.png +0 -0
- /package/{vendor → payload}/addon/Modules/Events/CatalogData_Forever.lua +0 -0
- /package/{vendor → payload}/addon/Modules/Events/CatalogData_Mainline.lua +0 -0
- /package/{vendor → payload}/addon/Modules/Events/CatalogData_Mists.lua +0 -0
- /package/{vendor → payload}/addon/Modules/Events/CatalogData_Titan.lua +0 -0
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
local ADDON_NAME, ns = ...
|
|
2
|
+
|
|
3
|
+
-- Bounded persistence for the workbench: run history and in-game "save to
|
|
4
|
+
-- record" exports, stored under LycheeToolkitDB through Core/Persistence.
|
|
5
|
+
-- Record bodies are plain data with no live references. Session-only state
|
|
6
|
+
-- (pending/protected sets, byte counters) never persists.
|
|
7
|
+
local HISTORY_SCHEMA_VERSION = 1
|
|
8
|
+
local EXPORT_SCHEMA_VERSION = 1
|
|
9
|
+
local EXPORT_SCHEMA = "lycheedev.export.v1"
|
|
10
|
+
|
|
11
|
+
local MAX_HISTORY_BYTES = 16 * 1024 * 1024
|
|
12
|
+
local MIN_HISTORY_ENTRY_BYTES = 16 * 1024
|
|
13
|
+
local MAX_CODE_BYTES = 12000
|
|
14
|
+
local MAX_RESULT_BYTES = 48000
|
|
15
|
+
local MAX_EXPORT_BYTES = 16 * 1024 * 1024
|
|
16
|
+
local MAX_EXPORT_RECORDS = 200
|
|
17
|
+
local METADATA_MAX_STRING_BYTES = 2048
|
|
18
|
+
local METADATA_MAX_DEPTH = 2
|
|
19
|
+
local METADATA_MAX_KEYS = 32
|
|
20
|
+
|
|
21
|
+
local currentRoot
|
|
22
|
+
local historyBytes = 0
|
|
23
|
+
local exportBytes = 0
|
|
24
|
+
-- Pending/protected are session-only; a SavedVariables load starts a fresh
|
|
25
|
+
-- session and therefore a fresh module state.
|
|
26
|
+
local pendingExports = {}
|
|
27
|
+
local pendingExportCount = 0
|
|
28
|
+
local protectedExports = {}
|
|
29
|
+
local protectedExportCount = 0
|
|
30
|
+
local historyWritesBlocked = false
|
|
31
|
+
local exportsWritesBlocked = false
|
|
32
|
+
|
|
33
|
+
local function Restricted(value)
|
|
34
|
+
return issecretvalue and issecretvalue(value)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
local function Plain(value)
|
|
38
|
+
return not Restricted(value)
|
|
39
|
+
and type(value) == "table" and getmetatable(value) == nil
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
local function TrimText(value, limit)
|
|
43
|
+
value = type(value) == "string" and value or tostring(value or "")
|
|
44
|
+
if #value <= limit then
|
|
45
|
+
return value
|
|
46
|
+
end
|
|
47
|
+
return value:sub(1, limit) .. "\n... <truncated>"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
local function GetStoredTreeBytes(value, seen)
|
|
51
|
+
if type(value) == "string" then
|
|
52
|
+
return #value
|
|
53
|
+
elseif type(value) ~= "table" then
|
|
54
|
+
return 8
|
|
55
|
+
elseif seen[value] then
|
|
56
|
+
return 0
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
seen[value] = true
|
|
60
|
+
local bytes = 48
|
|
61
|
+
for key, child in pairs(value) do
|
|
62
|
+
bytes = bytes + GetStoredTreeBytes(key, seen) + GetStoredTreeBytes(child, seen)
|
|
63
|
+
if bytes >= MAX_HISTORY_BYTES then
|
|
64
|
+
break
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
return bytes
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
local function GetHistoryEntryBytes(entry)
|
|
71
|
+
local treeBytes = Plain(entry.tree) and GetStoredTreeBytes(entry.tree, {}) or 0
|
|
72
|
+
local contentBytes = #(entry.code or "") + #(entry.result or "") + treeBytes + 128
|
|
73
|
+
return math.max(MIN_HISTORY_ENTRY_BYTES, contentBytes)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
local function GetExportEntryBytes(entry)
|
|
77
|
+
local payload = Plain(entry) and entry.payload or nil
|
|
78
|
+
return Plain(payload) and #(payload.content or "") or 0
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
-- Bounded metadata copy: strings of at most 2048 chars, nesting of at most 2
|
|
82
|
+
-- levels, at most 32 keys per table; anything else is dropped.
|
|
83
|
+
local function CopyExportMetadata(value, depth)
|
|
84
|
+
if Restricted(value) then
|
|
85
|
+
return nil
|
|
86
|
+
end
|
|
87
|
+
local valueType = type(value)
|
|
88
|
+
if valueType == "string" then
|
|
89
|
+
return value:sub(1, METADATA_MAX_STRING_BYTES)
|
|
90
|
+
elseif valueType == "number" or valueType == "boolean" then
|
|
91
|
+
return value
|
|
92
|
+
elseif valueType ~= "table" or depth >= METADATA_MAX_DEPTH then
|
|
93
|
+
return nil
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
local copied = {}
|
|
97
|
+
local count = 0
|
|
98
|
+
for key, child in pairs(value) do
|
|
99
|
+
if count >= METADATA_MAX_KEYS then
|
|
100
|
+
break
|
|
101
|
+
end
|
|
102
|
+
local keyType = type(key)
|
|
103
|
+
if (keyType == "string" or keyType == "number") and not Restricted(key) then
|
|
104
|
+
local safeChild = CopyExportMetadata(child, depth + 1)
|
|
105
|
+
if safeChild ~= nil then
|
|
106
|
+
copied[key] = safeChild
|
|
107
|
+
count = count + 1
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
return copied
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
local function ReadClientEnvironment()
|
|
115
|
+
local version, build, _, interfaceVersion
|
|
116
|
+
if GetBuildInfo then
|
|
117
|
+
local succeeded, v, b, _, i = pcall(GetBuildInfo)
|
|
118
|
+
if succeeded then
|
|
119
|
+
version, build, interfaceVersion = v, b, i
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
local locale
|
|
123
|
+
if GetLocale then
|
|
124
|
+
local succeeded, value = pcall(GetLocale)
|
|
125
|
+
if succeeded and not Restricted(value) then
|
|
126
|
+
locale = value
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
return {
|
|
130
|
+
addonName = ADDON_NAME,
|
|
131
|
+
clientId = ns.PlatformProfile and ns.PlatformProfile.product or nil,
|
|
132
|
+
version = not Restricted(version) and version or nil,
|
|
133
|
+
build = not Restricted(build) and build or nil,
|
|
134
|
+
interface = not Restricted(interfaceVersion) and interfaceVersion or nil,
|
|
135
|
+
locale = locale,
|
|
136
|
+
}
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
local function CreateExportRecord(id, kind, title, content, createdAt, metadata, options)
|
|
140
|
+
metadata = CopyExportMetadata(metadata, 0) or {}
|
|
141
|
+
options = Plain(options) and options or {}
|
|
142
|
+
return {
|
|
143
|
+
schema = EXPORT_SCHEMA,
|
|
144
|
+
id = id,
|
|
145
|
+
createdAt = tonumber(createdAt) or 0,
|
|
146
|
+
source = {
|
|
147
|
+
kind = type(kind) == "string" and kind or "unknown",
|
|
148
|
+
title = type(title) == "string" and title or "",
|
|
149
|
+
path = type(metadata.path) == "string" and metadata.path or nil,
|
|
150
|
+
},
|
|
151
|
+
payload = {
|
|
152
|
+
mediaType = type(options.mediaType) == "string" and options.mediaType or "text/plain",
|
|
153
|
+
encoding = "utf-8",
|
|
154
|
+
content = content,
|
|
155
|
+
byteCount = #content,
|
|
156
|
+
},
|
|
157
|
+
environment = ReadClientEnvironment(),
|
|
158
|
+
metadata = metadata,
|
|
159
|
+
}
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
-- Idempotent load-time normalization. Unknown fields on records are preserved
|
|
163
|
+
-- verbatim; nothing is read from legacy databases and nothing is imported.
|
|
164
|
+
local function NormalizeExportRecord(id, entry)
|
|
165
|
+
if not Plain(entry) or type(id) ~= "string" then
|
|
166
|
+
return nil
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
local payload = entry.payload
|
|
170
|
+
if Plain(payload) and type(payload.content) == "string" then
|
|
171
|
+
entry.id = id
|
|
172
|
+
entry.schema = type(entry.schema) == "string" and entry.schema or EXPORT_SCHEMA
|
|
173
|
+
entry.createdAt = tonumber(entry.createdAt) or 0
|
|
174
|
+
entry.source = Plain(entry.source) and entry.source or {}
|
|
175
|
+
entry.source.kind = type(entry.source.kind) == "string" and entry.source.kind or "unknown"
|
|
176
|
+
entry.source.title = type(entry.source.title) == "string" and entry.source.title or ""
|
|
177
|
+
entry.source.path = type(entry.source.path) == "string" and entry.source.path or nil
|
|
178
|
+
entry.metadata = CopyExportMetadata(entry.metadata, 0) or {}
|
|
179
|
+
if type(entry.source.path) ~= "string" then
|
|
180
|
+
entry.source.path = type(entry.metadata.path) == "string" and entry.metadata.path or nil
|
|
181
|
+
end
|
|
182
|
+
payload.mediaType = type(payload.mediaType) == "string" and payload.mediaType or "text/plain"
|
|
183
|
+
payload.encoding = "utf-8"
|
|
184
|
+
payload.byteCount = #payload.content
|
|
185
|
+
entry.environment = Plain(entry.environment) and entry.environment or {}
|
|
186
|
+
entry.environment.addonName = type(entry.environment.addonName) == "string"
|
|
187
|
+
and entry.environment.addonName or ADDON_NAME
|
|
188
|
+
return entry
|
|
189
|
+
end
|
|
190
|
+
return nil
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
local function NormalizeHistoryEntry(entry)
|
|
194
|
+
if not Plain(entry) then
|
|
195
|
+
return nil
|
|
196
|
+
end
|
|
197
|
+
entry.code = TrimText(entry.code, MAX_CODE_BYTES)
|
|
198
|
+
entry.result = TrimText(entry.result, MAX_RESULT_BYTES)
|
|
199
|
+
entry.succeeded = entry.succeeded and true or false
|
|
200
|
+
if type(entry.timestamp) ~= "number" then
|
|
201
|
+
entry.timestamp = nil
|
|
202
|
+
end
|
|
203
|
+
if not Plain(entry.tree) then
|
|
204
|
+
entry.tree = nil
|
|
205
|
+
end
|
|
206
|
+
return entry
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
local function PruneHistoryToBudget(root)
|
|
210
|
+
local entries = root.history.entries
|
|
211
|
+
while historyBytes > MAX_HISTORY_BYTES and #entries > 0 do
|
|
212
|
+
local entry = entries[#entries]
|
|
213
|
+
historyBytes = math.max(0, historyBytes - GetHistoryEntryBytes(entry))
|
|
214
|
+
entries[#entries] = nil
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
local function RemoveExport(root, id)
|
|
219
|
+
local entry = root.exports.records[id]
|
|
220
|
+
if entry then
|
|
221
|
+
exportBytes = math.max(0, exportBytes - GetExportEntryBytes(entry))
|
|
222
|
+
root.exports.records[id] = nil
|
|
223
|
+
end
|
|
224
|
+
if pendingExports[id] then
|
|
225
|
+
pendingExports[id] = nil
|
|
226
|
+
pendingExportCount = math.max(0, pendingExportCount - 1)
|
|
227
|
+
end
|
|
228
|
+
if protectedExports[id] then
|
|
229
|
+
protectedExports[id] = nil
|
|
230
|
+
protectedExportCount = math.max(0, protectedExportCount - 1)
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
local function FindPrunableIndex(root)
|
|
235
|
+
local order = root.exports.order
|
|
236
|
+
for index = #order, 1, -1 do
|
|
237
|
+
if not protectedExports[order[index]] then
|
|
238
|
+
return index
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
return nil
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
local function PruneExportsToBudget(root)
|
|
245
|
+
local exports = root.exports
|
|
246
|
+
while (exportBytes > MAX_EXPORT_BYTES or #exports.order > MAX_EXPORT_RECORDS)
|
|
247
|
+
and #exports.order > 0 do
|
|
248
|
+
local index = FindPrunableIndex(root)
|
|
249
|
+
if not index then
|
|
250
|
+
break
|
|
251
|
+
end
|
|
252
|
+
local id = exports.order[index]
|
|
253
|
+
table.remove(exports.order, index)
|
|
254
|
+
RemoveExport(root, id)
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
local function SectionVersion(section, defaultVersion)
|
|
259
|
+
local stored = section.version
|
|
260
|
+
if stored == nil then
|
|
261
|
+
return defaultVersion
|
|
262
|
+
end
|
|
263
|
+
return tonumber(stored)
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
local function InitializeSections(root)
|
|
267
|
+
historyWritesBlocked = false
|
|
268
|
+
exportsWritesBlocked = false
|
|
269
|
+
|
|
270
|
+
if not Plain(root.history) then
|
|
271
|
+
root.history = {}
|
|
272
|
+
end
|
|
273
|
+
local history = root.history
|
|
274
|
+
local historyVersion = SectionVersion(history, HISTORY_SCHEMA_VERSION)
|
|
275
|
+
if historyVersion == nil or historyVersion > HISTORY_SCHEMA_VERSION then
|
|
276
|
+
historyWritesBlocked = true
|
|
277
|
+
end
|
|
278
|
+
if type(history.entries) ~= "table" then
|
|
279
|
+
history.entries = {}
|
|
280
|
+
end
|
|
281
|
+
historyBytes = 0
|
|
282
|
+
for index = #history.entries, 1, -1 do
|
|
283
|
+
local entry = NormalizeHistoryEntry(history.entries[index])
|
|
284
|
+
if not entry then
|
|
285
|
+
table.remove(history.entries, index)
|
|
286
|
+
else
|
|
287
|
+
historyBytes = historyBytes + GetHistoryEntryBytes(entry)
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
PruneHistoryToBudget(root)
|
|
291
|
+
|
|
292
|
+
if not Plain(root.exports) then
|
|
293
|
+
root.exports = {}
|
|
294
|
+
end
|
|
295
|
+
local exports = root.exports
|
|
296
|
+
local exportsVersion = SectionVersion(exports, EXPORT_SCHEMA_VERSION)
|
|
297
|
+
if exportsVersion == nil or exportsVersion > EXPORT_SCHEMA_VERSION then
|
|
298
|
+
exportsWritesBlocked = true
|
|
299
|
+
end
|
|
300
|
+
exports.nextId = math.max(0, math.floor(tonumber(exports.nextId) or 0))
|
|
301
|
+
exports.records = Plain(exports.records) and exports.records or {}
|
|
302
|
+
exports.order = type(exports.order) == "table" and exports.order or {}
|
|
303
|
+
|
|
304
|
+
local validRecords = {}
|
|
305
|
+
exportBytes = 0
|
|
306
|
+
for id, entry in pairs(exports.records) do
|
|
307
|
+
local normalized = type(id) == "string" and NormalizeExportRecord(id, entry) or nil
|
|
308
|
+
if normalized then
|
|
309
|
+
validRecords[id] = normalized
|
|
310
|
+
exportBytes = exportBytes + GetExportEntryBytes(normalized)
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
exports.records = validRecords
|
|
314
|
+
|
|
315
|
+
local ordered = {}
|
|
316
|
+
local included = {}
|
|
317
|
+
for index = 1, #exports.order do
|
|
318
|
+
local id = exports.order[index]
|
|
319
|
+
if validRecords[id] and not included[id] then
|
|
320
|
+
ordered[#ordered + 1] = id
|
|
321
|
+
included[id] = true
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
for id in pairs(validRecords) do
|
|
325
|
+
if not included[id] then
|
|
326
|
+
ordered[#ordered + 1] = id
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
table.sort(ordered, function(left, right)
|
|
330
|
+
return validRecords[left].createdAt > validRecords[right].createdAt
|
|
331
|
+
end)
|
|
332
|
+
exports.order = ordered
|
|
333
|
+
PruneExportsToBudget(root)
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
-- Fetches the current database root at use time and (re)initializes the store
|
|
337
|
+
-- sections whenever the root is replaced (for example by a re-root).
|
|
338
|
+
local function EnsureState()
|
|
339
|
+
local root, reason = ns.Persistence.Current()
|
|
340
|
+
if not root then
|
|
341
|
+
return nil, reason or "state_not_loaded"
|
|
342
|
+
end
|
|
343
|
+
if root ~= currentRoot then
|
|
344
|
+
currentRoot = root
|
|
345
|
+
pendingExports = {}
|
|
346
|
+
pendingExportCount = 0
|
|
347
|
+
protectedExports = {}
|
|
348
|
+
protectedExportCount = 0
|
|
349
|
+
InitializeSections(root)
|
|
350
|
+
end
|
|
351
|
+
return root
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
local function AllocateTicket(root, timestamp)
|
|
355
|
+
local exports = root.exports
|
|
356
|
+
local id
|
|
357
|
+
repeat
|
|
358
|
+
-- The counter only ever grows and is never reset or reused, so tickets
|
|
359
|
+
-- stay unique across clears and sessions.
|
|
360
|
+
exports.nextId = exports.nextId + 1
|
|
361
|
+
id = string.format("LYCHEE-%s-%04d", date("%Y%m%d-%H%M%S", timestamp), exports.nextId)
|
|
362
|
+
until not exports.records[id]
|
|
363
|
+
return id
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
local History = {}
|
|
367
|
+
|
|
368
|
+
function History.Add(code, result, succeeded, tree)
|
|
369
|
+
local root, reason = EnsureState()
|
|
370
|
+
if not root then
|
|
371
|
+
return nil, reason
|
|
372
|
+
end
|
|
373
|
+
if historyWritesBlocked then
|
|
374
|
+
return nil, "state_unsupported_version"
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
local entry = {
|
|
378
|
+
code = TrimText(code, MAX_CODE_BYTES),
|
|
379
|
+
result = TrimText(result, MAX_RESULT_BYTES),
|
|
380
|
+
succeeded = succeeded and true or false,
|
|
381
|
+
timestamp = time(),
|
|
382
|
+
tree = Plain(tree) and tree or nil,
|
|
383
|
+
}
|
|
384
|
+
table.insert(root.history.entries, 1, entry)
|
|
385
|
+
|
|
386
|
+
historyBytes = historyBytes + GetHistoryEntryBytes(entry)
|
|
387
|
+
PruneHistoryToBudget(root)
|
|
388
|
+
return entry
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
function History.Get()
|
|
392
|
+
local root = EnsureState()
|
|
393
|
+
return root and root.history.entries or nil
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
function History.GetStats()
|
|
397
|
+
local root = EnsureState()
|
|
398
|
+
local count = root and #root.history.entries or 0
|
|
399
|
+
return count, historyBytes, MAX_HISTORY_BYTES
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
function History.Clear()
|
|
403
|
+
local root = EnsureState()
|
|
404
|
+
if not root then
|
|
405
|
+
return false
|
|
406
|
+
end
|
|
407
|
+
wipe(root.history.entries)
|
|
408
|
+
historyBytes = 0
|
|
409
|
+
return true
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
local Exports = {
|
|
413
|
+
SCHEMA = EXPORT_SCHEMA,
|
|
414
|
+
KINDS = {
|
|
415
|
+
run_result = true,
|
|
416
|
+
object_snapshot = true,
|
|
417
|
+
object_node = true,
|
|
418
|
+
event_log = true,
|
|
419
|
+
function_trace = true,
|
|
420
|
+
error_log = true,
|
|
421
|
+
automation_result = true,
|
|
422
|
+
},
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function Exports.Add(kind, title, content, metadata, options)
|
|
426
|
+
local root, reason = EnsureState()
|
|
427
|
+
if not root then
|
|
428
|
+
return nil, reason
|
|
429
|
+
end
|
|
430
|
+
if exportsWritesBlocked then
|
|
431
|
+
return nil, ns.L.EXPORT_DATABASE_NEWER
|
|
432
|
+
end
|
|
433
|
+
if Restricted(content) then
|
|
434
|
+
return nil, ns.L.EXPORT_FAILED
|
|
435
|
+
end
|
|
436
|
+
content = type(content) == "string" and content or tostring(content or "")
|
|
437
|
+
if content == "" then
|
|
438
|
+
return nil, ns.L.EXPORT_EMPTY
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
local timestamp = time()
|
|
442
|
+
local id = AllocateTicket(root, timestamp)
|
|
443
|
+
local entry = CreateExportRecord(id, kind, title, content, timestamp, metadata, options)
|
|
444
|
+
local entryBytes = GetExportEntryBytes(entry)
|
|
445
|
+
if entryBytes > MAX_EXPORT_BYTES then
|
|
446
|
+
return nil, ns.L.EXPORT_TOO_LARGE
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
root.exports.records[id] = entry
|
|
450
|
+
table.insert(root.exports.order, 1, id)
|
|
451
|
+
exportBytes = exportBytes + entryBytes
|
|
452
|
+
pendingExports[id] = true
|
|
453
|
+
pendingExportCount = pendingExportCount + 1
|
|
454
|
+
if Plain(options) and options.protect then
|
|
455
|
+
protectedExports[id] = true
|
|
456
|
+
protectedExportCount = protectedExportCount + 1
|
|
457
|
+
end
|
|
458
|
+
PruneExportsToBudget(root)
|
|
459
|
+
return id, entry
|
|
460
|
+
end
|
|
461
|
+
|
|
462
|
+
function Exports.Get(id)
|
|
463
|
+
local root = EnsureState()
|
|
464
|
+
return root and root.exports.records[id] or nil
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
function Exports.GetOrder()
|
|
468
|
+
local root = EnsureState()
|
|
469
|
+
return root and root.exports.order or nil
|
|
470
|
+
end
|
|
471
|
+
|
|
472
|
+
function Exports.GetStats()
|
|
473
|
+
local root = EnsureState()
|
|
474
|
+
local count = root and #root.exports.order or 0
|
|
475
|
+
return count, exportBytes, MAX_EXPORT_BYTES
|
|
476
|
+
end
|
|
477
|
+
|
|
478
|
+
function Exports.IsPending(id)
|
|
479
|
+
return type(id) == "string" and pendingExports[id] == true
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
function Exports.GetPendingCount()
|
|
483
|
+
return pendingExportCount
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
function Exports.IsProtected(id)
|
|
487
|
+
return type(id) == "string" and protectedExports[id] == true
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
function Exports.GetProtectedCount()
|
|
491
|
+
return protectedExportCount
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
function Exports.Protect(id)
|
|
495
|
+
local root = EnsureState()
|
|
496
|
+
if not root or type(id) ~= "string" or not root.exports.records[id] then
|
|
497
|
+
return false
|
|
498
|
+
end
|
|
499
|
+
if not protectedExports[id] then
|
|
500
|
+
protectedExports[id] = true
|
|
501
|
+
protectedExportCount = protectedExportCount + 1
|
|
502
|
+
end
|
|
503
|
+
return true
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
-- Records the flush of one record to disk: it leaves the pending and protected
|
|
507
|
+
-- sets and becomes ordinary saved data.
|
|
508
|
+
function Exports.MarkSaved(id)
|
|
509
|
+
local root = EnsureState()
|
|
510
|
+
if not root or type(id) ~= "string" or not root.exports.records[id] then
|
|
511
|
+
return false
|
|
512
|
+
end
|
|
513
|
+
if pendingExports[id] then
|
|
514
|
+
pendingExports[id] = nil
|
|
515
|
+
pendingExportCount = math.max(0, pendingExportCount - 1)
|
|
516
|
+
end
|
|
517
|
+
if protectedExports[id] then
|
|
518
|
+
protectedExports[id] = nil
|
|
519
|
+
protectedExportCount = math.max(0, protectedExportCount - 1)
|
|
520
|
+
end
|
|
521
|
+
return true
|
|
522
|
+
end
|
|
523
|
+
|
|
524
|
+
-- "pending" while the record still waits for its SavedVariables flush this
|
|
525
|
+
-- session, "saved" once it is ordinary on-disk data.
|
|
526
|
+
function Exports.GetState(id)
|
|
527
|
+
local root = EnsureState()
|
|
528
|
+
if not root or type(id) ~= "string" or not root.exports.records[id] then
|
|
529
|
+
return "none"
|
|
530
|
+
end
|
|
531
|
+
return pendingExports[id] and "pending" or "saved"
|
|
532
|
+
end
|
|
533
|
+
|
|
534
|
+
function Exports.Delete(id)
|
|
535
|
+
local root = EnsureState()
|
|
536
|
+
if not root or type(id) ~= "string" or not root.exports.records[id] then
|
|
537
|
+
return false
|
|
538
|
+
end
|
|
539
|
+
-- Results awaiting their reload disk write cannot be deleted.
|
|
540
|
+
if protectedExports[id] then
|
|
541
|
+
return false
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
RemoveExport(root, id)
|
|
545
|
+
local order = root.exports.order
|
|
546
|
+
for index = 1, #order do
|
|
547
|
+
if order[index] == id then
|
|
548
|
+
table.remove(order, index)
|
|
549
|
+
break
|
|
550
|
+
end
|
|
551
|
+
end
|
|
552
|
+
return true
|
|
553
|
+
end
|
|
554
|
+
|
|
555
|
+
function Exports.Clear()
|
|
556
|
+
local root = EnsureState()
|
|
557
|
+
if not root then
|
|
558
|
+
return 0
|
|
559
|
+
end
|
|
560
|
+
local removed = 0
|
|
561
|
+
local order = root.exports.order
|
|
562
|
+
for index = #order, 1, -1 do
|
|
563
|
+
local id = order[index]
|
|
564
|
+
if not protectedExports[id] then
|
|
565
|
+
table.remove(order, index)
|
|
566
|
+
RemoveExport(root, id)
|
|
567
|
+
removed = removed + 1
|
|
568
|
+
end
|
|
569
|
+
end
|
|
570
|
+
return removed
|
|
571
|
+
end
|
|
572
|
+
|
|
573
|
+
-- Precheck that a new record fits after pruning protected records aside;
|
|
574
|
+
-- reserved bytes keep headroom for failure reports.
|
|
575
|
+
function Exports.CanFit(byteCount, reserve)
|
|
576
|
+
local root = EnsureState()
|
|
577
|
+
if not root then
|
|
578
|
+
return false
|
|
579
|
+
end
|
|
580
|
+
byteCount = tonumber(byteCount) or 0
|
|
581
|
+
local budget = MAX_EXPORT_BYTES - math.max(0, tonumber(reserve) or 0)
|
|
582
|
+
if byteCount > budget then
|
|
583
|
+
return false
|
|
584
|
+
end
|
|
585
|
+
local projectedBytes = exportBytes + byteCount
|
|
586
|
+
local projectedCount = #root.exports.order + 1
|
|
587
|
+
if projectedBytes <= budget and projectedCount <= MAX_EXPORT_RECORDS then
|
|
588
|
+
return true
|
|
589
|
+
end
|
|
590
|
+
local order = root.exports.order
|
|
591
|
+
for index = #order, 1, -1 do
|
|
592
|
+
local id = order[index]
|
|
593
|
+
if not protectedExports[id] then
|
|
594
|
+
local entry = root.exports.records[id]
|
|
595
|
+
if entry then
|
|
596
|
+
projectedBytes = projectedBytes - GetExportEntryBytes(entry)
|
|
597
|
+
projectedCount = projectedCount - 1
|
|
598
|
+
if projectedBytes <= budget and projectedCount <= MAX_EXPORT_RECORDS then
|
|
599
|
+
return true
|
|
600
|
+
end
|
|
601
|
+
end
|
|
602
|
+
end
|
|
603
|
+
end
|
|
604
|
+
return false
|
|
605
|
+
end
|
|
606
|
+
|
|
607
|
+
ns.Stores = {
|
|
608
|
+
Initialize = EnsureState,
|
|
609
|
+
History = History,
|
|
610
|
+
Exports = Exports,
|
|
611
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
## Interface: 16001
|
|
2
|
+
## Title: Lychee Dev
|
|
3
|
+
## Version: 2.0.0
|
|
4
|
+
## SavedVariables: LycheeToolkitDB
|
|
5
|
+
|
|
6
|
+
Clients\Evergreen.lua
|
|
7
|
+
# --- Toolkit 2.0 core engines (Locale, Compat, Serializer, Inspector, Safety, Execute, Stores) ---
|
|
8
|
+
Core\Locale.lua
|
|
9
|
+
Core\Locale_enUS.lua
|
|
10
|
+
Core\Compat.lua
|
|
11
|
+
Core\Serializer.lua
|
|
12
|
+
Core\Inspector.lua
|
|
13
|
+
Core\Safety.lua
|
|
14
|
+
Core\Execute.lua
|
|
15
|
+
Core\Stores.lua
|
|
16
|
+
Core\Platform.lua
|
|
17
|
+
Core\Persistence.lua
|
|
18
|
+
Bridge\Session.lua
|
|
19
|
+
Core\Controls.lua
|
|
20
|
+
Bridge\CaptureWriter.lua
|
|
21
|
+
Bridge\MatrixSymbol.lua
|
|
22
|
+
Bridge\ReceiptView.lua
|
|
23
|
+
Bridge\ReportStore.lua
|
|
24
|
+
Bridge\ProbeRunner.lua
|
|
25
|
+
Bridge\Definitions.lua
|
|
26
|
+
Modules\AutomationView.lua
|
|
27
|
+
Bridge\ProbeQueue.lua
|
|
28
|
+
Bridge\Reentry.lua
|
|
29
|
+
Bridge\Identity.lua
|
|
30
|
+
# --- Workbench feature modules (object inspection, function trace, diagnostics) ---
|
|
31
|
+
Modules\ObjectInspector.lua
|
|
32
|
+
Modules\FunctionTrace.lua
|
|
33
|
+
Modules\Diagnostics.lua
|
|
34
|
+
# --- Event catalog (per client) and bounded monitor ---
|
|
35
|
+
Modules\Events\CatalogData_Forever.lua
|
|
36
|
+
Modules\Events\Catalog.lua
|
|
37
|
+
Modules\Events\Monitor.lua
|
|
38
|
+
# --- Workbench UI foundation (Widgets, TreeView, Export popup, Window shell) ---
|
|
39
|
+
UI\Widgets.lua
|
|
40
|
+
UI\TreeView.lua
|
|
41
|
+
UI\Export.lua
|
|
42
|
+
UI\Window.lua
|
|
43
|
+
# --- Workbench pages: later page modules insert their load line here ---
|
|
44
|
+
UI\Pages\About.lua
|
|
45
|
+
UI\Pages\Run.lua
|
|
46
|
+
UI\Pages\Object.lua
|
|
47
|
+
UI\Pages\Trace.lua
|
|
48
|
+
UI\Pages\Diagnostics.lua
|
|
49
|
+
UI\Pages\Events.lua
|
|
50
|
+
UI\Pages\Automation.lua
|
|
51
|
+
UI\Pages\ExportRecords.lua
|
|
52
|
+
Core\Runtime.lua
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
## Interface: 120100
|
|
2
|
+
## Title: Lychee Dev
|
|
3
|
+
## Version: 2.0.0
|
|
4
|
+
## SavedVariables: LycheeToolkitDB
|
|
5
|
+
|
|
6
|
+
Clients\Live.lua
|
|
7
|
+
# --- Toolkit 2.0 core engines (Locale, Compat, Serializer, Inspector, Safety, Execute, Stores) ---
|
|
8
|
+
Core\Locale.lua
|
|
9
|
+
Core\Locale_enUS.lua
|
|
10
|
+
Core\Compat.lua
|
|
11
|
+
Core\Serializer.lua
|
|
12
|
+
Core\Inspector.lua
|
|
13
|
+
Core\Safety.lua
|
|
14
|
+
Core\Execute.lua
|
|
15
|
+
Core\Stores.lua
|
|
16
|
+
Core\Platform.lua
|
|
17
|
+
Core\Persistence.lua
|
|
18
|
+
Bridge\Session.lua
|
|
19
|
+
Core\Controls.lua
|
|
20
|
+
Bridge\CaptureWriter.lua
|
|
21
|
+
Bridge\MatrixSymbol.lua
|
|
22
|
+
Bridge\ReceiptView.lua
|
|
23
|
+
Bridge\ReportStore.lua
|
|
24
|
+
Bridge\ProbeRunner.lua
|
|
25
|
+
Bridge\Definitions.lua
|
|
26
|
+
Modules\AutomationView.lua
|
|
27
|
+
Bridge\ProbeQueue.lua
|
|
28
|
+
Bridge\Reentry.lua
|
|
29
|
+
Bridge\Identity.lua
|
|
30
|
+
# --- Workbench feature modules (object inspection, function trace, diagnostics) ---
|
|
31
|
+
Modules\ObjectInspector.lua
|
|
32
|
+
Modules\FunctionTrace.lua
|
|
33
|
+
Modules\Diagnostics.lua
|
|
34
|
+
# --- Event catalog (per client) and bounded monitor ---
|
|
35
|
+
Modules\Events\CatalogData_Mainline.lua
|
|
36
|
+
Modules\Events\Catalog.lua
|
|
37
|
+
Modules\Events\Monitor.lua
|
|
38
|
+
# --- Workbench UI foundation (Widgets, TreeView, Export popup, Window shell) ---
|
|
39
|
+
UI\Widgets.lua
|
|
40
|
+
UI\TreeView.lua
|
|
41
|
+
UI\Export.lua
|
|
42
|
+
UI\Window.lua
|
|
43
|
+
# --- Workbench pages: later page modules insert their load line here ---
|
|
44
|
+
UI\Pages\About.lua
|
|
45
|
+
UI\Pages\Run.lua
|
|
46
|
+
UI\Pages\Object.lua
|
|
47
|
+
UI\Pages\Trace.lua
|
|
48
|
+
UI\Pages\Diagnostics.lua
|
|
49
|
+
UI\Pages\Events.lua
|
|
50
|
+
UI\Pages\Automation.lua
|
|
51
|
+
UI\Pages\ExportRecords.lua
|
|
52
|
+
Core\Runtime.lua
|