@audiofool/moondog 0.1.0
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 +125 -0
- package/assets/brand/moondog-lunar-record/moondog-logo-1x1.png +0 -0
- package/contracts/v1/capability-policy.schema.json +572 -0
- package/contracts/v1/definitions.schema.json +365 -0
- package/contracts/v1/library-track-observation.schema.json +138 -0
- package/contracts/v1/listening-event.schema.json +111 -0
- package/contracts/v1/profile-evidence.schema.json +237 -0
- package/contracts/v1/taste-event.schema.json +258 -0
- package/contracts/v1/tool-invocation.schema.json +318 -0
- package/contracts/v1/tool-receipt.schema.json +1066 -0
- package/contracts/v1/track-ref.schema.json +275 -0
- package/contracts/v2/profile-evidence.schema.json +284 -0
- package/package.json +105 -0
- package/scripts/contract-lib.mjs +361 -0
- package/scripts/contract-semantics.mjs +2630 -0
- package/scripts/demo-studio.mjs +58 -0
- package/scripts/moondog +52 -0
- package/scripts/moondog.mjs +954 -0
- package/src/core/apple-data-migration.mjs +50 -0
- package/src/core/apple-library-source-status.mjs +220 -0
- package/src/core/apple-projection-domain-services.mjs +2356 -0
- package/src/core/capability-catalog.mjs +577 -0
- package/src/core/listening-profile-domain-services.mjs +1010 -0
- package/src/core/lyric-library.mjs +121 -0
- package/src/core/lyric-profile.mjs +50 -0
- package/src/core/lyric-service.mjs +41 -0
- package/src/core/moondog-application.mjs +1827 -0
- package/src/core/state-directory.mjs +19 -0
- package/src/core/synthetic-domain-services.mjs +1485 -0
- package/src/core/uuid-v5.mjs +42 -0
- package/src/demo/fictional-spotify-history.mjs +400 -0
- package/src/demo/moondog-demo.mjs +355 -0
- package/src/demo/moondog-interactive-tasteprint-demo.mjs +293 -0
- package/src/demo/moondog-tasteprint-demo.mjs +631 -0
- package/src/importers/apple-music-library/import-batch.mjs +290 -0
- package/src/importers/apple-music-library/index.mjs +76 -0
- package/src/importers/apple-music-library/normalize.mjs +1126 -0
- package/src/importers/apple-music-library/parse-plist.mjs +357 -0
- package/src/importers/apple-music-library/projection-records.mjs +557 -0
- package/src/importers/apple-music-library/read-batch.mjs +276 -0
- package/src/importers/apple-music-library/sqlite-projection.mjs +1307 -0
- package/src/importers/apple-music-library/stable-ids.mjs +19 -0
- package/src/importers/apple-music-library/track-snapshot.schema.json +136 -0
- package/src/integrations/apple-music/catalog.mjs +770 -0
- package/src/integrations/cross-catalog-artist-identity.mjs +222 -0
- package/src/integrations/listenbrainz/history-file.mjs +560 -0
- package/src/integrations/lyrics/lrclib.mjs +55 -0
- package/src/integrations/open-music-similarity/artist-radio.mjs +806 -0
- package/src/integrations/public-playlists.mjs +104 -0
- package/src/integrations/spotify/account-data-history.mjs +545 -0
- package/src/integrations/spotify/account-data-profile.mjs +918 -0
- package/src/integrations/spotify/authentication.mjs +791 -0
- package/src/integrations/spotify/catalog-resolver.mjs +657 -0
- package/src/integrations/spotify/connection.mjs +125 -0
- package/src/integrations/spotify/credential-store.mjs +26 -0
- package/src/integrations/spotify/extended-streaming-history.mjs +525 -0
- package/src/integrations/spotify/history-archive.mjs +59 -0
- package/src/integrations/spotify/index.mjs +80 -0
- package/src/integrations/spotify/recent-activity.mjs +198 -0
- package/src/integrations/spotify/resolution-cache.mjs +260 -0
- package/src/integrations/spotify/service.mjs +713 -0
- package/src/integrations/spotify/settings.mjs +89 -0
- package/src/integrations/spotify/web-api-client.mjs +761 -0
- package/src/integrations/web/codex-web.mjs +263 -0
- package/src/integrations/youtube-music/takeout.mjs +143 -0
- package/src/memory/local-memory-store.mjs +1705 -0
- package/src/memory/reflection-worker.mjs +87 -0
- package/src/profile/apple-library-import.mjs +28 -0
- package/src/profile/history-import.mjs +163 -0
- package/src/profile/listener-corrections.mjs +217 -0
- package/src/profile/listening-history-store.mjs +2055 -0
- package/src/profile/listening-profile-projection.mjs +2520 -0
- package/src/profile/local-music-data.mjs +812 -0
- package/src/profile/music-import-bundle.mjs +91 -0
- package/src/profile/music-providers.mjs +25 -0
- package/src/profile/spotify-archive-catalog-hints.mjs +210 -0
- package/src/profile/spotify-archive-taste.mjs +482 -0
- package/src/runtime/pi/agent-runtime.mjs +6444 -0
- package/src/runtime/pi/authentication.mjs +104 -0
- package/src/runtime/pi/configured-runtime.mjs +98 -0
- package/src/runtime/pi/memory-agent-runtime.mjs +337 -0
- package/src/runtime/pi/model-catalog.mjs +62 -0
- package/src/runtime/pi/model-transport.mjs +117 -0
- package/src/runtime/pi/persistent-credential-store.mjs +670 -0
- package/src/runtime/pi/provider-registry.mjs +74 -0
- package/src/runtime/pi/runtime-settings.mjs +81 -0
- package/src/surfaces/cli/auth-command.mjs +355 -0
- package/src/surfaces/cli/brand-components.mjs +390 -0
- package/src/surfaces/cli/brand-theme.mjs +231 -0
- package/src/surfaces/cli/catalog-command.mjs +509 -0
- package/src/surfaces/cli/command-completions.mjs +113 -0
- package/src/surfaces/cli/data-command.mjs +214 -0
- package/src/surfaces/cli/format-output.mjs +750 -0
- package/src/surfaces/cli/history-import-view.mjs +445 -0
- package/src/surfaces/cli/import-guides.mjs +9 -0
- package/src/surfaces/cli/listenbrainz-command.mjs +129 -0
- package/src/surfaces/cli/listening-menu.mjs +171 -0
- package/src/surfaces/cli/profile-command.mjs +290 -0
- package/src/surfaces/cli/spotify-command.mjs +849 -0
- package/src/surfaces/cli/taste-profile-model.mjs +306 -0
- package/src/surfaces/cli/taste-profile-view.mjs +272 -0
- package/src/surfaces/cli/terminal-art.mjs +295 -0
- package/src/surfaces/cli/tui.mjs +1714 -0
- package/src/surfaces/cli/web-command.mjs +52 -0
- package/src/surfaces/html/tasteprint-artifact.mjs +96 -0
- package/src/surfaces/html/tasteprint.mjs +3575 -0
- package/src/surfaces/web/showcase.mjs +272 -0
- package/src/surfaces/web/studio-page.mjs +4148 -0
- package/src/surfaces/web/studio.mjs +2288 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { resolveMoondogAuthFile } from "../../runtime/pi/persistent-credential-store.mjs";
|
|
5
|
+
|
|
6
|
+
const SETTINGS_VERSION = 1;
|
|
7
|
+
const clientIdPattern = /^[A-Za-z0-9_-]{8,128}$/u;
|
|
8
|
+
|
|
9
|
+
function configurationError(message, cause) {
|
|
10
|
+
const error = new Error(message, cause ? { cause } : undefined);
|
|
11
|
+
error.name = "MoondogSpotifySettingsError";
|
|
12
|
+
error.code = "spotify_settings_invalid";
|
|
13
|
+
return error;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function normalizeClientId(value) {
|
|
17
|
+
const clientId = typeof value === "string" ? value.trim() : "";
|
|
18
|
+
if (!clientIdPattern.test(clientId)) {
|
|
19
|
+
throw configurationError("Spotify configuration requires a valid client ID.");
|
|
20
|
+
}
|
|
21
|
+
return clientId;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function resolveSpotifySettingsFile(environment = process.env) {
|
|
25
|
+
return path.join(
|
|
26
|
+
path.dirname(resolveMoondogAuthFile(environment)),
|
|
27
|
+
"spotify.json",
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function readSpotifyConfiguration(environment = process.env) {
|
|
32
|
+
const environmentClientId = environment.MOONDOG_SPOTIFY_CLIENT_ID?.trim();
|
|
33
|
+
if (environmentClientId) {
|
|
34
|
+
return {
|
|
35
|
+
clientId: normalizeClientId(environmentClientId),
|
|
36
|
+
source: "environment",
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const settingsFile = resolveSpotifySettingsFile(environment);
|
|
41
|
+
let source;
|
|
42
|
+
try {
|
|
43
|
+
source = await readFile(settingsFile, "utf8");
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (error?.code === "ENOENT") return undefined;
|
|
46
|
+
throw configurationError("Moondog could not read Spotify settings.", error);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let document;
|
|
50
|
+
try {
|
|
51
|
+
document = JSON.parse(source);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
throw configurationError("Moondog Spotify settings are not valid JSON.", error);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (
|
|
57
|
+
!document ||
|
|
58
|
+
typeof document !== "object" ||
|
|
59
|
+
Array.isArray(document) ||
|
|
60
|
+
document.version !== SETTINGS_VERSION ||
|
|
61
|
+
Object.keys(document).sort().join(",") !== "client_id,version"
|
|
62
|
+
) {
|
|
63
|
+
throw configurationError("Moondog Spotify settings use an unsupported shape.");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
clientId: normalizeClientId(document.client_id),
|
|
68
|
+
source: "settings",
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function writeSpotifyConfiguration(
|
|
73
|
+
clientId,
|
|
74
|
+
environment = process.env,
|
|
75
|
+
) {
|
|
76
|
+
const normalized = normalizeClientId(clientId);
|
|
77
|
+
const settingsFile = resolveSpotifySettingsFile(environment);
|
|
78
|
+
await mkdir(path.dirname(settingsFile), { recursive: true, mode: 0o700 });
|
|
79
|
+
await writeFile(
|
|
80
|
+
settingsFile,
|
|
81
|
+
`${JSON.stringify(
|
|
82
|
+
{ version: SETTINGS_VERSION, client_id: normalized },
|
|
83
|
+
null,
|
|
84
|
+
2,
|
|
85
|
+
)}\n`,
|
|
86
|
+
{ encoding: "utf8", mode: 0o600 },
|
|
87
|
+
);
|
|
88
|
+
return { clientId: normalized, source: "settings" };
|
|
89
|
+
}
|