dynamoi 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +69 -47
  2. package/dist/dynamoi.js +318 -165
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -5,77 +5,99 @@
5
5
  [![npm version](https://img.shields.io/npm/v/dynamoi?label=npm)](https://www.npmjs.com/package/dynamoi)
6
6
  [![license](https://img.shields.io/npm/l/dynamoi)](./LICENSE)
7
7
 
8
- The command line for [Dynamoi](https://dynamoi.com): music promotion that works
9
- with any distributor. Run real Spotify and YouTube ad campaigns, and see what
10
- each one moved. Smart Links, analytics and growth audits are free. Artists who
11
- want everything in one account can also release to 100+ stores through Dynamoi.
12
- Use it from a terminal, a script or an agent that can run shell commands.
8
+ The `dynamoi` command line runs [Dynamoi](https://dynamoi.com) music promotion
9
+ from a terminal, a script or any agent that can run shell commands. Check
10
+ campaign results, build free Smart Links, and launch Spotify and YouTube ad
11
+ campaigns, with the same account, tools and consent rules as the Dynamoi apps.
12
+ It works with any distributor.
13
13
 
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.
14
+ <p align="center">
15
+ <img alt="Running dynamoi --help in a terminal" src="https://raw.githubusercontent.com/getDynamoi/dynamoi/main/.github/assets/cli-help.gif" width="720">
16
+ </p>
18
17
 
19
18
  ## Install
20
19
 
21
20
  ```bash
22
- npm install --global dynamoi
23
- # or run it once
24
- npx dynamoi tools
25
- ```
21
+ # npm, run once without installing
22
+ npx dynamoi --help
26
23
 
27
- Node 20 or newer.
24
+ # Homebrew (macOS and Linux)
25
+ brew trust getdynamoi/tap && brew install getdynamoi/tap/dynamoi
28
26
 
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
27
+ # npm, installed globally
28
+ npm install --global dynamoi
35
29
  ```
36
30
 
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.
31
+ Needs Node 20 or newer. Homebrew installs Node for you.
32
+
33
+ ## Commands
44
34
 
45
- ## Use
35
+ | Command | What it does |
36
+ | --- | --- |
37
+ | `dynamoi login` | Sign in through your browser |
38
+ | `dynamoi whoami` | Show the signed-in account |
39
+ | `dynamoi logout` | Revoke the session and delete stored tokens |
40
+ | `dynamoi tools` | List every tool your account can use |
41
+ | `dynamoi tools --query "<intent>"` | Find up to ten matching tools; use `--limit 1..10` and `--json` as needed |
42
+ | `dynamoi help <tool>` | Show one tool's flags; `--json` returns its exact catalog definition |
43
+ | `dynamoi <tool> [--flag value]` | Run a tool. Add `--json` for machine-readable output |
46
44
 
47
45
  ```bash
48
- dynamoi tools # every tool your account can use
49
- dynamoi help get-campaign # flags for one tool
50
46
  dynamoi list-artists
51
47
  dynamoi get-artist-analytics --artist-id <id> --json
48
+ dynamoi get-growth-audit --artist-id <id>
52
49
  ```
53
50
 
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.
51
+ A command is the tool name without its `dynamoi_` prefix, with dashes. Flags
52
+ come from the tool's input schema, so `--artist-id` is `artistId`. Booleans
53
+ take `--flag` or `--no-flag`, lists repeat the flag or take commas, objects
54
+ take a JSON string, and `--input '<json>'` passes the whole argument object.
59
55
 
60
- ## Paid and consequential actions
56
+ The CLI has no tool list of its own. Every command is generated from the
57
+ schemas of Dynamoi's hosted MCP server at `https://dynamoi.com/mcp`, so new
58
+ tools appear without an update.
61
59
 
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:
60
+ For bounded discovery, start with `dynamoi tools --query "billing payment method" --json`,
61
+ then use the returned `schemaCommand` to load only the selected definition.
62
+ Search reads the current server catalog and returns names, short descriptions,
63
+ and read/write annotations; it never invokes a tool. Matching is by keyword,
64
+ so an unrelated result is not evidence that an operation is supported. The CLI
65
+ still fetches the full catalog over HTTP; the bounded result limits what an
66
+ agent needs to read. Exact schemas, defaults,
67
+ and consent requirements come from `dynamoi help <tool> --json`. Ordinary
68
+ `dynamoi tools --json` still returns the complete input-schema list.
65
69
 
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>`.
70
+ ## How sign-in works
72
71
 
73
- Dynamoi's server refuses the action without them. Results are never guaranteed.
72
+ `dynamoi login` uses OAuth 2.1 with PKCE and a loopback redirect on
73
+ `127.0.0.1`, the same sign-in as Claude Code and Codex. There are no API keys
74
+ to copy. Tokens are stored in your OS keychain (macOS Keychain, or the Secret
75
+ Service on Linux), with a `0600` file in `~/.config/dynamoi` as the fallback,
76
+ and sessions refresh on their own. Because the CLI signs in on your own
77
+ computer, it gets the full tool set.
78
+
79
+ ## Paid actions need your yes
80
+
81
+ Tools that spend money or submit something for you require explicit
82
+ confirmation arguments (`confirm...`, `authorize...`, `accepted...`), and the
83
+ CLI never fills them in for you.
84
+
85
+ - In a terminal, it shows the tool's summary and asks `[y/N]` first.
86
+ - In a script or an agent, you pass the flag yourself, for example
87
+ `--confirm-application-submission`.
88
+ - Budget consent versions and hashes are always passed explicitly. Find them
89
+ with `dynamoi help <tool>`.
90
+
91
+ Without them, Dynamoi's server refuses the action and charges nothing.
74
92
 
75
93
  ## Links
76
94
 
77
95
  - [Dynamoi](https://dynamoi.com) and [pricing](https://dynamoi.com/pricing)
78
- - [MCP server and library (`@dynamoi/mcp`)](https://github.com/getDynamoi/dynamoi)
96
+ - [MCP server and library](https://github.com/getDynamoi/dynamoi)
79
97
  - [MCP server docs](https://dynamoi.com/docs/mcp-server)
80
98
 
81
99
  MIT licensed.
100
+
101
+ ---
102
+
103
+ **Part of Dynamoi** · [MCP server](https://github.com/getDynamoi/dynamoi) · [CLI](https://github.com/getDynamoi/dynamoi/tree/main/cli) · [Agent plugins](https://github.com/getDynamoi/agent-plugins) · [Homebrew tap](https://github.com/getDynamoi/homebrew-tap) · [Chrome extension](https://github.com/getDynamoi/browser-extension) · [dynamoi.com](https://dynamoi.com) · [Docs](https://dynamoi.com/docs) · [Support](https://dynamoi.com/support)
package/dist/dynamoi.js CHANGED
@@ -3,7 +3,7 @@
3
3
  var package_default = {
4
4
  $schema: "https://www.schemastore.org/package",
5
5
  name: "dynamoi",
6
- version: "0.2.2",
6
+ version: "0.2.4",
7
7
  type: "module",
8
8
  license: "MIT",
9
9
  description: "Music promotion and distribution, built for AI agents: the Dynamoi command line.",
@@ -50,6 +50,232 @@ var package_default = {
50
50
  }
51
51
  };
52
52
 
53
+ // src/tools.ts
54
+ var isToolCommand = (tool) => tool.name.startsWith("dynamoi_");
55
+ var commandName = (tool) => tool.name.replace(/^dynamoi_/u, "").replaceAll("_", "-");
56
+ var flagName = (property) => property.replace(/([a-z0-9])([A-Z])/gu, "$1-$2").toLowerCase();
57
+ var properties = (tool) => Object.entries(tool.inputSchema.properties ?? {});
58
+ var kind = (schema) => {
59
+ if (schema.const === true) {
60
+ return "boolean";
61
+ }
62
+ const type = Array.isArray(schema.type) ? schema.type[0] : schema.type;
63
+ return type ?? "json";
64
+ };
65
+ var isConsentField = (property) => /^(confirm|authorize|accepted?)/u.test(property);
66
+ function convert(property, schema, raw) {
67
+ switch (kind(schema)) {
68
+ case "string":
69
+ return raw;
70
+ case "integer":
71
+ case "number": {
72
+ const value = Number(raw);
73
+ if (raw.trim() === "" || Number.isNaN(value)) {
74
+ throw new Error(`--${flagName(property)} must be a number.`);
75
+ }
76
+ return value;
77
+ }
78
+ case "boolean":
79
+ if (raw !== "true" && raw !== "false") {
80
+ throw new Error(`--${flagName(property)} must be true or false.`);
81
+ }
82
+ return raw === "true";
83
+ default:
84
+ try {
85
+ return JSON.parse(raw);
86
+ } catch {
87
+ return raw;
88
+ }
89
+ }
90
+ }
91
+ function parseArgs(tool, argv) {
92
+ const byFlag = new Map(properties(tool).map(([p, s]) => [flagName(p), [p, s]]));
93
+ const parsed = {
94
+ flags: {},
95
+ global: { help: false, json: false }
96
+ };
97
+ let i = 0;
98
+ const next = () => {
99
+ i += 1;
100
+ return argv[i];
101
+ };
102
+ for (;i < argv.length; i += 1) {
103
+ const arg = argv[i];
104
+ if (!arg.startsWith("--")) {
105
+ throw new Error(`Unexpected argument "${arg}". Flags start with --.`);
106
+ }
107
+ const eq = arg.indexOf("=");
108
+ let name = arg.slice(2, eq === -1 ? undefined : eq);
109
+ let inline = eq === -1 ? undefined : arg.slice(eq + 1);
110
+ if (name === "json" || name === "help") {
111
+ parsed.global[name] = true;
112
+ continue;
113
+ }
114
+ if (name === "input") {
115
+ const value = inline ?? next() ?? "";
116
+ Object.assign(parsed.flags, JSON.parse(value));
117
+ continue;
118
+ }
119
+ let negated = false;
120
+ if (!byFlag.has(name) && name.startsWith("no-") && byFlag.has(name.slice(3))) {
121
+ name = name.slice(3);
122
+ negated = true;
123
+ }
124
+ const entry = byFlag.get(name);
125
+ if (!entry) {
126
+ throw new Error(`Unknown flag --${name}. Try \`dynamoi help ${commandName(tool)}\`.`);
127
+ }
128
+ const [property, schema] = entry;
129
+ if (kind(schema) === "boolean") {
130
+ inline ??= negated ? "false" : "true";
131
+ parsed.flags[property] = convert(property, schema, inline);
132
+ continue;
133
+ }
134
+ const raw = inline ?? next();
135
+ if (raw === undefined) {
136
+ throw new Error(`--${name} needs a value.`);
137
+ }
138
+ if (kind(schema) === "array") {
139
+ const itemKind = schema.items ? kind(schema.items) : "string";
140
+ const items = itemKind === "json" || itemKind === "object" ? [raw] : raw.split(",");
141
+ const list = parsed.flags[property] ?? [];
142
+ parsed.flags[property] = [
143
+ ...list,
144
+ ...items.map((item) => schema.items ? convert(property, schema.items, item) : item)
145
+ ];
146
+ continue;
147
+ }
148
+ parsed.flags[property] = convert(property, schema, raw);
149
+ }
150
+ return parsed;
151
+ }
152
+ function missingRequired(tool, args) {
153
+ return (tool.inputSchema.required ?? []).filter((p) => args[p] === undefined);
154
+ }
155
+ function pendingConsent(tool, args) {
156
+ const pending = missingRequired(tool, args).filter(isConsentField);
157
+ const schemas = tool.inputSchema.properties ?? {};
158
+ return {
159
+ askable: pending.filter((p) => kind(schemas[p] ?? {}) === "boolean"),
160
+ explicit: pending.filter((p) => kind(schemas[p] ?? {}) !== "boolean")
161
+ };
162
+ }
163
+ function describeTool(tool) {
164
+ const required = new Set(tool.inputSchema.required ?? []);
165
+ const lines = [
166
+ `dynamoi ${commandName(tool)}`,
167
+ "",
168
+ tool.description ?? tool.title ?? "",
169
+ ""
170
+ ];
171
+ const rows = properties(tool);
172
+ if (rows.length > 0) {
173
+ lines.push("Flags:");
174
+ }
175
+ for (const [property, schema] of rows) {
176
+ const type = schema.enum ? schema.enum.join("|") : kind(schema);
177
+ const note = [
178
+ required.has(property) ? "required" : "",
179
+ schema.description ?? ""
180
+ ].filter(Boolean).join(". ");
181
+ lines.push(` --${flagName(property)} <${type}>${note ? ` ${note}` : ""}`);
182
+ }
183
+ lines.push("", "Also: --json for machine output, --input '<json>' for the whole argument object.");
184
+ return lines.join(`
185
+ `);
186
+ }
187
+
188
+ // src/catalog.ts
189
+ var words = (value) => value.toLowerCase().match(/[a-z0-9]+/gu) ?? [];
190
+ var stopWords = new Set([
191
+ "a",
192
+ "an",
193
+ "and",
194
+ "for",
195
+ "how",
196
+ "i",
197
+ "is",
198
+ "me",
199
+ "my",
200
+ "of",
201
+ "on",
202
+ "the",
203
+ "to",
204
+ "what",
205
+ "with"
206
+ ]);
207
+ function searchCatalog(tools, query, limit = 10) {
208
+ if (!query.trim() || query.length > 256) {
209
+ throw new Error("--query must contain 1 to 256 characters.");
210
+ }
211
+ if (!Number.isInteger(limit) || limit < 1 || limit > 10) {
212
+ throw new Error("--limit must be an integer from 1 to 10.");
213
+ }
214
+ const terms = [
215
+ ...new Set(words(query).filter((term) => !stopWords.has(term)))
216
+ ];
217
+ const matches = tools.map((tool) => {
218
+ const name = new Set(words(tool.name));
219
+ const title = new Set(words(tool.title ?? ""));
220
+ const description = new Set(words(tool.description ?? ""));
221
+ const score = terms.reduce((sum, term) => sum + (name.has(term) ? 8 : 0) + (title.has(term) ? 4 : 0) + (description.has(term) ? 1 : 0), 0);
222
+ return { score, tool };
223
+ }).filter((item) => item.score > 0).sort((left, right) => right.score - left.score || left.tool.name.localeCompare(right.tool.name));
224
+ return {
225
+ query,
226
+ tools: matches.slice(0, limit).map(({ tool }) => ({
227
+ command: commandName(tool),
228
+ description: (tool.description ?? "").slice(0, 240),
229
+ name: tool.name,
230
+ readOnly: tool.annotations?.readOnlyHint ?? null,
231
+ schemaCommand: `dynamoi help ${commandName(tool)} --json`,
232
+ title: tool.title ?? null
233
+ })),
234
+ totalMatches: matches.length
235
+ };
236
+ }
237
+ function parseCatalogArgs(args) {
238
+ let query;
239
+ let limit = 10;
240
+ let json = false;
241
+ for (let index = 0;index < args.length; index += 1) {
242
+ const arg = args[index];
243
+ if (arg === "--json") {
244
+ json = true;
245
+ continue;
246
+ }
247
+ const equals = arg.indexOf("=");
248
+ const flag = equals < 0 ? arg : arg.slice(0, equals);
249
+ if (flag !== "--query" && flag !== "--limit") {
250
+ throw new Error(`Unknown tools flag ${flag}. Use --query, --limit or --json.`);
251
+ }
252
+ if (equals < 0) {
253
+ index += 1;
254
+ }
255
+ const value = equals < 0 ? args[index] : arg.slice(equals + 1);
256
+ if (value === undefined || value.startsWith("--")) {
257
+ throw new Error(`${flag} needs a value.`);
258
+ }
259
+ if (flag === "--query") {
260
+ query = value;
261
+ } else {
262
+ limit = Number(value);
263
+ }
264
+ }
265
+ if (query === undefined && args.some((arg) => arg === "--limit" || arg.startsWith("--limit="))) {
266
+ throw new Error("--limit requires --query.");
267
+ }
268
+ return { json, limit, query };
269
+ }
270
+ function renderCatalogSearch(result) {
271
+ return [
272
+ `${result.tools.length} of ${result.totalMatches} keyword matches`,
273
+ ...result.tools.map((tool) => `${tool.command.padEnd(40)}${tool.description}`),
274
+ "Use dynamoi help <tool> --json for its complete schema."
275
+ ].join(`
276
+ `);
277
+ }
278
+
53
279
  // src/oauth.ts
54
280
  import { spawn as spawn2 } from "node:child_process";
55
281
  import { createHash, randomBytes } from "node:crypto";
@@ -404,8 +630,9 @@ async function readRpc(response) {
404
630
  }
405
631
  return JSON.parse(text || "{}");
406
632
  }
407
- async function post(method, params, token) {
408
- return fetch(MCP_URL, {
633
+ async function post(method, params, token, target, fetchRequest = fetch) {
634
+ return fetchRequest(target?.endpoint ?? MCP_URL, {
635
+ ...target ? { redirect: "error" } : {},
409
636
  body: JSON.stringify({ id: 1, jsonrpc: "2.0", method, params }),
410
637
  headers: {
411
638
  accept: "application/json, text/event-stream",
@@ -416,174 +643,84 @@ async function post(method, params, token) {
416
643
  method: "POST"
417
644
  });
418
645
  }
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);
646
+ function createRpc(target, fetchRequest = fetch) {
647
+ return async function rpc(method, params) {
648
+ let response = await post(method, params, target ? target.token : await accessToken(), target, fetchRequest);
649
+ if (!target && response.status === 401) {
650
+ const stored = await loadCredentials();
651
+ const next = stored ? await refresh(stored) : null;
652
+ if (next) {
653
+ response = await post(method, params, next.accessToken, undefined, fetchRequest);
654
+ }
426
655
  }
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;
656
+ if (response.status === 401) {
657
+ throw new Error(target ? "Synthetic preview bearer was rejected; no OAuth refresh attempted." : "Not signed in. Run `dynamoi login`.");
658
+ }
659
+ const body = await readRpc(response);
660
+ if (body.error || !response.ok) {
661
+ throw new Error(body.error?.message ?? `Dynamoi returned HTTP ${response.status}.`);
662
+ }
663
+ return body.result;
664
+ };
436
665
  }
437
- async function listTools() {
666
+ var rpc = createRpc();
667
+ async function listTools(request = rpc) {
438
668
  const tools = [];
439
669
  let cursor;
440
670
  do {
441
- const page = await rpc("tools/list", cursor ? { cursor } : {});
442
- tools.push(...page.tools.filter((tool) => tool.name.startsWith("dynamoi_")));
671
+ const page = await request("tools/list", cursor ? { cursor } : {});
672
+ tools.push(...page.tools.filter(isToolCommand));
443
673
  cursor = page.nextCursor;
444
674
  } while (cursor);
445
675
  return tools;
446
676
  }
447
- var callTool = (name, args) => rpc("tools/call", { arguments: args, name });
677
+ var callTool = (name, args, request = rpc) => request("tools/call", { arguments: args, name });
448
678
 
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);
679
+ // src/local-target.ts
680
+ import { lstatSync, readFileSync } from "node:fs";
681
+ import { homedir as homedir2 } from "node:os";
682
+ import { join } from "node:path";
683
+ function previewEndpoint(manifest, metadata, identity) {
684
+ if (manifest.state !== "ready" || manifest.data !== "synthetic" || manifest.surface === "public" || !/^dynamoi_agent_[a-z0-9_]+$/.test(manifest.database) || metadata.clones?.[manifest.database]?.source !== "empty" || !identity || manifest.identity !== identity)
685
+ throw new Error("A live, ready, empty-clone synthetic preview is required.");
686
+ const link = manifest.links.find((value) => {
687
+ const u = new URL(value);
688
+ return u.protocol === "http:" && ["127.0.0.1", "localhost"].includes(u.hostname) && !u.username && !u.password && !u.search && !u.hash && u.pathname === "/" && u.port === String(manifest.ports[0]);
689
+ });
690
+ if (!link)
691
+ throw new Error("Synthetic CLI requests require a loopback preview endpoint.");
692
+ return new URL("/mcp", link).href;
552
693
  }
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
- };
694
+ function readLocalTarget(args) {
695
+ const flags = ["--preview-manifest", "--bearer-file"];
696
+ if (!args.some((arg) => flags.includes(arg)))
697
+ return { argv: args };
698
+ if (args[0] !== flags[0] || args[2] !== flags[1] || !args[1] || !args[3] || args.slice(4).some((arg) => flags.includes(arg)))
699
+ throw new Error("Put --preview-manifest <run.json> --bearer-file <private-file> before the command.");
700
+ const argv = args.slice(4);
701
+ if (["login", "logout", "whoami"].includes(argv[0] ?? ""))
702
+ throw new Error("Synthetic preview mode supports tool commands only; OAuth credentials are isolated.");
703
+ const { endpoint } = readLocalPreview(args[1]);
704
+ const stat = lstatSync(args[3]);
705
+ if (!stat.isFile() || (stat.mode & 63) !== 0 || stat.uid !== process.getuid?.() || stat.size > 16384)
706
+ throw new Error("Bearer file must be a private, owned regular file (0600).");
707
+ const token = readFileSync(args[3], "utf8").trim();
708
+ if (!token || /\s/.test(token))
709
+ throw new Error("Bearer file is empty or invalid.");
710
+ return { argv, target: { endpoint, token } };
560
711
  }
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
- `);
712
+ function readLocalPreview(manifestPath) {
713
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
714
+ if (!Number.isSafeInteger(manifest.pid) || manifest.pid <= 0)
715
+ throw new Error("Invalid preview owner.");
716
+ const identity = readFileSync(`/proc/${manifest.pid}/stat`, "utf8").split(") ")[1]?.split(" ")[19] ?? "";
717
+ const metadata = JSON.parse(readFileSync(join(homedir2(), ".cache/dynamoi/agent-db/metadata.json"), "utf8"));
718
+ const endpoint = previewEndpoint(manifest, metadata, identity);
719
+ return { manifest, endpoint };
584
720
  }
585
721
 
586
722
  // src/run.ts
723
+ import { createInterface } from "node:readline/promises";
587
724
  var err = (line) => process.stderr.write(`${line}
588
725
  `);
589
726
  var terminal = {
@@ -638,10 +775,20 @@ var USAGE = `dynamoi ${VERSION}: Music promotion and distribution, built for AI
638
775
  Usage:
639
776
  dynamoi login | logout | whoami
640
777
  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) {
778
+ dynamoi tools --query <text> [--limit 1..10] [--json]
779
+ Find tools without loading every schema
780
+ dynamoi help <tool> [--json] Show flags or the exact catalog schema
781
+ dynamoi <tool> [--flag value] Run a tool; add --json for machine output
782
+ dynamoi --preview-manifest <run.json> --bearer-file <0600-file> <command>
783
+ Use a ready local synthetic preview only`;
784
+ async function main(args) {
785
+ const { argv, target } = readLocalTarget(args);
786
+ const request = createRpc(target);
644
787
  const [command, ...rest] = argv;
788
+ if (command === "help" && rest.length === 0 || command === "tools" && rest.includes("--help")) {
789
+ out(USAGE);
790
+ return 0;
791
+ }
645
792
  switch (command) {
646
793
  case undefined:
647
794
  case "--help":
@@ -680,10 +827,16 @@ async function main(argv) {
680
827
  default:
681
828
  break;
682
829
  }
683
- const tools = await listTools();
830
+ const catalogArgs = command === "tools" ? parseCatalogArgs(rest) : undefined;
831
+ const tools = await listTools(request);
684
832
  const find = (name) => tools.find((candidate) => commandName(candidate) === name?.replaceAll("_", "-").replace(/^dynamoi-/u, ""));
685
833
  if (command === "tools") {
686
- if (rest.includes("--json")) {
834
+ if (catalogArgs?.query !== undefined) {
835
+ const result = searchCatalog(tools, catalogArgs.query, catalogArgs.limit);
836
+ out(catalogArgs.json ? JSON.stringify(result) : renderCatalogSearch(result));
837
+ return 0;
838
+ }
839
+ if (catalogArgs?.json) {
687
840
  out(JSON.stringify(tools.map(({ name, description, inputSchema }) => ({
688
841
  description,
689
842
  inputSchema,
@@ -694,7 +847,7 @@ async function main(argv) {
694
847
  for (const tool of tools) {
695
848
  out(`${commandName(tool).padEnd(40)}${(tool.description ?? "").slice(0, 100)}`);
696
849
  }
697
- if (!await loadCredentials()) {
850
+ if (!target && !await loadCredentials()) {
698
851
  err2("\nSign in with `dynamoi login` to see every tool your account can use.");
699
852
  }
700
853
  return 0;
@@ -705,7 +858,7 @@ async function main(argv) {
705
858
  out(USAGE);
706
859
  return rest[0] ? 1 : 0;
707
860
  }
708
- out(describeTool(tool));
861
+ out(rest.includes("--json") ? JSON.stringify(tool) : describeTool(tool));
709
862
  return 0;
710
863
  }
711
864
  const tool = find(command);
@@ -715,7 +868,7 @@ async function main(argv) {
715
868
  }
716
869
  const parsed = parseArgs(tool, rest);
717
870
  if (parsed.global.help) {
718
- out(describeTool(tool));
871
+ out(parsed.global.json ? JSON.stringify(tool) : describeTool(tool));
719
872
  return 0;
720
873
  }
721
874
  const missing = missingRequired(tool, parsed.flags).filter((p) => !pendingConsent(tool, parsed.flags).askable.includes(p));
@@ -723,7 +876,7 @@ async function main(argv) {
723
876
  err2(`Missing required flags: ${missing.map((p) => `--${flagName(p)}`).join(", ")}`);
724
877
  return 2;
725
878
  }
726
- const result = await runTool(tool, parsed.flags, terminal);
879
+ const result = await runTool(tool, parsed.flags, terminal, (name, input) => callTool(name, input, request));
727
880
  const text = (result.content ?? []).map((part) => part.text ?? "").filter(Boolean).join(`
728
881
  `);
729
882
  if (parsed.global.json) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://www.schemastore.org/package",
3
3
  "name": "dynamoi",
4
- "version": "0.2.2",
4
+ "version": "0.2.4",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "Music promotion and distribution, built for AI agents: the Dynamoi command line.",