xstudio-linux 0.0.0-stage → 0.2.3

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 (222) hide show
  1. package/CHANGELOG.md +443 -0
  2. package/LICENSE +31 -0
  3. package/README.md +527 -2
  4. package/dist/adapter-cli/cli.d.ts +28 -0
  5. package/dist/adapter-cli/cli.js +235 -0
  6. package/dist/adapter-cli/cli.js.map +1 -0
  7. package/dist/adapter-mcp/server.d.ts +81 -0
  8. package/dist/adapter-mcp/server.js +477 -0
  9. package/dist/adapter-mcp/server.js.map +1 -0
  10. package/dist/config.d.ts +45 -0
  11. package/dist/config.js +78 -0
  12. package/dist/config.js.map +1 -0
  13. package/dist/core/catalog/pronunciation.d.ts +47 -0
  14. package/dist/core/catalog/pronunciation.js +402 -0
  15. package/dist/core/catalog/pronunciation.js.map +1 -0
  16. package/dist/core/catalog/singers.d.ts +46 -0
  17. package/dist/core/catalog/singers.js +122 -0
  18. package/dist/core/catalog/singers.js.map +1 -0
  19. package/dist/core/contracts.d.ts +348 -0
  20. package/dist/core/contracts.js +17 -0
  21. package/dist/core/contracts.js.map +1 -0
  22. package/dist/core/degrade/chain.d.ts +80 -0
  23. package/dist/core/degrade/chain.js +137 -0
  24. package/dist/core/degrade/chain.js.map +1 -0
  25. package/dist/core/diagnose/error-resolver.d.ts +51 -0
  26. package/dist/core/diagnose/error-resolver.js +202 -0
  27. package/dist/core/diagnose/error-resolver.js.map +1 -0
  28. package/dist/core/guard/skill-gate.d.ts +89 -0
  29. package/dist/core/guard/skill-gate.js +121 -0
  30. package/dist/core/guard/skill-gate.js.map +1 -0
  31. package/dist/core/midi/convert.d.ts +31 -0
  32. package/dist/core/midi/convert.js +125 -0
  33. package/dist/core/midi/convert.js.map +1 -0
  34. package/dist/core/midi/smf.d.ts +37 -0
  35. package/dist/core/midi/smf.js +422 -0
  36. package/dist/core/midi/smf.js.map +1 -0
  37. package/dist/core/render/artifacts.d.ts +37 -0
  38. package/dist/core/render/artifacts.js +417 -0
  39. package/dist/core/render/artifacts.js.map +1 -0
  40. package/dist/core/render/orchestrator.d.ts +110 -0
  41. package/dist/core/render/orchestrator.js +974 -0
  42. package/dist/core/render/orchestrator.js.map +1 -0
  43. package/dist/core/svip/codec.d.ts +30 -0
  44. package/dist/core/svip/codec.js +664 -0
  45. package/dist/core/svip/codec.js.map +1 -0
  46. package/dist/core/svip/document.d.ts +31 -0
  47. package/dist/core/svip/document.js +158 -0
  48. package/dist/core/svip/document.js.map +1 -0
  49. package/dist/core/svip/editor.d.ts +71 -0
  50. package/dist/core/svip/editor.js +245 -0
  51. package/dist/core/svip/editor.js.map +1 -0
  52. package/dist/core/svip/model.d.ts +74 -0
  53. package/dist/core/svip/model.js +158 -0
  54. package/dist/core/svip/model.js.map +1 -0
  55. package/dist/core/svip/tick.d.ts +21 -0
  56. package/dist/core/svip/tick.js +59 -0
  57. package/dist/core/svip/tick.js.map +1 -0
  58. package/dist/core/svip/validator.d.ts +39 -0
  59. package/dist/core/svip/validator.js +267 -0
  60. package/dist/core/svip/validator.js.map +1 -0
  61. package/dist/host/linux.d.ts +15 -0
  62. package/dist/host/linux.js +42 -0
  63. package/dist/host/linux.js.map +1 -0
  64. package/dist/host/sidecar.d.ts +61 -0
  65. package/dist/host/sidecar.js +365 -0
  66. package/dist/host/sidecar.js.map +1 -0
  67. package/dist/host/wine-launch.d.ts +60 -0
  68. package/dist/host/wine-launch.js +77 -0
  69. package/dist/host/wine-launch.js.map +1 -0
  70. package/dist/host/wine-paths.d.ts +30 -0
  71. package/dist/host/wine-paths.js +103 -0
  72. package/dist/host/wine-paths.js.map +1 -0
  73. package/dist/index.d.ts +20 -0
  74. package/dist/index.js +17 -0
  75. package/dist/index.js.map +1 -0
  76. package/dist/services.d.ts +55 -0
  77. package/dist/services.js +78 -0
  78. package/dist/services.js.map +1 -0
  79. package/dist/shared/errors.d.ts +61 -0
  80. package/dist/shared/errors.js +125 -0
  81. package/dist/shared/errors.js.map +1 -0
  82. package/dist/shared/paths.d.ts +8 -0
  83. package/dist/shared/paths.js +30 -0
  84. package/dist/shared/paths.js.map +1 -0
  85. package/dist/shared/schema.d.ts +26 -0
  86. package/dist/shared/schema.js +68 -0
  87. package/dist/shared/schema.js.map +1 -0
  88. package/dist/shared/types.d.ts +43 -0
  89. package/dist/shared/types.js +19 -0
  90. package/dist/shared/types.js.map +1 -0
  91. package/dist/tests/unit/artifacts.test.d.ts +1 -0
  92. package/dist/tests/unit/artifacts.test.js +243 -0
  93. package/dist/tests/unit/artifacts.test.js.map +1 -0
  94. package/dist/tests/unit/data-plane.test.d.ts +1 -0
  95. package/dist/tests/unit/data-plane.test.js +153 -0
  96. package/dist/tests/unit/data-plane.test.js.map +1 -0
  97. package/dist/tests/unit/degrade.test.d.ts +1 -0
  98. package/dist/tests/unit/degrade.test.js +133 -0
  99. package/dist/tests/unit/degrade.test.js.map +1 -0
  100. package/dist/tests/unit/diagnosis.test.d.ts +1 -0
  101. package/dist/tests/unit/diagnosis.test.js +66 -0
  102. package/dist/tests/unit/diagnosis.test.js.map +1 -0
  103. package/dist/tests/unit/errors.test.d.ts +1 -0
  104. package/dist/tests/unit/errors.test.js +83 -0
  105. package/dist/tests/unit/errors.test.js.map +1 -0
  106. package/dist/tests/unit/mcp-server.test.d.ts +1 -0
  107. package/dist/tests/unit/mcp-server.test.js +267 -0
  108. package/dist/tests/unit/mcp-server.test.js.map +1 -0
  109. package/dist/tests/unit/mcp-smoke.d.ts +6 -0
  110. package/dist/tests/unit/mcp-smoke.js +7 -0
  111. package/dist/tests/unit/mcp-smoke.js.map +1 -0
  112. package/dist/tests/unit/mcp-smoke.test.d.ts +1 -0
  113. package/dist/tests/unit/mcp-smoke.test.js +196 -0
  114. package/dist/tests/unit/mcp-smoke.test.js.map +1 -0
  115. package/dist/tests/unit/midi.test.d.ts +1 -0
  116. package/dist/tests/unit/midi.test.js +255 -0
  117. package/dist/tests/unit/midi.test.js.map +1 -0
  118. package/dist/tests/unit/pronunciation.test.d.ts +1 -0
  119. package/dist/tests/unit/pronunciation.test.js +83 -0
  120. package/dist/tests/unit/pronunciation.test.js.map +1 -0
  121. package/dist/tests/unit/registry-contract.test.d.ts +1 -0
  122. package/dist/tests/unit/registry-contract.test.js +114 -0
  123. package/dist/tests/unit/registry-contract.test.js.map +1 -0
  124. package/dist/tests/unit/render-orchestrator.test.d.ts +1 -0
  125. package/dist/tests/unit/render-orchestrator.test.js +548 -0
  126. package/dist/tests/unit/render-orchestrator.test.js.map +1 -0
  127. package/dist/tests/unit/sidecar.test.d.ts +1 -0
  128. package/dist/tests/unit/sidecar.test.js +299 -0
  129. package/dist/tests/unit/sidecar.test.js.map +1 -0
  130. package/dist/tests/unit/singers.test.d.ts +1 -0
  131. package/dist/tests/unit/singers.test.js +73 -0
  132. package/dist/tests/unit/singers.test.js.map +1 -0
  133. package/dist/tests/unit/skill-gate.test.d.ts +1 -0
  134. package/dist/tests/unit/skill-gate.test.js +182 -0
  135. package/dist/tests/unit/skill-gate.test.js.map +1 -0
  136. package/dist/tests/unit/svip-codec.test.d.ts +1 -0
  137. package/dist/tests/unit/svip-codec.test.js +182 -0
  138. package/dist/tests/unit/svip-codec.test.js.map +1 -0
  139. package/dist/tests/unit/svip-document.test.d.ts +1 -0
  140. package/dist/tests/unit/svip-document.test.js +137 -0
  141. package/dist/tests/unit/svip-document.test.js.map +1 -0
  142. package/dist/tests/unit/svip-editor.test.d.ts +1 -0
  143. package/dist/tests/unit/svip-editor.test.js +275 -0
  144. package/dist/tests/unit/svip-editor.test.js.map +1 -0
  145. package/dist/tests/unit/svip-tick.test.d.ts +1 -0
  146. package/dist/tests/unit/svip-tick.test.js +66 -0
  147. package/dist/tests/unit/svip-tick.test.js.map +1 -0
  148. package/dist/tools/common.d.ts +80 -0
  149. package/dist/tools/common.js +167 -0
  150. package/dist/tools/common.js.map +1 -0
  151. package/dist/tools/control.d.ts +21 -0
  152. package/dist/tools/control.js +376 -0
  153. package/dist/tools/control.js.map +1 -0
  154. package/dist/tools/data.d.ts +37 -0
  155. package/dist/tools/data.js +680 -0
  156. package/dist/tools/data.js.map +1 -0
  157. package/dist/tools/definition.d.ts +60 -0
  158. package/dist/tools/definition.js +44 -0
  159. package/dist/tools/definition.js.map +1 -0
  160. package/dist/tools/degrade.d.ts +3 -0
  161. package/dist/tools/degrade.js +30 -0
  162. package/dist/tools/degrade.js.map +1 -0
  163. package/dist/tools/guide.d.ts +10 -0
  164. package/dist/tools/guide.js +66 -0
  165. package/dist/tools/guide.js.map +1 -0
  166. package/dist/tools/open.d.ts +3 -0
  167. package/dist/tools/open.js +74 -0
  168. package/dist/tools/open.js.map +1 -0
  169. package/dist/tools/probe.d.ts +8 -0
  170. package/dist/tools/probe.js +132 -0
  171. package/dist/tools/probe.js.map +1 -0
  172. package/dist/tools/registry.d.ts +10 -0
  173. package/dist/tools/registry.js +16 -0
  174. package/dist/tools/registry.js.map +1 -0
  175. package/dist/version.d.ts +4 -0
  176. package/dist/version.js +19 -0
  177. package/dist/version.js.map +1 -0
  178. package/docs/DESIGN.md +553 -0
  179. package/docs/RECON-GUI.md +271 -0
  180. package/docs/RECON.md +339 -0
  181. package/docs/SPEC.md +786 -0
  182. package/docs/WINE.md +192 -0
  183. package/examples/.scratch/01-midi-to-wudi/wudi-demo.svip3 +0 -0
  184. package/examples/.scratch/01-midi-to-wudi/wudi-melody.mid +0 -0
  185. package/examples/.scratch/01-midi-to-wudi/wudi-roundtrip.mid +0 -0
  186. package/examples/.scratch/02-three-singers/melody.chenziyu.svip3 +0 -0
  187. package/examples/.scratch/02-three-singers/melody.hechang.svip3 +0 -0
  188. package/examples/.scratch/02-three-singers/melody.svip3 +0 -0
  189. package/examples/.scratch/02-three-singers/melody.wudi.svip3 +0 -0
  190. package/examples/.scratch/03-velocity-diction/phrase.svip3 +0 -0
  191. package/examples/.scratch/03-velocity-diction/phrase.svip3.bak.20261206-163755-200 +0 -0
  192. package/examples/.scratch/03-velocity-diction/phrase.svip3.bak.20261206-163755-203 +0 -0
  193. package/examples/.scratch/03-velocity-diction/phrase.svip3.bak.20261206-163755-204 +0 -0
  194. package/examples/.scratch/04-unknown-dialog-abort/dialog-demo.svip3 +0 -0
  195. package/examples/01-midi-to-wudi.mjs +144 -0
  196. package/examples/02-three-singers-compare.mjs +140 -0
  197. package/examples/03-velocity-diction-rerender.mjs +160 -0
  198. package/examples/04-unknown-dialog-abort.mjs +126 -0
  199. package/examples/README.md +101 -0
  200. package/examples/lib/harness.mjs +274 -0
  201. package/fixtures/midi/melody-480.mid +0 -0
  202. package/fixtures/midi/melody-96.mid +0 -0
  203. package/fixtures/svip/1.svip3 +0 -0
  204. package/fixtures/svip/3.svip3 +0 -0
  205. package/fixtures/uia/README.md +37 -0
  206. package/fixtures/uia/export-dialog.snapshot.json +446 -0
  207. package/fixtures/uia/main-window.snapshot.json +2997 -0
  208. package/fixtures/uia/open-dialog.snapshot.json +103 -0
  209. package/icon.svg +10 -0
  210. package/package.json +84 -4
  211. package/proto/xstudio.proto +128 -0
  212. package/scripts/check-contract.mjs +184 -0
  213. package/scripts/entry-smoke.mjs +26 -0
  214. package/scripts/inspect-svip.mjs +161 -0
  215. package/scripts/setup-venv.sh +93 -0
  216. package/scripts/wine-gui-probe.py +302 -0
  217. package/sidecar/xstudio_uia.py +1478 -0
  218. package/skills/xstudio-gui/SKILL.md +194 -0
  219. package/skills/xstudio-gui/assertions.md +103 -0
  220. package/skills/xstudio-gui/dialogs.md +90 -0
  221. package/skills/xstudio-gui/gestures.md +158 -0
  222. package/skills/xstudio-gui/ui-map.json +242 -0
package/docs/WINE.md ADDED
@@ -0,0 +1,192 @@
1
+ # Wine edition — architecture and calibration notes
2
+
3
+ Status: working notes for `xstudio-linux` 0.2.0. This file records how the
4
+ Linux/Wine port works, what was verified, and how to calibrate a new machine.
5
+ The Windows-era verification of the `.svip3` file format itself lives in
6
+ [RECON.md](RECON.md) and remains valid — the format does not depend on the OS.
7
+
8
+ ## 1. What changed from the Windows build (0.1.x → 0.2.0)
9
+
10
+ | Component | Windows (0.1.x, `main` branch) | Linux/Wine (0.2.0) |
11
+ |---|---|---|
12
+ | Host layer | DSH Host plugin (`adapter-dsh/`, Cordis lifecycle) | Standalone: programmatic API (`src/index.ts`), CLI (`src/adapter-cli/`), MCP stdio server (kept) |
13
+ | Config | Schemastery schema + Loader row | Hand-rolled validator (`src/config.ts`), `--config` JSON + `XSTUDIO_*` env vars |
14
+ | GUI sidecar | `sidecar/uia.ps1` — PowerShell 7 + .NET UIAutomation | `sidecar/xstudio_uia.py` — Python 3, AT-SPI2 (pyatspi or gi) + X11 (Xlib/xdotool), same JSON-lines protocol |
15
+ | Process discovery | `tasklist /FI IMAGENAME eq …` | `pgrep -f "NetEase Cloud Music XStudio"` |
16
+ | Paths | Native Windows paths | Linux paths on the host; converted to drive-letter form for anything typed into a Wine dialog |
17
+ | Knowledge plane | Tavily search (REST + OAuth-MCP), TTL cache, circuit breaker | Local-only: built-in singer catalog, local pronunciation rules, local dialog fingerprints; zero outbound network |
18
+ | Install dir | `D:\NetEase Cloud Music XStudio` default | Auto-detected candidates under the Wine prefix, `XSTUDIO_INSTALL_DIR` override |
19
+
20
+ Unchanged: the 24-tool surface, the result envelope (`via` / `product_line` /
21
+ `ok` / structured errors), the skill gate (`NEED_SKILL` before the first GUI
22
+ call), the destructive-action blacklist, snapshot-scoped refs, the `.svip3`
23
+ codec with unknown-field preservation, MIDI import/export, and the
24
+ orchestrator's budgets and dialog classification.
25
+
26
+ ## 2. Wine path translation
27
+
28
+ X Studio under Wine sees drive-letter paths; the plugin runs on the Linux host.
29
+
30
+ - `<prefix>/dosdevices/*` symlinks define the mapping (typically `c:` →
31
+ `<prefix>/drive_c`, `z:` → `/`). `readDriveMap()` resolves them once; a
32
+ dangling symlink is skipped.
33
+ - `linuxToWine()` picks the most specific non-`Z:` drive whose target prefixes
34
+ the Linux path; everything else falls back to `Z:\…` (Wine's own host-root
35
+ convention).
36
+ - `wineToLinux()` converts dialog-reported paths back before comparison.
37
+ - Explicit `wine.driveMappings` (e.g. `{"D:": "/mnt/d"}`) override the scan.
38
+
39
+ Conversion points in the orchestrator: project-open `set_text`, export
40
+ directory picker `set_text`, and the two `file_path_label` comparisons.
41
+
42
+ ## 3. The GUI sidecar protocol (unchanged contract)
43
+
44
+ Newline-delimited JSON on stdin/stdout, one request/response pair per line,
45
+ responses correlated by id, diagnostics on stderr only. Methods: `probe`,
46
+ `snapshot`, `act`, `assert`, `readDialog`, `respondDialog`, `abort`, `close`.
47
+ Stable sidecar error codes: `XSTUDIO_NOT_RUNNING`, `GUI_REF_NOT_FOUND`,
48
+ `GUI_FOCUS_LOST`, `GUI_ACTION_FAILED`.
49
+
50
+ Safety rules preserved from the Windows sidecar:
51
+
52
+ - refs are snapshot-scoped (`<token>:eN`); a stale ref is rejected, never
53
+ re-resolved against a moved tree;
54
+ - screen coordinates are never consumed;
55
+ - destructive element/dialog names (保存 / save / 覆盖 / overwrite / 删除 /
56
+ delete / 退出 / quit …) are refused;
57
+ - `--require-foreground` refuses mutating actions unless the X Studio window
58
+ is active (`_NET_ACTIVE_WINDOW` / xdotool).
59
+
60
+ ## 4. Accessibility under Wine — exhaustively attempted (2026-12-06)
61
+
62
+ **Verdict: no Wine→AT-SPI bridge exists in this stack; the element tree is
63
+ unreachable by any reasonable configuration. Every path in this section was
64
+ physically attempted on the reference machine, not inferred.**
65
+
66
+ The consequences for the tool surface: `xstudio_ui_snapshot` works at the
67
+ window level only (`tree_available: false`), element-addressed actions fail
68
+ explicitly with `GUI_REF_NOT_FOUND`, export automation stays on the guide
69
+ path, and render-progress observation is limited to window-level polling.
70
+ Data plane, project opening (`xstudio_open`), render triggering (uinput
71
+ Space), and window management are unaffected.
72
+
73
+ ### Attempted paths and their outcomes
74
+
75
+ 1. **AT-SPI bus reachability.** The bus is alive and reachable
76
+ (`org.a11y.Bus.GetAddress` → `unix:path=/run/user/1000/at-spi/bus_0`;
77
+ `at-spi2-registryd` and `at-spi-bus-launcher` running). The Wine process
78
+ has **no connection to it** (no bus fd among its 15 sockets). A bridge on
79
+ the Wine side would be required to create one.
80
+
81
+ 2. **Wine's built-in UIAutomation → AT-SPI bridge.** `wine-staging 11.23`
82
+ ships `uiautomationcore.dll`, but `strings` over its unix-side `.so` finds
83
+ **zero** `dbus`/`atspi` references — this Wine build has no AT-SPI backend
84
+ (upstream work exists on other branches; not in Arch's wine-staging 11.23).
85
+ Windows Qt6 apps use `QWindowsUiaAccessibility`, so the chain would be
86
+ Qt → UIA → Wine UIA server → (missing bridge) → AT-SPI. The first three
87
+ exist; the last does not.
88
+
89
+ 3. **`wine explorer /desktop=…` managed desktop.** Launched live with a file
90
+ argument. The app nests inside a single 1920×1080 managed window; this
91
+ required teaching the sidecar one-level nested window search (kept — it
92
+ also helps other container layouts). Outcome: the AT-SPI application list
93
+ is unchanged (no Wine app), and keyboard synthesis is *still* compositor-
94
+ routed (see §6), with the added complication that Wine's internal focus is
95
+ now a second routing hop. Not a path to the tree; normal (non-desktop)
96
+ launch remains the recommended mode.
97
+
98
+ 4. **Environment variables** (`NO_AT_BRIDGE`, `AT_SPI_BUS`, GNOME
99
+ accessibility vars) on the Wine process: irrelevant — Wine is a pure
100
+ Win32 process and consumes none of the GTK/AT-SPI client stack.
101
+
102
+ 5. **In-Wine UIA consumer** (a Windows-side automation client speaking to
103
+ Wine's UIA server): technically coherent but requires a Windows Python or
104
+ .NET runtime inside the prefix and a custom RPC bridge back to Linux —
105
+ far outside this project's zero-injection scope.
106
+
107
+ ### What would make the tree reachable
108
+
109
+ - A future Wine release implementing a UIA→AT-SPI bridge (upstream wishlist;
110
+ not in wine-staging 11.23), or
111
+ - Running X Studio under a native Linux Qt build (does not exist — X Studio
112
+ ships Windows/macOS only), or
113
+ - A vendor accessibility mode in X Studio itself (none known).
114
+
115
+ Re-run `scripts/wine-gui-probe.py` after any Wine upgrade; if a future build
116
+ exposes the app on the bus, `xstudio_ui_snapshot` will immediately report
117
+ `tree_available: true` and the element-addressed tools (dialogs, export
118
+ automation, machine-observable `preview_wait`) activate with no further
119
+ changes — the sidecar's AT-SPI backend was built and is already wired.
120
+
121
+ ## 5. Environment matrix
122
+
123
+ | Dependency | Required for | Check |
124
+ |---|---|---|
125
+ | Node.js ≥ 20 | everything | `node --version` |
126
+ | protobufjs (bundled via pnpm) | `.svip3` codec | — |
127
+ | Python 3 ≥ 3.8 | GUI sidecar | `python3 --version` |
128
+ | `python3-xlib` | X11 window queries (primary) | `python3 -c "import Xlib"` |
129
+ | `python3-gobject` + `at-spi2-core` | AT-SPI2 element tree | `python3 -c "import gi; gi.require_version('Atspi','2.0')"` |
130
+ | `xdotool` | window queries fallback, `send_keys`, foreground check fallback | `which xdotool` |
131
+ | ImageMagick (`import`) | optional snapshots | `which import` |
132
+ | `wine` | running X Studio | `wine --version` |
133
+
134
+ Every backend degrades independently: the sidecar reports
135
+ `backend: "atspi" | "x11-only"` in `probe`, and CI runs the protocol smoke
136
+ without any X server to prove the degradation is explicit.
137
+
138
+ ## 6. Keyboard routing — the Wayland focus insight (2026-12-06)
139
+
140
+ The deepest finding of the live rounds: **keyboard synthesis is routed by the
141
+ Wayland compositor, not the X server.**
142
+
143
+ - XTEST and `/dev/uinput` both inject events that plain X11 clients receive
144
+ (verified with a probe window), yet Wine received **none** of them while the
145
+ X-level `_NET_ACTIVE_WINDOW` pointed at X Studio.
146
+ - The missing layer was the **KWin Wayland focus**: only after activating the
147
+ window at the compositor level (a temporary KWin script setting
148
+ `workspace.activeWindow`) did a `/dev/uinput` Space reach Wine — measured
149
+ by Wine CPU activity and the app's own `XsToast` popping up, and confirmed
150
+ end-to-end by two TLS connections from the Wine process to NetEase cloud
151
+ hosts right after a Space-triggered render.
152
+
153
+ Consequences implemented in `sidecar/xstudio_uia.py`:
154
+
155
+ 1. `activate_window` is now two-level: a KWin scripting activation (compositor
156
+ focus) followed by the EWMH deiconify/raise (X-level state).
157
+ 2. `send_keys` prefers the `/dev/uinput` channel (kernel-level; reaches Wine
158
+ through Wayland→libinput→XWayland) and falls back to XTEST.
159
+ 3. `send_keys` requires the app to own the foreground *at the PID level*
160
+ (toasts/dialogs of the same Wine process count).
161
+
162
+ Calibration follow-ups from the same round (both fixed in the sidecar):
163
+
164
+ - **uinput device lifetime**: destroying the virtual device immediately after
165
+ emitting keys made KWin/libinput miss them entirely (journal:
166
+ `Failed to open /dev/input/eventN device`). The device now lives ~1.7 s and
167
+ is destroyed from a detached timer.
168
+ - **KWin script name collisions**: `loadScript` returns −1 when a script with
169
+ the same name is already registered; the activation script name now carries
170
+ a UUID suffix.
171
+ - **`xstudio_open` semantics**: the single-instance file-argument forward
172
+ reaches an instance that has passed its welcome screen; against a freshly
173
+ started (welcome-page) instance the forward is silently ignored. The tool's
174
+ 30 s title poll covers the normal case; against a just-started app, call
175
+ `xstudio_open` again once the welcome screen is up.
176
+
177
+ ## 7. Known limitations specific to Wine
178
+
179
+ - The export dialog's format combo-popup could not be driven even on native
180
+ Windows (defect #2 there); under Wine it is additionally subject to the
181
+ accessibility limitations above. Manual export via `xstudio_guide_print` is
182
+ the reliable path today.
183
+ - `source_path` inside edited projects keeps the path form the writer used.
184
+ The data plane normalizes it to forward slashes on write (after backup);
185
+ values Wine wrote as `Z:\…` are preserved verbatim when untouched.
186
+ - Cloud rendering is a vendor-side service; reachability from inside Wine is
187
+ the app's own concern. `CLOUD_UNREACHABLE` in a tool envelope means the
188
+ *app* reported a network problem, not that this plugin touched the network.
189
+ - `preview_wait` cannot observe render progress without the accessibility
190
+ tree; its window-level fallback polls the title and toast windows and
191
+ returns `completed: false` with honest evidence (machine-observable
192
+ progress is unavailable — confirm audibly or manually).
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Example 1 — MIDI + lyrics → a .svip3 sung by 伍笛, then the two-phase
4
+ * render hand-off.
5
+ *
6
+ * Data plane (real tools, no GUI, no network):
7
+ * 1. write a small Standard MIDI File with the plugin's own SMF writer;
8
+ * 2. xstudio_project_create: MIDI + one lyric per note + singer 伍笛;
9
+ * 3. xstudio_project_read to inspect the result;
10
+ * 4. xstudio_midi_export and compare note counts (round-trip sanity).
11
+ *
12
+ * Control plane (simulated in-memory sidecar/renderer — this example NEVER
13
+ * touches the real X Studio window):
14
+ * 5. xstudio_preview_trigger + xstudio_preview_wait (two-phase render);
15
+ * 6. xstudio_guide_print as the manual fallback for a human.
16
+ *
17
+ * Run: node examples/01-midi-to-wudi.mjs
18
+ */
19
+ import { writeFile, readFile } from 'node:fs/promises'
20
+ import { join } from 'node:path'
21
+ import {
22
+ check,
23
+ createDataToolbox,
24
+ createFakeControlToolbox,
25
+ distModule,
26
+ freshDir,
27
+ info,
28
+ rel,
29
+ reportEnvelope,
30
+ requireDist,
31
+ runExample,
32
+ section,
33
+ } from './lib/harness.mjs'
34
+
35
+ await runExample('01 — MIDI + lyrics → 伍笛 singing project', async () => {
36
+ requireDist()
37
+ const { writeSmf, parseSmf } = await distModule('core/midi/smf.js')
38
+ const workdir = await freshDir('01-midi-to-wudi')
39
+
40
+ section('1. Write a Standard MIDI File (4/4, 96 BPM, C major)')
41
+ const melody = {
42
+ ppq: 480,
43
+ tempoBpm: 96,
44
+ notes: [
45
+ { startTick: 0, lengthTick: 480, pitch: 60, velocity: 100 },
46
+ { startTick: 480, lengthTick: 480, pitch: 62, velocity: 96 },
47
+ { startTick: 960, lengthTick: 480, pitch: 64, velocity: 96 },
48
+ { startTick: 1440, lengthTick: 720, pitch: 65, velocity: 104 },
49
+ { startTick: 2160, lengthTick: 480, pitch: 64, velocity: 96 },
50
+ { startTick: 2640, lengthTick: 480, pitch: 62, velocity: 92 },
51
+ { startTick: 3120, lengthTick: 480, pitch: 60, velocity: 100 },
52
+ { startTick: 3600, lengthTick: 960, pitch: 60, velocity: 88 },
53
+ ],
54
+ }
55
+ const midiPath = join(workdir, 'wudi-melody.mid')
56
+ await writeFile(midiPath, writeSmf(melody))
57
+ info(`wrote ${rel(midiPath)} (${(await readFile(midiPath)).length} bytes, ${melody.notes.length} notes)`)
58
+
59
+ const toolbox = await createDataToolbox({ workdir })
60
+ try {
61
+ section('2. xstudio_probe — decide which path is usable')
62
+ const probe = reportEnvelope('xstudio_probe', await toolbox.call('xstudio_probe'))
63
+ check(probe.ok && probe.via === 'pb', 'xstudio_probe must succeed via pb')
64
+ info(`install detected: ${probe.data.xstudio.installed} · app running: ${probe.data.xstudio.running}`)
65
+ info(`sidecar: ${probe.data.gui.sidecar} · wine prefix: ${probe.data.xstudio.winePrefix}`)
66
+ info(`degradation chain: ${probe.data.paths.preferredChain.join(' → ')}`)
67
+ check(toolbox.names.length === 25, `expected 25 tools, got ${toolbox.names.length}`)
68
+
69
+ section('3. xstudio_project_create — MIDI + lyrics + singer 伍笛')
70
+ const projectPath = join(workdir, 'wudi-demo.svip3')
71
+ const created = reportEnvelope(
72
+ 'xstudio_project_create',
73
+ await toolbox.call('xstudio_project_create', {
74
+ out_path: projectPath,
75
+ singer_id: 'beta-netease:wudi',
76
+ midi_path: midiPath,
77
+ lyrics: ['你', '好', '世', '界', '这', '是', '旋', '律'],
78
+ bpm: 96,
79
+ track_label: 'example-01',
80
+ }),
81
+ )
82
+ check(created.ok && created.via === 'pb', 'project_create must succeed via pb')
83
+ info(`project: ${rel(projectPath)} · notes: ${created.data.note_count}`)
84
+
85
+ section('4. xstudio_project_read — inspect the written project')
86
+ const read = reportEnvelope(
87
+ 'xstudio_project_read',
88
+ await toolbox.call('xstudio_project_read', { path: projectPath, include: 'all' }),
89
+ )
90
+ check(read.ok, 'project_read must succeed')
91
+ const summary = read.data.summary
92
+ info(`singer: ${summary.track.singer_name} · tempo: ${summary.tempo_bpm} BPM · time sig: ${summary.time_signature.numerator}/${summary.time_signature.denominator}`)
93
+ info(`notes: ${read.data.note_count} · preserved unknown fields: ${read.data.unknown_field_count}`)
94
+ for (const note of read.data.notes.slice(0, 4)) {
95
+ info(`note p${note.position_tick} len${note.length_tick} pitch${note.midi_pitch} 「${note.lyric_text}」/${note.phoneme_roman || '(none)'}`)
96
+ }
97
+ check(read.data.notes[0].lyric_text === '你', 'first lyric should be 你')
98
+ check(read.data.summary.track.singer_name === '伍笛', 'singer name should be 伍笛')
99
+
100
+ section('5. xstudio_midi_export — round-trip sanity back to MIDI')
101
+ const exportedPath = join(workdir, 'wudi-roundtrip.mid')
102
+ const exported = reportEnvelope(
103
+ 'xstudio_midi_export',
104
+ await toolbox.call('xstudio_midi_export', { project_path: projectPath, out_path: exportedPath }),
105
+ )
106
+ check(exported.ok, 'midi_export must succeed')
107
+ const roundTrip = parseSmf(new Uint8Array(await readFile(exportedPath)))
108
+ info(`exported ${rel(exportedPath)} (${exported.data.bytes} bytes, ${exported.data.note_count} notes)`)
109
+ check(roundTrip.notes.length === melody.notes.length, 'MIDI round trip must keep every note')
110
+ check(roundTrip.tempoBpm === 96, `round-trip tempo must be 96, got ${roundTrip.tempoBpm}`)
111
+
112
+ section('6. Control plane — two-phase cloud render (SIMULATED GUI)')
113
+ const control = await createFakeControlToolbox({ workdir })
114
+ const trigger = reportEnvelope(
115
+ 'xstudio_preview_trigger (simulated)',
116
+ await control.call('xstudio_preview_trigger', { project_path: projectPath }),
117
+ )
118
+ check(trigger.ok && trigger.via === 'gui', 'preview_trigger must report via gui')
119
+ for (const step of trigger.data.steps) info(`step: ${step}`)
120
+ const wait = reportEnvelope(
121
+ 'xstudio_preview_wait (simulated)',
122
+ await control.call('xstudio_preview_wait', { timeout_ms: 60000 }),
123
+ )
124
+ check(wait.ok && wait.data.completed === true, 'preview_wait must complete')
125
+ info(`render evidence: ${wait.data.evidence.join(' / ')}`)
126
+
127
+ section('7. xstudio_guide_print — manual fallback for a human')
128
+ const guide = reportEnvelope(
129
+ 'xstudio_guide_print',
130
+ await toolbox.call('xstudio_guide_print', { topic: 'render', project_path: projectPath }),
131
+ )
132
+ check(guide.ok && guide.via === 'guide', 'guide_print must report via guide')
133
+ for (const line of guide.data.markdown.split('\n').filter((line) => line.startsWith('1.') || line.startsWith('4.') || line.startsWith('6.'))) {
134
+ info(line)
135
+ }
136
+
137
+ console.log('\nDone. Generated files:')
138
+ info(`${rel(projectPath)} — the project X Studio will render`)
139
+ info(`${rel(exportedPath)} — MIDI round-trip proof`)
140
+ info('Open the project in X Studio and press play to hear 伍笛 sing it; the plugin does not start the app by itself.')
141
+ } finally {
142
+ await toolbox.dispose()
143
+ }
144
+ })
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Example 2 — one melody, three singers (dry-run estimate then batch write),
4
+ * using the built-in local singer catalog.
5
+ *
6
+ * Tavily enrichment was removed in xstudio-linux, so the catalog is the
7
+ * built-in list; this example shows filters and the refresh compatibility
8
+ * warning instead of a network refresh.
9
+ *
10
+ * Steps:
11
+ * 1. create one base melody project (data-plane notes);
12
+ * 2. xstudio_singers_list → via "pb" from the built-in catalog;
13
+ * 3. refresh:true → same local data plus a compatibility warning;
14
+ * 4. xstudio_batch dry_run → estimated_cloud_requests (confirm before rendering);
15
+ * 5. xstudio_batch → one .svip3 per singer, verify each singer name;
16
+ * 6. simulate the three guarded render hand-offs (no real GUI is touched).
17
+ *
18
+ * Run: node examples/02-three-singers-compare.mjs
19
+ */
20
+ import { join } from 'node:path'
21
+ import { readdir } from 'node:fs/promises'
22
+ import {
23
+ check,
24
+ createDataToolbox,
25
+ createFakeControlToolbox,
26
+ freshDir,
27
+ info,
28
+ rel,
29
+ reportEnvelope,
30
+ requireDist,
31
+ runExample,
32
+ section,
33
+ } from './lib/harness.mjs'
34
+
35
+ const MELODY = [
36
+ { pos: 0, len: 480, pitch: 60, lyric: '一' },
37
+ { pos: 480, len: 480, pitch: 62, lyric: '二' },
38
+ { pos: 960, len: 480, pitch: 64, lyric: '三' },
39
+ { pos: 1440, len: 480, pitch: 65, lyric: '四' },
40
+ ]
41
+
42
+ await runExample('02 — same melody, three singers (batch + local catalog)', async () => {
43
+ requireDist()
44
+ const workdir = await freshDir('02-three-singers')
45
+
46
+ section('1. xstudio_project_create — one base melody with explicit notes')
47
+ const toolbox = await createDataToolbox({
48
+ workdir,
49
+ config: { defaultSinger: 'beta-netease:wudi' },
50
+ })
51
+ try {
52
+ const basePath = join(workdir, 'melody.svip3')
53
+ const created = reportEnvelope(
54
+ 'xstudio_project_create',
55
+ await toolbox.call('xstudio_project_create', {
56
+ out_path: basePath,
57
+ // Base variant uses a singer that is NOT one of the three batch targets,
58
+ // so every variant is an obvious content change (each job also reports
59
+ // `changed`, and a job equal to the source is still materialized).
60
+ singer_id: 'beta-netease:xiaobing',
61
+ bpm: 120,
62
+ notes: MELODY,
63
+ }),
64
+ )
65
+ check(created.ok && created.data.note_count === MELODY.length, 'base project creation failed')
66
+
67
+ section('2. xstudio_singers_list — the built-in catalog, via "pb"')
68
+ const listed = reportEnvelope(
69
+ 'xstudio_singers_list()',
70
+ await toolbox.call('xstudio_singers_list', {}),
71
+ )
72
+ check(listed.ok && listed.via === 'pb', 'the local catalog must report via pb')
73
+ const ids = listed.data.singers.map((singer) => singer.id)
74
+ info(`singers (${listed.data.count}): ${listed.data.singers.map((s) => `${s.name} <${s.id}>`).join(', ')}`)
75
+ check(ids.includes('beta-netease:wudi') && ids.includes('beta-netease:hechang'), 'the catalog must include the seeded singers')
76
+
77
+ section('3. refresh:true still works — local data plus a compatibility warning')
78
+ const refreshed = reportEnvelope(
79
+ 'xstudio_singers_list(refresh:true)',
80
+ await toolbox.call('xstudio_singers_list', { refresh: true }),
81
+ )
82
+ check(refreshed.ok && refreshed.via === 'pb', 'refresh stays local in xstudio-linux')
83
+ check((refreshed.data.warnings ?? []).some((warning) => warning.includes('Tavily')), 'refresh must warn that Tavily was removed')
84
+ info(`warnings: ${refreshed.data.warnings.join(' | ')}`)
85
+
86
+ section('4. xstudio_batch(dry_run:true) — estimate cloud render requests first')
87
+ const jobs = ['beta-netease:wudi', 'beta-netease:hechang', 'beta-netease:chenziyu'].map((singerId) => ({
88
+ project_path: basePath,
89
+ singer_id: singerId,
90
+ }))
91
+ const dry = reportEnvelope(
92
+ 'xstudio_batch(dry_run:true)',
93
+ await toolbox.call('xstudio_batch', { jobs, concurrency: 3, dry_run: true }),
94
+ )
95
+ check(dry.ok && dry.data.estimated_cloud_requests === 3, 'dry run must estimate 3 cloud requests')
96
+ info(`estimated_cloud_requests = ${dry.data.estimated_cloud_requests} (one cloud render per singer variant)`)
97
+ info('Nothing was written during the dry run; confirm with the user before triggering cloud renders.')
98
+
99
+ section('5. xstudio_batch — write one .svip3 per singer')
100
+ const batch = reportEnvelope(
101
+ 'xstudio_batch',
102
+ await toolbox.call('xstudio_batch', { jobs, concurrency: 3 }),
103
+ )
104
+ check(batch.ok, 'batch must succeed')
105
+ for (const job of batch.data.jobs) {
106
+ check(job.ok === true, `batch job failed: ${job.error ?? 'unknown'}`)
107
+ info(`${job.singer_id} → ${rel(job.out_path)} (changed=${job.changed})`)
108
+ }
109
+ const names = (await readdir(workdir)).filter((name) => name.endsWith('.svip3')).sort()
110
+ info(`.svip3 files in ${rel(workdir)}: ${names.join(', ')} (1 base + 3 variants)`)
111
+ const variants = ['melody.wudi.svip3', 'melody.hechang.svip3', 'melody.chenziyu.svip3']
112
+ for (const variant of variants) check(names.includes(variant), `missing batch variant ${variant}`)
113
+
114
+ section('6. Verify each variant carries the right singer (data-plane read)')
115
+ const expected = new Map([
116
+ ['beta-netease:wudi', '伍笛'],
117
+ ['beta-netease:hechang', '何畅'],
118
+ ['beta-netease:chenziyu', '陈子渝'],
119
+ ])
120
+ for (const job of batch.data.jobs) {
121
+ const read = await toolbox.call('xstudio_project_read', { path: job.out_path })
122
+ check(read.ok, `cannot read ${job.out_path}`)
123
+ check(read.data.summary.track.singer_name === expected.get(job.singer_id), `wrong singer in ${job.out_path}`)
124
+ info(`${rel(job.out_path)} → singer ${read.data.summary.track.singer_name}, ${read.data.note_count} notes`)
125
+ }
126
+
127
+ section('7. Guarded cloud renders (SIMULATED GUI) — one per variant')
128
+ const control = await createFakeControlToolbox({ workdir })
129
+ for (const job of batch.data.jobs) {
130
+ const trigger = reportEnvelope(`preview_trigger ${job.singer_id} (simulated)`, await control.call('xstudio_preview_trigger', { project_path: job.out_path }))
131
+ check(trigger.ok, 'trigger must succeed')
132
+ const wait = await control.call('xstudio_preview_wait', { timeout_ms: 120000 })
133
+ info(`${wait.data.completed ? 'completed' : 'timed out'} in ${wait.data.elapsed_ms} ms (${wait.data.evidence.length} evidence items)`)
134
+ check(wait.ok && wait.data.completed, 'render must complete')
135
+ }
136
+ info(`cloud requests that a real run would make: ${batch.data.estimated_cloud_requests}`)
137
+ } finally {
138
+ await toolbox.dispose()
139
+ }
140
+ })
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Example 3 — tune velocity and diction, then re-render and export.
4
+ *
5
+ * Data plane (real tools, no GUI, no network; Tavily disabled → local pinyin):
6
+ * 1. create a short sung phrase;
7
+ * 2. xstudio_velocity_set: global velocity offset 0.7 → 1.0;
8
+ * 3. xstudio_lyrics_align (auto): assign lyrics + phonemes (local rules);
9
+ * 4. xstudio_note_edit: fix one note's pitching/diction ("咬字");
10
+ * 5. xstudio_project_read to verify, and count the automatic backups.
11
+ *
12
+ * Control plane (SIMULATED GUI — the real X Studio window is never touched):
13
+ * 6. two-phase render + export through fake tool definitions;
14
+ * 7. a simulated cloud outage → CLOUD_UNREACHABLE envelope, then
15
+ * xstudio_guide_print so a human can finish manually.
16
+ *
17
+ * Run: node examples/03-velocity-diction-rerender.mjs
18
+ */
19
+ import { join } from 'node:path'
20
+ import { readdir } from 'node:fs/promises'
21
+ import {
22
+ check,
23
+ createDataToolbox,
24
+ createFakeControlToolbox,
25
+ fakeRender,
26
+ freshDir,
27
+ info,
28
+ rel,
29
+ reportEnvelope,
30
+ requireDist,
31
+ runExample,
32
+ section,
33
+ } from './lib/harness.mjs'
34
+
35
+ await runExample('03 — velocity + diction tweak → re-render → export', async () => {
36
+ requireDist()
37
+ const workdir = await freshDir('03-velocity-diction')
38
+
39
+ const toolbox = await createDataToolbox({ workdir })
40
+ try {
41
+ section('1. Create the phrase (one note per word, 120 BPM)')
42
+ const projectPath = join(workdir, 'phrase.svip3')
43
+ const created = reportEnvelope(
44
+ 'xstudio_project_create',
45
+ await toolbox.call('xstudio_project_create', {
46
+ out_path: projectPath,
47
+ singer_id: 'beta-netease:hechang',
48
+ bpm: 120,
49
+ notes: [
50
+ { pos: 0, len: 480, pitch: 60, lyric: '啦' },
51
+ { pos: 480, len: 480, pitch: 62, lyric: '啦' },
52
+ { pos: 960, len: 480, pitch: 64, lyric: '啦' },
53
+ { pos: 1440, len: 960, pitch: 60, lyric: '啦' },
54
+ ],
55
+ }),
56
+ )
57
+ check(created.ok && created.data.note_count === 4, 'phrase creation failed')
58
+ info(`created ${rel(projectPath)} — singer ${created.data.summary.track.singer_name}`)
59
+
60
+ section('2. xstudio_velocity_set — raise the global velocity offset 0.7 → 1.0')
61
+ const velocity = reportEnvelope(
62
+ 'xstudio_velocity_set',
63
+ await toolbox.call('xstudio_velocity_set', { project_path: projectPath, value: 1.0 }),
64
+ )
65
+ check(velocity.ok, 'velocity_set must succeed')
66
+ check(velocity.data.summary.track.velocity_offset === 1, 'velocity offset must be 1.0')
67
+ info(`write: changed=${velocity.data.write.changed} bytes=${velocity.data.write.bytes_written} backup=${rel(velocity.data.write.backup_path ?? '')}`)
68
+
69
+ section('3. xstudio_lyrics_align(auto) — lyrics + phonemes, local rules only')
70
+ const aligned = reportEnvelope(
71
+ 'xstudio_lyrics_align',
72
+ await toolbox.call('xstudio_lyrics_align', {
73
+ project_path: projectPath,
74
+ lyrics: ['你', '好', '世', '界'],
75
+ mode: 'auto',
76
+ }),
77
+ )
78
+ check(aligned.ok, 'lyrics_align must succeed')
79
+ info(`aligned ${aligned.data.aligned} notes via ${aligned.via}`)
80
+ for (const lookup of aligned.data.unresolved) {
81
+ info(`low-confidence: ${lookup.char} → ${lookup.pinyin} (${lookup.confidence})`)
82
+ }
83
+ check(aligned.data.aligned === 4, 'all four notes should be aligned')
84
+
85
+ section('4. xstudio_note_edit — diction/pitch fix on the second note')
86
+ const edited = reportEnvelope(
87
+ 'xstudio_note_edit',
88
+ await toolbox.call('xstudio_note_edit', {
89
+ project_path: projectPath,
90
+ note_ref: { index: 1 },
91
+ fields: { pitch: 63, lyric: '好', phoneme: 'hao' },
92
+ }),
93
+ )
94
+ check(edited.ok, 'note_edit must succeed')
95
+ info(`note[1] is now pitch ${edited.data.note.midi_pitch}, lyric 「${edited.data.note.lyric_text}」/${edited.data.note.phoneme_roman}`)
96
+ check(edited.data.note.midi_pitch === 63, 'pitch edit must be applied')
97
+ check(edited.data.note.phoneme_roman === 'hao', 'phoneme edit must be applied')
98
+
99
+ section('5. xstudio_project_read — verify, and count automatic backups')
100
+ const read = reportEnvelope(
101
+ 'xstudio_project_read(include:all)',
102
+ await toolbox.call('xstudio_project_read', { path: projectPath, include: 'all' }),
103
+ )
104
+ check(read.ok, 'project_read must succeed')
105
+ for (const note of read.data.notes) {
106
+ info(`p${note.position_tick} len${note.length_tick} pitch${note.midi_pitch} 「${note.lyric_text}」/${note.phoneme_roman}`)
107
+ }
108
+ const notes = read.data.notes
109
+ check(notes[1].lyric_text === '好' && notes[1].phoneme_roman === 'hao', 'diction edit must persist')
110
+ check(notes[3].lyric_text === '界', 'other notes must keep their absolute positions and values')
111
+ const backups = (await readdir(workdir)).filter((name) => name.includes('.bak.'))
112
+ info(`backups created by the write transactions: ${backups.length} → ${backups.sort().join(', ')}`)
113
+ check(backups.length >= 3, 'every mutation after create should have made a backup')
114
+
115
+ section('6. Re-render + export (SIMULATED GUI)')
116
+ const control = await createFakeControlToolbox({ workdir })
117
+ const trigger = reportEnvelope('preview_trigger (simulated)', await control.call('xstudio_preview_trigger', { project_path: projectPath }))
118
+ check(trigger.ok && trigger.via === 'gui', 'preview_trigger must report via gui')
119
+ const wait = reportEnvelope('preview_wait (simulated)', await control.call('xstudio_preview_wait', { timeout_ms: 120000 }))
120
+ check(wait.ok && wait.data.completed, 'render must complete')
121
+ const exported = reportEnvelope(
122
+ 'export_run (simulated)',
123
+ await control.call('xstudio_export_run', {
124
+ project_path: projectPath,
125
+ format: 'wav',
126
+ sample_rate: 48000,
127
+ out_dir: join(workdir, 'out'),
128
+ }),
129
+ )
130
+ check(exported.ok && exported.via === 'gui', 'export_run must report via gui')
131
+ info(`exported ${exported.data.format} → ${rel(exported.data.path)} (${exported.data.bytes} bytes)`)
132
+
133
+ section('7. Simulate a cloud outage → CLOUD_UNREACHABLE + manual fallback')
134
+ const offlineLog = []
135
+ const outage = new TypeError('fetch failed')
136
+ outage.cause = new Error('getaddrinfo ENOTFOUND cloud.xstudio')
137
+ const offlineControl = await createFakeControlToolbox({
138
+ workdir,
139
+ sidecar: undefined,
140
+ render: fakeRender(offlineLog, { triggerError: outage }),
141
+ })
142
+ const failed = await offlineControl.call('xstudio_preview_trigger', { project_path: projectPath })
143
+ reportEnvelope('preview_trigger (cloud down, simulated)', failed)
144
+ check(failed.ok === false, 'a cloud outage must produce a failed envelope, not a throw')
145
+ check(failed.error.code === 'CLOUD_UNREACHABLE', `expected CLOUD_UNREACHABLE, got ${failed.error.code}`)
146
+ info('the project file is untouched; data-plane edits still work')
147
+
148
+ const guide = reportEnvelope(
149
+ 'xstudio_guide_print',
150
+ await toolbox.call('xstudio_guide_print', { topic: 'export', project_path: projectPath }),
151
+ )
152
+ check(guide.ok && guide.via === 'guide', 'guide_print must report via guide')
153
+ for (const line of guide.data.markdown.split('\n').filter((line) => /^\d\./.test(line))) info(line)
154
+
155
+ console.log('\nDone. The rendered/exported artifacts are simulated; with X Studio')
156
+ console.log('running, the same tool calls drive the real export dialog.')
157
+ } finally {
158
+ await toolbox.dispose()
159
+ }
160
+ })