xstudio-linux 0.0.0-stage → 0.2.4

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 +469 -0
  2. package/LICENSE +31 -0
  3. package/README.md +542 -2
  4. package/dist/adapter-cli/cli.d.ts +28 -0
  5. package/dist/adapter-cli/cli.js +233 -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 +473 -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 +207 -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 +87 -0
  149. package/dist/tools/common.js +174 -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 +561 -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 +193 -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 +196 -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
@@ -0,0 +1,161 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Read-only .svip3 wire inspector.
4
+ *
5
+ * Decodes a project file with a generic protobuf wire scanner (no schema, no
6
+ * dependencies) and prints every field number, wire type, raw bytes and decoded
7
+ * value. Used to reproduce the evidence recorded in docs/RECON.md.
8
+ *
9
+ * Usage:
10
+ * node scripts/inspect-svip.mjs fixtures/svip/1.svip3
11
+ * node scripts/inspect-svip.mjs fixtures/svip/*.svip3 --json > evidence.json
12
+ *
13
+ * This script never writes to the project file.
14
+ */
15
+ import { readFileSync } from 'node:fs'
16
+ import { createHash } from 'node:crypto'
17
+
18
+ const WIRE_NAMES = { 0: 'varint', 1: 'fixed64', 2: 'length-delimited', 5: 'fixed32' }
19
+
20
+ /** Read one varint, returning its BigInt value and end offset. */
21
+ function readVarint(buffer, offset) {
22
+ let value = 0n
23
+ let shift = 0n
24
+ let position = offset
25
+ for (;;) {
26
+ if (position >= buffer.length) throw new Error(`truncated varint at byte ${offset}`)
27
+ const byte = buffer[position]
28
+ position += 1
29
+ value |= BigInt(byte & 0x7f) << shift
30
+ if ((byte & 0x80) === 0) break
31
+ shift += 7n
32
+ if (shift > 70n) throw new Error(`varint longer than 10 bytes at byte ${offset}`)
33
+ }
34
+ return { value, end: position }
35
+ }
36
+
37
+ /** True when the bytes are a printable UTF-8 string (a plausible protobuf string). */
38
+ function printable(buffer) {
39
+ if (buffer.length === 0) return false
40
+ const text = buffer.toString('utf8')
41
+ if (text.includes('\uFFFD')) return false
42
+ return /^[\x20-\x7e\u00a0-\uffff\r\n\t]*$/.test(text)
43
+ }
44
+
45
+ /** Try to parse bytes as a sequence of complete protobuf fields. */
46
+ function isMessage(buffer) {
47
+ let position = 0
48
+ try {
49
+ while (position < buffer.length) {
50
+ const tag = readVarint(buffer, position)
51
+ position = tag.end
52
+ const wire = Number(tag.value & 7n)
53
+ if (wire === 0) position = readVarint(buffer, position).end
54
+ else if (wire === 1) position += 8
55
+ else if (wire === 5) position += 4
56
+ else if (wire === 2) {
57
+ const length = readVarint(buffer, position)
58
+ position = length.end + Number(length.value)
59
+ } else return false
60
+ if (position > buffer.length) return false
61
+ }
62
+ return true
63
+ } catch {
64
+ return false
65
+ }
66
+ }
67
+
68
+ /** Decode one message into a flat list of field records (recursing into nested messages). */
69
+ function decode(buffer, path, depth = 0) {
70
+ const fields = []
71
+ let position = 0
72
+ while (position < buffer.length) {
73
+ const start = position
74
+ const tag = readVarint(buffer, position)
75
+ position = tag.end
76
+ const fieldNo = Number(tag.value >> 3n)
77
+ const wire = Number(tag.value & 7n)
78
+ const record = {
79
+ path: `${path}.${fieldNo}`,
80
+ field: fieldNo,
81
+ wire,
82
+ wire_name: WIRE_NAMES[wire] ?? `unknown(${wire})`,
83
+ tag_hex: buffer.subarray(start, tag.end).toString('hex'),
84
+ raw_hex: '',
85
+ value: null,
86
+ ascii: null,
87
+ children: null,
88
+ }
89
+ if (wire === 0) {
90
+ const varint = readVarint(buffer, position)
91
+ position = varint.end
92
+ record.value = varint.value.toString()
93
+ if (varint.value === 18446744073709551615n) record.value = '18446744073709551615 (uint64 max, 0xFFFFFFFFFFFFFFFF)'
94
+ else if (varint.value <= 0x7fffffffn) record.value = Number(varint.value)
95
+ } else if (wire === 1) {
96
+ const raw = buffer.subarray(position, position + 8)
97
+ position += 8
98
+ record.raw_hex = raw.toString('hex')
99
+ record.value = `le=${raw.readBigUInt64LE(0).toString()}`
100
+ } else if (wire === 5) {
101
+ const raw = buffer.subarray(position, position + 4)
102
+ position += 4
103
+ record.raw_hex = raw.toString('hex')
104
+ record.value = `le_uint=${raw.readUInt32LE(0)} le_float=${raw.readFloatLE(0)}`
105
+ } else if (wire === 2) {
106
+ const length = readVarint(buffer, position)
107
+ position = length.end
108
+ const raw = buffer.subarray(position, position + Number(length.value))
109
+ position += Number(length.value)
110
+ record.raw_hex = raw.toString('hex')
111
+ record.value = `length=${raw.length}`
112
+ if (printable(raw)) record.ascii = raw.toString('utf8')
113
+ else if (raw.length > 0 && isMessage(raw) && depth < 12) record.children = decode(raw, record.path, depth + 1)
114
+ } else {
115
+ record.value = 'unsupported wire type; stopping'
116
+ position = buffer.length
117
+ }
118
+ record.bytes = buffer.subarray(start, position).toString('hex')
119
+ fields.push(record)
120
+ for (const child of record.children ?? []) fields.push(child)
121
+ }
122
+ return fields
123
+ }
124
+
125
+ const args = process.argv.slice(2)
126
+ const asJson = args.includes('--json')
127
+ const files = args.filter((argument) => !argument.startsWith('--'))
128
+ if (files.length === 0) {
129
+ console.error('usage: node scripts/inspect-svip.mjs <file.svip3> [...] [--json]')
130
+ process.exit(2)
131
+ }
132
+
133
+ const output = []
134
+ for (const file of files) {
135
+ const buffer = readFileSync(file)
136
+ const report = {
137
+ file,
138
+ bytes: buffer.length,
139
+ sha256: createHash('sha256').update(buffer).digest('hex'),
140
+ head_hex: buffer.subarray(0, 64).toString('hex'),
141
+ fields: decode(buffer, 'root'),
142
+ }
143
+ output.push(report)
144
+ }
145
+
146
+ if (asJson) {
147
+ process.stdout.write(`${JSON.stringify(output, null, 2)}\n`)
148
+ } else {
149
+ for (const report of output) {
150
+ console.log(`=== ${report.file} ===`)
151
+ console.log(`bytes=${report.bytes} sha256=${report.sha256}`)
152
+ console.log(`head_hex=${report.head_hex}`)
153
+ for (const field of report.fields) {
154
+ const depth = field.path.split('.').length - 2
155
+ const indent = ' '.repeat(Math.max(0, depth))
156
+ const value = field.ascii !== null ? `ascii=${JSON.stringify(field.ascii)}` : String(field.value)
157
+ console.log(`${indent}${field.path} w${field.wire} ${field.wire_name} [${field.bytes.slice(0, 96)}] ${value}`)
158
+ }
159
+ console.log('')
160
+ }
161
+ }
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env bash
2
+ # One-shot environment preparation for the xstudio-linux GUI sidecar.
3
+ #
4
+ # Creates a Python venv that inherits the system's site-packages (for gi /
5
+ # Atspi) and installs python-xlib into it, then prints how to point the
6
+ # package at it. No sudo required — the venv lives inside the repository.
7
+ #
8
+ # Usage:
9
+ # scripts/setup-venv.sh # create/refresh .venv, verify, print hint
10
+ # scripts/setup-venv.sh --check # only verify, no install
11
+ set -euo pipefail
12
+
13
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
14
+ VENV="$ROOT/.venv"
15
+ PYTHON="${XSTUDIO_SETUP_PYTHON:-}"
16
+
17
+ if [[ -z "$PYTHON" ]]; then
18
+ for candidate in /usr/bin/python3 python3; do
19
+ if command -v "$candidate" >/dev/null 2>&1; then PYTHON="$candidate"; break; fi
20
+ done
21
+ fi
22
+ if [[ -z "$PYTHON" ]]; then
23
+ echo "✗ no python3 found on PATH" >&2
24
+ exit 1
25
+ fi
26
+ echo "python: $PYTHON ($("$PYTHON" --version 2>&1))"
27
+
28
+ check() {
29
+ "$VENV/bin/python" - "$@" << 'PYEOF'
30
+ import sys
31
+ problems = []
32
+ try:
33
+ import Xlib # noqa: F401
34
+ print("✓ python-xlib (X11 window queries, XTEST input)")
35
+ except ImportError:
36
+ problems.append("python-xlib missing — run scripts/setup-venv.sh without --check")
37
+ try:
38
+ import gi
39
+ gi.require_version("Atspi", "2.0")
40
+ from gi.repository import Atspi # noqa: F401
41
+ print("✓ gi.Atspi (accessibility tree; reachability of the Wine app is separate)")
42
+ except Exception as e: # noqa: BLE001
43
+ print(f"△ gi.Atspi unavailable: {e}")
44
+ try:
45
+ import shutil
46
+ if shutil.which("xdotool"):
47
+ print("✓ xdotool found (optional fallback)")
48
+ else:
49
+ print("△ xdotool not found (optional; XTEST covers keyboard input)")
50
+ except Exception: # noqa: BLE001
51
+ pass
52
+ if problems:
53
+ print("✗ " + "; ".join(problems))
54
+ sys.exit(1)
55
+ PYEOF
56
+ }
57
+
58
+ if [[ "${1:-}" == "--check" ]]; then
59
+ if [[ ! -x "$VENV/bin/python" ]]; then
60
+ echo "✗ $VENV does not exist yet — run scripts/setup-venv.sh" >&2
61
+ exit 1
62
+ fi
63
+ check
64
+ exit 0
65
+ fi
66
+
67
+ if command -v uv >/dev/null 2>&1; then
68
+ echo "creating venv with uv (--system-site-packages so gi stays importable)…"
69
+ uv venv --system-site-packages --python "$PYTHON" "$VENV" 2>/dev/null \
70
+ || uv venv --system-site-packages --python "$PYTHON" "$VENV" --clear
71
+ uv pip install --python "$VENV/bin/python" python-xlib
72
+ else
73
+ echo "creating venv with $PYTHON -m venv…"
74
+ "$PYTHON" -m venv --system-site-packages "$VENV"
75
+ if [[ -x "$VENV/bin/pip" ]]; then
76
+ "$VENV/bin/pip" install python-xlib
77
+ else
78
+ echo "△ no pip in the venv; python-xlib could not be installed" >&2
79
+ echo " install it via the distro (e.g. pacman -S python-xlib) and re-run --check" >&2
80
+ fi
81
+ fi
82
+
83
+ check && echo && cat << HINT
84
+
85
+ ✓ venv ready. Point the package at it:
86
+
87
+ export XSTUDIO_PYTHON="$VENV/bin/python"
88
+
89
+ Then verify:
90
+
91
+ node dist/adapter-cli/cli.js xstudio_probe --json '{"activate":true}'
92
+
93
+ HINT
@@ -0,0 +1,302 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Wine GUI calibration probe for xstudio-linux.
5
+
6
+ Read-only diagnostic: prints what the X11 server and the AT-SPI2 accessibility
7
+ bus can see of the X Studio window running under Wine. Run this BEFORE using
8
+ the GUI control plane on a new machine to verify the element tree is reachable,
9
+ and to tune the window matcher (WM_CLASS / title) if needed.
10
+
11
+ Usage:
12
+ python3 scripts/wine-gui-probe.py [--depth N] [--elements N] [--json]
13
+
14
+ Requires nothing else to run: every backend degrades to a "not available" note.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import argparse
20
+ import json
21
+ import re
22
+ import subprocess
23
+ import sys
24
+
25
+ PROCESS_NAME = "NetEase Cloud Music XStudio"
26
+ # Native Windows: WM_CLASS "Qt622QWindowIcon"; Wine: lowercased process name
27
+ # with .exe suffix (verified live). Accept both.
28
+ WINDOW_CLASS_PATTERN = re.compile(
29
+ r"Qt.*QWindowIcon.*|netease cloud music xstudio(\.exe)?",
30
+ re.IGNORECASE,
31
+ )
32
+ HELPER_TITLE_PATTERN = re.compile(
33
+ r"^(Default IME|JUCEWindow|Windows Audio|DirectSound|MSCTFIME UI|IME)$",
34
+ re.IGNORECASE,
35
+ )
36
+
37
+ # --- X11 ---------------------------------------------------------------
38
+
39
+ _XLIB = False
40
+ try:
41
+ from Xlib import display as xdisplay
42
+
43
+ _XLIB = True
44
+ except Exception:
45
+ xdisplay = None
46
+
47
+ _ATSPI = False
48
+ _ATSPI_VIA_GI = False
49
+ try:
50
+ import pyatspi
51
+
52
+ _ATSPI = True
53
+ except Exception:
54
+ pyatspi = None
55
+ try:
56
+ import gi
57
+
58
+ gi.require_version('Atspi', '2.0')
59
+ from gi.repository import Atspi as _AtspiGI
60
+
61
+ pyatspi = _AtspiGI # minimal duck-type: get_desktop / roles
62
+ _ATSPI = True
63
+ _ATSPI_VIA_GI = True
64
+ except Exception:
65
+ pyatspi = None
66
+
67
+
68
+ def x11_windows(): # type: ignore[no-untyped-def]
69
+ if not _XLIB:
70
+ return None
71
+ try:
72
+ dpy = xdisplay.Display()
73
+ net_wm_name_atom = dpy.intern_atom("_NET_WM_NAME")
74
+ net_wm_pid_atom = dpy.intern_atom("_NET_WM_PID")
75
+ root = dpy.screen().root
76
+ windows = []
77
+ for child in root.query_tree().children:
78
+ try:
79
+ # _NET_WM_NAME (UTF-8) first — Wine CJK titles are unreadable
80
+ # through legacy WM_NAME (verified live).
81
+ name = ""
82
+ prop = child.get_full_property(net_wm_name_atom, 0)
83
+ if prop is not None and prop.value:
84
+ name = prop.value.decode("utf-8", "replace")
85
+ if not name:
86
+ name = str(child.get_wm_name() or "")
87
+ except Exception:
88
+ name = ""
89
+ try:
90
+ wm_class = child.get_wm_class() or ("", "")
91
+ except Exception:
92
+ wm_class = ("", "")
93
+ try:
94
+ pid = 0
95
+ prop = child.get_full_property(net_wm_pid_atom, 0)
96
+ if prop is not None and prop.value:
97
+ pid = int(prop.value[0])
98
+ except Exception:
99
+ pid = 0
100
+ try:
101
+ geo = child.get_geometry()
102
+ geometry = f"{geo.width}x{geo.height}+{geo.x}+{geo.y}"
103
+ except Exception:
104
+ geometry = "?"
105
+ windows.append(
106
+ {
107
+ "xid": int(child.id),
108
+ "title": name,
109
+ "class": f"{wm_class[0]}|{wm_class[1]}",
110
+ "pid": int(pid),
111
+ "geometry": geometry,
112
+ }
113
+ )
114
+ return windows
115
+ except Exception as error:
116
+ return [{"error": f"Xlib query failed: {error}"}]
117
+
118
+
119
+ def xdotool_windows(): # type: ignore[no-untyped-def]
120
+ try:
121
+ result = subprocess.run(
122
+ ["xdotool", "search", "--name", PROCESS_NAME], capture_output=True, text=True, timeout=5, check=False
123
+ )
124
+ if result.returncode != 0:
125
+ return None
126
+ ids = [line.strip() for line in result.stdout.splitlines() if line.strip()]
127
+ out = []
128
+ for xid in ids:
129
+ name = subprocess.run(["xdotool", "getwindowname", xid], capture_output=True, text=True, timeout=5, check=False)
130
+ out.append({"xid": xid, "title": name.stdout.strip() if name.returncode == 0 else ""})
131
+ return out
132
+ except Exception as error:
133
+ return [{"error": f"xdotool failed: {error}"}]
134
+
135
+
136
+ def _desktop(): # type: ignore[no-untyped-def]
137
+ if not _ATSPI:
138
+ return None
139
+ try:
140
+ if _ATSPI_VIA_GI:
141
+ return pyatspi.get_desktop(0)
142
+ return pyatspi.Registry.getDesktop(0)
143
+ except Exception:
144
+ return None
145
+
146
+
147
+ def _child_count(node): # type: ignore[no-untyped-def]
148
+ try:
149
+ if _ATSPI_VIA_GI:
150
+ return node.get_child_count()
151
+ return node.childCount
152
+ except Exception:
153
+ return 0
154
+
155
+
156
+ def _child_at(node, index): # type: ignore[no-untyped-def]
157
+ try:
158
+ if _ATSPI_VIA_GI:
159
+ return node.get_child_at_index(index)
160
+ return node[index]
161
+ except Exception:
162
+ return None
163
+
164
+
165
+ def _node_name(node): # type: ignore[no-untyped-def]
166
+ try:
167
+ return node.get_name() if _ATSPI_VIA_GI else (node.name or "")
168
+ except Exception:
169
+ return ""
170
+
171
+
172
+ def _node_role(node): # type: ignore[no-untyped-def]
173
+ try:
174
+ return node.get_role_name() if _ATSPI_VIA_GI else (node.getRoleName() or "")
175
+ except Exception:
176
+ return "?"
177
+
178
+
179
+ def atspi_apps(): # type: ignore[no-untyped-def]
180
+ desktop = _desktop()
181
+ if desktop is None:
182
+ return None if not _ATSPI else [{"error": "AT-SPI desktop unreachable"}]
183
+ apps = []
184
+ for index in range(_child_count(desktop)):
185
+ app = _child_at(desktop, index)
186
+ if app is None:
187
+ continue
188
+ try:
189
+ apps.append({"name": _node_name(app), "children": _child_count(app)})
190
+ except Exception as error:
191
+ apps.append({"name": "?", "error": str(error)})
192
+ return apps
193
+
194
+
195
+ def atspi_tree(app_name_fragment: str, max_depth: int, max_elements: int): # type: ignore[no-untyped-def]
196
+ desktop = _desktop()
197
+ if desktop is None:
198
+ return None
199
+ app_count = _child_count(desktop)
200
+ for index in range(app_count):
201
+ app = _child_at(desktop, index)
202
+ if app is None:
203
+ continue
204
+ if app_name_fragment.lower() not in _node_name(app).lower():
205
+ continue
206
+ lines = []
207
+ queue = [(app, 0)]
208
+ count = 0
209
+ while queue and count < max_elements:
210
+ node, depth = queue.pop(0)
211
+ count += 1
212
+ lines.append(f"{' ' * depth}[{_node_role(node)}] {_node_name(node)!r}")
213
+ if depth >= max_depth:
214
+ continue
215
+ for child_index in range(_child_count(node)):
216
+ child = _child_at(node, child_index)
217
+ if child is not None:
218
+ queue.append((child, depth + 1))
219
+ return {"app": _node_name(app), "elements": count, "tree": lines}
220
+ return {"app": None, "elements": 0, "tree": [], "note": "no AT-SPI application matched"}
221
+
222
+
223
+ def main() -> int:
224
+ parser = argparse.ArgumentParser(description="Wine GUI calibration probe (read-only).")
225
+ parser.add_argument("--depth", type=int, default=4, help="AT-SPI tree print depth (default 4)")
226
+ parser.add_argument("--elements", type=int, default=150, help="max AT-SPI elements printed (default 150)")
227
+ parser.add_argument("--json", action="store_true", help="emit raw JSON instead of text")
228
+ args = parser.parse_args()
229
+
230
+ report = {
231
+ "xlib": _XLIB,
232
+ "atspi": _ATSPI,
233
+ "atspi_backend": "pyatspi" if not _ATSPI_VIA_GI else ("gi" if _ATSPI_VIA_GI else "none"),
234
+ "xdotool": subprocess.run(["which", "xdotool"], capture_output=True, text=True).returncode == 0,
235
+ "import_cmd": subprocess.run(["which", "import"], capture_output=True, text=True).returncode == 0,
236
+ "x11_windows": x11_windows() or xdotool_windows(),
237
+ "atspi_apps": atspi_apps(),
238
+ }
239
+
240
+ matched = None
241
+ windows = report["x11_windows"]
242
+ if isinstance(windows, list):
243
+ # Class match alone identifies the process; title may be empty under
244
+ # Wine. Rank same-process candidates by geometry — the main window is
245
+ # the largest; helper windows (IME/audio/JUCE) are excluded by name.
246
+ best_area = -1
247
+ for window in windows:
248
+ if not (isinstance(window, dict) and WINDOW_CLASS_PATTERN.search(window.get("class", ""))):
249
+ continue
250
+ if HELPER_TITLE_PATTERN.match(window.get("title", "")):
251
+ continue
252
+ geometry = str(window.get("geometry", "0x0"))
253
+ try:
254
+ area = int(geometry.split("x")[0]) * int(geometry.split("+")[0].split("x")[1])
255
+ except Exception:
256
+ area = 0
257
+ if area > best_area:
258
+ best_area = area
259
+ matched = window
260
+ report["matched_main_window"] = matched
261
+ if matched is not None:
262
+ report["atspi_tree"] = atspi_tree(matched["title"], args.depth, args.elements)
263
+
264
+ if args.json:
265
+ print(json.dumps(report, ensure_ascii=False, indent=2))
266
+ return 0
267
+
268
+ print("== xstudio-linux Wine GUI calibration probe ==")
269
+ print(f"Xlib available: {report['xlib']}")
270
+ print(f"AT-SPI2 available: {report['atspi']}")
271
+ print(f"xdotool available: {report['xdotool']}")
272
+ print(f"ImageMagick 'import': {report['import_cmd']}")
273
+ print()
274
+ print(f"X11 windows: {len(windows) if isinstance(windows, list) else windows}")
275
+ if isinstance(windows, list):
276
+ for window in windows[:40]:
277
+ if isinstance(window, dict) and "title" in window:
278
+ print(f" xid={window.get('xid')} class={window.get('class', '?')!r} title={window.get('title')!r}")
279
+ print()
280
+ print(f"Main-window matcher matched: {matched if matched else 'NOTHING (tune WINDOW_CLASS_PATTERN / PROCESS_NAME)'}")
281
+ print()
282
+ apps = report["atspi_apps"]
283
+ if apps is None:
284
+ print("AT-SPI apps: pyatspi not importable — pip install pyatspi / python3-pyatspi")
285
+ else:
286
+ print(f"AT-SPI applications: {apps}")
287
+ tree = report.get("atspi_tree")
288
+ if tree:
289
+ print()
290
+ print(f"AT-SPI tree of matched app ({tree.get('app')}): {tree.get('elements')} elements, depth<={args.depth}")
291
+ for line in tree.get("tree", [])[: args.elements]:
292
+ print(f" {line}")
293
+ else:
294
+ print()
295
+ print("AT-SPI tree: UNAVAILABLE — the GUI control plane will degrade to guide-only for element actions.")
296
+ print("Next steps: enable desktop accessibility (AT_SPI_BUS), try X11 instead of Wayland,")
297
+ print("or run inside the Wine prefix: wine explorer /desktop to force a managed window.")
298
+ return 0
299
+
300
+
301
+ if __name__ == "__main__":
302
+ sys.exit(main())