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.
- package/CHANGELOG.md +469 -0
- package/LICENSE +31 -0
- package/README.md +542 -2
- package/dist/adapter-cli/cli.d.ts +28 -0
- package/dist/adapter-cli/cli.js +233 -0
- package/dist/adapter-cli/cli.js.map +1 -0
- package/dist/adapter-mcp/server.d.ts +81 -0
- package/dist/adapter-mcp/server.js +473 -0
- package/dist/adapter-mcp/server.js.map +1 -0
- package/dist/config.d.ts +45 -0
- package/dist/config.js +78 -0
- package/dist/config.js.map +1 -0
- package/dist/core/catalog/pronunciation.d.ts +47 -0
- package/dist/core/catalog/pronunciation.js +402 -0
- package/dist/core/catalog/pronunciation.js.map +1 -0
- package/dist/core/catalog/singers.d.ts +46 -0
- package/dist/core/catalog/singers.js +122 -0
- package/dist/core/catalog/singers.js.map +1 -0
- package/dist/core/contracts.d.ts +348 -0
- package/dist/core/contracts.js +17 -0
- package/dist/core/contracts.js.map +1 -0
- package/dist/core/degrade/chain.d.ts +80 -0
- package/dist/core/degrade/chain.js +137 -0
- package/dist/core/degrade/chain.js.map +1 -0
- package/dist/core/diagnose/error-resolver.d.ts +51 -0
- package/dist/core/diagnose/error-resolver.js +202 -0
- package/dist/core/diagnose/error-resolver.js.map +1 -0
- package/dist/core/guard/skill-gate.d.ts +89 -0
- package/dist/core/guard/skill-gate.js +121 -0
- package/dist/core/guard/skill-gate.js.map +1 -0
- package/dist/core/midi/convert.d.ts +31 -0
- package/dist/core/midi/convert.js +125 -0
- package/dist/core/midi/convert.js.map +1 -0
- package/dist/core/midi/smf.d.ts +37 -0
- package/dist/core/midi/smf.js +422 -0
- package/dist/core/midi/smf.js.map +1 -0
- package/dist/core/render/artifacts.d.ts +37 -0
- package/dist/core/render/artifacts.js +417 -0
- package/dist/core/render/artifacts.js.map +1 -0
- package/dist/core/render/orchestrator.d.ts +110 -0
- package/dist/core/render/orchestrator.js +974 -0
- package/dist/core/render/orchestrator.js.map +1 -0
- package/dist/core/svip/codec.d.ts +30 -0
- package/dist/core/svip/codec.js +664 -0
- package/dist/core/svip/codec.js.map +1 -0
- package/dist/core/svip/document.d.ts +31 -0
- package/dist/core/svip/document.js +158 -0
- package/dist/core/svip/document.js.map +1 -0
- package/dist/core/svip/editor.d.ts +71 -0
- package/dist/core/svip/editor.js +245 -0
- package/dist/core/svip/editor.js.map +1 -0
- package/dist/core/svip/model.d.ts +74 -0
- package/dist/core/svip/model.js +158 -0
- package/dist/core/svip/model.js.map +1 -0
- package/dist/core/svip/tick.d.ts +21 -0
- package/dist/core/svip/tick.js +59 -0
- package/dist/core/svip/tick.js.map +1 -0
- package/dist/core/svip/validator.d.ts +39 -0
- package/dist/core/svip/validator.js +267 -0
- package/dist/core/svip/validator.js.map +1 -0
- package/dist/host/linux.d.ts +15 -0
- package/dist/host/linux.js +42 -0
- package/dist/host/linux.js.map +1 -0
- package/dist/host/sidecar.d.ts +61 -0
- package/dist/host/sidecar.js +365 -0
- package/dist/host/sidecar.js.map +1 -0
- package/dist/host/wine-launch.d.ts +60 -0
- package/dist/host/wine-launch.js +77 -0
- package/dist/host/wine-launch.js.map +1 -0
- package/dist/host/wine-paths.d.ts +30 -0
- package/dist/host/wine-paths.js +103 -0
- package/dist/host/wine-paths.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/services.d.ts +55 -0
- package/dist/services.js +78 -0
- package/dist/services.js.map +1 -0
- package/dist/shared/errors.d.ts +61 -0
- package/dist/shared/errors.js +125 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/shared/paths.d.ts +8 -0
- package/dist/shared/paths.js +30 -0
- package/dist/shared/paths.js.map +1 -0
- package/dist/shared/schema.d.ts +26 -0
- package/dist/shared/schema.js +68 -0
- package/dist/shared/schema.js.map +1 -0
- package/dist/shared/types.d.ts +43 -0
- package/dist/shared/types.js +19 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/tests/unit/artifacts.test.d.ts +1 -0
- package/dist/tests/unit/artifacts.test.js +243 -0
- package/dist/tests/unit/artifacts.test.js.map +1 -0
- package/dist/tests/unit/data-plane.test.d.ts +1 -0
- package/dist/tests/unit/data-plane.test.js +153 -0
- package/dist/tests/unit/data-plane.test.js.map +1 -0
- package/dist/tests/unit/degrade.test.d.ts +1 -0
- package/dist/tests/unit/degrade.test.js +133 -0
- package/dist/tests/unit/degrade.test.js.map +1 -0
- package/dist/tests/unit/diagnosis.test.d.ts +1 -0
- package/dist/tests/unit/diagnosis.test.js +66 -0
- package/dist/tests/unit/diagnosis.test.js.map +1 -0
- package/dist/tests/unit/errors.test.d.ts +1 -0
- package/dist/tests/unit/errors.test.js +83 -0
- package/dist/tests/unit/errors.test.js.map +1 -0
- package/dist/tests/unit/mcp-server.test.d.ts +1 -0
- package/dist/tests/unit/mcp-server.test.js +267 -0
- package/dist/tests/unit/mcp-server.test.js.map +1 -0
- package/dist/tests/unit/mcp-smoke.d.ts +6 -0
- package/dist/tests/unit/mcp-smoke.js +7 -0
- package/dist/tests/unit/mcp-smoke.js.map +1 -0
- package/dist/tests/unit/mcp-smoke.test.d.ts +1 -0
- package/dist/tests/unit/mcp-smoke.test.js +196 -0
- package/dist/tests/unit/mcp-smoke.test.js.map +1 -0
- package/dist/tests/unit/midi.test.d.ts +1 -0
- package/dist/tests/unit/midi.test.js +255 -0
- package/dist/tests/unit/midi.test.js.map +1 -0
- package/dist/tests/unit/pronunciation.test.d.ts +1 -0
- package/dist/tests/unit/pronunciation.test.js +83 -0
- package/dist/tests/unit/pronunciation.test.js.map +1 -0
- package/dist/tests/unit/registry-contract.test.d.ts +1 -0
- package/dist/tests/unit/registry-contract.test.js +114 -0
- package/dist/tests/unit/registry-contract.test.js.map +1 -0
- package/dist/tests/unit/render-orchestrator.test.d.ts +1 -0
- package/dist/tests/unit/render-orchestrator.test.js +548 -0
- package/dist/tests/unit/render-orchestrator.test.js.map +1 -0
- package/dist/tests/unit/sidecar.test.d.ts +1 -0
- package/dist/tests/unit/sidecar.test.js +299 -0
- package/dist/tests/unit/sidecar.test.js.map +1 -0
- package/dist/tests/unit/singers.test.d.ts +1 -0
- package/dist/tests/unit/singers.test.js +73 -0
- package/dist/tests/unit/singers.test.js.map +1 -0
- package/dist/tests/unit/skill-gate.test.d.ts +1 -0
- package/dist/tests/unit/skill-gate.test.js +207 -0
- package/dist/tests/unit/skill-gate.test.js.map +1 -0
- package/dist/tests/unit/svip-codec.test.d.ts +1 -0
- package/dist/tests/unit/svip-codec.test.js +182 -0
- package/dist/tests/unit/svip-codec.test.js.map +1 -0
- package/dist/tests/unit/svip-document.test.d.ts +1 -0
- package/dist/tests/unit/svip-document.test.js +137 -0
- package/dist/tests/unit/svip-document.test.js.map +1 -0
- package/dist/tests/unit/svip-editor.test.d.ts +1 -0
- package/dist/tests/unit/svip-editor.test.js +275 -0
- package/dist/tests/unit/svip-editor.test.js.map +1 -0
- package/dist/tests/unit/svip-tick.test.d.ts +1 -0
- package/dist/tests/unit/svip-tick.test.js +66 -0
- package/dist/tests/unit/svip-tick.test.js.map +1 -0
- package/dist/tools/common.d.ts +87 -0
- package/dist/tools/common.js +174 -0
- package/dist/tools/common.js.map +1 -0
- package/dist/tools/control.d.ts +21 -0
- package/dist/tools/control.js +376 -0
- package/dist/tools/control.js.map +1 -0
- package/dist/tools/data.d.ts +37 -0
- package/dist/tools/data.js +680 -0
- package/dist/tools/data.js.map +1 -0
- package/dist/tools/definition.d.ts +60 -0
- package/dist/tools/definition.js +44 -0
- package/dist/tools/definition.js.map +1 -0
- package/dist/tools/degrade.d.ts +3 -0
- package/dist/tools/degrade.js +30 -0
- package/dist/tools/degrade.js.map +1 -0
- package/dist/tools/guide.d.ts +10 -0
- package/dist/tools/guide.js +66 -0
- package/dist/tools/guide.js.map +1 -0
- package/dist/tools/open.d.ts +3 -0
- package/dist/tools/open.js +74 -0
- package/dist/tools/open.js.map +1 -0
- package/dist/tools/probe.d.ts +8 -0
- package/dist/tools/probe.js +132 -0
- package/dist/tools/probe.js.map +1 -0
- package/dist/tools/registry.d.ts +10 -0
- package/dist/tools/registry.js +16 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.js +19 -0
- package/dist/version.js.map +1 -0
- package/docs/DESIGN.md +561 -0
- package/docs/RECON-GUI.md +271 -0
- package/docs/RECON.md +339 -0
- package/docs/SPEC.md +786 -0
- package/docs/WINE.md +193 -0
- package/examples/.scratch/01-midi-to-wudi/wudi-demo.svip3 +0 -0
- package/examples/.scratch/01-midi-to-wudi/wudi-melody.mid +0 -0
- package/examples/.scratch/01-midi-to-wudi/wudi-roundtrip.mid +0 -0
- package/examples/.scratch/02-three-singers/melody.chenziyu.svip3 +0 -0
- package/examples/.scratch/02-three-singers/melody.hechang.svip3 +0 -0
- package/examples/.scratch/02-three-singers/melody.svip3 +0 -0
- package/examples/.scratch/02-three-singers/melody.wudi.svip3 +0 -0
- package/examples/.scratch/03-velocity-diction/phrase.svip3 +0 -0
- package/examples/.scratch/03-velocity-diction/phrase.svip3.bak.20261206-163755-200 +0 -0
- package/examples/.scratch/03-velocity-diction/phrase.svip3.bak.20261206-163755-203 +0 -0
- package/examples/.scratch/03-velocity-diction/phrase.svip3.bak.20261206-163755-204 +0 -0
- package/examples/.scratch/04-unknown-dialog-abort/dialog-demo.svip3 +0 -0
- package/examples/01-midi-to-wudi.mjs +144 -0
- package/examples/02-three-singers-compare.mjs +140 -0
- package/examples/03-velocity-diction-rerender.mjs +160 -0
- package/examples/04-unknown-dialog-abort.mjs +126 -0
- package/examples/README.md +101 -0
- package/examples/lib/harness.mjs +274 -0
- package/fixtures/midi/melody-480.mid +0 -0
- package/fixtures/midi/melody-96.mid +0 -0
- package/fixtures/svip/1.svip3 +0 -0
- package/fixtures/svip/3.svip3 +0 -0
- package/fixtures/uia/README.md +37 -0
- package/fixtures/uia/export-dialog.snapshot.json +446 -0
- package/fixtures/uia/main-window.snapshot.json +2997 -0
- package/fixtures/uia/open-dialog.snapshot.json +103 -0
- package/icon.svg +10 -0
- package/package.json +84 -4
- package/proto/xstudio.proto +128 -0
- package/scripts/check-contract.mjs +184 -0
- package/scripts/entry-smoke.mjs +26 -0
- package/scripts/inspect-svip.mjs +161 -0
- package/scripts/setup-venv.sh +93 -0
- package/scripts/wine-gui-probe.py +302 -0
- package/sidecar/xstudio_uia.py +1478 -0
- package/skills/xstudio-gui/SKILL.md +196 -0
- package/skills/xstudio-gui/assertions.md +103 -0
- package/skills/xstudio-gui/dialogs.md +90 -0
- package/skills/xstudio-gui/gestures.md +158 -0
- package/skills/xstudio-gui/ui-map.json +242 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/** The only suggested actions a diagnosis may return. */
|
|
2
|
+
export const DIAGNOSIS_ACTIONS = [
|
|
3
|
+
'retry',
|
|
4
|
+
'dismiss',
|
|
5
|
+
'login_required',
|
|
6
|
+
'update_available',
|
|
7
|
+
'manual',
|
|
8
|
+
];
|
|
9
|
+
/** Longest dialog snippet quoted into a manual instruction. */
|
|
10
|
+
export const MAX_DIALOG_INSTRUCTION_CHARS = 120;
|
|
11
|
+
const ALLOWED_ACTIONS = new Set(DIAGNOSIS_ACTIONS);
|
|
12
|
+
/** Safe, canned handling advice per action (never sourced from search results). */
|
|
13
|
+
const SAFE_INSTRUCTIONS = Object.freeze({
|
|
14
|
+
retry: '检查网络连接后重试;.svip3 项目文件不受影响,数据面编辑仍可用。',
|
|
15
|
+
dismiss: '关闭或忽略此弹窗,然后继续当前步骤。',
|
|
16
|
+
login_required: '请在 X Studio 中手动登录后再重试;插件不会绕过登录或鉴权。',
|
|
17
|
+
update_available: '任务进行中先忽略更新(UIA 元素树可能变化);任务结束后再手动更新 X Studio。',
|
|
18
|
+
manual: '请手动处理此弹窗,并记录弹窗原文以便排查。',
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Local dialog fingerprint table.
|
|
22
|
+
*
|
|
23
|
+
* `action` uses the {@link DialogFingerprint} vocabulary (dismiss/cancel/
|
|
24
|
+
* confirm/retry/login/manual); `match` entries are alternative substrings,
|
|
25
|
+
* any one of which identifies the dialog. More specific fingerprints come
|
|
26
|
+
* first so "无法连接网络" matches cloud-unreachable rather than a generic one.
|
|
27
|
+
*/
|
|
28
|
+
export const KNOWN_DIALOGS = Object.freeze([
|
|
29
|
+
{
|
|
30
|
+
id: 'login-required',
|
|
31
|
+
match: ['请先登录', '请登录', '登录后', '未登录', '登录已过期', '登录失效', '需要登录', 'login required', 'please log in', 'sign in to continue'],
|
|
32
|
+
action: 'login',
|
|
33
|
+
instruction: '手动登录 X Studio(插件不会绕过登录),登录后重新触发云端渲染。',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 'update-available',
|
|
37
|
+
match: ['发现新版本', '有新版本', '是否更新', '立即更新', '版本更新', '更新提示', 'update available', 'new version'],
|
|
38
|
+
action: 'manual',
|
|
39
|
+
instruction: '任务进行中先忽略更新(UIA 元素树可能变化),任务结束后再手动更新 X Studio。',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'resource-downloading',
|
|
43
|
+
match: ['正在下载', '下载中', '资源下载', '下载音色', '音色下载', '声库下载', '下载资源', '请稍候', 'downloading'],
|
|
44
|
+
action: 'manual',
|
|
45
|
+
instruction: '等待音色/声库下载完成后再触发云端渲染。',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 'save-changes',
|
|
49
|
+
match: ['是否保存更改', '保存更改', '是否保存', '要保存吗', '未保存的更改', 'save changes', 'unsaved changes', 'save before'],
|
|
50
|
+
action: 'cancel',
|
|
51
|
+
instruction: '选择“取消/否”;插件以自己的 *.bak.<timestamp> 备份为准,不需要保存 GUI 改动。',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: 'overwrite-confirm',
|
|
55
|
+
match: ['覆盖', '已存在', '是否替换', 'overwrite', 'replace existing', 'file exists'],
|
|
56
|
+
action: 'cancel',
|
|
57
|
+
instruction: '选择“取消”,不要覆盖已有文件;如需另存请更换输出路径。',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: 'no-singer-model',
|
|
61
|
+
match: ['未安装', '声库', '歌手模型', '音色不存在', '音色未下载', 'singer model', 'voice bank', 'voicebank', 'missing model'],
|
|
62
|
+
action: 'manual',
|
|
63
|
+
instruction: '先在 X Studio 歌手库中下载/安装对应歌手声库,再重新渲染。',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'render-failed',
|
|
67
|
+
match: ['渲染失败', '合成失败', '生成失败', '预览失败', 'render failed', 'render error', 'synthesis failed'],
|
|
68
|
+
action: 'retry',
|
|
69
|
+
instruction: '点击“重试”;若连续失败,检查网络与登录状态,或改用 xstudio_guide_print 手动渲染。',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: 'cloud-unreachable',
|
|
73
|
+
match: ['无法连接', '连接失败', '网络错误', '网络异常', '网络连接', '断网', '服务器连接', 'cloud unreachable', 'network error', 'cannot connect', 'connection failed', 'server unreachable'],
|
|
74
|
+
action: 'retry',
|
|
75
|
+
instruction: '检查网络后重试;.svip3 项目文件不受影响,数据面编辑仍可用。',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: 'network-error',
|
|
79
|
+
match: ['网络', '超时', 'timeout', 'offline', '离线', 'net::', '连接超时'],
|
|
80
|
+
action: 'retry',
|
|
81
|
+
instruction: '检查网络后重试;离线时仅数据面可用。',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: 'quota-limit',
|
|
85
|
+
match: ['额度', '配额', '次数已用完', '次数不足', '超出限制', '上限', 'quota', 'limit exceeded', 'requests exceeded', 'vip', '会员专享', '开通会员'],
|
|
86
|
+
action: 'manual',
|
|
87
|
+
instruction: '云端合成额度或会员限制不足;等待额度恢复或手动开通会员后重试。',
|
|
88
|
+
},
|
|
89
|
+
]);
|
|
90
|
+
/** Map a fingerprint action onto the diagnosis enum (never auto-confirm). */
|
|
91
|
+
export function suggestionForFingerprint(action) {
|
|
92
|
+
switch (action) {
|
|
93
|
+
case 'retry':
|
|
94
|
+
return 'retry';
|
|
95
|
+
case 'login':
|
|
96
|
+
return 'login_required';
|
|
97
|
+
case 'dismiss':
|
|
98
|
+
case 'cancel':
|
|
99
|
+
case 'confirm':
|
|
100
|
+
return 'dismiss';
|
|
101
|
+
case 'manual':
|
|
102
|
+
default:
|
|
103
|
+
return 'manual';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Fingerprint ids whose generic `action` is coarser than the diagnosis enum
|
|
108
|
+
* (e.g. `update-available` carries action "manual" but the diagnosis enum has a
|
|
109
|
+
* precise `update_available`).
|
|
110
|
+
*/
|
|
111
|
+
const FINGERPRINT_SUGGESTIONS = Object.freeze({
|
|
112
|
+
'login-required': 'login_required',
|
|
113
|
+
'update-available': 'update_available',
|
|
114
|
+
'resource-downloading': 'manual',
|
|
115
|
+
'save-changes': 'dismiss',
|
|
116
|
+
'overwrite-confirm': 'dismiss',
|
|
117
|
+
'no-singer-model': 'manual',
|
|
118
|
+
'render-failed': 'retry',
|
|
119
|
+
'cloud-unreachable': 'retry',
|
|
120
|
+
'network-error': 'retry',
|
|
121
|
+
'quota-limit': 'manual',
|
|
122
|
+
});
|
|
123
|
+
/** The diagnosis action for one known fingerprint. */
|
|
124
|
+
export function diagnosisActionForFingerprint(fingerprint) {
|
|
125
|
+
return FINGERPRINT_SUGGESTIONS[fingerprint.id] ?? suggestionForFingerprint(fingerprint.action);
|
|
126
|
+
}
|
|
127
|
+
/** NFKC-normalize, collapse all whitespace and trim (defensive on unknown input). */
|
|
128
|
+
export function normalizeDialogText(text) {
|
|
129
|
+
if (typeof text !== 'string')
|
|
130
|
+
return '';
|
|
131
|
+
try {
|
|
132
|
+
return text.normalize('NFKC').replace(/\s+/g, ' ').trim();
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return text.replace(/\s+/g, ' ').trim();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function dialogSnippet(text, maxLength) {
|
|
139
|
+
const normalized = normalizeDialogText(text);
|
|
140
|
+
return normalized.length > maxLength ? normalized.slice(0, maxLength) : normalized;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Match a dialog against the local fingerprint table.
|
|
144
|
+
*
|
|
145
|
+
* Returns the most specific fingerprint (table order) whose any-of match
|
|
146
|
+
* needles appears in the normalized dialog text, or null for unknown dialogs.
|
|
147
|
+
*/
|
|
148
|
+
export function matchKnownDialog(text) {
|
|
149
|
+
const normalized = normalizeDialogText(text);
|
|
150
|
+
if (normalized === '')
|
|
151
|
+
return null;
|
|
152
|
+
const lower = normalized.toLowerCase();
|
|
153
|
+
for (const fingerprint of KNOWN_DIALOGS) {
|
|
154
|
+
for (const needle of fingerprint.match) {
|
|
155
|
+
if (lower.includes(needle.toLowerCase()))
|
|
156
|
+
return fingerprint;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
function manualInstructionFor(action, dialogText) {
|
|
162
|
+
if (action !== 'manual')
|
|
163
|
+
return SAFE_INSTRUCTIONS[action];
|
|
164
|
+
const snippet = dialogSnippet(dialogText, MAX_DIALOG_INSTRUCTION_CHARS);
|
|
165
|
+
return snippet === ''
|
|
166
|
+
? SAFE_INSTRUCTIONS.manual
|
|
167
|
+
: `${SAFE_INSTRUCTIONS.manual}弹窗内容:“${snippet}”。`;
|
|
168
|
+
}
|
|
169
|
+
/** The always-safe unknown-dialog result. */
|
|
170
|
+
export function fallbackDiagnosis(dialogText, reason) {
|
|
171
|
+
const snippet = dialogSnippet(dialogText, MAX_DIALOG_INSTRUCTION_CHARS);
|
|
172
|
+
return {
|
|
173
|
+
cause: `未匹配本地指纹(${reason})`,
|
|
174
|
+
suggestedAction: 'manual',
|
|
175
|
+
manualInstruction: snippet === '' ? SAFE_INSTRUCTIONS.manual : `${SAFE_INSTRUCTIONS.manual}弹窗内容:“${snippet}”。`,
|
|
176
|
+
confidence: 0,
|
|
177
|
+
via: 'local-fallback',
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Diagnose one X Studio dialog (local fingerprints only; never throws).
|
|
182
|
+
*
|
|
183
|
+
* Known fingerprints resolve with `via: "pb"` and confidence 1. Unknown
|
|
184
|
+
* dialogs return the always-safe `manual` action with `via: "local-fallback"`.
|
|
185
|
+
*/
|
|
186
|
+
export async function diagnoseDialog(errorText, _deps = {}) {
|
|
187
|
+
const normalized = normalizeDialogText(errorText);
|
|
188
|
+
if (normalized === '')
|
|
189
|
+
return fallbackDiagnosis('', '弹窗文本为空');
|
|
190
|
+
const known = matchKnownDialog(normalized);
|
|
191
|
+
if (known !== null) {
|
|
192
|
+
return {
|
|
193
|
+
cause: `已知弹窗指纹:${known.id}`,
|
|
194
|
+
suggestedAction: diagnosisActionForFingerprint(known),
|
|
195
|
+
manualInstruction: known.instruction,
|
|
196
|
+
confidence: 1,
|
|
197
|
+
via: 'pb',
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
return fallbackDiagnosis(normalized, '无匹配指纹;Tavily 诊断已在 xstudio-linux 中移除');
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=error-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-resolver.js","sourceRoot":"","sources":["../../../src/core/diagnose/error-resolver.ts"],"names":[],"mappings":"AAWA,yDAAyD;AACzD,MAAM,CAAC,MAAM,iBAAiB,GAAkD;IAC9E,OAAO;IACP,SAAS;IACT,gBAAgB;IAChB,kBAAkB;IAClB,QAAQ;CACA,CAAA;AAEV,+DAA+D;AAC/D,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAA;AAE/C,MAAM,eAAe,GAAG,IAAI,GAAG,CAAS,iBAAiB,CAAC,CAAA;AAE1D,mFAAmF;AACnF,MAA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,CAAC,CAAA;IACvE,OAAO;QACL,KAAK,EAAE,WAAW,MAAM,GAAG;QAC3B,eAAe,EAAE,QAAQ;QACzB,iBAAiB,EACf,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,MAAM,SAAS,OAAO,IAAI;QAC7F,UAAU,EAAE,CAAC;QACb,GAAG,EAAE,gBAAgB;KACtB,CAAA;AACH,CAAC;AASD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,SAAiB,EAAE,QAAsB,EAAE;IAC9E,MAAM,UAAU,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAA;IACjD,IAAI,UAAU,KAAK,EAAE;QAAE,OAAO,iBAAiB,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;IAE7D,MAAM,KAAK,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAA;IAC1C,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO;YACL,KAAK,EAAE,UAAU,KAAK,CAAC,EAAE,EAAE;YAC3B,eAAe,EAAE,6BAA6B,CAAC,KAAK,CAAC;YACrD,iBAAiB,EAAE,KAAK,CAAC,WAAW;YACpC,UAAU,EAAE,CAAC;YACb,GAAG,EAAE,IAAI;SACV,CAAA;IACH,CAAC;IACD,OAAO,iBAAiB,CAAC,UAAU,EAAE,qCAAqC,CAAC,CAAA;AAC7E,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime precondition gate for the GUI control plane.
|
|
3
|
+
*
|
|
4
|
+
* Since 0.2.4 the standalone adapters inject an always-loaded probe, so the
|
|
5
|
+
* gate passes every GUI tool by default and the xstudio-gui skill is
|
|
6
|
+
* recommended reading rather than a hard requirement (the sidecar still
|
|
7
|
+
* enforces the safety rules — destructive-action blacklist, foreground gate,
|
|
8
|
+
* unknown-dialog escalation — at runtime). The decision core is kept intact
|
|
9
|
+
* so hosts that want the old behavior can supply their own probe, and tests
|
|
10
|
+
* exercise it directly.
|
|
11
|
+
*
|
|
12
|
+
* The gate is deliberately whitelist-based: only the nine GUI control tools
|
|
13
|
+
* are gated, and data-plane tools are never touched. A host that cannot answer
|
|
14
|
+
* the probe degrades to a per-session one-time prompt so the tools can never
|
|
15
|
+
* become permanently unreachable.
|
|
16
|
+
* @module xstudio-linux/core/guard/skill-gate
|
|
17
|
+
*/
|
|
18
|
+
/** The skill that must be loaded before any GUI control tool runs. */
|
|
19
|
+
export declare const REQUIRED_SKILL: "xstudio-gui";
|
|
20
|
+
/** The GUI control-plane tools covered by the gate (whitelist). */
|
|
21
|
+
export declare const GUI_CONTROL_TOOLS: readonly ["xstudio_open", "xstudio_ui_snapshot", "xstudio_ui_act", "xstudio_ui_assert", "xstudio_ui_dialog_respond", "xstudio_ui_abort", "xstudio_preview_trigger", "xstudio_preview_wait", "xstudio_export_run"];
|
|
22
|
+
/** Tools explicitly exempt from the gate (self-check and skill loading itself). */
|
|
23
|
+
export declare const SKILL_GATE_EXEMPT_TOOLS: readonly ["xstudio_probe", "skill"];
|
|
24
|
+
/** Why the gate reached its verdict. */
|
|
25
|
+
export type SkillGateReason = 'SKILL_LOADED' | 'NEED_SKILL' | 'ONE_TIME_PASS' | 'HOST_QUERY_UNAVAILABLE' | 'NOT_GATED';
|
|
26
|
+
/** The verdict returned by SkillGate.evaluate. */
|
|
27
|
+
export interface SkillGateVerdict {
|
|
28
|
+
/** Whether the tool may run. */
|
|
29
|
+
allowed: boolean;
|
|
30
|
+
/** Why. */
|
|
31
|
+
reason: SkillGateReason;
|
|
32
|
+
/** The skill this gate enforces. */
|
|
33
|
+
requiredSkill: typeof REQUIRED_SKILL;
|
|
34
|
+
/** A model-facing next step (empty when allowed without caveat). */
|
|
35
|
+
nextStep: string;
|
|
36
|
+
/** Whether the host could answer the loaded-state question (diagnostics/tests). */
|
|
37
|
+
hostQuery: 'available' | 'unavailable';
|
|
38
|
+
}
|
|
39
|
+
/** A host-supplied probe for "has this session loaded the required skill?". */
|
|
40
|
+
export interface SkillLoadProbe {
|
|
41
|
+
/**
|
|
42
|
+
* Resolve the loaded state for one agent/session.
|
|
43
|
+
* @returns true loaded, false not loaded, or undefined when the host cannot
|
|
44
|
+
* answer (missing service, unknown agent, ...).
|
|
45
|
+
*/
|
|
46
|
+
isSkillLoaded(agent?: unknown): boolean | undefined | Promise<boolean | undefined>;
|
|
47
|
+
}
|
|
48
|
+
/** Construction options. */
|
|
49
|
+
export interface SkillGateOptions {
|
|
50
|
+
/** Host answer source; omitted means "host query unavailable". */
|
|
51
|
+
probe?: SkillLoadProbe;
|
|
52
|
+
}
|
|
53
|
+
/** The message attached to a NEED_SKILL failure. */
|
|
54
|
+
export declare const NEED_SKILL_MESSAGE = "GUI control tools require the xstudio-gui skill to be loaded first.";
|
|
55
|
+
/** The hint attached to a NEED_SKILL failure (mentions the UIA-wedge recovery). */
|
|
56
|
+
export declare const NEED_SKILL_HINT = "Load skills/xstudio-gui/SKILL.md with the skill tool, then retry. It contains the destructive-action blacklist, foreground gate semantics, unknown-dialog escalation rules, and the UIA-wedge recovery procedure: if snapshot/assert hang past ~20 s, do NOT retry into the blocked serial channel; kill the sidecar and let the host respawn it.";
|
|
57
|
+
/** The actionable follow-up list attached to a NEED_SKILL failure. */
|
|
58
|
+
export declare const NEED_SKILL_NEXT_STEPS: readonly string[];
|
|
59
|
+
/** True when toolName is one of the gated GUI control tools. */
|
|
60
|
+
export declare function isGuiControlTool(toolName: string): boolean;
|
|
61
|
+
/** True when toolName is explicitly exempt from the gate. */
|
|
62
|
+
export declare function isExemptFromSkillGate(toolName: string): boolean;
|
|
63
|
+
/** The per-session key used by the degraded one-time fallback. */
|
|
64
|
+
export declare function skillGateSessionKey(agent: unknown): string;
|
|
65
|
+
/**
|
|
66
|
+
* The gate. One instance per plugin activation (DSH) or per MCP process, so a
|
|
67
|
+
* plugin reload resets the degraded one-time prompt state. It holds no global
|
|
68
|
+
* cross-session state: the only mutable state is the set of session keys that
|
|
69
|
+
* already received the one-time prompt while the host query was unavailable.
|
|
70
|
+
*/
|
|
71
|
+
export declare class SkillGate {
|
|
72
|
+
#private;
|
|
73
|
+
constructor(options?: SkillGateOptions);
|
|
74
|
+
/** Session keys that already received the one-time degraded prompt. */
|
|
75
|
+
get promptedSessions(): readonly string[];
|
|
76
|
+
/** Clear the degraded prompt state (plugin reload / tests). */
|
|
77
|
+
reset(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Decide whether toolName may run for agent.
|
|
80
|
+
* Never throws: a throwing probe is treated as "host query unavailable".
|
|
81
|
+
*/
|
|
82
|
+
evaluate(toolName: string, agent?: unknown): Promise<SkillGateVerdict>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Convenience alias matching the v0.1.2 specification wording: evaluate the
|
|
86
|
+
* gate for one tool/agent pair. The adapter wiring uses a single SkillGate
|
|
87
|
+
* instance per activation; this helper keeps the semantic name available.
|
|
88
|
+
*/
|
|
89
|
+
export declare function requireSkillLoaded(toolName: string, gate: SkillGate, agent?: unknown): Promise<SkillGateVerdict>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime precondition gate for the GUI control plane.
|
|
3
|
+
*
|
|
4
|
+
* Since 0.2.4 the standalone adapters inject an always-loaded probe, so the
|
|
5
|
+
* gate passes every GUI tool by default and the xstudio-gui skill is
|
|
6
|
+
* recommended reading rather than a hard requirement (the sidecar still
|
|
7
|
+
* enforces the safety rules — destructive-action blacklist, foreground gate,
|
|
8
|
+
* unknown-dialog escalation — at runtime). The decision core is kept intact
|
|
9
|
+
* so hosts that want the old behavior can supply their own probe, and tests
|
|
10
|
+
* exercise it directly.
|
|
11
|
+
*
|
|
12
|
+
* The gate is deliberately whitelist-based: only the nine GUI control tools
|
|
13
|
+
* are gated, and data-plane tools are never touched. A host that cannot answer
|
|
14
|
+
* the probe degrades to a per-session one-time prompt so the tools can never
|
|
15
|
+
* become permanently unreachable.
|
|
16
|
+
* @module xstudio-linux/core/guard/skill-gate
|
|
17
|
+
*/
|
|
18
|
+
/** The skill that must be loaded before any GUI control tool runs. */
|
|
19
|
+
export const REQUIRED_SKILL = 'xstudio-gui';
|
|
20
|
+
/** The GUI control-plane tools covered by the gate (whitelist). */
|
|
21
|
+
export const GUI_CONTROL_TOOLS = [
|
|
22
|
+
'xstudio_open',
|
|
23
|
+
'xstudio_ui_snapshot',
|
|
24
|
+
'xstudio_ui_act',
|
|
25
|
+
'xstudio_ui_assert',
|
|
26
|
+
'xstudio_ui_dialog_respond',
|
|
27
|
+
'xstudio_ui_abort',
|
|
28
|
+
'xstudio_preview_trigger',
|
|
29
|
+
'xstudio_preview_wait',
|
|
30
|
+
'xstudio_export_run',
|
|
31
|
+
];
|
|
32
|
+
/** Tools explicitly exempt from the gate (self-check and skill loading itself). */
|
|
33
|
+
export const SKILL_GATE_EXEMPT_TOOLS = ['xstudio_probe', 'skill'];
|
|
34
|
+
/** The message attached to a NEED_SKILL failure. */
|
|
35
|
+
export const NEED_SKILL_MESSAGE = 'GUI control tools require the xstudio-gui skill to be loaded first.';
|
|
36
|
+
/** The hint attached to a NEED_SKILL failure (mentions the UIA-wedge recovery). */
|
|
37
|
+
export const NEED_SKILL_HINT = 'Load skills/xstudio-gui/SKILL.md with the skill tool, then retry. It contains the destructive-action blacklist, foreground gate semantics, unknown-dialog escalation rules, and the UIA-wedge recovery procedure: if snapshot/assert hang past ~20 s, do NOT retry into the blocked serial channel; kill the sidecar and let the host respawn it.';
|
|
38
|
+
/** The actionable follow-up list attached to a NEED_SKILL failure. */
|
|
39
|
+
export const NEED_SKILL_NEXT_STEPS = [
|
|
40
|
+
'Call the skill tool with name "xstudio-gui" and read the result.',
|
|
41
|
+
'Then retry the same GUI tool. Until then no sidecar request is sent.',
|
|
42
|
+
'If a GUI call already wedged past ~20 s, kill the sidecar process instead of retrying (see the skill).',
|
|
43
|
+
];
|
|
44
|
+
/** True when toolName is one of the gated GUI control tools. */
|
|
45
|
+
export function isGuiControlTool(toolName) {
|
|
46
|
+
return GUI_CONTROL_TOOLS.includes(toolName);
|
|
47
|
+
}
|
|
48
|
+
/** True when toolName is explicitly exempt from the gate. */
|
|
49
|
+
export function isExemptFromSkillGate(toolName) {
|
|
50
|
+
return SKILL_GATE_EXEMPT_TOOLS.includes(toolName);
|
|
51
|
+
}
|
|
52
|
+
/** The per-session key used by the degraded one-time fallback. */
|
|
53
|
+
export function skillGateSessionKey(agent) {
|
|
54
|
+
if (typeof agent === 'object' && agent !== null) {
|
|
55
|
+
const id = agent.id;
|
|
56
|
+
if (typeof id === 'string' && id !== '')
|
|
57
|
+
return 'session:' + id;
|
|
58
|
+
if (typeof id === 'number' && Number.isFinite(id))
|
|
59
|
+
return 'session:' + id;
|
|
60
|
+
}
|
|
61
|
+
return 'session:unknown';
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The gate. One instance per plugin activation (DSH) or per MCP process, so a
|
|
65
|
+
* plugin reload resets the degraded one-time prompt state. It holds no global
|
|
66
|
+
* cross-session state: the only mutable state is the set of session keys that
|
|
67
|
+
* already received the one-time prompt while the host query was unavailable.
|
|
68
|
+
*/
|
|
69
|
+
export class SkillGate {
|
|
70
|
+
#probe;
|
|
71
|
+
#prompted = new Set();
|
|
72
|
+
constructor(options = {}) {
|
|
73
|
+
this.#probe = options.probe;
|
|
74
|
+
}
|
|
75
|
+
/** Session keys that already received the one-time degraded prompt. */
|
|
76
|
+
get promptedSessions() {
|
|
77
|
+
return [...this.#prompted];
|
|
78
|
+
}
|
|
79
|
+
/** Clear the degraded prompt state (plugin reload / tests). */
|
|
80
|
+
reset() {
|
|
81
|
+
this.#prompted.clear();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Decide whether toolName may run for agent.
|
|
85
|
+
* Never throws: a throwing probe is treated as "host query unavailable".
|
|
86
|
+
*/
|
|
87
|
+
async evaluate(toolName, agent) {
|
|
88
|
+
if (isExemptFromSkillGate(toolName) || !isGuiControlTool(toolName)) {
|
|
89
|
+
return { allowed: true, reason: 'NOT_GATED', requiredSkill: REQUIRED_SKILL, nextStep: '', hostQuery: 'unavailable' };
|
|
90
|
+
}
|
|
91
|
+
let loaded;
|
|
92
|
+
try {
|
|
93
|
+
loaded = this.#probe === undefined ? undefined : await this.#probe.isSkillLoaded(agent);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
loaded = undefined;
|
|
97
|
+
}
|
|
98
|
+
if (loaded === true) {
|
|
99
|
+
return { allowed: true, reason: 'SKILL_LOADED', requiredSkill: REQUIRED_SKILL, nextStep: '', hostQuery: 'available' };
|
|
100
|
+
}
|
|
101
|
+
if (loaded === false) {
|
|
102
|
+
return { allowed: false, reason: 'NEED_SKILL', requiredSkill: REQUIRED_SKILL, nextStep: NEED_SKILL_MESSAGE, hostQuery: 'available' };
|
|
103
|
+
}
|
|
104
|
+
// Host query unavailable: degrade to one prompt per session, then pass.
|
|
105
|
+
const key = skillGateSessionKey(agent);
|
|
106
|
+
if (this.#prompted.has(key)) {
|
|
107
|
+
return { allowed: true, reason: 'ONE_TIME_PASS', requiredSkill: REQUIRED_SKILL, nextStep: '', hostQuery: 'unavailable' };
|
|
108
|
+
}
|
|
109
|
+
this.#prompted.add(key);
|
|
110
|
+
return { allowed: false, reason: 'NEED_SKILL', requiredSkill: REQUIRED_SKILL, nextStep: NEED_SKILL_MESSAGE, hostQuery: 'unavailable' };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Convenience alias matching the v0.1.2 specification wording: evaluate the
|
|
115
|
+
* gate for one tool/agent pair. The adapter wiring uses a single SkillGate
|
|
116
|
+
* instance per activation; this helper keeps the semantic name available.
|
|
117
|
+
*/
|
|
118
|
+
export async function requireSkillLoaded(toolName, gate, agent) {
|
|
119
|
+
return gate.evaluate(toolName, agent);
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=skill-gate.js.map
|
|
@@ -0,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EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,CAAA;QACvH,CAAC;QACD,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;YACrB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,EAAE,WAAW,EAAE,CAAA;QACtI,CAAC;QAED,wEAAwE;QACxE,MAAM,GAAG,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAA;QACtC,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,CAAA;QAC1H,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACvB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,EAAE,aAAa,EAAE,CAAA;IACxI,CAAC;CACF;AACD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAAgB,EAChB,IAAe,EACf,KAAe;IAEf,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;AACvC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { NoteModel } from '../contracts.js';
|
|
2
|
+
import type { MidiFileModel } from './smf.js';
|
|
3
|
+
/**
|
|
4
|
+
* Convert MIDI notes onto the .svip3 timeline.
|
|
5
|
+
*
|
|
6
|
+
* Notes are ordered by start tick first (the same order the MIDI parser
|
|
7
|
+
* returns), and `options.lyrics` are applied in that order: the first lyric
|
|
8
|
+
* belongs to the earliest note. Missing lyrics become empty strings; extra
|
|
9
|
+
* lyrics are ignored. `phoneme_roman` is left empty for the pronunciation
|
|
10
|
+
* pipeline / `xstudio_lyrics_align` to fill.
|
|
11
|
+
*
|
|
12
|
+
* @throws {XStudioError} MIDI_EMPTY when the file carries no notes.
|
|
13
|
+
* @throws {XStudioError} PROJECT_INVALID for an invalid target PPQ or note.
|
|
14
|
+
*/
|
|
15
|
+
export declare function midiToNotes(midi: MidiFileModel, options?: {
|
|
16
|
+
lyrics?: string[];
|
|
17
|
+
targetPpq?: number;
|
|
18
|
+
}): NoteModel[];
|
|
19
|
+
/**
|
|
20
|
+
* Convert .svip3 notes into a MIDI model at the project's 480 PPQ.
|
|
21
|
+
*
|
|
22
|
+
* The .svip3 format stores no velocity, so every exported note gets 100 (a
|
|
23
|
+
* neutral mf velocity); the caller supplies the project tempo. Notes are
|
|
24
|
+
* sorted by start tick, matching what {@link parseSmf} returns.
|
|
25
|
+
*
|
|
26
|
+
* @throws {XStudioError} MIDI_EMPTY when there are no notes to export.
|
|
27
|
+
* @throws {XStudioError} PROJECT_INVALID when a note cannot be represented.
|
|
28
|
+
*/
|
|
29
|
+
export declare function notesToMidi(notes: NoteModel[], options?: {
|
|
30
|
+
bpm?: number;
|
|
31
|
+
}): MidiFileModel;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversion between Standard MIDI Files and .svip3 notes.
|
|
3
|
+
*
|
|
4
|
+
* The .svip3 timeline is always PPQ 480 (`core/svip/tick.ts`); a MIDI file may
|
|
5
|
+
* declare any metrical resolution, so imports scale positions and lengths by
|
|
6
|
+
* `targetPpq / midi.ppq` (rounding to the nearest tick, with a minimum length
|
|
7
|
+
* of one tick). Exports simply reuse the project's 480 PPQ.
|
|
8
|
+
*
|
|
9
|
+
* @module xstudio-linux/core/midi/convert
|
|
10
|
+
*/
|
|
11
|
+
import { ErrorCode, XStudioError } from '../../shared/errors.js';
|
|
12
|
+
import { createNote } from '../svip/model.js';
|
|
13
|
+
import { PPQ } from '../svip/tick.js';
|
|
14
|
+
/** Velocity used when exporting .svip3 notes, which carry no velocity value. */
|
|
15
|
+
const EXPORT_VELOCITY = 100;
|
|
16
|
+
/** Default tempo for exports when the caller does not pass one. */
|
|
17
|
+
const DEFAULT_EXPORT_BPM = 120;
|
|
18
|
+
/** Lowest / highest MIDI note number. */
|
|
19
|
+
const MIN_MIDI_PITCH = 0;
|
|
20
|
+
const MAX_MIDI_PITCH = 127;
|
|
21
|
+
/** Largest PPQ a Standard MIDI File header can declare. */
|
|
22
|
+
const MAX_PPQ = 0x7fff;
|
|
23
|
+
/**
|
|
24
|
+
* Convert MIDI notes onto the .svip3 timeline.
|
|
25
|
+
*
|
|
26
|
+
* Notes are ordered by start tick first (the same order the MIDI parser
|
|
27
|
+
* returns), and `options.lyrics` are applied in that order: the first lyric
|
|
28
|
+
* belongs to the earliest note. Missing lyrics become empty strings; extra
|
|
29
|
+
* lyrics are ignored. `phoneme_roman` is left empty for the pronunciation
|
|
30
|
+
* pipeline / `xstudio_lyrics_align` to fill.
|
|
31
|
+
*
|
|
32
|
+
* @throws {XStudioError} MIDI_EMPTY when the file carries no notes.
|
|
33
|
+
* @throws {XStudioError} PROJECT_INVALID for an invalid target PPQ or note.
|
|
34
|
+
*/
|
|
35
|
+
export function midiToNotes(midi, options = {}) {
|
|
36
|
+
if (typeof midi !== 'object' || midi === null) {
|
|
37
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, 'MIDI model must be an object');
|
|
38
|
+
}
|
|
39
|
+
if (!Array.isArray(midi.notes)) {
|
|
40
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, 'MIDI model notes must be an array');
|
|
41
|
+
}
|
|
42
|
+
if (midi.notes.length === 0) {
|
|
43
|
+
throw new XStudioError(ErrorCode.MIDI_EMPTY, 'the MIDI file contains no notes to import');
|
|
44
|
+
}
|
|
45
|
+
if (!Number.isInteger(midi.ppq) || midi.ppq < 1 || midi.ppq > MAX_PPQ) {
|
|
46
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, `MIDI ppq must be an integer between 1 and ${MAX_PPQ}, got ${String(midi.ppq)}`);
|
|
47
|
+
}
|
|
48
|
+
const targetPpq = options.targetPpq ?? PPQ;
|
|
49
|
+
if (!Number.isInteger(targetPpq) || targetPpq < 1 || targetPpq > 0xf0000) {
|
|
50
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, `target ppq must be a positive integer, got ${String(options.targetPpq)}`);
|
|
51
|
+
}
|
|
52
|
+
const lyrics = options.lyrics ?? [];
|
|
53
|
+
const scale = targetPpq / midi.ppq;
|
|
54
|
+
const ordered = [...midi.notes].sort(compareMidiNotes);
|
|
55
|
+
return ordered.map((note, index) => {
|
|
56
|
+
const pitch = note.pitch;
|
|
57
|
+
if (!Number.isInteger(pitch) || pitch < MIN_MIDI_PITCH || pitch > MAX_MIDI_PITCH) {
|
|
58
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, `MIDI note ${index} has an invalid pitch: ${String(pitch)}`);
|
|
59
|
+
}
|
|
60
|
+
if (!Number.isInteger(note.startTick) || note.startTick < 0) {
|
|
61
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, `MIDI note ${index} has an invalid startTick: ${String(note.startTick)}`);
|
|
62
|
+
}
|
|
63
|
+
if (!Number.isInteger(note.lengthTick) || note.lengthTick < 1) {
|
|
64
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, `MIDI note ${index} has an invalid lengthTick: ${String(note.lengthTick)}`);
|
|
65
|
+
}
|
|
66
|
+
const lyric = lyrics[index];
|
|
67
|
+
return createNote({
|
|
68
|
+
positionTick: Math.max(0, Math.round(note.startTick * scale)),
|
|
69
|
+
// A .svip3 note must last at least one tick.
|
|
70
|
+
lengthTick: Math.max(1, Math.round(note.lengthTick * scale)),
|
|
71
|
+
midiPitch: pitch,
|
|
72
|
+
lyricText: typeof lyric === 'string' ? lyric : '',
|
|
73
|
+
phonemeRoman: '',
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Convert .svip3 notes into a MIDI model at the project's 480 PPQ.
|
|
79
|
+
*
|
|
80
|
+
* The .svip3 format stores no velocity, so every exported note gets 100 (a
|
|
81
|
+
* neutral mf velocity); the caller supplies the project tempo. Notes are
|
|
82
|
+
* sorted by start tick, matching what {@link parseSmf} returns.
|
|
83
|
+
*
|
|
84
|
+
* @throws {XStudioError} MIDI_EMPTY when there are no notes to export.
|
|
85
|
+
* @throws {XStudioError} PROJECT_INVALID when a note cannot be represented.
|
|
86
|
+
*/
|
|
87
|
+
export function notesToMidi(notes, options = {}) {
|
|
88
|
+
if (!Array.isArray(notes)) {
|
|
89
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, 'notes must be an array');
|
|
90
|
+
}
|
|
91
|
+
if (notes.length === 0) {
|
|
92
|
+
throw new XStudioError(ErrorCode.MIDI_EMPTY, 'the track has no notes to export as MIDI');
|
|
93
|
+
}
|
|
94
|
+
const tempoBpm = options.bpm ?? DEFAULT_EXPORT_BPM;
|
|
95
|
+
if (typeof tempoBpm !== 'number' || !Number.isFinite(tempoBpm) || tempoBpm <= 0) {
|
|
96
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, `bpm must be a positive number, got ${String(tempoBpm)}`);
|
|
97
|
+
}
|
|
98
|
+
const converted = notes.map((note, index) => {
|
|
99
|
+
if (!Number.isInteger(note.positionTick) || note.positionTick < 0) {
|
|
100
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, `note ${index} has an invalid positionTick: ${String(note.positionTick)}`);
|
|
101
|
+
}
|
|
102
|
+
if (!Number.isInteger(note.lengthTick) || note.lengthTick < 1) {
|
|
103
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, `note ${index} has an invalid lengthTick: ${String(note.lengthTick)}`);
|
|
104
|
+
}
|
|
105
|
+
if (!Number.isInteger(note.midiPitch) || note.midiPitch < MIN_MIDI_PITCH || note.midiPitch > MAX_MIDI_PITCH) {
|
|
106
|
+
throw new XStudioError(ErrorCode.PROJECT_INVALID, `note ${index} has an invalid midiPitch: ${String(note.midiPitch)}`);
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
startTick: note.positionTick,
|
|
110
|
+
lengthTick: note.lengthTick,
|
|
111
|
+
pitch: note.midiPitch,
|
|
112
|
+
velocity: EXPORT_VELOCITY,
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
converted.sort((a, b) => a.startTick - b.startTick || a.pitch - b.pitch || a.lengthTick - b.lengthTick);
|
|
116
|
+
return { ppq: PPQ, tempoBpm, notes: converted };
|
|
117
|
+
}
|
|
118
|
+
/** Deterministic MIDI note order: start tick, then pitch, then length, then velocity. */
|
|
119
|
+
function compareMidiNotes(a, b) {
|
|
120
|
+
return (a.startTick - b.startTick ||
|
|
121
|
+
a.pitch - b.pitch ||
|
|
122
|
+
a.lengthTick - b.lengthTick ||
|
|
123
|
+
(a.velocity ?? 0) - (b.velocity ?? 0));
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../../src/core/midi/convert.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAEhE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAGrC,gFAAgF;AAChF,MAAM,eAAe,GAAG,GAAG,CAAA;AAC3B,mEAAmE;AACnE,MAAM,kBAAkB,GAAG,GAAG,CAAA;AAC9B,yCAAyC;AACzC,MAAM,cAAc,GAAG,CAAC,CAAA;AACxB,MAAM,cAAc,GAAG,GAAG,CAAA;AAC1B,2DAA2D;AA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AE,CAAgB;IAC1D,OAAO,CACL,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS;QACzB,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK;QACjB,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU;QAC3B,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,CACtC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** One note as it appears in a Standard MIDI File. */
|
|
2
|
+
export interface MidiNoteModel {
|
|
3
|
+
/** Absolute start tick in the file's PPQ resolution. */
|
|
4
|
+
startTick: number;
|
|
5
|
+
/** Duration in ticks (always positive). */
|
|
6
|
+
lengthTick: number;
|
|
7
|
+
/** MIDI note number, 0..127 (60 = C4). */
|
|
8
|
+
pitch: number;
|
|
9
|
+
/** Note-on velocity, 1..127. */
|
|
10
|
+
velocity: number;
|
|
11
|
+
}
|
|
12
|
+
/** A parsed Standard MIDI File. */
|
|
13
|
+
export interface MidiFileModel {
|
|
14
|
+
/** Ticks per quarter note declared by the file header. */
|
|
15
|
+
ppq: number;
|
|
16
|
+
/** Tempo in BPM from the first tempo meta event (120 when absent). */
|
|
17
|
+
tempoBpm: number;
|
|
18
|
+
/** Notes sorted by start tick, then pitch, then length, then velocity. */
|
|
19
|
+
notes: MidiNoteModel[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parse a Standard MIDI File.
|
|
23
|
+
*
|
|
24
|
+
* @throws {XStudioError} MIDI_PARSE_FAILED for anything that is not a valid
|
|
25
|
+
* format 0/1 SMF with a metrical (non-SMPTE) time division.
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseSmf(bytes: Uint8Array): MidiFileModel;
|
|
28
|
+
/**
|
|
29
|
+
* Write a Standard MIDI File (format 1: a tempo conductor track plus one note
|
|
30
|
+
* track). The output is deterministic: the same model always produces the same
|
|
31
|
+
* bytes, and parsing those bytes returns the same model (notes sorted by the
|
|
32
|
+
* documented comparator).
|
|
33
|
+
*
|
|
34
|
+
* @throws {XStudioError} PROJECT_INVALID when the model cannot be represented
|
|
35
|
+
* on the MIDI wire (invalid PPQ, tempo, pitch, velocity, tick).
|
|
36
|
+
*/
|
|
37
|
+
export declare function writeSmf(midi: MidiFileModel): Uint8Array;
|