@doitian/dsh-music 0.1.5 → 0.1.7
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/README.md +59 -724
- package/cordis.patch.yml +12 -8
- package/lib/dj.js +239 -47
- package/lib/index.js +53 -5
- package/lib/panel.html +351 -167
- package/lib/router.js +49 -2
- package/lib/session.js +96 -9
- package/lib/state.js +60 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,379 +1,79 @@
|
|
|
1
1
|
# @doitian/dsh-music
|
|
2
2
|
|
|
3
|
-
NetEase Cloud Music ([music.163.com](https://music.163.com)) playback and an AI DJ
|
|
3
|
+
NetEase Cloud Music ([music.163.com](https://music.163.com)) playback and an AI DJ for DeepSeek Harness.
|
|
4
4
|
|
|
5
|
-
A **Music** entry
|
|
5
|
+
A **Music** entry in the DSH sidebar opens a player: queue, synced lyrics, QR sign-in, NetEase likes, and an AI DJ that keeps the queue stocked. The agent can drive the same player through seven tools.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
┌──────────────────────────────────────────────────────────────────┐
|
|
9
|
-
│ 音乐 music.163.com [AI DJ] [mood] [account] │
|
|
10
|
-
│ │
|
|
11
|
-
│ ♪ 海屿你 — 马也_Crabbit │
|
|
12
|
-
│ 上一首 · 播放 · 下一首 · 列表 · 喜欢 · 静音 · 音量 │
|
|
13
|
-
│ │
|
|
14
|
-
│ 歌词 Lyrics │
|
|
15
|
-
│ [00:12.40] ... │
|
|
16
|
-
│ 播放队列 Queue (12) │
|
|
17
|
-
└──────────────────────────────────────────────────────────────────┘
|
|
18
|
-
```
|
|
7
|
+
Developing the plugin, or curious how it works? See [docs/DESIGN.md](https://github.com/doitian/dsh-music/blob/main/docs/DESIGN.md).
|
|
19
8
|
|
|
20
9
|
## Install
|
|
21
10
|
|
|
22
|
-
|
|
23
|
-
packages** — so it installs either from npm or straight from a checkout.
|
|
24
|
-
|
|
25
|
-
### From npm
|
|
26
|
-
|
|
27
|
-
The package is published as **`@doitian/dsh-music`**. In the Desktop app, install
|
|
28
|
-
it from the GUI, because the `dsh plugin` CLI refuses this profile
|
|
29
|
-
(`profile "desktop" is managed exclusively by the Electron application`):
|
|
11
|
+
In the desktop app: **Plugins** → **Add plugin** → `@doitian/dsh-music`, then restart the app. **Music** appears in the sidebar.
|
|
30
12
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
For any other profile, from a shell:
|
|
13
|
+
For a profile other than `desktop`, install from a terminal instead:
|
|
34
14
|
|
|
35
15
|
```powershell
|
|
36
16
|
dsh plugin --profile <name> add @doitian/dsh-music
|
|
37
17
|
```
|
|
38
18
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Point the profile at a working tree instead — this is what developing the plugin
|
|
42
|
-
looks like. Add it to the profile's `package.json` directly:
|
|
43
|
-
|
|
44
|
-
```json
|
|
45
|
-
{
|
|
46
|
-
"dependencies": {
|
|
47
|
-
"@doitian/dsh-music": "link:C:/path/to/dsh-music"
|
|
48
|
-
},
|
|
49
|
-
"dsh": {
|
|
50
|
-
"profile": {
|
|
51
|
-
"bundles": [
|
|
52
|
-
"@deepseek-ai/dsh-base",
|
|
53
|
-
"@deepseek-ai/dsh-web-app",
|
|
54
|
-
"@doitian/dsh-music"
|
|
55
|
-
]
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
A `link:` dependency keeps the profile pointing at the working tree, so edits
|
|
62
|
-
need no reinstall. Note that this is what makes a plugin *remount* re-read the
|
|
63
|
-
served page while the module stays cached — see
|
|
64
|
-
[Reloading a change](#reloading-a-change).
|
|
65
|
-
|
|
66
|
-
**Language.** The UI follows the Harness language (Settings → Language): the
|
|
67
|
-
sidebar label and error page register a zh/en dictionary with the host's
|
|
68
|
-
`locale` service, and the player page follows the shell's `<html lang>` live.
|
|
69
|
-
Switching language re-renders both in place — no restart.
|
|
19
|
+
The player follows the Harness language setting (中文 or English).
|
|
70
20
|
|
|
71
|
-
|
|
72
|
-
tool for it: that flow installs the published tarball, which replaces the
|
|
73
|
-
`link:` dependency. Re-add the link if it happens.
|
|
21
|
+
## Sign in
|
|
74
22
|
|
|
75
|
-
|
|
23
|
+
Optional. Signed out, search, charts, playlists, lyrics and non-VIP playback all work; VIP tracks return no audio.
|
|
76
24
|
|
|
77
|
-
|
|
78
|
-
`cordis.patch.yml` edit is required. Restart the app (or reload the profile) and
|
|
79
|
-
**Music** appears in the sidebar.
|
|
80
|
-
|
|
81
|
-
## Sign in (optional)
|
|
82
|
-
|
|
83
|
-
Without credentials the plugin works anonymously: search, charts, playlists,
|
|
84
|
-
lyrics, and non-VIP playback all function. VIP tracks return no audio URL.
|
|
85
|
-
|
|
86
|
-
Sign in from the player (**登录 Sign in** in the header), which renders a QR
|
|
87
|
-
code to scan with the NetEase Cloud Music mobile app, or ask the agent to use
|
|
88
|
-
`music_login`. The session cookie is stored in `$DSH_HOME/music/session.json`.
|
|
89
|
-
|
|
90
|
-
`fee=1` (VIP-only) tracks are gated by NetEase for anonymous sessions; that is
|
|
91
|
-
an upstream entitlement rule, not a plugin limit.
|
|
25
|
+
Click **登录 Sign in** in the player and scan the QR code with the NetEase Cloud Music app, or ask the agent to use `music_login`. The cookie is stored in `$DSH_HOME/music/session.json`.
|
|
92
26
|
|
|
93
27
|
## Agent tools
|
|
94
28
|
|
|
95
29
|
| Tool | Purpose |
|
|
96
30
|
|---|---|
|
|
97
|
-
| `music_search` | Search NetEase for songs
|
|
98
|
-
| `music_play` | Queue and
|
|
99
|
-
| `music_queue` | Show
|
|
100
|
-
| `music_control` |
|
|
101
|
-
| `music_dj` | Run or configure the AI DJ, with an optional mood brief
|
|
102
|
-
| `music_now_playing` | What is playing
|
|
103
|
-
| `music_login` |
|
|
31
|
+
| `music_search` | Search NetEase for songs |
|
|
32
|
+
| `music_play` | Queue and play, by ids or a search query |
|
|
33
|
+
| `music_queue` | Show, append, insert, replace, remove, jump, clear |
|
|
34
|
+
| `music_control` | Play, pause, next, previous, seek, volume, mute, mode |
|
|
35
|
+
| `music_dj` | Run or configure the AI DJ, with an optional mood brief or a temporary boost |
|
|
36
|
+
| `music_now_playing` | What is playing and next, and whether you're signed in |
|
|
37
|
+
| `music_login` | Status, QR, poll, set a cookie, log out |
|
|
104
38
|
|
|
105
|
-
|
|
106
|
-
opened the Music page.
|
|
39
|
+
Music plays in the Harness window, so keep it open. Playback continues while you switch to a conversation.
|
|
107
40
|
|
|
108
|
-
##
|
|
41
|
+
## Using the player
|
|
109
42
|
|
|
110
|
-
|
|
43
|
+
On a wide window the player has two columns: what is playing on the left — cover, the song's controls, transport and lyrics — and what comes next on the right — the AI DJ card and the queue. On a narrow one they stack.
|
|
111
44
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
|
117
|
-
| `exhigh` *(default)* | 320 kbps MP3 (~10 MB) |
|
|
118
|
-
| `higher` / `standard` | 192 / 128 kbps MP3 |
|
|
119
|
-
|
|
120
|
-
**A refusal walks down the ladder.** Entitlement and availability are per track:
|
|
121
|
-
a track with no lossless master, or a level the region does not carry, answers
|
|
122
|
-
`code -110` while the same track streams fine one tier lower. The request steps
|
|
123
|
-
down until something plays, and the caption reports what was *actually* served —
|
|
124
|
-
`▶ FLAC · 1677 kbps`, or `▶ MP3 · 320 kbps (exhigh, 已降级/downgraded)` when the
|
|
125
|
-
rich request could not be honoured. It never silently pretends, and it never
|
|
126
|
-
leaves you with silence because you asked for more than the track has.
|
|
127
|
-
|
|
128
|
-
The choice is saved in `session.json` and beats `config.audioLevel` in the
|
|
129
|
-
profile patch, the same precedence the DJ's model route uses. An unknown value in
|
|
130
|
-
either place falls back to `exhigh` rather than failing a stream.
|
|
131
|
-
|
|
132
|
-
Two implementation details worth knowing:
|
|
133
|
-
|
|
134
|
-
- **The level rides in the stream URL** (`/music/stream/<id>?level=lossless`),
|
|
135
|
-
and the CDN-URL cache is keyed by level as well as track. The same track at
|
|
136
|
-
two qualities is two different files, so reusing one resolution while the
|
|
137
|
-
browser range-requests the other would corrupt the byte stream.
|
|
138
|
-
- **Switching quality mid-track loads a fresh resource and resumes in place**,
|
|
139
|
-
restoring the position from the previous file once metadata arrives, rather
|
|
140
|
-
than restarting the song. The resource check runs on every poll, not behind
|
|
141
|
-
the transport-revision gate — quality is not a one-shot transport change, and
|
|
142
|
-
gating it meant a switch did nothing until something else moved the revision.
|
|
143
|
-
|
|
144
|
-
`/music/health` reports both: `audio.preferred` and `audio.last` (what the last
|
|
145
|
-
stream actually served, including `downgraded`).
|
|
146
|
-
|
|
147
|
-
## Likes and taste
|
|
148
|
-
|
|
149
|
-
A track holds one of three taste levels — **liked**, **unrated**, or
|
|
150
|
-
**disliked** — and the player draws whichever it is:
|
|
151
|
-
|
|
152
|
-
| Control | Level it sets |
|
|
45
|
+
**Quality.** Pick a level under the transport controls: `standard`, `higher`, `exhigh` (320 kbps, the default), `lossless`, `hires`, or the spatial tiers `jymaster`, `dolby`, `sky`, `jyeffect`. If a track doesn't offer the level, playback steps down until something plays, and the caption shows what was actually served.
|
|
46
|
+
|
|
47
|
+
**Taste.** Each track is liked, unrated or disliked:
|
|
48
|
+
|
|
49
|
+
| Control | Effect |
|
|
153
50
|
|---|---|
|
|
154
|
-
|
|
|
155
|
-
|
|
|
156
|
-
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
A like is a **NetEase** like, not a plugin flag, and the two halves of what that
|
|
160
|
-
needs are both plain endpoints:
|
|
161
|
-
|
|
162
|
-
- `POST /api/song/like` — one of the few *write* endpoints the web API still
|
|
163
|
-
serves unencrypted, so no `weapi` client is needed. It takes the direction
|
|
164
|
-
rather than toggling: the page always says which level it wants, so a stale
|
|
165
|
-
poll cannot turn a click into the wrong one, and disliking a liked track is one
|
|
166
|
-
request instead of two racing ones.
|
|
167
|
-
- `GET /api/song/like/check` — which of a batch of ids are liked. The answer is
|
|
168
|
-
cached per track (5 minutes), so a whole queue's hearts cost one request, and
|
|
169
|
-
only tracks with no fresh answer ever cost another.
|
|
170
|
-
|
|
171
|
-
Four properties are worth knowing, because they are what makes a heart mean
|
|
172
|
-
something:
|
|
173
|
-
|
|
174
|
-
- **An unknown track is not an unliked one.** A track nobody has asked about has
|
|
175
|
-
no answer, and renders as unrated until NetEase gives one.
|
|
176
|
-
- **A refusal is not an answer.** An anonymous session answers `code 301` for
|
|
177
|
-
every id, and a delisted track answers `400` with NetEase's own reason
|
|
178
|
-
(`下架歌曲无法收藏` for 晴天, for instance). Both leave the heart empty and say
|
|
179
|
-
why in the toast; a refused check is retried later instead of being cached as
|
|
180
|
-
"not liked", so signing in mid-session fills the hearts without a restart.
|
|
181
|
-
- **The account is the record.** `feedback.likes` in `session.json` is a *copy*
|
|
182
|
-
of the account's likes, kept for the DJ's taste digest. It is reconciled with
|
|
183
|
-
the account at startup — one read of the liked playlist — so a like made on
|
|
184
|
-
the phone counts, and a like an earlier build recorded locally (because it had
|
|
185
|
-
nowhere to send it) does not linger as a phantom.
|
|
186
|
-
- **A dislike is local.** The plain web API has no dislike endpoint, so this is
|
|
187
|
-
where the plugin's own taste memory is the only record. Liking and disliking
|
|
188
|
-
are the same three levels rather than two flags: one replaces the other, and
|
|
189
|
-
disliking a liked track removes it on NetEase as well.
|
|
190
|
-
- **Removing a queued track is a dislike, once.** The row's ✕ goes through the
|
|
191
|
-
queue endpoint, whose removal *is* the judgement: the row leaves the list and
|
|
192
|
-
an unrated track is recorded as disliked in the same request, so the DJ does
|
|
193
|
-
not derive it again from the same similarity. The confirm names the removal —
|
|
194
|
-
the judgement is the host's side of it. A track that already carries a level
|
|
195
|
-
keeps it, because removing is often just queue housekeeping (clearing out what
|
|
196
|
-
has already been heard) and rewriting a like into a dislike would be worse
|
|
197
|
-
than missing the signal. Removing the track that is playing also advances
|
|
198
|
-
playback, which a removal otherwise would not.
|
|
199
|
-
|
|
200
|
-
### Skips
|
|
201
|
-
|
|
202
|
-
A skip is a fourth, softer signal, and nobody has to press anything for it:
|
|
203
|
-
**moving to the next track before 30 seconds, or before a quarter of the track
|
|
204
|
-
when that is longer**, records one — from the transport row or the agent's
|
|
205
|
-
`music_control next`; jumping to a queue row does not count. It is local, like
|
|
206
|
-
a dislike.
|
|
207
|
-
|
|
208
|
-
What does *not* count is as deliberate as what does: going back, a track ending
|
|
209
|
-
or failing on its own, single-repeat mode (which stays on the track), and a
|
|
210
|
-
track that never reported a position — paused, blocked by autoplay, or still
|
|
211
|
-
loading — because a track nobody heard was not rejected. Nor does the next
|
|
212
|
-
that the transport row's **✕** presses after a dislike: the dislike is already
|
|
213
|
-
the record, and counting it as a skip too would weigh an early dislike more
|
|
214
|
-
than a later one.
|
|
215
|
-
|
|
216
|
-
The DJ reads skips at two grains:
|
|
217
|
-
|
|
218
|
-
- **Per track.** One skip is a penalty, since it may have been the wrong
|
|
219
|
-
moment rather than the wrong song. A second takes the track out of the pool
|
|
220
|
-
for good, like a dislike.
|
|
221
|
-
- **Per artist.** The skip marks the play it cut short in the history, and that
|
|
222
|
-
play stops counting toward the artist's affinity — otherwise abandoning an
|
|
223
|
-
artist's songs would keep making them a "favourite". Skipped plays then count
|
|
224
|
-
against the artist instead, and the model is shown the recently skipped
|
|
225
|
-
tracks and the artists skipped more than once.
|
|
51
|
+
| ♡ (beside the title, or on a queue row) | Like on your NetEase account. Click again to unlike. |
|
|
52
|
+
| ✕ (beside the title) | Dislike: the track leaves the queue, and the next one plays. Local only; the DJ stops picking it. |
|
|
53
|
+
| ✕ (queue row) | Remove the track. An unrated track is also recorded as disliked. |
|
|
54
|
+
|
|
55
|
+
**Skips.** Pressing next before 30 s (or before a quarter of a long track) counts as a skip. One skip lowers a track's rank; two remove it from the DJ's picks, and skipped plays count against the artist. A dislike is not also counted as a skip.
|
|
226
56
|
|
|
227
57
|
## The AI DJ
|
|
228
58
|
|
|
229
|
-
|
|
230
|
-
`djAutoExtendBelow`, it gathers candidates and appends a batch:
|
|
231
|
-
|
|
232
|
-
- similar songs (`simiSong`) for the current track and recent plays the
|
|
233
|
-
listener heard through — never a disliked or skipped one, and topped up from
|
|
234
|
-
the likes when the history is thin,
|
|
235
|
-
- personal FM (私人FM), two calls of three tracks, when signed in,
|
|
236
|
-
- up to six liked tracks not played in the last three days, marked `[liked]`
|
|
237
|
-
for the model,
|
|
238
|
-
- the daily recommendations and the anonymous new-song feed,
|
|
239
|
-
- the four general charts — 飙升榜, 新歌榜, 原创榜, 热歌榜 — sampled together,
|
|
240
|
-
- for a mood brief, its best-loved playlists, and a keyword song search.
|
|
241
|
-
|
|
242
|
-
Personal FM stands in for heartbeat mode (心动模式), which would be the better
|
|
243
|
-
personalised source but answers `code 500` on the plain web API for every seed;
|
|
244
|
-
it needs the `weapi` transport this plugin does not implement. `simiSong`
|
|
245
|
-
answers five tracks whatever `limit` asks for.
|
|
246
|
-
|
|
247
|
-
**A brief finds music through playlists.** A song search only matches titles
|
|
248
|
-
and lyrics, so "rainy afternoon jazz" mostly finds library tracks literally
|
|
249
|
-
named *Rainy Afternoon Jazz*. Listeners name and tag playlists by mood (雨天,
|
|
250
|
-
爵士, 深夜…), so the brief searches playlists, takes the most played among
|
|
251
|
-
the six most relevant (skipping any under ten tracks), and samples across
|
|
252
|
-
them.
|
|
253
|
-
|
|
254
|
-
**The model rewrites the brief first.** Playlists are named in Chinese, so an
|
|
255
|
-
English brief searched as written matches badly — live, "90s cantopop" found
|
|
256
|
-
Notorious B.I.G. and Eminem. When a model route is available, one call turns
|
|
257
|
-
the brief into up to three Chinese search terms the way listeners name
|
|
258
|
-
playlists (`90年代 粤语金曲`, `港乐 经典`, `粤语老歌`), and the same brief then
|
|
259
|
-
found 张国荣, 刘德华 and 许冠杰. Each term gets its own playlist, so one broad
|
|
260
|
-
term cannot take every slot, and the song search uses the first.
|
|
261
|
-
|
|
262
|
-
The rewrite is made **once per brief, not per plan**, and kept for a week: a
|
|
263
|
-
brief means the same thing next week. It uses the curation route and the same
|
|
264
|
-
session identity. Without a model, or when the rewrite answers nothing usable,
|
|
265
|
-
the brief is searched as written — the plan never fails over it — and the
|
|
266
|
-
rewrite is tried again after half an hour rather than on every plan. The terms
|
|
267
|
-
used are reported as `searchedAs` on the plan and on `dj.lastPlan`, and the
|
|
268
|
-
`music_dj` result says *Brief searched as: …*.
|
|
269
|
-
|
|
270
|
-
### Caching, sampling and pacing
|
|
271
|
-
|
|
272
|
-
Most sources change on the scale of hours or days, so each is cached for
|
|
273
|
-
about as long as it stays the same, per account where it is personal:
|
|
274
|
-
|
|
275
|
-
| Source | Kept for |
|
|
276
|
-
|---|---|
|
|
277
|
-
| similar songs (per seed), track details (per id) | 24 h |
|
|
278
|
-
| a playlist's track list | 12 h |
|
|
279
|
-
| a brief's rewrite into search terms | 7 days (30 min after a failed one) |
|
|
280
|
-
| the charts, a brief's searches | 6 h |
|
|
281
|
-
| the daily recommendations | 3 h |
|
|
282
|
-
| the new-song feed | 1 h |
|
|
283
|
-
| personal FM | never — every call answers a different three |
|
|
284
|
-
|
|
285
|
-
**Every plan samples.** Each source contributes a random handful up to its
|
|
286
|
-
quota — similar 14, daily 8, charts 8, new songs 6, likes 6, FM 6, and for a
|
|
287
|
-
brief 15 from its playlists plus 8 from the song search — drawn only from
|
|
288
|
-
tracks still eligible, and kept in the source's own order. Taking the first
|
|
289
|
-
few would serve the same tracks until the source changed; sampling a cached
|
|
290
|
-
list yields a different handful every plan for free. It also reaches past
|
|
291
|
-
what NetEase sends in full: for a playlist the account does not own, only
|
|
292
|
-
the first 20 tracks come with details, but every id does, so the DJ samples
|
|
293
|
-
ids from the whole list and looks up just the ones it chose. The quotas also
|
|
294
|
-
keep any one source from crowding the others out of the pool.
|
|
295
|
-
|
|
296
|
-
**Requests are paced, not fired as a burst.** Each request starts a random
|
|
297
|
-
0.25–0.75 s after the previous one, so a plan reads like someone clicking
|
|
298
|
-
through the app rather than a crawler. Only the DJ's own probing is paced;
|
|
299
|
-
searches and plays you ask for go out at once. Live, a first plan with a
|
|
300
|
-
brief sends 14 requests over about 7 s; the next one, mostly from cache,
|
|
301
|
-
sends 2. The DJ stocks the queue before it runs dry, so the wait is not
|
|
302
|
-
heard.
|
|
303
|
-
|
|
304
|
-
Then one of two tiers chooses:
|
|
305
|
-
|
|
306
|
-
- **Model tier** — when `dj.provider` and `dj.model` are configured (or a
|
|
307
|
-
single provider is discoverable), the candidate pool plus a taste digest
|
|
308
|
-
(recently played, favourite artists, likes, dislikes) goes to
|
|
309
|
-
`ctx.llm.stream()`, and the model returns the picks and a one-line vibe. This
|
|
310
|
-
is the tier that reasons about a mood.
|
|
311
|
-
- **Heuristic tier** — always available: candidates are scored by mood-brief
|
|
312
|
-
match and artist affinity, then interleaved so consecutive tracks do not
|
|
313
|
-
share an artist. See [Heuristic tier](#heuristic-tier).
|
|
314
|
-
|
|
315
|
-
Either way, the pool never holds a track that is disliked, recently played, or
|
|
316
|
-
**already in the queue** — a batch is appended, so a pick the queue already
|
|
317
|
-
holds would be dropped and the batch would come up short. The model is also
|
|
318
|
-
told which track its picks will follow, and is held to the count it was asked
|
|
319
|
-
for.
|
|
320
|
-
|
|
321
|
-
**Every model call carries a session identity.** A leaf call cannot set headers
|
|
322
|
-
— `GenerateOptions` has no `headers` field — so `sessionId` is the only identity
|
|
323
|
-
a plugin can give a provider, and each adapter maps it onto whatever that
|
|
324
|
-
provider calls a per-conversation header: pi-ai emits `x-opencode-session` for
|
|
325
|
-
the `opencode-go` route. Without it, a provider that keys on the conversation
|
|
326
|
-
sees an anonymous client ignoring its conventions.
|
|
327
|
-
|
|
328
|
-
The identity is minted once per install and persisted in `session.json`, so
|
|
329
|
-
every plan and every restart stays inside one conversation; `dj.sessionId` pins
|
|
330
|
-
it explicitly instead. A request with no identity is refused rather than sent
|
|
331
|
-
bare, so the failure is a recorded `dj.modelError` rather than a silent one.
|
|
332
|
-
|
|
333
|
-
Two other properties are worth knowing:
|
|
334
|
-
|
|
335
|
-
- **The DJ is not an agent, and does not start one.** It is plugin code that
|
|
336
|
-
gathers candidates, makes one model call, and stocks the queue. Routing that
|
|
337
|
-
call through a DSH agent would buy conversation memory and an audit trail at
|
|
338
|
-
the cost of a session lifecycle (rotation, tool masking, disposal).
|
|
339
|
-
- **The model tier is stateless.** Each plan sends its own pool and gets its
|
|
340
|
-
picks back; there is no accumulated transcript, no context growth and no drift
|
|
341
|
-
from a previous mood — which is the property, not a limitation, for this job.
|
|
342
|
-
|
|
343
|
-
The model tier is optional and silent on failure; the DJ never blocks playback.
|
|
344
|
-
It only ever **stocks the queue** — it never starts or stops playback, so a
|
|
345
|
-
top-up while paused stays paused, and one that refills an empty queue after the
|
|
346
|
-
last track ended resumes on its own because the desired state was already
|
|
347
|
-
"playing".
|
|
59
|
+
Turn it on with the switch in the player's AI DJ card, or with `music_dj`. When fewer than 3 tracks remain, the DJ appends a batch of 5. It only stocks the queue; it never starts or stops playback.
|
|
348
60
|
|
|
349
|
-
|
|
61
|
+
**How it learns your taste:** from your NetEase likes, and from songs you hear through. A song the DJ picked counts only once you've listened past the skip window, so its own picks can't teach it what you like.
|
|
350
62
|
|
|
351
|
-
**
|
|
352
|
-
panel: a provider picker, a model picker, and three buttons.
|
|
63
|
+
**Where it looks:** songs similar to what you've heard and liked, personal FM and liked songs you haven't heard in three days (when signed in), the daily recommendations, new songs, and the four main charts. Signed in, the charts and new songs get fewer slots and your own sources more. Each source is cached for hours and sampled, so batches vary; requests to NetEase are spaced out rather than sent in a burst.
|
|
353
64
|
|
|
354
|
-
|
|
355
|
-
|---|---|
|
|
356
|
-
| **保存 Save** | Applies the pair immediately and persists it in `session.json` |
|
|
357
|
-
| **测试 Test** | Runs one throwaway plan (nothing is queued) and reports the route it used, the track it would have picked, and — on failure — exactly why |
|
|
358
|
-
| **回退 Revert** | Clears the saved choice so the profile patch applies again |
|
|
65
|
+
**Boosts.** Want more songs like the one playing for a while, or fewer, without a lasting like or dislike? Press **▲** (more like this) or **▼** (fewer like this) beside the song title. A boost lasts an hour, then expires on its own. While the DJ is on, **▲** also queues a few similar songs right after the current one, and **▼** takes the DJ's upcoming picks that are like it out of the queue (songs you queued yourself stay). Active boosts are listed in the AI DJ card with their time left; press ✕ on one, or the filled arrow, to end it early. The agent can set them too, for any length from 5 minutes to 12 hours.
|
|
359
66
|
|
|
360
|
-
The
|
|
361
|
-
models. The catalogue is **advisory**: core resolution accepts unlisted ids, so
|
|
362
|
-
**其他… / Other…** reveals a text field for any id the route serves — which is
|
|
363
|
-
how you keep using a model the adapter's catalogue does not list.
|
|
67
|
+
**Mood brief.** Type a mood in the AI DJ card, such as `雨天 爵士` or `90s cantopop`. The DJ searches NetEase playlists for it. With a model available, the brief is first rewritten into Chinese search terms, once per brief.
|
|
364
68
|
|
|
365
|
-
|
|
69
|
+
**Who chooses:**
|
|
366
70
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
3. **discovery** — the first route, then its first catalogued model
|
|
71
|
+
- **Model tier:** a model picks from the candidates by your taste and the mood, and writes a one-line vibe. It calls the model directly; it is not an agent and starts no conversation.
|
|
72
|
+
- **Heuristic tier:** used when no model is available or a call fails. Candidates are scored by mood match, favourite artists, and your likes, dislikes and skips.
|
|
370
73
|
|
|
371
|
-
|
|
372
|
-
*自动 / auto*. Saving beats the patch deliberately; otherwise a stale patch pin
|
|
373
|
-
would silently override what you just picked. **回退 Revert** is how you hand
|
|
374
|
-
control back to the patch.
|
|
74
|
+
### Choosing the model
|
|
375
75
|
|
|
376
|
-
|
|
76
|
+
By default the DJ uses your session's default model. To use another, pick a provider and model in the player's **AI DJ 模型 / DJ model** panel (**测试 Test** checks it without touching the queue), or set it in your profile's `cordis.patch.yml`:
|
|
377
77
|
|
|
378
78
|
```yaml
|
|
379
79
|
- id: music
|
|
@@ -384,403 +84,38 @@ control back to the patch.
|
|
|
384
84
|
model: deepseek-v4.1-flash
|
|
385
85
|
```
|
|
386
86
|
|
|
387
|
-
|
|
388
|
-
adapter route — read them from the `llm-pi-ai` entry's `config.providers` (or
|
|
389
|
-
ask the agent for `ctx.llm.listProviders()`); `model` is any id that route
|
|
390
|
-
accepts.
|
|
391
|
-
|
|
392
|
-
**Pin it, or follow the session.** With both fields unset the DJ inherits
|
|
393
|
-
`agent-default-model` — the same selection the composer's model picker writes,
|
|
394
|
-
so it is the model the agent loop itself runs on — which is why "use my session
|
|
395
|
-
model" needs no configuration. Pinning `dj.provider`/`dj.model` curates on
|
|
396
|
-
something else instead, and pinning is what makes the two choices independent:
|
|
397
|
-
|
|
398
|
-
```yaml
|
|
399
|
-
- id: agent-default-model # the agent loop / session model
|
|
400
|
-
config: { provider: opencode-go, model: deepseek-v4.1-flash }
|
|
401
|
-
- id: music
|
|
402
|
-
config:
|
|
403
|
-
dj: # the DJ's own model, when you want a different one
|
|
404
|
-
provider: opencode-go
|
|
405
|
-
model: minimax-m3
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
Three things worth knowing:
|
|
409
|
-
|
|
410
|
-
- **`config` is replaced, not merged.** The loader assigns the whole object
|
|
411
|
-
(`entry.ts`: `this.options.config = value`), so if you also want, say,
|
|
412
|
-
`audioLevel`, keep every option in one block. Schema defaults fill the rest.
|
|
413
|
-
- **Discovery is the last resort, and its choice is arbitrary.** Only when
|
|
414
|
-
neither a pin nor `agent-default-model` exists does the DJ ask the mounted LLM
|
|
415
|
-
service for its routes (`listProviders()`), take the first, then take that
|
|
416
|
-
route's first catalogue entry. On this machine `opencode-go`'s catalogue is
|
|
417
|
-
`minimax-m3, deepseek-v4-flash, gpt-5.6-luna`, so discovery curates with
|
|
418
|
-
**MiniMax-M3** — not a recommendation, just the first row.
|
|
419
|
-
- **Partial pins are honoured.** A `provider` alone keeps that route and picks
|
|
420
|
-
its first catalogue model; a `model` alone keeps that model on the first
|
|
421
|
-
route.
|
|
422
|
-
|
|
423
|
-
Confirm it took effect:
|
|
424
|
-
|
|
425
|
-
| Where | What to look for |
|
|
426
|
-
|---|---|
|
|
427
|
-
| `/music/health` | `dj.model` is your pinned pair; `dj.modelSource` is `panel`, `config`, `agent-default` or `discovered`; `dj.resolvedFrom` is what the last plan actually used (`pin`, `agent-default`, `discovered`); `dj.sessionModel` is the deployment's own model; `dj.lastRoute` is the route that curated the last batch; `dj.sessionId` is the identity every call carries; `dj.modelError` is `null` once the tier works |
|
|
428
|
-
| Player, DJ status line | **AI DJ** plus the route (heuristic runs read **AI DJ (heuristic)**, and a declined tier prints the reason) |
|
|
429
|
-
| **测试 Test** in the player | Answers "does this route work?" in one click, without touching the queue |
|
|
430
|
-
| `music_dj` tool result | `AI DJ is on (model via opencode-go/deepseek-v4.1-flash)` |
|
|
431
|
-
|
|
432
|
-
**If the tier declines, `dj.modelError` says why** — the tier is non-fatal by
|
|
433
|
-
design, so without that field every cause looks the same. It reports
|
|
434
|
-
`no LLM service is mounted (ctx.get("llm") returned nothing)` when no adapter
|
|
435
|
-
service is present, names a half-configured pin (`opencode-go/?`), or carries
|
|
436
|
-
the provider's own failure (a `LlmError` code such as `NO_ADAPTER`,
|
|
437
|
-
`MISSING_CREDENTIAL`, `AUTH`, `RATE_LIMIT`). The heuristic tier covers that batch
|
|
438
|
-
either way.
|
|
439
|
-
|
|
440
|
-
**If a provider says your usage does not follow its conventions**, the first
|
|
441
|
-
thing to check is the route's identity, not the request: pi-ai adds
|
|
442
|
-
`x-opencode-session` only for its own catalog routes `opencode-go` and
|
|
443
|
-
`opencode`. A hand-declared route id that merely points at
|
|
444
|
-
`https://opencode.ai/zen/go/v1` gets no wrapper and therefore no header, with
|
|
445
|
-
nothing in the logs to say so — keep the catalog route name. For the same
|
|
446
|
-
reason, do not set `x-opencode-session` in a profile's `headers`: the adapter
|
|
447
|
-
lets a configured value win over the generated one, which would freeze a single
|
|
448
|
-
id across every conversation. What remains after that is entitlement rather
|
|
449
|
-
than convention — a plan that only permits its own client's traffic cannot be
|
|
450
|
-
satisfied by a header, only by delegating transport to that client.
|
|
451
|
-
|
|
452
|
-
To see the bytes rather than trust the reasoning, run the bundled probe, point a
|
|
453
|
-
route's `baseURL` at it for one plan, and read what actually leaves the process:
|
|
454
|
-
|
|
455
|
-
```powershell
|
|
456
|
-
npm run probe:headers # http://127.0.0.1:8787 -> https://opencode.ai
|
|
457
|
-
```
|
|
458
|
-
|
|
459
|
-
You should see `x-opencode-session` carrying the DJ's id, and
|
|
460
|
-
`user-agent: deepseek-harness/<version> (+…)` — attribution that must never be
|
|
461
|
-
replaced by a provider-shaped one. Take the `baseURL` back out afterwards.
|
|
462
|
-
|
|
463
|
-
Editing `config` recomposes the running host, but **the plugin module itself is
|
|
464
|
-
cached** — restart the harness for the new route to take effect. If the model
|
|
465
|
-
tier fails for any reason (no adapter, bad credentials, unparseable reply,
|
|
466
|
-
rate limit) the DJ logs a warning and falls back to the heuristic tier for that
|
|
467
|
-
batch; it never leaves the queue empty.
|
|
468
|
-
|
|
469
|
-
### Heuristic tier
|
|
470
|
-
|
|
471
|
-
Always available, used whenever the model tier is unavailable. Each candidate
|
|
472
|
-
scores:
|
|
473
|
-
|
|
474
|
-
| Signal | Weight |
|
|
475
|
-
|---|---|
|
|
476
|
-
| matches the mood brief (keyword search) | +3.0 |
|
|
477
|
-
| from personal FM | +1.0 |
|
|
478
|
-
| similar to the current or recent tracks | +0.6 |
|
|
479
|
-
| a rested like | +0.5 |
|
|
480
|
-
| per artist among the listener's most played (skipped plays excluded) | +2.2 |
|
|
481
|
-
| per artist shared with the current track | +1.4 |
|
|
482
|
-
| per artist play count in the last 60 plays, skips excluded | +0.15 each, capped at +1.0 |
|
|
483
|
-
| per artist skip among the last 150 plays | −0.6 each, capped at −2.4 |
|
|
484
|
-
| skipped once (twice excludes it) | −1.5 |
|
|
485
|
-
| VIP-only | −0.4 |
|
|
486
|
-
| jitter, so repeat plans differ | 0–0.8 |
|
|
487
|
-
|
|
488
|
-
The brief outweighs a favourite artist on purpose: it is the listener's explicit
|
|
489
|
-
ask, and without that weight a chart hit by a favourite would outrank every
|
|
490
|
-
track that matches it. The ranked list is then interleaved starting from the
|
|
491
|
-
track the batch is appended after, so no two adjacent tracks share an artist —
|
|
492
|
-
including the seam between the old queue and the new batch.
|
|
87
|
+
The player's choice wins over the profile; **回退 Revert** hands control back. If the DJ falls back to heuristics, the health page shows why in `dj.modelError` (see [Troubleshooting](#troubleshooting)).
|
|
493
88
|
|
|
494
89
|
## Configuration
|
|
495
90
|
|
|
496
|
-
|
|
497
|
-
add `config` to the inserted entry:
|
|
498
|
-
|
|
499
|
-
```yaml
|
|
500
|
-
- insert:
|
|
501
|
-
- id: music
|
|
502
|
-
name: '@doitian/dsh-music'
|
|
503
|
-
config:
|
|
504
|
-
audioLevel: exhigh # exhigh (320 kbps) | standard | higher | lossless
|
|
505
|
-
dataDir: D:\dsh-data\music # default $DSH_HOME/music
|
|
506
|
-
requestTimeoutMs: 15000
|
|
507
|
-
dj:
|
|
508
|
-
provider: opencode-go # enables the model tier
|
|
509
|
-
model: deepseek-v4.1-flash
|
|
510
|
-
sessionId: music-dj-mine # optional: pin the provider-visible identity
|
|
511
|
-
```
|
|
91
|
+
All fields are optional, under the plugin entry's `config` in your profile's `cordis.patch.yml`. The loader replaces `config` as a whole, so keep every option in one block.
|
|
512
92
|
|
|
513
93
|
| Field | Default | Meaning |
|
|
514
94
|
|---|---|---|
|
|
515
|
-
| `
|
|
516
|
-
| `dataDir` | `$DSH_HOME/music` | Where `session.json`
|
|
517
|
-
| `
|
|
518
|
-
| `
|
|
519
|
-
| `dj.provider` / `dj.model` | unset | Model route for the DJ's model tier — see [Choosing the model](#choosing-the-model). Unset, the tier follows `agent-default-model` and only then falls back to discovery; any failure falls back to heuristics. |
|
|
520
|
-
| `dj.sessionId` | minted, persisted | The identity every model call carries. Adapters map it onto the provider's per-conversation header. Pin it to control what a provider sees, or leave it unset and let the DJ mint one per install. |
|
|
95
|
+
| `audioLevel` | `exhigh` | Starting quality, until you pick one in the player |
|
|
96
|
+
| `dataDir` | `$DSH_HOME/music` | Where `session.json` lives |
|
|
97
|
+
| `requestTimeoutMs` | `15000` | NetEase request deadline |
|
|
98
|
+
| `dj.provider` / `dj.model` | session model | The DJ's model, as above |
|
|
521
99
|
|
|
522
|
-
|
|
523
|
-
threshold) are persisted in `session.json` and edited from the panel.
|
|
100
|
+
Batch size (`djBatchSize`, 5) and refill threshold (`djAutoExtendBelow`, 3) have no control in the player. Edit them in `session.json` while the harness is stopped.
|
|
524
101
|
|
|
525
|
-
##
|
|
102
|
+
## Troubleshooting
|
|
526
103
|
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
│ (keeps playing while you are in a session)
|
|
532
|
-
└─ sidebar "音乐 Music" ── iframe ──▶ /music/panel (player UI, no audio)
|
|
533
|
-
│ fetch (same origin)
|
|
534
|
-
▼
|
|
535
|
-
/music/api/* (JSON)
|
|
536
|
-
/music/stream/<id> (audio bytes)
|
|
537
|
-
│
|
|
538
|
-
host plugin ───────┘
|
|
539
|
-
├─ lib/netease.js NetEase web API (no weapi encryption)
|
|
540
|
-
├─ lib/session.js cookie store + QR login state machine
|
|
541
|
-
├─ lib/state.js queue, cursor, transport revisions
|
|
542
|
-
├─ lib/dj.js candidate pool + model/heuristic tiers
|
|
543
|
-
├─ lib/cache.js source cache, pool sampling, request pacing
|
|
544
|
-
├─ lib/likes.js the account's like state, cached
|
|
545
|
-
└─ lib/router.js JSON API, HTML, Range-capable audio proxy
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
Four design notes:
|
|
549
|
-
|
|
550
|
-
- **Audio is proxied, not redirected.** CDN URLs expire after 20 minutes and
|
|
551
|
-
need the session cookie at *resolution* time, so the host resolves and streams
|
|
552
|
-
the bytes (cache 15 min, `Range` forwarded upstream so seeking works). It also
|
|
553
|
-
keeps playback same-origin, avoiding mixed-content and CORS entirely.
|
|
554
|
-
- **Playback lives in the shell document, not in the page.** The layout renders
|
|
555
|
-
only the **active** `main` slot entry —
|
|
556
|
-
`renderSlot('main', {}, { entryKey: activePanelId ?? 'conversation' })` — so
|
|
557
|
-
opening a Session unmounts the Music page and discards its document. An
|
|
558
|
-
`<audio>` owned by that page would stop the music, which is exactly what
|
|
559
|
-
happened before contract 2. The engine is created on the client plugin's own
|
|
560
|
-
lifetime, survives every panel switch, and the page is a remote control:
|
|
561
|
-
`window.__dshMusicEngine.sync()` applies a command without waiting for the
|
|
562
|
-
next poll. A `panelContract` value on `/music/health` keeps a half-updated
|
|
563
|
-
browser (new bundle, old host) from playing every track twice.
|
|
564
|
-
- **The host owns the desired state; the engine owns the audio element.** They
|
|
565
|
-
reconcile through `rev` / `transportRev` counters, so agent tools, the page,
|
|
566
|
-
and the DJ all drive one state machine instead of three.
|
|
567
|
-
- **The client half is hand-written.** `lib/client.js` is a plain
|
|
568
|
-
`window.__ModuleLoader__` bundle using only baseline `react`, so there is no
|
|
569
|
-
tsdown/Vite step. It registers the sidebar row (`sidebar.panellist`, a list
|
|
570
|
-
slot) and the page (`main`, the layout's keyed slot) with the same id, and
|
|
571
|
-
`ctx.slots.inject` waits for those slots to be declared.
|
|
572
|
-
|
|
573
|
-
## Security notes
|
|
574
|
-
|
|
575
|
-
- The `/music` route prefix is registered on the bare HTTP server, which owns no
|
|
576
|
-
authentication of its own. Anyone who can reach the port can browse the
|
|
577
|
-
library, stream audio, and **change the account's likes** — `POST
|
|
578
|
-
/music/api/taste` is the panel's own control, so it is a real write to the
|
|
579
|
-
NetEase account. The route is loopback-only in the shipped composition. It
|
|
580
|
-
exposes no credentials — only search results, the queue, the like state, and
|
|
581
|
-
audio bytes.
|
|
582
|
-
- The NetEase cookie lives in `$DSH_HOME/music/session.json` in plain text, the
|
|
583
|
-
same posture as the rest of the profile's session data. `music_login` with
|
|
584
|
-
`set_cookie` accepts a pasted `MUSIC_U`, and the value is never returned by any
|
|
585
|
-
endpoint.
|
|
586
|
-
|
|
587
|
-
### Diagnostics
|
|
588
|
-
|
|
589
|
-
`GET /music/health` is unauthenticated and answers with the facts worth having
|
|
590
|
-
when something looks wrong:
|
|
591
|
-
|
|
592
|
-
```json
|
|
593
|
-
{
|
|
594
|
-
"ok": true,
|
|
595
|
-
"prefix": "/music",
|
|
596
|
-
"panelContract": 2,
|
|
597
|
-
"authenticated": true,
|
|
598
|
-
"account": { "nickname": "…", "vip": true },
|
|
599
|
-
"playing": false,
|
|
600
|
-
"queued": 0,
|
|
601
|
-
"tools": ["music_search", "music_play", "music_queue", "music_control",
|
|
602
|
-
"music_dj", "music_now_playing", "music_login"],
|
|
603
|
-
"dj": { "enabled": false, "model": null, "lastRoute": null,
|
|
604
|
-
"modelError": null, "lastPlanAt": null, "error": null },
|
|
605
|
-
"likes": { "cached": 12, "pending": 0, "error": null },
|
|
606
|
-
"dataDir": "C:\\Users\\…\\.dsh\\music",
|
|
607
|
-
"session": { "authenticated": true, "nickname": "…", "vip": true },
|
|
608
|
-
"uptimeMs": 123456
|
|
609
|
-
}
|
|
610
|
-
```
|
|
104
|
+
- **No sound:** Chromium blocks audio until you interact with the page. Click anywhere in the window once.
|
|
105
|
+
- **The DJ isn't using the model:** check `dj.modelError` on the health page.
|
|
106
|
+
- **A provider says your usage breaks its conventions:** use the provider's catalog route name (for example `opencode-go`), and don't set `x-opencode-session` in the profile's `headers`.
|
|
107
|
+
- **Changed a setting in the profile and nothing happened:** restart the app.
|
|
611
108
|
|
|
612
|
-
`
|
|
613
|
-
that failed to register would otherwise leave a route that answers normally.
|
|
614
|
-
Seeing all seven names is what proves startup completed. `panelContract` is the
|
|
615
|
-
page/engine boundary the browser half checks before it starts playback. `likes`
|
|
616
|
-
is the cache behind the hearts: `cached` is how many answers it holds, and
|
|
617
|
-
`error` names why a check produced none — an anonymous session never asks, so
|
|
618
|
-
both stay empty.
|
|
109
|
+
**The health page** is `/music/health` on the Harness's own address — for example `http://127.0.0.1:<port>/music/health`, using the port the Harness window is served on. It reports the account, the queue, the DJ's model state, and which tools registered.
|
|
619
110
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
Chromium refuses to start audio until the page has been **interacted with**, and
|
|
623
|
-
the plugin's desired state can say "playing" long before that — the agent
|
|
624
|
-
queued something, or the DJ refilled the queue while the page was loading. The
|
|
625
|
-
player then shows:
|
|
626
|
-
|
|
627
|
-
> 浏览器需要你先与页面交互一次才会播放声音 / Chromium needs one interaction with this window before it will play audio
|
|
628
|
-
|
|
629
|
-
**Click the button, or anywhere in the window.** That one gesture grants sticky
|
|
630
|
-
activation for the rest of the page's life, after which agent- and DJ-initiated
|
|
631
|
-
playback works without asking again. Typing in the chat counts too.
|
|
632
|
-
|
|
633
|
-
The engine retries on every 500 ms poll, so recovery is automatic — and it must
|
|
634
|
-
be, because a refused `play()` does not change the transport revision. Gating
|
|
635
|
-
the retry behind that revision (an earlier bug) left the music stopped for good,
|
|
636
|
-
with the hint showing and pressing it doing nothing.
|
|
637
|
-
|
|
638
|
-
### Who owns the `<audio>` element
|
|
639
|
-
|
|
640
|
-
Normally the client plugin's **engine in the shell document**, so playback
|
|
641
|
-
survives opening a session (the layout renders only the *active* panel). But the
|
|
642
|
-
player page is re-read from disk on every plugin mount, while the browser bundle
|
|
643
|
-
it pairs with is pinned to its own revision — so the two can disagree. When they
|
|
644
|
-
do, `GET /music/health` will not advertise the matching `panelContract`, the
|
|
645
|
-
engine declares itself inert, and **the page owns the audio element itself**.
|
|
646
|
-
That is the older behaviour: it plays normally, it just stops when you open a
|
|
647
|
-
session. Exactly one transport ever owns playback; the unusable one is stood
|
|
648
|
-
down first. A restart brings both halves back into agreement.
|
|
649
|
-
|
|
650
|
-
## Development
|
|
651
|
-
|
|
652
|
-
```powershell
|
|
653
|
-
npm run check # node --check on every module
|
|
654
|
-
npm test # 154 deterministic tests: pure, like state, DJ, browser half
|
|
655
|
-
npm run test:live # 34 integration tests against the live NetEase API
|
|
656
|
-
npm run test:all # both
|
|
657
|
-
```
|
|
658
|
-
|
|
659
|
-
The split matters for CI. `npm test` never touches the network, so it is what
|
|
660
|
-
runs on every push and gates a release. `npm run test:live` drives the real API,
|
|
661
|
-
and **GitHub's runners cannot reach it** — from a US runner
|
|
662
|
-
`/api/search/get/web` answers in ~350 ms with an empty result set, so its first
|
|
663
|
-
assertion fails on a network condition rather than a regression. It therefore
|
|
664
|
-
lives in `.github/workflows/live.yml` on manual dispatch only, and the
|
|
665
|
-
authoritative run is local, before a release. `MUSIC_OFFLINE=1` skips the
|
|
666
|
-
network cases inside it.
|
|
667
|
-
|
|
668
|
-
Or run one file directly:
|
|
669
|
-
|
|
670
|
-
```powershell
|
|
671
|
-
node test/netease.test.mjs # 34 pure: normalisation, quality ladder, likes, cookies, taste, skips, player state
|
|
672
|
-
node test/cache.test.mjs # 10 source cache: lifetimes, shared loads, sampling, pacing
|
|
673
|
-
node test/likes.test.mjs # 12 like-state cache: what counts as an answer, refusals, batching, writes
|
|
674
|
-
node test/dj.test.mjs # 60 AI DJ: model call identity, route resolution, failure reporting, curation, skips, pool sources, caching, brief rewriting, queue invariants
|
|
675
|
-
node test/client.test.mjs # 38 browser half: the engine against a fake DOM, and the page it pairs with
|
|
676
|
-
node test/host.test.mjs # 34 integration: routes, streaming, curation, quality, taste, skips
|
|
677
|
-
```
|
|
111
|
+
## Security
|
|
678
112
|
|
|
679
|
-
The
|
|
680
|
-
|
|
681
|
-
pinned-route happy path, both chunk spellings (`type`/`kind`), index filtering,
|
|
682
|
-
prose-wrapped JSON, the session identity every call must carry, inheritance from
|
|
683
|
-
the session model, discovery, and every fallback are covered without a provider.
|
|
684
|
-
|
|
685
|
-
The integration tests mount the plugin against stand-in `tools`/`webServer`
|
|
686
|
-
services and drive the captured route over a real `node:http` server, so they
|
|
687
|
-
exercise the same path the browser takes — including a real `Range` request
|
|
688
|
-
against the NetEase CDN and a real AI DJ plan. Because they talk to a live
|
|
689
|
-
third-party API, an occasional failure there can be the network rather than the
|
|
690
|
-
code; re-run before investigating.
|
|
691
|
-
|
|
692
|
-
The browser-half tests execute `lib/client.js` for real against a minimal fake
|
|
693
|
-
DOM (fake `window`, `document`, `fetch`), which is how the central property is
|
|
694
|
-
proven: **the engine creates and drives the `<audio>` element with no React
|
|
695
|
-
component ever rendered**, so playback cannot depend on the Music page being
|
|
696
|
-
mounted. They also cover the seek handshake, failure reporting, disposal, and
|
|
697
|
-
the contract handshake.
|
|
698
|
-
|
|
699
|
-
The same fake DOM boots `lib/panel.html` itself, with an engine that reports
|
|
700
|
-
`playback: true` — the shell document owns the audio element. That is the case
|
|
701
|
-
where the page must fetch everything it renders on its own: lyrics used to be
|
|
702
|
-
requested only from the local fallback transport's `applySource`, so with the
|
|
703
|
-
engine playing the pane stayed empty for every track. Three tests hold the
|
|
704
|
-
line: the rendered track is asked for, one fetch per track rather than one per
|
|
705
|
-
poll, and a track change replaces the pane. Two more cover the pane's shape: it
|
|
706
|
-
is capped to a few lines, collapses to its header on demand, and remembers that
|
|
707
|
-
choice across loads — while still fetching the lines, so expanding is instant.
|
|
708
|
-
|
|
709
|
-
`npm test` runs the five deterministic files in sequence (`npm run test:all`
|
|
710
|
-
adds the live one), deliberately **not** `node --test <dir>`: the directory form forks one child process per file, which
|
|
711
|
-
is blocked in sandboxed environments.
|
|
712
|
-
|
|
713
|
-
### Reloading a change
|
|
714
|
-
|
|
715
|
-
- **Profile configuration** changes (bundle selection, `cordis.patch.yml`)
|
|
716
|
-
recompose the running host: the loader re-reads the layers and mounts or
|
|
717
|
-
unmounts the affected entry. Adding the bundle to `dsh.profile.bundles` and
|
|
718
|
-
touching `cordis.patch.yml` was enough to load the plugin into an already
|
|
719
|
-
running host.
|
|
720
|
-
- **Plugin source** changes need a **process restart**. A disable/enable
|
|
721
|
-
round-trip does remount the entry (the route genuinely goes away and comes
|
|
722
|
-
back), but Node caches the ESM module, so the remounted entry runs the *old*
|
|
723
|
-
code. Treat `lib/*.js` and `lib/panel.html` edits as restart-required.
|
|
724
|
-
- **Agent tools** register on the host, so they appear in **new** agent
|
|
725
|
-
sessions. A session that was already running keeps the tool list it started
|
|
726
|
-
with.
|
|
727
|
-
|
|
728
|
-
`lib/vendor/qrcode.js` is the MIT-licensed
|
|
729
|
-
[qrcode-generator](https://github.com/kazuhikoarase/qrcode-generator) by
|
|
730
|
-
Kazuhiko Arase, vendored so QR sign-in needs no network call or build step.
|
|
731
|
-
|
|
732
|
-
### Releasing
|
|
733
|
-
|
|
734
|
-
Releases are cut from GitHub and published by the `publish` workflow with **npm
|
|
735
|
-
trusted publishing (OIDC)**. There is no `NPM_TOKEN` secret and no
|
|
736
|
-
`NODE_AUTH_TOKEN` in the repository, and adding one would disable the OIDC
|
|
737
|
-
exchange and break publishing.
|
|
738
|
-
|
|
739
|
-
1. Bump `version` in `package.json`, commit, and push.
|
|
740
|
-
2. Create a GitHub release whose tag is `v<version>` — `v0.1.2` for `0.1.2` —
|
|
741
|
-
pointing at that commit.
|
|
742
|
-
|
|
743
|
-
The workflow runs `npm run check`, the deterministic suites, asserts the tag
|
|
744
|
-
matches `package.json`, and publishes. A tag push alone publishes nothing: the
|
|
745
|
-
trigger is `release: published`.
|
|
746
|
-
|
|
747
|
-
Two timings look like failures and are not:
|
|
748
|
-
|
|
749
|
-
- **A green job is not yet a live version.** The registry records a
|
|
750
|
-
`0.0.0-stage` placeholder first and reports the package as *being processed*;
|
|
751
|
-
the version becomes installable roughly a minute later. Inside that window the
|
|
752
|
-
packument still answers `404`, and publishing the same version from a second
|
|
753
|
-
place is refused with `409 Cannot publish over previously staged version`.
|
|
754
|
-
- **Registry reads can lag the publish**, so an `npm view` run immediately
|
|
755
|
-
afterwards may still say `404`. Wait a minute, or read it from CI instead.
|
|
756
|
-
|
|
757
|
-
Versions published this way carry a SLSA provenance attestation naming the
|
|
758
|
-
workflow, tag, and commit — `npm view @doitian/dsh-music@<version> dist.attestations`.
|
|
759
|
-
`0.1.0` predates the trusted publisher: it was published by hand and has none.
|
|
113
|
+
- The `/music` routes have no authentication of their own; they are served on loopback only. Anyone who can reach the port can browse, stream, and change the account's likes.
|
|
114
|
+
- The NetEase cookie is stored in plain text in `session.json` and is never returned by any endpoint.
|
|
760
115
|
|
|
761
116
|
## Known limitations
|
|
762
117
|
|
|
763
|
-
-
|
|
764
|
-
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
refusal (`403` plus a reason) rather than retrying.
|
|
768
|
-
- **No `weapi`/`eapi` encryption**, so scrobbling and playlist writes are not
|
|
769
|
-
implemented. Liking a track needs none of it — see
|
|
770
|
-
[Likes and taste](#likes-and-taste) — but a *dislike* stays local, because
|
|
771
|
-
there is no plain endpoint for one.
|
|
772
|
-
- **`apiPrefix` must stay `music`** unless `BASE` in `lib/client.js` is changed
|
|
773
|
-
to match.
|
|
774
|
-
- **The DJ's model tier is covered against stub contracts, not a live
|
|
775
|
-
provider** — request building, the session identity, route resolution, both
|
|
776
|
-
chunk spellings, index filtering and every fallback are tested, but a real
|
|
777
|
-
end-to-end model call has not been observed here. The heuristic tier is what
|
|
778
|
-
the live runs exercised.
|
|
779
|
-
- **The identity only becomes a header on the catalog routes that define one.**
|
|
780
|
-
pi-ai adds `x-opencode-session` for its own `opencode-go`/`opencode` routes. A
|
|
781
|
-
hand-declared route id pointing at the same endpoint gets no wrapper, so the
|
|
782
|
-
header is simply absent — keep the catalog route name, and never pin
|
|
783
|
-
`x-opencode-session` in a profile's `headers` (a configured value wins over
|
|
784
|
-
the generated one and freezes a single id for every conversation).
|
|
785
|
-
- **Chromium autoplay policy** may block playback the agent starts before the
|
|
786
|
-
user has interacted with the page; the panel then shows a *click to play* hint.
|
|
118
|
+
- VIP tracks don't play while signed out, and some tracks are sold per album, so they don't play even with VIP (for example 晴天, `id 186016`).
|
|
119
|
+
- Without NetEase's encrypted API there is no scrobbling, no playlist editing and no heartbeat mode (心动模式), and a dislike stays local.
|
|
120
|
+
- The DJ's model mode hasn't yet been tested end to end with a real model. If it misbehaves, `dj.modelError` says why, and the DJ keeps working without it.
|
|
121
|
+
- Only your newest 500 likes are offered back as candidates.
|