lycheedev 1.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.
Files changed (60) hide show
  1. package/bin/lycheedev.js +257 -0
  2. package/package.json +42 -0
  3. package/src/addon.js +87 -0
  4. package/src/config.js +64 -0
  5. package/src/doctor.js +100 -0
  6. package/src/install.js +131 -0
  7. package/src/paths.js +93 -0
  8. package/src/python.js +107 -0
  9. package/src/skill.js +48 -0
  10. package/src/wow.js +110 -0
  11. package/vendor/addon/Core/Bootstrap.lua +131 -0
  12. package/vendor/addon/Core/Clients/Mainline.lua +9 -0
  13. package/vendor/addon/Core/Clients/Mists.lua +9 -0
  14. package/vendor/addon/Core/Clients/Titan.lua +9 -0
  15. package/vendor/addon/Core/Compatibility.lua +43 -0
  16. package/vendor/addon/Core/Database.lua +859 -0
  17. package/vendor/addon/Core/Inspector.lua +647 -0
  18. package/vendor/addon/Core/Locale.lua +307 -0
  19. package/vendor/addon/Core/Locale_enUS.lua +318 -0
  20. package/vendor/addon/Core/Safety.lua +42 -0
  21. package/vendor/addon/Core/Serializer.lua +324 -0
  22. package/vendor/addon/Libs/AutomationQR.lua +1176 -0
  23. package/vendor/addon/Lychee Dev_Mainline.toc +43 -0
  24. package/vendor/addon/Lychee Dev_Mists.toc +43 -0
  25. package/vendor/addon/Lychee Dev_Wrath.toc +43 -0
  26. package/vendor/addon/Media/GitHub.png +0 -0
  27. package/vendor/addon/Media/Logo.png +0 -0
  28. package/vendor/addon/Modules/Automation/Controller.lua +757 -0
  29. package/vendor/addon/Modules/Automation/Report.lua +409 -0
  30. package/vendor/addon/Modules/Automation/auto/auto.lua +12 -0
  31. package/vendor/addon/Modules/Diagnostics.lua +238 -0
  32. package/vendor/addon/Modules/Events/Catalog.lua +184 -0
  33. package/vendor/addon/Modules/Events/CatalogData_Mainline.lua +1788 -0
  34. package/vendor/addon/Modules/Events/CatalogData_Mists.lua +1489 -0
  35. package/vendor/addon/Modules/Events/CatalogData_Titan.lua +1492 -0
  36. package/vendor/addon/Modules/Events/Monitor.lua +181 -0
  37. package/vendor/addon/Modules/FunctionTrace.lua +85 -0
  38. package/vendor/addon/Modules/ObjectInspector.lua +329 -0
  39. package/vendor/addon/UI/AutomationOverlay.lua +183 -0
  40. package/vendor/addon/UI/Export.lua +140 -0
  41. package/vendor/addon/UI/Features.lua +890 -0
  42. package/vendor/addon/UI/MainWindow.lua +1145 -0
  43. package/vendor/addon/UI/Pages/About.lua +223 -0
  44. package/vendor/addon/UI/Pages/Automation.lua +417 -0
  45. package/vendor/addon/UI/Pages/Diagnostics.lua +289 -0
  46. package/vendor/addon/UI/Pages/ExportRecords.lua +387 -0
  47. package/vendor/addon/UI/Pages/Object.lua +573 -0
  48. package/vendor/addon/UI/Pages/Trace.lua +165 -0
  49. package/vendor/skill/SKILL.md +94 -0
  50. package/vendor/skill/agents/openai.yaml +4 -0
  51. package/vendor/skill/references/automation.md +327 -0
  52. package/vendor/skill/references/runtime-investigations.md +97 -0
  53. package/vendor/skill/scripts/automation/__init__.py +1 -0
  54. package/vendor/skill/scripts/automation/registry.py +516 -0
  55. package/vendor/skill/scripts/automation/saved_variables.py +438 -0
  56. package/vendor/skill/scripts/automation/session.py +207 -0
  57. package/vendor/skill/scripts/automation/windows.py +573 -0
  58. package/vendor/skill/scripts/automation.py +865 -0
  59. package/vendor/skill/scripts/requirements.txt +13 -0
  60. package/vendor/skill/scripts/selftest_offline.py +981 -0
@@ -0,0 +1,165 @@
1
+ local ADDON_NAME, ns = ...
2
+ local L = ns.L
3
+
4
+ local ROW_HEIGHT = 38
5
+ local LIST_WIDTH = 520
6
+ local VISIBLE_ROWS = 18
7
+
8
+ local function SetReadOnlyText(panel, text)
9
+ local editBox = panel.editBox
10
+ editBox.savedText, editBox.updatingText = text or "", true
11
+ editBox:SetText(text or "")
12
+ editBox.updatingText = nil
13
+ editBox:SetCursorPosition(0)
14
+ panel.scroll:SetVerticalScroll(0)
15
+ end
16
+
17
+ local function CreateLineInput(parent, ui)
18
+ local panel = ui.CreatePanel(parent, ui.editorR, ui.editorG, ui.editorB, 1)
19
+ local editBox = CreateFrame("EditBox", nil, panel)
20
+ editBox:SetAutoFocus(false)
21
+ editBox:SetFontObject(ChatFontNormal)
22
+ editBox:SetTextColor(0.94, 0.95, 0.96)
23
+ editBox:SetTextInsets(9, 9, 0, 0)
24
+ editBox:SetPoint("TOPLEFT", 1, -1)
25
+ editBox:SetPoint("BOTTOMRIGHT", -1, 1)
26
+ editBox:SetScript("OnEscapePressed", function(self) self:ClearFocus() end)
27
+ panel.editBox = editBox
28
+ return panel
29
+ end
30
+
31
+ function ns.CreateTracePage(parent, ui)
32
+ local page = CreateFrame("Frame", nil, parent)
33
+ page:SetAllPoints(parent)
34
+ local input = CreateLineInput(page, ui)
35
+ input:SetPoint("TOPLEFT", 14, -84)
36
+ input:SetPoint("TOPRIGHT", -250, -84)
37
+ input:SetHeight(30)
38
+ input.editBox:SetText("C_AddOns.GetAddOnInfo")
39
+ local traceButton = ui.CreateButton(page, 112, L.START_TRACE, true)
40
+ traceButton:SetPoint("TOPRIGHT", -14, -84)
41
+ local clear = ui.CreateButton(page, 100, L.CLEAR_LOG, false)
42
+ clear:SetPoint("RIGHT", traceButton, "LEFT", -8, 0)
43
+ page.traceButton = traceButton
44
+ page.clearButton = clear
45
+
46
+ local dot = page:CreateTexture(nil, "ARTWORK")
47
+ dot:SetSize(5, 5)
48
+ dot:SetPoint("TOPLEFT", input, "BOTTOMLEFT", 2, -15)
49
+ local status = page:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
50
+ status:SetPoint("LEFT", dot, "RIGHT", 7, 0)
51
+ local function SetStatus(text, r, g, b)
52
+ status:SetText(text) status:SetTextColor(r, g, b, 0.92) dot:SetColorTexture(r, g, b, 0.92)
53
+ end
54
+
55
+ local listLabel = ui.CreateSectionLabel(page, L.CALL_RECORDS)
56
+ listLabel:SetPoint("TOPLEFT", 17, -152)
57
+ local detailLabel = ui.CreateSectionLabel(page, L.CALL_ARGUMENTS)
58
+ detailLabel:SetPoint("TOPLEFT", LIST_WIDTH + 29, -152)
59
+ local listPanel = ui.CreatePanel(page, ui.editorR, ui.editorG, ui.editorB, 0.78)
60
+ listPanel:SetPoint("TOPLEFT", 14, -172)
61
+ listPanel:SetPoint("BOTTOMLEFT", 14, 54)
62
+ listPanel:SetWidth(LIST_WIDTH)
63
+ local scroll = ui.CreateScrollArea(listPanel, 8, 8, 7, 8)
64
+ local content = CreateFrame("Frame", nil, scroll)
65
+ content:SetWidth(LIST_WIDTH - 26) content:SetHeight(1) scroll:SetScrollChild(content)
66
+ local empty = listPanel:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
67
+ empty:SetPoint("TOP", 0, -24) empty:SetText(L.NO_CALLS_CAPTURED) empty:SetTextColor(1, 1, 1, 0.32)
68
+ local selected
69
+ local Format
70
+ local detail = ui.CreateTextArea(page, true)
71
+ detail:SetPoint("TOPLEFT", LIST_WIDTH + 26, -172)
72
+ detail:SetPoint("BOTTOMRIGHT", -14, 54)
73
+ detail.editBox:SetWidth(ui.windowWidth - LIST_WIDTH - 78)
74
+ SetReadOnlyText(detail, L.SELECT_CALL_DETAIL)
75
+
76
+ local exportDetail = ui.CreateButton(page, 92, L.SAVE_TO_DISK, false)
77
+ exportDetail:SetPoint("BOTTOMRIGHT", -14, 14)
78
+ exportDetail:SetScript("OnClick", function()
79
+ local recordCount = ns.FunctionTrace.GetCount()
80
+ if recordCount > 0 then
81
+ ui.ExportText("function_trace", L.CALL_RECORDS, function()
82
+ local records = {}
83
+ for index = 1, recordCount do
84
+ records[index] = ns.FunctionTrace.GetRecord(index)
85
+ end
86
+ return ns.SerializeForExport(records)
87
+ end, { recordCount = recordCount })
88
+ end
89
+ end)
90
+ page.exportDetail = exportDetail
91
+
92
+ local rows, refreshQueued = {}, false
93
+ local function SyncTraceButton()
94
+ local running = ns.FunctionTrace.IsRunning()
95
+ ui.SetButtonText(traceButton, running and L.STOP_TRACE or L.START_TRACE)
96
+ ui.SetButtonVariant(traceButton, running and "danger" or "primary")
97
+ end
98
+ Format = function(record)
99
+ if not record then return L.SELECT_CALL_DETAIL end
100
+ local lines = { string.format(L.TRACE_PATH, record.path), string.format(L.ELAPSED_DETAIL, record.elapsed), "" }
101
+ if #record.arguments == 0 then lines[#lines + 1] = L.NO_ARGUMENTS end
102
+ for index = 1, #record.arguments do lines[#lines + 1] = "[" .. index .. "] = " .. record.arguments[index] end
103
+ return table.concat(lines, "\n")
104
+ end
105
+ local function CreateRow(index)
106
+ local row = ui.CreateListRow(content, ROW_HEIGHT)
107
+ row:SetWidth(LIST_WIDTH - 26)
108
+ local elapsed = row:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
109
+ elapsed:SetPoint("LEFT", 8, 0) elapsed:SetWidth(62) elapsed:SetJustifyH("LEFT") elapsed:SetTextColor(1, 1, 1, 0.38) row.elapsed = elapsed
110
+ local name = row:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
111
+ name:SetPoint("TOPLEFT", 72, -5) name:SetPoint("TOPRIGHT", -8, -5) name:SetJustifyH("LEFT") name:SetWordWrap(false) row.name = name
112
+ local summary = row:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
113
+ summary:SetPoint("BOTTOMLEFT", 72, 5) summary:SetPoint("BOTTOMRIGHT", -8, 5) summary:SetJustifyH("LEFT") summary:SetWordWrap(false) summary:SetTextColor(1, 1, 1, 0.38) row.summary = summary
114
+ row:SetScript("OnEnter", function(self) self.isHovered = true ui.SetListRowState(self, self.record == selected, true) end)
115
+ row:SetScript("OnLeave", function(self) self.isHovered = nil ui.SetListRowState(self, self.record == selected, false) end)
116
+ row:SetScript("OnClick", function(self) selected = self.record SetReadOnlyText(detail, Format(selected)) page:Refresh() end)
117
+ rows[index] = row return row
118
+ end
119
+ function page:Refresh()
120
+ for index = 1, #rows do rows[index]:Hide() end
121
+ local recordCount = ns.FunctionTrace.GetCount()
122
+ ui.SetButtonEnabled(clear, recordCount > 0)
123
+ ui.SetButtonEnabled(exportDetail, recordCount > 0)
124
+ local offset = scroll:GetVerticalScroll() if issecretvalue and issecretvalue(offset) then offset = 0 end
125
+ local first = math.floor((offset or 0) / ROW_HEIGHT) + 1
126
+ local last, pool = math.min(recordCount, first + VISIBLE_ROWS - 1), 0
127
+ for recordIndex = first, last do
128
+ pool = pool + 1
129
+ local record = ns.FunctionTrace.GetRecord(recordIndex)
130
+ local row = rows[pool] or CreateRow(pool)
131
+ row.record = record row:ClearAllPoints() row:SetPoint("TOPLEFT", 0, -((recordIndex - 1) * ROW_HEIGHT))
132
+ row.elapsed:SetText(string.format("+%.2fs", record.elapsed)) row.name:SetText(record.path) row.summary:SetText(record.summary ~= "" and record.summary or L.NO_ARGUMENTS)
133
+ ui.SetListRowState(row, record == selected, row.isHovered) row:Show()
134
+ end
135
+ content:SetHeight(math.max(1, recordCount * ROW_HEIGHT)) scroll:UpdateScrollChildRect() empty:SetShown(recordCount == 0)
136
+ end
137
+ scroll.onVerticalScrollChanged = function() page:Refresh() end
138
+ local function QueueRefresh()
139
+ if refreshQueued then return end
140
+ refreshQueued = true
141
+ C_Timer.After(0, function() refreshQueued = false if page:IsShown() then page:Refresh() end end)
142
+ end
143
+ traceButton:SetScript("OnClick", function()
144
+ if ns.FunctionTrace.IsRunning() then
145
+ ns.FunctionTrace.Stop()
146
+ SetStatus(L.STOPPED, 0.55, 0.60, 0.65)
147
+ SyncTraceButton()
148
+ return
149
+ end
150
+
151
+ local succeeded, errorMessage = ns.FunctionTrace.Start(input.editBox:GetText(), QueueRefresh)
152
+ SetStatus(succeeded and string.format(L.TRACING_FUNCTION, ns.FunctionTrace.GetActivePath()) or errorMessage, succeeded and 0.42 or ui.accentR, succeeded and 0.76 or ui.accentG, succeeded and 0.43 or ui.accentB)
153
+ SyncTraceButton()
154
+ end)
155
+ clear:SetScript("OnClick", function() ns.FunctionTrace.Clear() selected = nil SetReadOnlyText(detail, L.SELECT_CALL_DETAIL) page:Refresh() end)
156
+ input.editBox:SetScript("OnEnterPressed", function() traceButton:Click() end)
157
+ function page:Activate() input.editBox:SetFocus() page:Refresh() end
158
+ function page:Stop()
159
+ ns.FunctionTrace.Stop()
160
+ SetStatus(L.STOPPED, 0.55, 0.60, 0.65)
161
+ SyncTraceButton()
162
+ end
163
+ SetStatus(L.STOPPED, 0.55, 0.60, 0.65) SyncTraceButton() page:Refresh()
164
+ return page
165
+ end
@@ -0,0 +1,94 @@
1
+ ---
2
+ name: lychee-dev
3
+ description: Use when working with the Lychee Dev WoW addon to read persisted runtime evidence by Ticket or prepare bounded /run memory/CPU investigations, object inspection, and event monitoring. Do not use for generic WoW API research or unrelated addon implementation.
4
+ ---
5
+
6
+ # Lychee Dev skill
7
+
8
+ Use this skill as the operational guide for Lychee Dev, an in-game evidence workbench. The desired output is either (a) an evidence-backed diagnosis from SavedVariables or (b) a command/workflow the user can paste into WoW and report back.
9
+
10
+ ## Choose the workflow
11
+
12
+ - **Persisted evidence:** locate the WoW `WTF` SavedVariables file, find the exact Ticket, and read the complete payload.
13
+ - **Run:** open `/dev`, use the Run page, and paste `/run` or `/script` Lua.
14
+ - **Automated task delivery:** when the user authorized scripted task delivery and reload, use the Python tooling in `scripts/` to upsert a task block, run it, decode the completion notice, reload once, and read the Ticket. Read [references/automation.md](references/automation.md) first; live-window steps still need per-host verification.
15
+ - **Memory/CPU investigation:** use Run with a question-specific script; read [references/runtime-investigations.md](references/runtime-investigations.md) before designing a probe.
16
+ - **Objects:** open `/dev` > Objects and inspect a global/object path or use the mouse picker.
17
+ - **Events:** open `/dev` > Events, search the current client's catalog, select events, start monitoring, reproduce the behavior, then stop and save.
18
+
19
+ The Performance page, automatic capture, health scan and function benchmark have been removed. Run, Objects, Events, Trace, Errors and Saved Records remain available. Do not route a new investigation to the removed UI. There are no separate `/object` or `/event` slash commands. Do not invent them; give the `/dev` UI steps instead.
20
+
21
+ ## Read SavedVariables
22
+
23
+ 1. Search the user's WoW installation for the global SavedVariables file, normally `WTF/Account/<account>/SavedVariables/Lychee Dev.lua`. The exact account/realm path is installation-specific. Use a filename search or `rg` for `LycheeDevDB`/the Ticket rather than assuming a path.
24
+ 2. Treat the file as data, not trusted code. Do not `dofile` or execute an unknown SavedVariables file in the host environment. Use a restricted Lua parser/sandbox or inspect the relevant assignment safely.
25
+ 3. For a Ticket `LYCHEE-...`, read:
26
+
27
+ ```text
28
+ LycheeDevDB.exports.records[TICKET]
29
+ LycheeDevDB.exports.records[TICKET].payload.content
30
+ ```
31
+
32
+ Validate `schema == "lychee.evidence.v1"`, and use `source.kind`, `source.title`, `source.path`, `environment`, and `createdAt` to identify the record. Validate the report schema inside the payload separately; record-level schema/source do not belong to `metadata`. Prefer the exact Ticket already supplied to the owning task, including directly delivered messages; do not ask the user to resend it to several tasks. The payload is the authoritative complete report; `metadata` is bounded context, not a replacement for it.
33
+ Current kinds include `run_result`, `object_snapshot`, `object_node`, `event_log`, `function_trace`, `error_log`, and `automation_result` (whose payload is one `lychee.automation.result.v1` JSON report and whose `metadata.contentChecksum` is an Adler-32 over the exact payload bytes). Legacy `performance_*` records remain valid historical evidence; read their complete payload without requiring the deleted module or discarding them.
34
+ 4. `LycheeDevDB.exports.order` is newest-first. Recent ad-hoc runs are in `LycheeDevDB.history` and may contain `code`, `result`, and a bounded `tree`; they are not the same as a saved export. Old installations may contain `DumperDB`, which the addon migrates into `LycheeDevDB`.
35
+ 5. A record created in-game is only in memory until `/reload`, logout, or exit. If the user has not completed one of those writes, explain that the Ticket cannot yet be found on disk. Exports and history are bounded and older entries can be pruned.
36
+
37
+ When reporting persisted evidence, quote the Ticket, source kind, client environment, and the exact payload path. Do not claim that a record is absent until the likely SavedVariables locations and the exact Ticket have been searched.
38
+
39
+ ## Run commands
40
+
41
+ The runner accepts either `/run` or `/script` prefixes and evaluates Lua 5.1 code. Prefer returning a compact structured report; use `print` for short scalar messages. Check the installed runner and serializer limits before delivery. A returned value is captured immediately, so an asynchronous script needs a verified completion/export writer; do not return an unfinished table and assume later mutations will be saved.
42
+
43
+ ```text
44
+ /run print(GetBuildInfo())
45
+ /run return { addon = MyAddon, profile = MyAddonDB and MyAddonDB.profile }
46
+ /script return UIParent and { name = UIParent:GetName(), shown = UIParent:IsShown() }
47
+ ```
48
+
49
+ Give commands that are explicit and bounded. Avoid unbounded table walks, per-frame polling, network calls, protected UI mutations, and writes to SavedVariables unless the user explicitly requests them. Lychee Dev truncates large run output, and combat blocks the workbench and active inspection/monitoring tools.
50
+
51
+ One complete investigation does not mean pasting a bundle of implementation source. Use Run for a small probe; for large source-dependent studies, use a verified independent diagnostic carrier and a short entry command, with its installation/loading and cleanup explained. Never assume WoW can read arbitrary host files or hot-load Lua. When the user asks for one paste, cover the automatic matrix from one practical entry point and one final report; list external actions and missing coverage honestly. For a requested check, include the exact pasteable command, what result to expect, and what field or error the user should report back. If a value may be secret in combat, tell the user to leave combat before running it and do not suggest comparing or formatting that value.
52
+
53
+ ## Object inspection
54
+
55
+ Use the Objects page for live object state. Valid paths are `_G`, dot-separated identifiers, numeric indexes, and quoted string indexes, for example:
56
+
57
+ ```text
58
+ _G.MyAddon
59
+ MyAddon.db.profile
60
+ _G["MyAddon"]["db"]
61
+ UIParent
62
+ ```
63
+
64
+ The page can search globals or fields, expand tables, show frame overview/children/regions, and save an object snapshot or node. The mouse picker temporarily hides the window; press `F` or `Enter` to capture the object under the cursor, `Esc` to cancel. If a path is not known, use a short run command to return the candidate global, then inspect that path in Objects.
65
+
66
+ Never promise a complete object graph: inspection is bounded, cyclic tables are marked, and secret combat values stop the read. Protected Blizzard frames must not be mutated as part of a diagnostic command.
67
+
68
+ ## Event monitoring
69
+
70
+ Use the Events page, not a guessed slash command:
71
+
72
+ 1. Search for the uppercase event name in the catalog shown for the running client (for example `PLAYER_TARGET_CHANGED`).
73
+ 2. Select one or more events and click **Start Monitoring**.
74
+ 3. Reproduce the behavior, click **Stop Monitoring**, inspect payload arguments, and use **Save** if the evidence must be handed to an Agent.
75
+
76
+ Event names and payload signatures are build-specific. The supported profiles are Retail `12.1.0`/Interface `120100`, Classic Mists `5.5.4`/`50504`, and Classic Titan `3.80.2`/`38002`; do not transfer a signature between profiles without checking the catalog. `ALL`/“monitor all events” is an explicit diagnostic mode, not a default recommendation. Monitoring is bounded (newest 500 records; at most 16 arguments per record, each shortened), and it stops on combat entry.
77
+
78
+ ## Delivery and ownership
79
+
80
+ Use available computer controls only within the authorized workflow. Inspect their actual capabilities before attempting game input; a browser-only tool cannot type into WoW. After a failed input attempt, verify focus/state once and use one manual paste when reliable native input is unavailable. Do not loop speculative key presses.
81
+
82
+ If the user authorized clipboard delivery, announce the exact script/version, write it, and read back the clipboard to verify equality. Keep that version stable while awaiting execution. A revision needs an explicit replacement notice and a new verification; another task's clipboard, game session, or pending probe is not yours to replace.
83
+
84
+ Do not deploy addon changes or run destructive Provider/storage experiments merely to diagnose a problem. Preserve the current task's decision scope: a request for a proposal remains a proposal; an authorized implementation can proceed. A past project's memory target or plan-only decision is not a universal skill restriction.
85
+
86
+ ## Handoff format
87
+
88
+ For a command request, answer with:
89
+
90
+ 1. **Paste:** the exact `/run` or `/script` text, or the `/dev` page and fields to use.
91
+ 2. **Reproduce:** the short action sequence and when to start/stop monitoring.
92
+ 3. **Report back:** the expected output fields or the Ticket to copy after saving and reloading.
93
+
94
+ For a Ticket request, return the record's `source.kind`, client/build, creation time, payload path, and a concise evidence-based finding. Keep observations separate from hypotheses, and state when the evidence is truncated, pending disk write, client-specific, or blocked by combat/secret values.
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "Lychee Dev skill"
3
+ short_description: "Read WoW evidence and prepare bounded Run investigations"
4
+ default_prompt: "Use $lychee-dev to investigate a specific WoW issue through Lychee Dev Run, one bounded script, and complete Ticket evidence."
@@ -0,0 +1,327 @@
1
+ # Automation: task delivery, reload and receipt
2
+
3
+ This reference covers the automated loop between an Agent, the Python tooling
4
+ in `scripts/`, and the in-game Automation page (`/dev` > Automation). The full
5
+ design lives in the addon repository at
6
+ `add-on/docs/design/AutomationOpticalTransport.md`; this page is the practical
7
+ contract and describes the CLI exactly as implemented.
8
+
9
+ ## The loop in one paragraph
10
+
11
+ You (the Agent) prepare a bounded Lua probe and deliver it as one task block in
12
+ the installed `Modules/Automation/auto/auto.lua`. The block only registers
13
+ data; it never runs at load. After an input-side `/reload`, the command
14
+ `/dev auto run <task-id>` executes the block. While it runs, three RGB status
15
+ blocks show at the top-left of the screen. When the result is committed to the
16
+ in-memory SavedVariables database, they are replaced by one static QR code at
17
+ the top-right that carries only the identity:
18
+ `{"v":1,"ticket":"...","task":"...","run":"...","ts":...}`. `capture`, `run`
19
+ and `bugs` keep one WGC capture session open and poll it until that notice is
20
+ decoded or `--timeout` expires. The tooling then cross-checks the notice `task`
21
+ and `run` against the request it actually delivered, logs a `reload_requested`
22
+ intent, sends one `/reload` so the game writes the database to disk, then reads
23
+ the exact Ticket out of the SavedVariables file, verifies its identity,
24
+ payload and checksum, and stores the complete report as local artifacts.
25
+ `/dev auto bug <n>` skips the task file and the input-side reload; it snapshots
26
+ recent error records and follows the same notice -> reload -> read path.
27
+
28
+ ## Hard rules
29
+
30
+ - One execution per client at a time: while a request is running the addon
31
+ answers new requests with a busy message. Finished results that you have not
32
+ acknowledged may queue up to three; only the cap refuses new work, and a
33
+ reload resets the count.
34
+ - Always acknowledge what you read. The addon cannot see whether a result was
35
+ picked up, so run `ack --status received` (or `failed`) after reading one.
36
+ Without it the result keeps occupying a backlog slot until a reload.
37
+ - The same `requestId` never executes twice in one session; re-running the
38
+ command re-shows the same notice instead.
39
+ - Results awaiting their reload are protected: normal export pruning, record
40
+ deletion and cache clears skip them. `/dev auto stop` only hides the notice
41
+ UI; it never cancels a run and never deletes pending results.
42
+ - One notice triggers at most one reload. The host log deduplicates on
43
+ `(installation, requestId, ticket)`; after a script restart, check the log
44
+ and the SavedVariables file before repeating anything.
45
+ - A decoded notice is accepted only when its `task` (and `run`, when known)
46
+ matches the command that was just delivered. A stale QR left on screen from
47
+ an earlier run is logged as `notice_identity_mismatch` and ignored.
48
+ - Host wait timeouts mean "unknown", not "failed": never auto-rerun a task
49
+ because its notice was missed. Inspect first (see Recovery).
50
+
51
+ ## Task blocks
52
+
53
+ Write task blocks only through the CLI so locking, escaping and limits stay
54
+ correct:
55
+
56
+ ```text
57
+ python scripts/automation.py task upsert --install-dir <addon dir> \
58
+ --id inspect-example --source-file probe.lua \
59
+ --request-id req-20260912-000001-aaaaaa --revision rev-1
60
+ python scripts/automation.py task list --install-dir <addon dir>
61
+ python scripts/automation.py task remove --install-dir <addon dir> --id inspect-example
62
+ ```
63
+
64
+ - Task IDs are `[A-Za-z0-9_-]{1,64}`. Each Agent owns its own task IDs;
65
+ never remove or rewrite another task's block.
66
+ - A new execution needs a new `requestId`. Updating the source always means a
67
+ new `requestId` and a new `revision`.
68
+ - The writer verifies `--expect-revision` on replacement, holds an exclusive
69
+ lock file (`auto.lua.lock` in the installation directory), preserves
70
+ everything outside the `BEGIN`/`END LYCHEE DEV TASK` markers verbatim, and
71
+ replaces the file atomically. It refuses more than 16 blocks, more than
72
+ 1 MiB of registry, or a source over 256 KiB.
73
+ - The source file is read as raw bytes and must be valid UTF-8, but it does not
74
+ have to be ASCII: the generated Lua shell stays ASCII and escapes every
75
+ non-ASCII byte as `\ddd`. `sourceBytes` and the block's `sourceChecksum` are
76
+ computed on those exact source bytes, so a CRLF source file keeps its CRLF.
77
+ - `task upsert` prints one JSON object:
78
+ `{"taskId":...,"requestId":...,"revision":...,"sourceBytes":N,"fileHash":"<sha256 of the written file>"}`.
79
+ `fileHash` is recorded after the atomic write, so it identifies the file
80
+ revision another writer may have replaced.
81
+ - `task list` prints `taskId<TAB>requestId<TAB>revision<TAB>sourceBytesB`;
82
+ `task remove` prints `removed <id>` or `<id> not present`.
83
+ - Task sources must be Lua 5.1 with clear boundaries: register cleanup
84
+ handlers with `ctx.OnCleanup(fn)`, stop your own timers/frames/events there.
85
+ - Release packaging always ships an empty registry; keep local probes out of
86
+ commits.
87
+
88
+ ## The execution context
89
+
90
+ The task runs with full access to WoW globals inside a captured environment:
91
+
92
+ - `print(...)` — captured into the report stdout (bounded by the block's
93
+ `outputLimit`, default 384 KiB).
94
+ - `Finish(value, ...)` — complete the task successfully with return values.
95
+ - `Fail(message[, code])` — complete as failed.
96
+ - `SetAsync()` — declare the task asynchronous; the chunk returning then does
97
+ NOT complete it. Sync tasks end when they return; async tasks must call
98
+ `Finish`/`Fail` from their own callbacks. Late callbacks are ignored.
99
+ - `IsCancelled()` — cooperative cancel flag; `/dev auto cancel <task-id>`
100
+ finalizes the run as `cancelled` and runs your cleanup handlers.
101
+ - `OnCleanup(fn)` — register cleanup; handlers run on any finalization.
102
+ - `Log(message)` — bounded lifecycle log line (128 entries / 16 KiB in the
103
+ report).
104
+
105
+ The architecture cannot force-stop an infinite loop and cannot roll back side
106
+ effects. Generate bounded, cancellable probes only.
107
+
108
+ ## In-game commands
109
+
110
+ | Command | Behavior |
111
+ | --- | --- |
112
+ | `/dev` | Opens the workbench (unchanged). |
113
+ | `/dev auto run <task-id>` | Validates the loaded block and executes its current request. |
114
+ | `/dev auto bug <1-100> [request-id]` | Snapshots up to 100 saved error records (all sessions, provider storage order, newest last-first). |
115
+ | `/dev auto status <task-id>` | Prints the latest execution state; re-shows the notice when the result still exists. |
116
+ | `/dev auto show <ticket>` | Re-shows the notice for a kept historical result. |
117
+ | `/dev auto cancel <task-id>` | Cooperative cancel; saves a cancelled report and its Ticket. |
118
+ | `/dev auto ack <ticket> received\|failed` | Records that the host read this ticket (or failed to). Clears the pending-flush block so the next run can start **without a reload**. |
119
+ | `/dev auto stop` | Hides the notice UI only; the pending record and the busy state stay. |
120
+
121
+ ### Reporting the read outcome back
122
+
123
+ The plugin cannot observe whether the host actually read a result, so nothing on
124
+ the game side changes when a ticket is picked up. While a result is pending its
125
+ disk write, the controller answers every new request with the busy message, and
126
+ that block only ends with a reload — unless you tell it what happened:
127
+
128
+ ```text
129
+ python scripts/automation.py --installation retail-main ack \
130
+ --hwnd 0x1234 --ticket LYCHEE-... --status received
131
+ ```
132
+
133
+ That sends `/dev auto ack <ticket> received` through the normal command channel.
134
+ Use `--status failed` when the read failed; the reason stays in your host log.
135
+ The index record keeps `receivedAt` and `receivedStatus`, and the Automation page
136
+ shows "Read by the host" / "Host read failed" instead of a permanent
137
+ "Awaiting reload". Acknowledging an unknown ticket or an invalid status changes
138
+ nothing and reports why.
139
+
140
+ The built-in error task is reported with task ID `bug` and inner report
141
+ `requestType` `bug`; its `params` are `{"count": n, "scope": ...}`.
142
+
143
+ ## Host CLI
144
+
145
+ Global options, valid for every subcommand:
146
+
147
+ - `--data-dir <dir>` — host data directory holding the log, artifacts and
148
+ profiles; default `%LOCALAPPDATA%\LycheeDev\automation`.
149
+ - `--installation <name>` — installation scope for the log and the reload
150
+ dedup key; default `default`. Pass the same name to every command of one
151
+ orchestration session, and use `--all-installations` when inspecting more
152
+ than one.
153
+
154
+ ### task
155
+
156
+ `task upsert|remove|list` with `--install-dir <dir>` or `--profile <name>`.
157
+ Upsert also takes `--id`, `--source-file`, `--request-id`, `--revision`,
158
+ `--expect-revision`, `--created-at`, `--expires-at`, `--expected-interface`
159
+ and `--output-limit`. Generated IDs are `req-<UTC stamp>-<hex>`.
160
+
161
+ ### profile
162
+
163
+ ```text
164
+ python scripts/automation.py profile set --name retail-main --client retail \
165
+ --wow-root <WoW root> --addon-dir <addon dir> \
166
+ --sv-path "<WoW>/WTF/Account/<account>/SavedVariables/Lychee Dev.lua"
167
+ python scripts/automation.py profile show --name retail-main
168
+ ```
169
+
170
+ `profile set` requires `--client`, `--wow-root` and `--addon-dir`; both
171
+ directories must exist. The stored profile also records the client folder
172
+ (`retail` -> `_retail_`, `classic` -> `_classic_`, `titan` -> `_classic_arena`).
173
+ Profiles are written atomically to `<data-dir>/profiles.json`.
174
+
175
+ ### sv find / sv read
176
+
177
+ ```text
178
+ python scripts/automation.py --installation retail-main sv find --profile retail-main
179
+ python scripts/automation.py --installation retail-main sv read --profile retail-main \
180
+ --ticket LYCHEE-... --task inspect-example --request-id req-... --revision rev-1
181
+ ```
182
+
183
+ - `sv find` requires `--profile`, resolves the client folder under `--wow-root`
184
+ (a profile may point at the WoW root or at the client folder itself) and
185
+ prints each account-level `SavedVariables/Lychee Dev.lua` candidate. It exits
186
+ 1 when there is no candidate.
187
+ - `sv read` requires `--ticket` plus either `--sv <path>` or `--profile`. It
188
+ refuses any file that is not named `Lychee Dev.lua` and refuses `.bak`.
189
+ - Optional identity checks: `--task`, `--request-id`, `--revision`,
190
+ `--created-at`, `--request-type task|bug`.
191
+ - `--retries` (default 3) and `--retry-delay` (default 0.5 s) bound the reads
192
+ of a torn, replaced or temporarily unreadable file; the failure message
193
+ reports how many attempts were made.
194
+ - The reader uses a restricted parser (no Lua evaluation), exactly locates
195
+ `LycheeDevDB.exports.records[TICKET]`, verifies the envelope (`schema`,
196
+ `ticket`, `createdAt`), the payload (`mediaType` `application/json`,
197
+ `encoding` `utf-8`, real UTF-8 byte count against `byteCount`, 1 MiB report
198
+ limit), the metadata identity (`taskId`, `executionId`, `revision`,
199
+ `resultSchema`, terminal `status`, `complete`, `checksumAlgorithm adler32`)
200
+ and recomputes the Adler-32 `contentChecksum`. It then parses the inner
201
+ `lychee.automation.result.v1` JSON report and verifies its version, terminal
202
+ status, `complete`/`incompleteReasons`, client/character `environment`,
203
+ `requestType` and, for bug reports, `params`.
204
+ - Success prints
205
+ `{"ticket":...,"status":...,"complete":...,"byteCount":N,"sha256":"...","attempts":N,"artifacts":{...}}`.
206
+ - Artifacts (`evidence.json`, `report.json`, `content.json`) land under
207
+ `<data-dir>/received/<ticket>/` and are written byte-for-byte: the recorded
208
+ `byteCount` and SHA-256 describe the exact bytes on disk, with no newline
209
+ translation of `payload.content`. The host log records `received` with the
210
+ attempt count and whether the file changed during the read.
211
+
212
+ ### capture / send
213
+
214
+ ```text
215
+ python scripts/automation.py capture --hwnd 0x1234 [--pid <pid>] [--exe-path <exe>] \
216
+ [--timeout 120] [--interval 0.1]
217
+ python scripts/automation.py send --hwnd 0x1234 --text "/reload" \
218
+ [--pid <pid>] [--exe-path <exe>] [--request-id req-... --ticket LYCHEE-...]
219
+ ```
220
+
221
+ - `capture` opens one `windows-capture` session for the window, decodes the
222
+ QR with `zxingcpp.read_barcodes` (QR only) and prints the notice JSON. It
223
+ compares the top-right ROI on every `--interval` (default 0.1 s) until
224
+ `--timeout` (default 120 s) expires, then exits 5. Only the newest ROI is
225
+ kept, so frames never pile up.
226
+ - `send` always logs `command_sent` before input. When the text is `/reload`
227
+ and both `--request-id` and `--ticket` are given it also applies the reload
228
+ dedup key, so the same notice can never trigger a second reload.
229
+ - Both confirm the window identity (HWND, and `--pid`/`--exe-path` when given)
230
+ immediately before use and re-check the foreground before typing.
231
+
232
+ ### run / bugs
233
+
234
+ ```text
235
+ python scripts/automation.py --installation retail-main run \
236
+ --task inspect-example --sv "<...>/Lychee Dev.lua" --hwnd 0x1234 \
237
+ --install-dir <addon dir> [--request-id req-...] [--revision rev-1] \
238
+ [--timeout 120] [--interval 0.1]
239
+ python scripts/automation.py --installation retail-main bugs \
240
+ --count 20 --sv "<...>/Lychee Dev.lua" --hwnd 0x1234 [--timeout 120] [--interval 0.1]
241
+ ```
242
+
243
+ - `run` does not send the input-side `/reload` itself: after `task upsert` the
244
+ new block is only in the file, so reload the client first (or run a task that
245
+ is already loaded), then call `run`.
246
+ - `run` delivers `/dev auto run <task-id>`, then polls for a notice whose
247
+ `task` equals `--task` and whose `run` equals the loaded block's `requestId`
248
+ (read from `Modules/Automation/auto/auto.lua` when `--install-dir` or
249
+ `--profile` is given). A missing task block is an explicit failure.
250
+ - `bugs` validates that `--count` is 1-100 without silently fixing it,
251
+ delivers `/dev auto bug <count>` and requires a notice with task `bug`.
252
+ - On a matching notice both flows log the `reload_requested` intent, snapshot
253
+ the SV file, send one `/reload`, wait for the file to change within
254
+ `--timeout`, then run the same verification as `sv read`.
255
+ - Because a task can run far longer than one capture interval, the capture
256
+ session stays open for the whole wait; it stops when the notice is decoded,
257
+ the window closes, or the timeout expires.
258
+
259
+ ### status / recover
260
+
261
+ ```text
262
+ python scripts/automation.py --installation retail-main status --limit 50 [--event received]
263
+ python scripts/automation.py --installation retail-main recover
264
+ ```
265
+
266
+ Both read the host log scoped to `--installation` (use `--all-installations`
267
+ to read every scope). `status` prints the most recent records (`--limit`,
268
+ default 20; 0 prints all). `recover` prints recent records and lists tickets
269
+ whose reload was requested but never received. For those, read the
270
+ SavedVariables file first: if the Ticket is already on disk, run `sv read`
271
+ directly; if not, exactly one explicit reload retry is allowed — never a loop.
272
+ If the game crashed before writing, the report is lost; record that
273
+ uncertainty in your findings.
274
+
275
+ ## Exit codes
276
+
277
+ | Code | Meaning |
278
+ | --- | --- |
279
+ | 0 | Success. |
280
+ | 1 | Invalid usage, missing binding/profile, unsafe path refused, non-UTF-8 source, or an unexpected failure (with traceback). |
281
+ | 2 | Task registry failure (schema, kind, marker, revision conflict, lock/limit refusal). |
282
+ | 3 | SavedVariables read or verification failure after all attempts. |
283
+ | 4 | Window identity, command input, or missing optional capture dependency (`windows-capture`/`numpy`/`zxing-cpp`) failure. |
284
+ | 5 | No notice decoded before the timeout, or the game did not rewrite its SavedVariables file in time. |
285
+
286
+ Expected failures print one `error: ...` line on stderr; they never dump a
287
+ traceback for a missing dependency, a missing argument or a bad source file.
288
+
289
+ ## Optional dependencies
290
+
291
+ ```text
292
+ python -m pip install --target <dir> -r scripts/requirements.txt
293
+ ```
294
+
295
+ `scripts/requirements.txt` pins the verified versions: `zxing-cpp==3.1.1`,
296
+ `windows-capture==2.0.1`, `numpy==2.5.3`, `opencv-python==5.0.0.93`. The code
297
+ uses only the interfaces those versions actually expose: `read_barcodes`
298
+ (zxing-cpp 3.x, `read_bars` does not exist), `WindowsCapture(window_hwnd=...)`
299
+ with `on_frame_arrived`/`on_closed` handlers, `start_free_threaded()` /
300
+ `CaptureControl.stop()` and `Frame.convert_to_bgr()`.
301
+
302
+ ## Recovery
303
+
304
+ ```text
305
+ python scripts/automation.py --installation retail-main recover
306
+ python scripts/automation.py --installation retail-main status --event run_unresolved
307
+ ```
308
+
309
+ `recover` prints recent host log events and lists tickets whose reload was
310
+ requested but never received. For those, read the SavedVariables file first:
311
+ if the Ticket is already on disk, run `sv read` directly; if not, exactly one
312
+ explicit reload retry is allowed — never a loop. `run_unresolved`,
313
+ `sv_write_timeout` and `notice_identity_mismatch` records tell you which step
314
+ stopped and why. If the game crashed before writing, the report is lost;
315
+ record that uncertainty in your findings.
316
+
317
+ ## Known verification gaps
318
+
319
+ Live-window steps (WGC capture, SendInput delivery, real SavedVariables
320
+ writes, DPI/scaling) are implemented against the verified installed package
321
+ interfaces but have not been exercised in a running game. Before relying on
322
+ them: run `capture`/`send` against a real client, measure the notice QR size
323
+ and DPI scaling per client, confirm command input reliability, and record real
324
+ reload timing. The offline-verified parts are the task registry writer, the
325
+ restricted SavedVariables reader and verifier, the session log/dedup/artifacts,
326
+ the notice validation and identity checks, the polling shape and the CLI exit
327
+ behaviour; they are covered by `scripts/selftest_offline.py`.