@audiofool/moondog 0.4.0-beta.3 → 0.4.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +19 -8
  2. package/package.json +1 -1
  3. package/scripts/moondog.mjs +95 -103
  4. package/src/core/apple-library-source-status.mjs +64 -18
  5. package/src/core/apple-projection-domain-services.mjs +63 -52
  6. package/src/core/capability-catalog.mjs +18 -2
  7. package/src/core/import-source-history.mjs +28 -0
  8. package/src/core/library-draft.mjs +16 -0
  9. package/src/core/library-names.mjs +12 -0
  10. package/src/core/library-store.mjs +361 -23
  11. package/src/core/listener-avoids.mjs +31 -0
  12. package/src/core/listening-action.mjs +41 -0
  13. package/src/core/listening-moment.mjs +67 -0
  14. package/src/core/listening-now.mjs +69 -28
  15. package/src/core/listening-profile-domain-services.mjs +28 -18
  16. package/src/core/listening-scope.mjs +119 -0
  17. package/src/core/moondog-application.mjs +1003 -267
  18. package/src/core/play-follower.mjs +73 -37
  19. package/src/core/portable-playlist.mjs +125 -0
  20. package/src/core/profile-discovery-draft.mjs +35 -0
  21. package/src/core/track-title.mjs +70 -4
  22. package/src/i18n/import-history.mjs +647 -0
  23. package/src/i18n/messages/de.mjs +3 -3
  24. package/src/i18n/messages/en.mjs +3 -3
  25. package/src/i18n/messages/es.mjs +3 -3
  26. package/src/i18n/messages/fr.mjs +3 -3
  27. package/src/i18n/messages/it.mjs +3 -3
  28. package/src/i18n/messages/ja.mjs +3 -3
  29. package/src/i18n/messages/ko.mjs +3 -3
  30. package/src/i18n/messages/pt.mjs +3 -3
  31. package/src/i18n/messages/zh-Hant.mjs +3 -3
  32. package/src/i18n/messages/zh.mjs +3 -3
  33. package/src/i18n/screen/es.mjs +89 -26
  34. package/src/i18n/screen/ja.mjs +88 -25
  35. package/src/i18n/screen/pt.mjs +89 -26
  36. package/src/i18n/screen/zh.mjs +88 -25
  37. package/src/importers/apple-music-library/import-batch.mjs +64 -32
  38. package/src/importers/apple-music-library/normalize.mjs +36 -6
  39. package/src/importers/apple-music-library/save-time.mjs +17 -0
  40. package/src/importers/zip-reader.mjs +24 -2
  41. package/src/integrations/apple-music/catalog-playlist-reader.mjs +111 -0
  42. package/src/integrations/apple-music/catalog.mjs +84 -25
  43. package/src/integrations/apple-music/song-id.mjs +13 -0
  44. package/src/integrations/apple-music/terminal-preview-player.mjs +154 -44
  45. package/src/integrations/listenbrainz/history-file.mjs +63 -35
  46. package/src/integrations/netease/ncm-cli-player.mjs +355 -68
  47. package/src/integrations/netease/queue-occurrence.mjs +138 -0
  48. package/src/integrations/playlist-links.mjs +93 -30
  49. package/src/integrations/public-playlists.mjs +21 -15
  50. package/src/integrations/spotify/account-data-history.mjs +9 -10
  51. package/src/integrations/spotify/account-data-profile.mjs +1 -0
  52. package/src/integrations/spotify/extended-streaming-history.mjs +57 -52
  53. package/src/integrations/spotify/history-archive.mjs +8 -18
  54. package/src/integrations/spotify/library-snapshot.mjs +2 -1
  55. package/src/integrations/spotify/service.mjs +29 -11
  56. package/src/integrations/spotify/web-api-client.mjs +2 -2
  57. package/src/integrations/stable-audio/local-generator.mjs +13 -5
  58. package/src/integrations/youtube-music/takeout.mjs +12 -8
  59. package/src/memory/local-memory-store.mjs +479 -27
  60. package/src/memory/reflection-worker.mjs +1 -0
  61. package/src/profile/apple-library-import.mjs +56 -2
  62. package/src/profile/history-import.mjs +58 -27
  63. package/src/profile/listener-corrections.mjs +2 -4
  64. package/src/profile/listener-profile-build.mjs +128 -45
  65. package/src/profile/listener-profile-store.mjs +25 -4
  66. package/src/profile/listener-profile-verification.mjs +11 -5
  67. package/src/profile/listener-profile-worker.mjs +24 -8
  68. package/src/profile/listening-history-store.mjs +944 -367
  69. package/src/profile/listening-profile-projection.mjs +123 -156
  70. package/src/profile/local-file-import.mjs +172 -0
  71. package/src/profile/moondog-suggestions.mjs +40 -11
  72. package/src/profile/profile-exploration.mjs +36 -6
  73. package/src/profile/recorded-measures.mjs +5 -0
  74. package/src/profile/spotify-archive-taste.mjs +41 -65
  75. package/src/runtime/pi/agent-runtime.mjs +360 -215
  76. package/src/runtime/pi/custom-endpoints.mjs +30 -8
  77. package/src/runtime/pi/memory-agent-runtime.mjs +43 -3
  78. package/src/runtime/pi/playback-rules.mjs +100 -0
  79. package/src/runtime/pi/profile-build-runtime.mjs +81 -24
  80. package/src/surfaces/cli/brand-components.mjs +9 -6
  81. package/src/surfaces/cli/command-completions.mjs +8 -1
  82. package/src/surfaces/cli/format-output.mjs +207 -34
  83. package/src/surfaces/cli/history-import-view.mjs +130 -21
  84. package/src/surfaces/cli/listenbrainz-command.mjs +7 -2
  85. package/src/surfaces/cli/listener-profile-command.mjs +67 -10
  86. package/src/surfaces/cli/listening-menu.mjs +3 -0
  87. package/src/surfaces/cli/profile-command.mjs +1 -0
  88. package/src/surfaces/cli/spotify-command.mjs +17 -25
  89. package/src/surfaces/cli/taste-period.mjs +22 -0
  90. package/src/surfaces/cli/taste-profile-model.mjs +52 -32
  91. package/src/surfaces/cli/tui.mjs +557 -170
  92. package/src/surfaces/html/tasteprint.mjs +181 -93
  93. package/src/surfaces/import-source-history.mjs +80 -0
@@ -1,8 +1,17 @@
1
- import { sanitizeTerminalText } from "./format-output.mjs";
1
+ import { recentListeningPeriod, recordedHistoryThrough } from "./taste-period.mjs";
2
+ import { utcDay } from "../import-source-history.mjs";
3
+ import { collectionCoverageLines, profiledListeningMetrics, sanitizeTerminalText } from "./format-output.mjs";
2
4
  import { intlLocale, screenTranslator } from "../../i18n/index.mjs";
3
5
 
4
6
  const MAX_ITEMS_PER_SOURCE = 10;
5
7
 
8
+ // The listener can review every choice they've saved. Listening rankings and agent summaries stay bounded.
9
+ export async function readTasteReviewProfile(application) {
10
+ const profile = await application.getProfileSummary({ maxItems: MAX_ITEMS_PER_SOURCE }, { includeReviewTracks: true });
11
+ const reviewChoices = application.tasteReviewChoices?.();
12
+ return Array.isArray(reviewChoices) ? { ...profile, reviewChoices } : profile;
13
+ }
14
+
6
15
  function items(value) {
7
16
  return Array.isArray(value) ? value.slice(0, MAX_ITEMS_PER_SOURCE) : [];
8
17
  }
@@ -39,6 +48,15 @@ function date(value) {
39
48
  Number.isFinite(Date.parse(value)) ? inline(value).slice(0, 10) : "";
40
49
  }
41
50
 
51
+ function playsInMultipleYears(item) {
52
+ const first = utcDay(item?.first_played_at);
53
+ const last = utcDay(item?.last_played_at);
54
+ if (first && last) return first.slice(0, 4) < last.slice(0, 4);
55
+ const years = Array.isArray(item?.yearly_plays) ? item.yearly_plays : [];
56
+ const played = years.filter(row => Number.isInteger(row?.year) && Number.isInteger(row.plays) && row.plays > 0);
57
+ return new Set(played.map(row => row.year)).size > 1;
58
+ }
59
+
42
60
  function targetFor(item, kind) {
43
61
  const label = kind === "artist" ? item?.name ?? item?.label : item?.label;
44
62
  if (!inline(label) || !["artist", "track"].includes(kind)) return null;
@@ -83,32 +101,27 @@ function itemMetrics(item, tr) {
83
101
  return values;
84
102
  }
85
103
 
86
- function overview(profile, tr) {
104
+ function overview(profile, tr, { playCount, timedCount, hours }) {
87
105
  const coverage = profile?.coverage ?? {};
88
106
  const lines = [];
89
- const durationUnavailable = coverage.effective_listening_events > 0 && coverage.events_with_played_duration === 0;
90
- const hours = durationUnavailable ? undefined : amount(coverage.listening_hours, tr.locale);
107
+ const durationUnavailable = playCount > 0 && timedCount === 0;
91
108
  const listening = [
92
- ...(count(coverage.effective_listening_events) !== undefined ? [tr.n(coverage.effective_listening_events, "{count} play", "{count} plays")] : []),
93
- ...(hours !== undefined ? [tr("{hours} h", { hours })] : []),
109
+ ...(count(playCount) !== undefined ? [tr.n(playCount, "{count} play", "{count} plays")] : []),
110
+ ...(hours ? [hours] : []),
94
111
  ...(count(coverage.listening_tracks) !== undefined ? [tr.n(coverage.listening_tracks, "{count} track", "{count} tracks")] : []),
95
112
  ];
96
113
  if (durationUnavailable) listening.push(tr("listening time unknown"));
97
- if (listening.length && !(coverage.effective_listening_events === 0 && (coverage.tracks_observed > 0 || coverage.collection_tracks > 0))) {
114
+ const collections = collectionCoverageLines(coverage, tr);
115
+ if (listening.length && !(playCount === 0 && collections.length)) {
98
116
  lines.push(listening.join(" · "));
99
117
  }
100
- if (Number.isSafeInteger(coverage.tracks_observed) && coverage.tracks_observed > 0) {
101
- const loved = count(coverage.loved_or_favorited);
102
- const tracks = tr.n(coverage.tracks_observed, "{count} track", "{count} tracks");
103
- lines.push(loved === undefined ? tr("Apple Music library: {tracks}", { tracks })
104
- : tr("Apple Music library: {tracks} · {loved} loved", { tracks, loved: tr.number(coverage.loved_or_favorited) }));
118
+ lines.push(...collections);
119
+ if (timedCount > 0 && timedCount < playCount) {
120
+ lines.push(tr("Listening time is known for {count} of those plays", { count: tr.number(timedCount) }));
105
121
  }
122
+ const privatePlays = profile?.listening_behavior?.context?.incognito_events_excluded;
123
+ if (privatePlays > 0) lines.push(tr.n(privatePlays, "{count} private-session play left out", "{count} private-session plays left out"));
106
124
  const source = profile?.listening_source ?? {};
107
- const collections = items(coverage.collection_sources).filter((collection) => collection.tracks > 0);
108
- if (collections.length > 1) lines.push(tr("{songs} across {count} services", { songs: tr.n(coverage.collection_tracks, "{count} song", "{count} songs"), count: collections.length }));
109
- for (const collection of collections) {
110
- if (collection.tracks > 0) lines.push(`${inline(collection.label)}: ${tr.n(collection.tracks, "{count} song", "{count} songs")}`);
111
- }
112
125
  const providers = items(source.providers).map(inline).filter(Boolean).map((provider) => ({
113
126
  spotify: "Spotify",
114
127
  listenbrainz: "ListenBrainz",
@@ -149,20 +162,23 @@ function explicitKind(item) {
149
162
 
150
163
  /** Build a private, bounded review view from structured profile evidence. */
151
164
  export function buildTasteProfileModel(profile = {}, tr = screenTranslator("en")) {
152
- const metrics = (item) => itemMetrics(profile.coverage?.events_with_played_duration === 0
165
+ const listening = profiledListeningMetrics(profile, tr);
166
+ const metrics = (item) => itemMetrics(listening.timedCount === 0
153
167
  ? { ...item, listening_minutes: undefined } : item, tr);
154
168
  const withDetails = (source, details) => details.length ? tr("{source}: {details}", { source, details: details.join(" · ") }) : source;
155
169
  const subjects = new Map();
156
- const seenDetails = new Map();
170
+ const appleLibrary = tr("In your Apple Music library");
171
+ const applePlayCount = tr("Apple Music play count");
157
172
  const assertions = profile?.listener_assertions ?? {};
158
173
  const behavior = profile?.listening_behavior ?? {};
159
174
  const curated = profile?.curated_preferences ?? {};
160
175
 
161
- function add(item, kind, source, detail, { assertion = false } = {}) {
176
+ function add(item, kind, source, detail, { assertion = false, membership = false } = {}) {
162
177
  const target = targetFor(item, kind);
163
178
  if (!target) return;
164
179
  const key = subjectKey(target);
165
180
  let subject = subjects.get(key);
181
+ if (membership && subject?.evidence.some(entry => entry.source === appleLibrary || entry.source === applePlayCount)) return;
166
182
  if (!subject) {
167
183
  subject = {
168
184
  key,
@@ -174,9 +190,8 @@ export function buildTasteProfileModel(profile = {}, tr = screenTranslator("en")
174
190
  evidence: [],
175
191
  };
176
192
  subjects.set(key, subject);
177
- seenDetails.set(key, new Set());
178
193
  }
179
- const evidenceId = identifier(item?.evidence_id);
194
+ const evidenceId = identifier(item?.evidence_id ?? (assertion ? item?.correction_id : null));
180
195
  if (evidenceId && !subject.evidence.some((evidence) => evidence.id === evidenceId)) {
181
196
  subject.evidence.push({ id: evidenceId, source: inline(source) });
182
197
  subject.evidenceId ??= evidenceId;
@@ -187,13 +202,12 @@ export function buildTasteProfileModel(profile = {}, tr = screenTranslator("en")
187
202
  if (correctionId) subject.correctionId = correctionId;
188
203
  }
189
204
  const line = inline(detail);
190
- if (line && !seenDetails.get(key).has(line)) {
205
+ if (line && !subject.detailLines.includes(line)) {
191
206
  subject.detailLines.push(line);
192
- seenDetails.get(key).add(line);
193
207
  }
194
208
  }
195
209
 
196
- const activeAssertions = [
210
+ const activeAssertions = profile?.reviewChoices ?? [
197
211
  ...items(assertions.active),
198
212
  ...items(assertions.preferences),
199
213
  ...items(assertions.avoids),
@@ -206,24 +220,26 @@ export function buildTasteProfileModel(profile = {}, tr = screenTranslator("en")
206
220
  const key = subjectKey(target);
207
221
  if (seenAssertions.has(key)) continue;
208
222
  seenAssertions.add(key);
209
- const when = date(item.asserted_at);
223
+ const when = date(item.asserted_at ?? item.occurred_at);
210
224
  const note = inline(item.note);
211
225
  add(item, item.entity_type, tr("Your choice"), [item.stance === "like" ? tr("You said: I like this") : tr("You said: keep this out"),
212
226
  ...(when ? [when] : []), ...(note ? [`"${note}"`] : [])].join(" · "), { assertion: true });
213
227
  }
214
228
 
215
- const recentDays = count(behavior.context?.recent_window_days);
216
- const recentSource = recentDays ? tr("Lately (last {count} days)", { count: recentDays }) : tr("Lately");
229
+ const recentSource = `${tr("Lately")} · ${recentListeningPeriod(profile, tr)}`;
217
230
  for (const [field, kind, source] of [
218
231
  ["repeat_tracks", "track", tr("Most played")],
219
- ["enduring_artists", "artist", tr("Across the years")],
232
+ ["enduring_artists", "artist", tr("All recorded listening")],
220
233
  ["recent_tracks", "track", recentSource],
221
234
  ["recent_artists", "artist", recentSource],
222
- ["rediscovery_tracks", "track", tr("Gone quiet")],
235
+ ["rediscovery_tracks", "track", `${tr("Gone quiet")} · ${recordedHistoryThrough(profile, tr)}`],
223
236
  ["historical_return_tracks", "track", tr("Came back")],
224
237
  ["back_to_back_tracks", "track", tr("Played in a row")],
225
238
  ]) {
226
- for (const item of items(behavior[field])) add(item, kind, source, withDetails(source, metrics(item)));
239
+ for (const item of items(behavior[field])) {
240
+ const label = field === "enduring_artists" && playsInMultipleYears(item) ? tr("Across the years") : source;
241
+ add(item, kind, label, withDetails(label, metrics(item)));
242
+ }
227
243
  }
228
244
  for (const item of items(behavior.time_capsule_tracks)) {
229
245
  const year = count(item?.capsule_year);
@@ -282,6 +298,10 @@ export function buildTasteProfileModel(profile = {}, tr = screenTranslator("en")
282
298
  : tr("Shows up through one of their tracks."));
283
299
  }
284
300
 
301
+ for (const track of Array.isArray(profile?.reviewLibraryTracks) ? profile.reviewLibraryTracks : []) {
302
+ add(track, "track", appleLibrary, appleLibrary, { membership: true });
303
+ }
304
+
285
305
  for (const subject of subjects.values()) {
286
306
  if (subject.kind !== "track") continue;
287
307
  const artist = subjects.get(subjectKey({ entityType: "artist", label: subject.target.artistCredit }));
@@ -295,7 +315,7 @@ export function buildTasteProfileModel(profile = {}, tr = screenTranslator("en")
295
315
  }
296
316
 
297
317
  return {
298
- summaryLines: overview(profile, tr),
318
+ summaryLines: overview(profile, tr, listening),
299
319
  subjects: [...subjects.values()],
300
320
  emptyLines: [
301
321
  tr("Nothing to look at yet."),