dynamoi 0.1.0 → 0.2.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Dynamoi LLC
3
+ Copyright (c) 2026 Dynamoi
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,12 +1,81 @@
1
1
  # dynamoi
2
2
 
3
- The command line for [Dynamoi](https://dynamoi.com): full-service music distribution and promotion under one roof.
3
+ **Music distribution and promotion, built for AI agents.**
4
4
 
5
- Release to 100+ stores, run real Spotify and YouTube ad campaigns, and see what each one moved, from your terminal or your AI agent.
5
+ [![npm version](https://img.shields.io/npm/v/dynamoi?label=npm)](https://www.npmjs.com/package/dynamoi)
6
+ [![license](https://img.shields.io/npm/l/dynamoi)](./LICENSE)
6
7
 
7
- The full CLI is coming soon. Today, connect Claude, ChatGPT, Codex or Cursor through the [Dynamoi MCP server](https://dynamoi.com/docs/mcp-server).
8
+ The command line for [Dynamoi](https://dynamoi.com): full-service music
9
+ distribution and promotion under one roof. Release to 100+ stores, run real
10
+ Spotify and YouTube ad campaigns, and see what each one moved. Smart Links,
11
+ analytics and growth audits are free. Use it from a terminal, a script or an
12
+ agent that can run shell commands.
8
13
 
9
- - Website: https://dynamoi.com
10
- - Pricing: https://dynamoi.com/pricing
11
- - MCP server: https://dynamoi.com/mcp-server
12
- - Support: support@dynamoi.com
14
+ It is a thin client for Dynamoi's hosted MCP server at
15
+ `https://dynamoi.com/mcp`, so it follows the same account, tools and consent
16
+ rules as the apps. It has no tool list of its own: every command comes from the
17
+ server's tool schemas, so new tools appear without an update.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install --global dynamoi
23
+ # or run it once
24
+ npx dynamoi tools
25
+ ```
26
+
27
+ Node 20 or newer.
28
+
29
+ ## Sign in
30
+
31
+ ```bash
32
+ dynamoi login # opens your browser; sign in with your Dynamoi account
33
+ dynamoi whoami
34
+ dynamoi logout # revokes the session and deletes stored tokens
35
+ ```
36
+
37
+ `dynamoi login` uses OAuth 2.1 with PKCE and a loopback redirect on
38
+ `127.0.0.1`, the same sign-in as Claude Code and Codex. There are no API keys.
39
+ Tokens go to your OS keychain (macOS Keychain, or the Secret Service on Linux)
40
+ and fall back to a `0600` file in `$XDG_CONFIG_HOME/dynamoi` (default
41
+ `~/.config/dynamoi`). Sessions refresh on their own. Because the app signs in on
42
+ your own computer, it gets the Full tool set; before sign-in you see only the
43
+ directory set.
44
+
45
+ ## Use
46
+
47
+ ```bash
48
+ dynamoi tools # every tool your account can use
49
+ dynamoi help get-campaign # flags for one tool
50
+ dynamoi list-artists
51
+ dynamoi get-artist-analytics --artist-id <id> --json
52
+ ```
53
+
54
+ A command is the tool name without its `dynamoi_` prefix, with dashes. Flags come
55
+ from the tool's input schema: `--artist-id` is `artistId`. Booleans are
56
+ `--flag` or `--no-flag`, lists repeat the flag or take commas, and objects take a
57
+ JSON string. `--input '<json>'` passes the whole argument object. `--json` prints
58
+ the structured result.
59
+
60
+ ## Paid and consequential actions
61
+
62
+ Tools that spend money or submit something on your behalf require explicit
63
+ confirmation arguments (`confirm...`, `authorize...`, `accepted...`). The CLI
64
+ never sets them for you:
65
+
66
+ - In a terminal, it shows the tool's summary and asks `[y/N]` before granting a
67
+ required yes/no confirmation.
68
+ - Without a terminal, such as in a script or an agent, pass the flag yourself,
69
+ for example `--confirm-application-submission`.
70
+ - Consent versions and hashes are always passed explicitly. Read them in
71
+ `dynamoi help <tool>`.
72
+
73
+ Dynamoi's server refuses the action without them. Results are never guaranteed.
74
+
75
+ ## Links
76
+
77
+ - [Dynamoi](https://dynamoi.com) and [pricing](https://dynamoi.com/pricing)
78
+ - [MCP server and library (`@dynamoi/mcp`)](https://github.com/getDynamoi/dynamoi)
79
+ - [MCP server docs](https://dynamoi.com/docs/mcp-server)
80
+
81
+ MIT licensed.
@@ -0,0 +1,739 @@
1
+ #!/usr/bin/env node
2
+ // package.json
3
+ var package_default = {
4
+ $schema: "https://www.schemastore.org/package",
5
+ name: "dynamoi",
6
+ version: "0.2.0",
7
+ type: "module",
8
+ license: "MIT",
9
+ description: "Music distribution and promotion, built for AI agents: the Dynamoi command line.",
10
+ keywords: [
11
+ "music-distribution",
12
+ "music-promotion",
13
+ "music-marketing",
14
+ "spotify-promotion",
15
+ "youtube-promotion",
16
+ "smart-links",
17
+ "advertising-management",
18
+ "music-analytics",
19
+ "cli",
20
+ "mcp",
21
+ "ai-agents"
22
+ ],
23
+ homepage: "https://dynamoi.com",
24
+ repository: {
25
+ type: "git",
26
+ url: "git+https://github.com/getDynamoi/dynamoi.git",
27
+ directory: "cli"
28
+ },
29
+ bugs: {
30
+ url: "https://github.com/getDynamoi/dynamoi/issues"
31
+ },
32
+ bin: {
33
+ dynamoi: "./dist/dynamoi.js"
34
+ },
35
+ files: [
36
+ "LICENSE",
37
+ "README.md",
38
+ "dist/dynamoi.js"
39
+ ],
40
+ engines: {
41
+ node: ">=20"
42
+ },
43
+ publishConfig: {
44
+ access: "public"
45
+ },
46
+ scripts: {
47
+ build: "bun build src/main.ts --target node --outfile dist/dynamoi.js",
48
+ prepack: "bun run build",
49
+ typecheck: "tsrs --noEmit -p tsconfig.json"
50
+ }
51
+ };
52
+
53
+ // src/oauth.ts
54
+ import { spawn as spawn2 } from "node:child_process";
55
+ import { createHash, randomBytes } from "node:crypto";
56
+ import { createServer } from "node:http";
57
+
58
+ // src/callback-page.ts
59
+ var BLOOM = `<svg class="bloom" viewBox="200 200 624 624" aria-hidden="true"><g transform="translate(512 512) scale(1.0033) translate(41.66 8.42)"><path d="M4.85,-59.64 C29.19,-78.22 32.45,-84.42 61.79,-93.14 A44.00,44.00 0 1 0 8.85,-152.75 C-3.28,-124.65 -6.63,-96.94 -7.99,-66.36 A8,8 0 0 0 4.85,-59.64Z"/><path d="M45.67,-39.10 C81.78,-36.49 90.63,-39.14 123.45,-23.87 A49.67,49.67 0 1 0 124.19,-114.27 C91.12,-99.54 66.29,-78.27 40.61,-52.76 A8,8 0 0 0 45.67,-39.10Z"/><path d="M59.91,7.25 C87.25,38.91 97.16,44.85 111.47,84.16 A55.33,55.33 0 1 0 184.12,13.90 C145.31,-1.72 107.95,-5.16 66.13,-5.98 A8,8 0 0 0 59.91,7.25Z"/><path d="M32.89,50.81 C26.66,97.90 28.83,111.64 6.29,153.44 A61.00,61.00 0 1 0 117.64,162.49 C102.15,117.60 77.39,83.21 46.96,46.74 A8,8 0 0 0 32.89,50.81Z"/><path d="M-20.77,57.01 C-66.35,84.39 -77.61,96.16 -129.95,105.57 A66.67,66.67 0 1 0 -62.24,207.50 C-33.27,162.90 -20.07,117.53 -8.83,65.56 A8,8 0 0 0 -20.77,57.01Z"/><path d="M-58.91,15.02 C-112.90,-8.46 -131.34,-11.44 -173.48,-52.56 A72.33,72.33 0 1 0 -221.44,71.49 C-162.60,69.41 -113.26,52.57 -59.00,29.73 A8,8 0 0 0 -58.91,15.02Z"/><path class="lead" d="M-43.70,-42.41 C-53.84,-106.19 -61.95,-125.66 -48.78,-188.89 A78.00,78.00 0 1 0 -189.68,-160.99 C-153.41,-107.55 -109.08,-71.68 -56.19,-34.60 A8,8 0 0 0 -43.70,-42.41Z"/></g></svg>`;
60
+ var STYLE = `
61
+ :root{--ground:#0c0b0a;--surface:#181715;--fg:#f4ece0;--fg-muted:rgb(244 236 224/.78);--fg-faint:rgb(244 236 224/.52);--line:rgb(244 236 224/.13);--accent:#e2733f;--ember:#d9622b;--ease-out:cubic-bezier(.16,1,.3,1);color-scheme:dark}
62
+ *{box-sizing:border-box;margin:0}
63
+ body{min-height:100dvh;display:grid;place-items:center;padding:16px;background:radial-gradient(ellipse 80% 50% at 50% 0%,rgb(226 115 63/.12),transparent 70%),var(--ground);color:var(--fg);font:16px/1.5 Inter,system-ui,-apple-system,"Segoe UI",sans-serif;-webkit-font-smoothing:antialiased}
64
+ main{width:min(400px,100%);padding:40px 32px 32px;background:var(--surface);border:1px solid var(--line);border-radius:20px;text-align:center;box-shadow:0 24px 64px rgb(0 0 0/.45);animation:rise .6s var(--ease-out) both}
65
+ .lockup{display:inline-flex;align-items:center;gap:10px;margin-bottom:32px}
66
+ .bloom{width:36px;height:36px;fill:var(--fg)}.bloom .lead{fill:var(--ember)}
67
+ .word{font-size:26px;font-weight:800;letter-spacing:-.045em;line-height:1}
68
+ .status{width:48px;height:48px;margin:0 auto 20px;display:grid;place-items:center;border-radius:50%;background:rgb(226 115 63/.12);border:1px solid rgb(226 115 63/.32);color:var(--accent)}
69
+ .status svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round}
70
+ h1{font-size:22px;font-weight:650;letter-spacing:-.02em;margin-bottom:8px}
71
+ p{color:var(--fg-muted)}
72
+ code{white-space:nowrap;font:14px ui-monospace,SFMono-Regular,Menlo,monospace;padding:2px 6px;border-radius:6px;background:var(--ground);border:1px solid var(--line);color:var(--fg)}
73
+ footer{margin-top:32px;padding-top:20px;border-top:1px solid var(--line);font-size:13px;color:var(--fg-faint)}
74
+ footer a{color:inherit;text-decoration:none}footer a:hover{color:var(--fg)}
75
+ @keyframes rise{from{opacity:0;transform:translateY(8px)}}
76
+ @media (prefers-reduced-motion:reduce){main{animation:none}}`;
77
+ var CHECK = `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>`;
78
+ var ALERT = `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 7v6M12 17h.01"/></svg>`;
79
+ function callbackPage(ok) {
80
+ const [title, body, icon] = ok ? [
81
+ "You're signed in",
82
+ "You can close this tab and go back to your terminal.",
83
+ CHECK
84
+ ] : [
85
+ "Sign-in couldn't be verified",
86
+ "Go back to your terminal and run <code>dynamoi login</code> again.",
87
+ ALERT
88
+ ];
89
+ return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${title} · Dynamoi</title><style>${STYLE}</style></head><body><main><div class="lockup">${BLOOM}<span class="word">dynamoi</span></div><div class="status">${icon}</div><h1>${title}</h1><p>${body}</p><footer><a href="https://dynamoi.com">dynamoi.com</a></footer></main></body></html>`;
90
+ }
91
+
92
+ // src/store.ts
93
+ import { spawn } from "node:child_process";
94
+ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
95
+ import { homedir } from "node:os";
96
+ import path from "node:path";
97
+ var SERVICE = "dynamoi-cli";
98
+ var ACCOUNT = "default";
99
+ function exec(cmd, args, stdin) {
100
+ return new Promise((resolve) => {
101
+ const child = spawn(cmd, args, { stdio: ["pipe", "pipe", "ignore"] });
102
+ let out = "";
103
+ const timer = setTimeout(() => child.kill(), 5000);
104
+ child.stdout.on("data", (chunk) => {
105
+ out += chunk;
106
+ });
107
+ child.on("error", () => resolve(null));
108
+ child.on("close", (code) => {
109
+ clearTimeout(timer);
110
+ resolve(code === 0 ? out : null);
111
+ });
112
+ child.stdin.on("error", () => {
113
+ return;
114
+ });
115
+ child.stdin.end(stdin);
116
+ });
117
+ }
118
+ var keychain = process.platform === "darwin" ? {
119
+ clear: () => exec("security", [
120
+ "delete-generic-password",
121
+ "-s",
122
+ SERVICE,
123
+ "-a",
124
+ ACCOUNT
125
+ ]),
126
+ read: () => exec("security", [
127
+ "find-generic-password",
128
+ "-s",
129
+ SERVICE,
130
+ "-a",
131
+ ACCOUNT,
132
+ "-w"
133
+ ]),
134
+ write: (secret) => exec("security", [
135
+ "add-generic-password",
136
+ "-U",
137
+ "-s",
138
+ SERVICE,
139
+ "-a",
140
+ ACCOUNT,
141
+ "-w",
142
+ secret
143
+ ])
144
+ } : process.platform === "linux" ? {
145
+ clear: () => exec("secret-tool", [
146
+ "clear",
147
+ "service",
148
+ SERVICE,
149
+ "account",
150
+ ACCOUNT
151
+ ]),
152
+ read: () => exec("secret-tool", [
153
+ "lookup",
154
+ "service",
155
+ SERVICE,
156
+ "account",
157
+ ACCOUNT
158
+ ]),
159
+ write: (secret) => exec("secret-tool", [
160
+ "store",
161
+ "--label=Dynamoi CLI",
162
+ "service",
163
+ SERVICE,
164
+ "account",
165
+ ACCOUNT
166
+ ], secret)
167
+ } : null;
168
+ function credentialsFile() {
169
+ const config = process.env.XDG_CONFIG_HOME || path.join(homedir(), ".config");
170
+ return path.join(config, "dynamoi", "credentials.json");
171
+ }
172
+ function parse(raw) {
173
+ try {
174
+ const value = JSON.parse(raw ?? "");
175
+ return typeof value.accessToken === "string" && typeof value.clientId === "string" ? value : null;
176
+ } catch {
177
+ return null;
178
+ }
179
+ }
180
+ async function loadCredentials() {
181
+ const fromKeychain = parse(await keychain?.read() ?? null);
182
+ if (fromKeychain) {
183
+ return fromKeychain;
184
+ }
185
+ try {
186
+ return parse(await readFile(credentialsFile(), "utf8"));
187
+ } catch {
188
+ return null;
189
+ }
190
+ }
191
+ async function saveCredentials(credentials) {
192
+ const secret = JSON.stringify(credentials);
193
+ if (keychain && await keychain.write(secret) !== null) {
194
+ await rm(credentialsFile(), { force: true });
195
+ return;
196
+ }
197
+ const file = credentialsFile();
198
+ await mkdir(path.dirname(file), { mode: 448, recursive: true });
199
+ await writeFile(file, secret, { mode: 384 });
200
+ await chmod(file, 384);
201
+ }
202
+ async function clearCredentials() {
203
+ await keychain?.clear();
204
+ await rm(credentialsFile(), { force: true });
205
+ }
206
+
207
+ // src/oauth.ts
208
+ var BASE_URL = "https://dynamoi.com";
209
+ var MCP_URL = `${BASE_URL}/mcp`;
210
+ var b64url = (bytes) => bytes.toString("base64url");
211
+ async function jsonBody(response) {
212
+ try {
213
+ return await response.json();
214
+ } catch {
215
+ return {};
216
+ }
217
+ }
218
+ async function serverMetadata() {
219
+ const response = await fetch(`${BASE_URL}/.well-known/oauth-authorization-server`);
220
+ if (!response.ok) {
221
+ throw new Error(`Dynamoi sign-in is unavailable (HTTP ${response.status}).`);
222
+ }
223
+ return await response.json();
224
+ }
225
+ async function postForm(url, body) {
226
+ const response = await fetch(url, {
227
+ body: new URLSearchParams(body),
228
+ headers: { accept: "application/json" },
229
+ method: "POST"
230
+ });
231
+ const json = await jsonBody(response);
232
+ if (!response.ok) {
233
+ throw new Error(json.error_description ?? json.error ?? `HTTP ${response.status}`);
234
+ }
235
+ return json;
236
+ }
237
+ function toCredentials(token, clientId, previous) {
238
+ return {
239
+ accessToken: token.access_token,
240
+ clientId,
241
+ expiresAt: Date.now() + (token.expires_in ?? 3600) * 1000,
242
+ refreshToken: token.refresh_token ?? previous?.refreshToken,
243
+ scope: token.scope ?? previous?.scope ?? ""
244
+ };
245
+ }
246
+ function openBrowser(url) {
247
+ const [cmd, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url.replaceAll("&", "^&")]] : ["xdg-open", [url]];
248
+ spawn2(cmd, args, { detached: true, stdio: "ignore" }).on("error", () => {
249
+ return;
250
+ }).unref();
251
+ }
252
+ function listenForRedirect(state) {
253
+ return new Promise((resolveListening, rejectListening) => {
254
+ let settle;
255
+ let fail;
256
+ const result = new Promise((resolve, reject) => {
257
+ settle = resolve;
258
+ fail = reject;
259
+ });
260
+ const timer = setTimeout(() => {
261
+ server.close();
262
+ fail(new Error("Timed out waiting for browser sign-in."));
263
+ }, 5 * 60000);
264
+ const server = createServer((request, response) => {
265
+ const url = new URL(request.url ?? "/", "http://127.0.0.1");
266
+ if (url.pathname !== "/callback") {
267
+ response.writeHead(404).end();
268
+ return;
269
+ }
270
+ const ok = url.searchParams.get("state") === state;
271
+ response.writeHead(ok ? 200 : 400, {
272
+ "content-type": "text/html; charset=utf-8"
273
+ }).end(callbackPage(ok));
274
+ if (ok) {
275
+ clearTimeout(timer);
276
+ server.close();
277
+ settle(url.searchParams);
278
+ }
279
+ });
280
+ server.once("error", rejectListening);
281
+ server.listen(0, "127.0.0.1", () => resolveListening({
282
+ port: server.address().port,
283
+ result
284
+ }));
285
+ });
286
+ }
287
+ async function login(print, open = openBrowser) {
288
+ const meta = await serverMetadata();
289
+ const state = b64url(randomBytes(16));
290
+ const { port, result } = await listenForRedirect(state);
291
+ const redirectUri = `http://127.0.0.1:${port}/callback`;
292
+ const scope = (meta.scopes_supported ?? []).join(" ");
293
+ const registration = await fetch(meta.registration_endpoint, {
294
+ body: JSON.stringify({
295
+ client_name: "Dynamoi CLI",
296
+ grant_types: ["authorization_code", "refresh_token"],
297
+ redirect_uris: [redirectUri],
298
+ response_types: ["code"],
299
+ scope,
300
+ token_endpoint_auth_method: "none"
301
+ }),
302
+ headers: { "content-type": "application/json" },
303
+ method: "POST"
304
+ });
305
+ const client = await jsonBody(registration);
306
+ if (!(registration.ok && client.client_id)) {
307
+ throw new Error(`Could not register the CLI (HTTP ${registration.status}).`);
308
+ }
309
+ const verifier = b64url(randomBytes(32));
310
+ const authorize = new URL(meta.authorization_endpoint);
311
+ authorize.search = new URLSearchParams({
312
+ client_id: client.client_id,
313
+ code_challenge: b64url(createHash("sha256").update(verifier).digest()),
314
+ code_challenge_method: "S256",
315
+ redirect_uri: redirectUri,
316
+ resource: MCP_URL,
317
+ response_type: "code",
318
+ scope,
319
+ state
320
+ }).toString();
321
+ print(`Open this URL to sign in to Dynamoi:
322
+ ${authorize}`);
323
+ open(authorize.toString());
324
+ const params = await result;
325
+ const error = params.get("error");
326
+ const code = params.get("code");
327
+ if (error || !code) {
328
+ throw new Error(params.get("error_description") ?? error ?? "Sign-in failed.");
329
+ }
330
+ const iss = params.get("iss");
331
+ if (iss && iss !== meta.issuer) {
332
+ throw new Error("Sign-in response came from an unexpected issuer.");
333
+ }
334
+ const token = await postForm(meta.token_endpoint, {
335
+ client_id: client.client_id,
336
+ code,
337
+ code_verifier: verifier,
338
+ grant_type: "authorization_code",
339
+ redirect_uri: redirectUri,
340
+ resource: MCP_URL
341
+ });
342
+ const credentials = toCredentials(token, client.client_id);
343
+ await saveCredentials(credentials);
344
+ return credentials;
345
+ }
346
+ async function refresh(credentials) {
347
+ if (!credentials.refreshToken) {
348
+ return null;
349
+ }
350
+ try {
351
+ const meta = await serverMetadata();
352
+ const token = await postForm(meta.token_endpoint, {
353
+ client_id: credentials.clientId,
354
+ grant_type: "refresh_token",
355
+ refresh_token: credentials.refreshToken,
356
+ resource: MCP_URL
357
+ });
358
+ const next = toCredentials(token, credentials.clientId, credentials);
359
+ await saveCredentials(next);
360
+ return next;
361
+ } catch {
362
+ return null;
363
+ }
364
+ }
365
+ async function accessToken() {
366
+ const stored = await loadCredentials();
367
+ if (!stored) {
368
+ return null;
369
+ }
370
+ if (stored.expiresAt - Date.now() > 60000) {
371
+ return stored.accessToken;
372
+ }
373
+ return (await refresh(stored))?.accessToken ?? null;
374
+ }
375
+ async function revoke(credentials) {
376
+ const token = credentials.refreshToken ?? credentials.accessToken;
377
+ const meta = await serverMetadata();
378
+ if (meta.revocation_endpoint) {
379
+ try {
380
+ await postForm(meta.revocation_endpoint, {
381
+ client_id: credentials.clientId,
382
+ token
383
+ });
384
+ } catch {}
385
+ }
386
+ }
387
+ async function userInfo(token) {
388
+ const meta = await serverMetadata();
389
+ const response = await fetch(meta.userinfo_endpoint ?? "", {
390
+ headers: { authorization: `Bearer ${token}` }
391
+ });
392
+ if (!response.ok) {
393
+ throw new Error(`Could not read the signed-in account (HTTP ${response.status}).`);
394
+ }
395
+ return await response.json();
396
+ }
397
+
398
+ // src/mcp.ts
399
+ async function readRpc(response) {
400
+ const text = await response.text();
401
+ if ((response.headers.get("content-type") ?? "").includes("text/event-stream")) {
402
+ const data = text.split(/\r?\n/u).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim()).pop();
403
+ return JSON.parse(data ?? "{}");
404
+ }
405
+ return JSON.parse(text || "{}");
406
+ }
407
+ async function post(method, params, token) {
408
+ return fetch(MCP_URL, {
409
+ body: JSON.stringify({ id: 1, jsonrpc: "2.0", method, params }),
410
+ headers: {
411
+ accept: "application/json, text/event-stream",
412
+ "content-type": "application/json",
413
+ "mcp-protocol-version": "2025-06-18",
414
+ ...token ? { authorization: `Bearer ${token}` } : {}
415
+ },
416
+ method: "POST"
417
+ });
418
+ }
419
+ async function rpc(method, params) {
420
+ let response = await post(method, params, await accessToken());
421
+ if (response.status === 401) {
422
+ const stored = await loadCredentials();
423
+ const next = stored ? await refresh(stored) : null;
424
+ if (next) {
425
+ response = await post(method, params, next.accessToken);
426
+ }
427
+ }
428
+ if (response.status === 401) {
429
+ throw new Error("Not signed in. Run `dynamoi login`.");
430
+ }
431
+ const body = await readRpc(response);
432
+ if (body.error || !response.ok) {
433
+ throw new Error(body.error?.message ?? `Dynamoi returned HTTP ${response.status}.`);
434
+ }
435
+ return body.result;
436
+ }
437
+ async function listTools() {
438
+ const tools = [];
439
+ let cursor;
440
+ do {
441
+ const page = await rpc("tools/list", cursor ? { cursor } : {});
442
+ tools.push(...page.tools.filter((tool) => tool.name.startsWith("dynamoi_")));
443
+ cursor = page.nextCursor;
444
+ } while (cursor);
445
+ return tools;
446
+ }
447
+ var callTool = (name, args) => rpc("tools/call", { arguments: args, name });
448
+
449
+ // src/run.ts
450
+ import { createInterface } from "node:readline/promises";
451
+
452
+ // src/tools.ts
453
+ var commandName = (tool) => tool.name.replace(/^dynamoi_/u, "").replaceAll("_", "-");
454
+ var flagName = (property) => property.replace(/([a-z0-9])([A-Z])/gu, "$1-$2").toLowerCase();
455
+ var properties = (tool) => Object.entries(tool.inputSchema.properties ?? {});
456
+ var kind = (schema) => {
457
+ if (schema.const === true) {
458
+ return "boolean";
459
+ }
460
+ const type = Array.isArray(schema.type) ? schema.type[0] : schema.type;
461
+ return type ?? "json";
462
+ };
463
+ var isConsentField = (property) => /^(confirm|authorize|accepted?)/u.test(property);
464
+ function convert(property, schema, raw) {
465
+ switch (kind(schema)) {
466
+ case "string":
467
+ return raw;
468
+ case "integer":
469
+ case "number": {
470
+ const value = Number(raw);
471
+ if (raw.trim() === "" || Number.isNaN(value)) {
472
+ throw new Error(`--${flagName(property)} must be a number.`);
473
+ }
474
+ return value;
475
+ }
476
+ case "boolean":
477
+ if (raw !== "true" && raw !== "false") {
478
+ throw new Error(`--${flagName(property)} must be true or false.`);
479
+ }
480
+ return raw === "true";
481
+ default:
482
+ try {
483
+ return JSON.parse(raw);
484
+ } catch {
485
+ return raw;
486
+ }
487
+ }
488
+ }
489
+ function parseArgs(tool, argv) {
490
+ const byFlag = new Map(properties(tool).map(([p, s]) => [flagName(p), [p, s]]));
491
+ const parsed = {
492
+ flags: {},
493
+ global: { help: false, json: false }
494
+ };
495
+ let i = 0;
496
+ const next = () => {
497
+ i += 1;
498
+ return argv[i];
499
+ };
500
+ for (;i < argv.length; i += 1) {
501
+ const arg = argv[i];
502
+ if (!arg.startsWith("--")) {
503
+ throw new Error(`Unexpected argument "${arg}". Flags start with --.`);
504
+ }
505
+ const eq = arg.indexOf("=");
506
+ let name = arg.slice(2, eq === -1 ? undefined : eq);
507
+ let inline = eq === -1 ? undefined : arg.slice(eq + 1);
508
+ if (name === "json" || name === "help") {
509
+ parsed.global[name] = true;
510
+ continue;
511
+ }
512
+ if (name === "input") {
513
+ const value = inline ?? next() ?? "";
514
+ Object.assign(parsed.flags, JSON.parse(value));
515
+ continue;
516
+ }
517
+ let negated = false;
518
+ if (!byFlag.has(name) && name.startsWith("no-") && byFlag.has(name.slice(3))) {
519
+ name = name.slice(3);
520
+ negated = true;
521
+ }
522
+ const entry = byFlag.get(name);
523
+ if (!entry) {
524
+ throw new Error(`Unknown flag --${name}. Try \`dynamoi help ${commandName(tool)}\`.`);
525
+ }
526
+ const [property, schema] = entry;
527
+ if (kind(schema) === "boolean") {
528
+ inline ??= negated ? "false" : "true";
529
+ parsed.flags[property] = convert(property, schema, inline);
530
+ continue;
531
+ }
532
+ const raw = inline ?? next();
533
+ if (raw === undefined) {
534
+ throw new Error(`--${name} needs a value.`);
535
+ }
536
+ if (kind(schema) === "array") {
537
+ const itemKind = schema.items ? kind(schema.items) : "string";
538
+ const items = itemKind === "json" || itemKind === "object" ? [raw] : raw.split(",");
539
+ const list = parsed.flags[property] ?? [];
540
+ parsed.flags[property] = [
541
+ ...list,
542
+ ...items.map((item) => schema.items ? convert(property, schema.items, item) : item)
543
+ ];
544
+ continue;
545
+ }
546
+ parsed.flags[property] = convert(property, schema, raw);
547
+ }
548
+ return parsed;
549
+ }
550
+ function missingRequired(tool, args) {
551
+ return (tool.inputSchema.required ?? []).filter((p) => args[p] === undefined);
552
+ }
553
+ function pendingConsent(tool, args) {
554
+ const pending = missingRequired(tool, args).filter(isConsentField);
555
+ const schemas = tool.inputSchema.properties ?? {};
556
+ return {
557
+ askable: pending.filter((p) => kind(schemas[p] ?? {}) === "boolean"),
558
+ explicit: pending.filter((p) => kind(schemas[p] ?? {}) !== "boolean")
559
+ };
560
+ }
561
+ function describeTool(tool) {
562
+ const required = new Set(tool.inputSchema.required ?? []);
563
+ const lines = [
564
+ `dynamoi ${commandName(tool)}`,
565
+ "",
566
+ tool.description ?? tool.title ?? "",
567
+ ""
568
+ ];
569
+ const rows = properties(tool);
570
+ if (rows.length > 0) {
571
+ lines.push("Flags:");
572
+ }
573
+ for (const [property, schema] of rows) {
574
+ const type = schema.enum ? schema.enum.join("|") : kind(schema);
575
+ const note = [
576
+ required.has(property) ? "required" : "",
577
+ schema.description ?? ""
578
+ ].filter(Boolean).join(". ");
579
+ lines.push(` --${flagName(property)} <${type}>${note ? ` ${note}` : ""}`);
580
+ }
581
+ lines.push("", "Also: --json for machine output, --input '<json>' for the whole argument object.");
582
+ return lines.join(`
583
+ `);
584
+ }
585
+
586
+ // src/run.ts
587
+ var err = (line) => process.stderr.write(`${line}
588
+ `);
589
+ var terminal = {
590
+ ask: async (question) => {
591
+ const rl = createInterface({
592
+ input: process.stdin,
593
+ output: process.stderr
594
+ });
595
+ try {
596
+ return await rl.question(question);
597
+ } finally {
598
+ rl.close();
599
+ }
600
+ },
601
+ isTty: Boolean(process.stdin.isTTY && process.stderr.isTTY)
602
+ };
603
+ async function runTool(tool, args, io, call = callTool) {
604
+ const { askable, explicit } = pendingConsent(tool, args);
605
+ if (explicit.length > 0 || askable.length > 0 && !io.isTty) {
606
+ const flags = [...explicit, ...askable].map((p) => `--${flagName(p)}`);
607
+ throw new Error(`${commandName(tool)} needs your explicit consent. Pass ${flags.join(", ")} yourself after reading \`dynamoi help ${commandName(tool)}\`.`);
608
+ }
609
+ if (askable.length > 0) {
610
+ err(`${tool.description ?? commandName(tool)}
611
+
612
+ Arguments: ${JSON.stringify(args)}`);
613
+ const answer = await io.ask(`Confirm ${askable.join(", ")} and proceed? [y/N] `);
614
+ if (!/^y(es)?$/iu.test(answer.trim())) {
615
+ throw new Error("Cancelled. Nothing was sent.");
616
+ }
617
+ for (const property of askable) {
618
+ args[property] = true;
619
+ }
620
+ }
621
+ return call(tool.name, args);
622
+ }
623
+
624
+ // src/main.ts
625
+ var VERSION = package_default.version;
626
+ process.stdout.on("error", (error) => {
627
+ if (error.code === "EPIPE") {
628
+ process.exit(0);
629
+ }
630
+ throw error;
631
+ });
632
+ var out = (line) => process.stdout.write(`${line}
633
+ `);
634
+ var err2 = (line) => process.stderr.write(`${line}
635
+ `);
636
+ var USAGE = `dynamoi ${VERSION}: Music distribution and promotion, built for AI agents.
637
+
638
+ Usage:
639
+ dynamoi login | logout | whoami
640
+ dynamoi tools List what your account can do
641
+ dynamoi help <tool> Show a tool's flags
642
+ dynamoi <tool> [--flag value] Run a tool; add --json for machine output`;
643
+ async function main(argv) {
644
+ const [command, ...rest] = argv;
645
+ switch (command) {
646
+ case undefined:
647
+ case "--help":
648
+ case "-h":
649
+ out(USAGE);
650
+ return 0;
651
+ case "--version":
652
+ case "-v":
653
+ out(VERSION);
654
+ return 0;
655
+ case "login": {
656
+ await login(out);
657
+ const token = await accessToken();
658
+ out(`Signed in${token ? ` as ${(await userInfo(token)).email}` : ""}.`);
659
+ return 0;
660
+ }
661
+ case "logout": {
662
+ const stored = await loadCredentials();
663
+ if (stored) {
664
+ await revoke(stored);
665
+ }
666
+ await clearCredentials();
667
+ out("Signed out.");
668
+ return 0;
669
+ }
670
+ case "whoami": {
671
+ const token = await accessToken();
672
+ if (!token) {
673
+ err2("Not signed in. Run `dynamoi login`.");
674
+ return 1;
675
+ }
676
+ const info = await userInfo(token);
677
+ out(rest.includes("--json") ? JSON.stringify(info) : `${info.name ?? ""} <${info.email ?? info.sub}>`.trim());
678
+ return 0;
679
+ }
680
+ default:
681
+ break;
682
+ }
683
+ const tools = await listTools();
684
+ const find = (name) => tools.find((candidate) => commandName(candidate) === name?.replaceAll("_", "-").replace(/^dynamoi-/u, ""));
685
+ if (command === "tools") {
686
+ if (rest.includes("--json")) {
687
+ out(JSON.stringify(tools.map(({ name, description, inputSchema }) => ({
688
+ description,
689
+ inputSchema,
690
+ name
691
+ }))));
692
+ return 0;
693
+ }
694
+ for (const tool of tools) {
695
+ out(`${commandName(tool).padEnd(40)}${(tool.description ?? "").slice(0, 100)}`);
696
+ }
697
+ if (!await loadCredentials()) {
698
+ err2("\nSign in with `dynamoi login` to see every tool your account can use.");
699
+ }
700
+ return 0;
701
+ }
702
+ if (command === "help") {
703
+ const tool = find(rest[0]);
704
+ if (!tool) {
705
+ out(USAGE);
706
+ return rest[0] ? 1 : 0;
707
+ }
708
+ out(describeTool(tool));
709
+ return 0;
710
+ }
711
+ const tool = find(command);
712
+ if (!tool) {
713
+ err2(`Unknown command "${command}". Run \`dynamoi tools\` to list what is available.`);
714
+ return 1;
715
+ }
716
+ const parsed = parseArgs(tool, rest);
717
+ if (parsed.global.help) {
718
+ out(describeTool(tool));
719
+ return 0;
720
+ }
721
+ const missing = missingRequired(tool, parsed.flags).filter((p) => !pendingConsent(tool, parsed.flags).askable.includes(p));
722
+ if (missing.length > 0) {
723
+ err2(`Missing required flags: ${missing.map((p) => `--${flagName(p)}`).join(", ")}`);
724
+ return 2;
725
+ }
726
+ const result = await runTool(tool, parsed.flags, terminal);
727
+ const text = (result.content ?? []).map((part) => part.text ?? "").filter(Boolean).join(`
728
+ `);
729
+ if (parsed.global.json) {
730
+ out(JSON.stringify(result.structuredContent ?? result, null, 2));
731
+ } else {
732
+ out(text || JSON.stringify(result.structuredContent ?? result, null, 2));
733
+ }
734
+ return result.isError ? 1 : 0;
735
+ }
736
+ main(process.argv.slice(2)).then((code) => process.exit(code)).catch((error) => {
737
+ err2(error instanceof Error ? error.message : String(error));
738
+ process.exit(1);
739
+ });
package/package.json CHANGED
@@ -1,14 +1,49 @@
1
1
  {
2
- "name": "dynamoi",
3
- "version": "0.1.0",
4
- "description": "Dynamoi command line: music distribution and promotion from your terminal and AI agents. The full CLI is coming; connect your AI agent through the Dynamoi MCP server today.",
5
- "keywords": ["music", "music-distribution", "music-promotion", "spotify", "youtube", "smart-links", "cli", "ai-agents", "mcp"],
6
- "homepage": "https://dynamoi.com",
7
- "repository": { "type": "git", "url": "git+https://github.com/getDynamoi/mcp.git" },
8
- "bugs": { "email": "support@dynamoi.com" },
9
- "license": "MIT",
10
- "author": "Dynamoi (https://dynamoi.com)",
11
- "bin": { "dynamoi": "bin/dynamoi.js" },
12
- "files": ["bin", "README.md", "LICENSE"],
13
- "engines": { "node": ">=18" }
2
+ "$schema": "https://www.schemastore.org/package",
3
+ "name": "dynamoi",
4
+ "version": "0.2.0",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "description": "Music distribution and promotion, built for AI agents: the Dynamoi command line.",
8
+ "keywords": [
9
+ "music-distribution",
10
+ "music-promotion",
11
+ "music-marketing",
12
+ "spotify-promotion",
13
+ "youtube-promotion",
14
+ "smart-links",
15
+ "advertising-management",
16
+ "music-analytics",
17
+ "cli",
18
+ "mcp",
19
+ "ai-agents"
20
+ ],
21
+ "homepage": "https://dynamoi.com",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/getDynamoi/dynamoi.git",
25
+ "directory": "cli"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/getDynamoi/dynamoi/issues"
29
+ },
30
+ "bin": {
31
+ "dynamoi": "./dist/dynamoi.js"
32
+ },
33
+ "files": [
34
+ "LICENSE",
35
+ "README.md",
36
+ "dist/dynamoi.js"
37
+ ],
38
+ "engines": {
39
+ "node": ">=20"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "scripts": {
45
+ "build": "bun build src/main.ts --target node --outfile dist/dynamoi.js",
46
+ "prepack": "bun run build",
47
+ "typecheck": "tsrs --noEmit -p tsconfig.json"
48
+ }
14
49
  }
package/bin/dynamoi.js DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
- console.log(`Dynamoi: music distribution and promotion, under one roof.
3
-
4
- The full Dynamoi command line is coming soon.
5
- Today, connect Claude, ChatGPT, Codex or Cursor through the Dynamoi MCP server:
6
- https://dynamoi.com/docs/mcp-server
7
-
8
- Learn more: https://dynamoi.com`);