lycheedev 1.0.0 → 1.0.2

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 (50) hide show
  1. package/bin/lycheedev.js +58 -8
  2. package/package.json +1 -1
  3. package/vendor/addon/Core/Bootstrap.lua +131 -131
  4. package/vendor/addon/Core/Clients/Mainline.lua +9 -9
  5. package/vendor/addon/Core/Clients/Mists.lua +9 -9
  6. package/vendor/addon/Core/Clients/Titan.lua +9 -9
  7. package/vendor/addon/Core/Compatibility.lua +43 -43
  8. package/vendor/addon/Core/Database.lua +859 -859
  9. package/vendor/addon/Core/Inspector.lua +647 -647
  10. package/vendor/addon/Core/Locale.lua +307 -307
  11. package/vendor/addon/Core/Locale_enUS.lua +318 -318
  12. package/vendor/addon/Core/Safety.lua +42 -42
  13. package/vendor/addon/Core/Serializer.lua +324 -324
  14. package/vendor/addon/Libs/AutomationQR.lua +1176 -1176
  15. package/vendor/addon/Lychee Dev_Mainline.toc +43 -43
  16. package/vendor/addon/Lychee Dev_Mists.toc +43 -43
  17. package/vendor/addon/Lychee Dev_Wrath.toc +43 -43
  18. package/vendor/addon/Modules/Automation/Controller.lua +757 -757
  19. package/vendor/addon/Modules/Automation/Report.lua +409 -409
  20. package/vendor/addon/Modules/Automation/auto/auto.lua +12 -12
  21. package/vendor/addon/Modules/Diagnostics.lua +238 -238
  22. package/vendor/addon/Modules/Events/Catalog.lua +184 -184
  23. package/vendor/addon/Modules/Events/CatalogData_Mainline.lua +1788 -1788
  24. package/vendor/addon/Modules/Events/CatalogData_Mists.lua +1489 -1489
  25. package/vendor/addon/Modules/Events/CatalogData_Titan.lua +1492 -1492
  26. package/vendor/addon/Modules/Events/Monitor.lua +181 -181
  27. package/vendor/addon/Modules/FunctionTrace.lua +85 -85
  28. package/vendor/addon/Modules/ObjectInspector.lua +329 -329
  29. package/vendor/addon/UI/AutomationOverlay.lua +183 -183
  30. package/vendor/addon/UI/Export.lua +140 -140
  31. package/vendor/addon/UI/Features.lua +890 -890
  32. package/vendor/addon/UI/MainWindow.lua +1145 -1145
  33. package/vendor/addon/UI/Pages/About.lua +223 -223
  34. package/vendor/addon/UI/Pages/Automation.lua +417 -417
  35. package/vendor/addon/UI/Pages/Diagnostics.lua +289 -289
  36. package/vendor/addon/UI/Pages/ExportRecords.lua +387 -387
  37. package/vendor/addon/UI/Pages/Object.lua +573 -573
  38. package/vendor/addon/UI/Pages/Trace.lua +165 -165
  39. package/vendor/skill/SKILL.md +94 -94
  40. package/vendor/skill/agents/openai.yaml +4 -4
  41. package/vendor/skill/references/automation.md +327 -327
  42. package/vendor/skill/references/runtime-investigations.md +97 -97
  43. package/vendor/skill/scripts/automation/__init__.py +1 -1
  44. package/vendor/skill/scripts/automation/registry.py +516 -516
  45. package/vendor/skill/scripts/automation/saved_variables.py +438 -438
  46. package/vendor/skill/scripts/automation/session.py +207 -207
  47. package/vendor/skill/scripts/automation/windows.py +573 -573
  48. package/vendor/skill/scripts/automation.py +865 -865
  49. package/vendor/skill/scripts/requirements.txt +13 -13
  50. package/vendor/skill/scripts/selftest_offline.py +981 -981
@@ -1,327 +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`.
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`.