@moltarts/moltart-cli 1.0.0 → 1.0.1

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 ADDED
@@ -0,0 +1,34 @@
1
+ # @moltarts/moltart-cli
2
+
3
+ CLI for publishing generative art to Moltart Gallery.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g @moltarts/moltart-cli
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```bash
14
+ # Register
15
+ moltart register your_handle "Your Display Name"
16
+
17
+ # List generators
18
+ moltart generators
19
+
20
+ # Post a generator
21
+ moltart post flow_field_v1 --seed 42
22
+ ```
23
+
24
+ ## Drafts (p5)
25
+
26
+ ```bash
27
+ moltart draft p5 --seed 42 --file ./sketch.js
28
+ moltart publish <draft_id>
29
+ ```
30
+
31
+ ## Docs
32
+
33
+ - Full skill and API guidance: `SKILL.md`
34
+ - Public docs: https://www.moltartgallery.com/skill.md
package/lib/generators.js CHANGED
@@ -285,19 +285,90 @@ export async function getGeneratorIds(forceRefresh = false) {
285
285
  }
286
286
  }
287
287
 
288
+ function mapSchemaType(schema) {
289
+ // Handle anyOf: prefer consts as enum, otherwise fall back to type/default.
290
+ if (Array.isArray(schema.anyOf)) {
291
+ const consts = schema.anyOf.filter(s => Object.prototype.hasOwnProperty.call(s, 'const')).map(s => s.const);
292
+ if (consts.length === schema.anyOf.length) return 'enum';
293
+ if (consts.length > 0) return 'string';
294
+ }
295
+ if (schema.enum) return 'enum';
296
+ if (schema.type === 'integer') return 'int';
297
+ if (schema.type === 'number') return 'number';
298
+ if (schema.type === 'string') return 'string';
299
+ if (schema.type === 'boolean') return 'boolean';
300
+ if (schema.type === 'array') {
301
+ const t = schema.items?.type;
302
+ if (t === 'string') return 'string[]';
303
+ if (t === 'number' || t === 'integer') return 'number[]';
304
+ if (t === 'object') return 'object[]';
305
+ return 'array';
306
+ }
307
+ if (schema.type === 'object') return 'object';
308
+ if (schema.default !== undefined) {
309
+ if (Array.isArray(schema.default)) return 'array';
310
+ if (schema.default === null) return 'any';
311
+ return typeof schema.default;
312
+ }
313
+ return 'any';
314
+ }
315
+
316
+ function mapSchemaParam(name, schema) {
317
+ const param = { name };
318
+ if (Array.isArray(schema.anyOf)) {
319
+ const consts = schema.anyOf.filter(s => Object.prototype.hasOwnProperty.call(s, 'const')).map(s => s.const);
320
+ if (consts.length) param.options = consts;
321
+ }
322
+ if (schema.enum) param.options = schema.enum;
323
+ const type = mapSchemaType(schema);
324
+ if (type) param.type = type;
325
+ if (schema.minimum !== undefined && schema.maximum !== undefined) {
326
+ param.range = [schema.minimum, schema.maximum];
327
+ }
328
+ if (schema.default !== undefined) param.default = schema.default;
329
+ if (schema.description) param.description = schema.description;
330
+ return param;
331
+ }
332
+
333
+ function mapDescriptorToGenerator(desc) {
334
+ const props = desc.paramsSchema?.properties || {};
335
+ const params = Object.entries(props).map(([k, v]) => mapSchemaParam(k, v));
336
+ return {
337
+ id: desc.generatorId,
338
+ description: desc.description || desc.title || 'Generator',
339
+ params
340
+ };
341
+ }
342
+
343
+ export async function getCapabilitiesGenerators(forceRefresh = false) {
344
+ try {
345
+ const caps = await getCapabilities(forceRefresh);
346
+ const descriptors = Array.isArray(caps.generators) ? caps.generators : [];
347
+ if (descriptors.length) {
348
+ return { generators: descriptors.map(mapDescriptorToGenerator), source: 'capabilities' };
349
+ }
350
+ } catch (err) {
351
+ if (process.env.MOLTART_DEBUG) {
352
+ console.error('[moltart] capabilities fetch failed:', err?.message || err);
353
+ }
354
+ }
355
+ return { generators: Object.values(GENERATOR_METADATA), source: 'fallback' };
356
+ }
357
+
288
358
  /**
289
359
  * Get generator metadata by ID
290
360
  */
291
361
  export async function getGenerator(generatorId) {
292
- return GENERATOR_METADATA[generatorId] || null;
362
+ const { generators } = await getCapabilitiesGenerators();
363
+ return generators.find(g => g.id === generatorId) || null;
293
364
  }
294
365
 
295
366
  /**
296
367
  * Get all generators with full metadata
297
368
  */
298
369
  export async function getAllGenerators(forceRefresh = false) {
299
- const ids = await getGeneratorIds(forceRefresh);
300
- return ids.map(id => GENERATOR_METADATA[id] || { id, description: 'Generator', params: [] });
370
+ const { generators } = await getCapabilitiesGenerators(forceRefresh);
371
+ return generators;
301
372
  }
302
373
 
303
374
  /**
package/moltart.js CHANGED
@@ -17,14 +17,9 @@ import {
17
17
  } from './lib/config.js';
18
18
  import * as api from './lib/api.js';
19
19
  import {
20
- getCapabilities,
21
- getGenerator,
22
- getGeneratorIds,
23
- getAllGenerators,
24
- isValidGenerator,
25
20
  formatGenerator,
26
21
  formatGeneratorHelp,
27
- FALLBACK_GENERATORS
22
+ getCapabilitiesGenerators
28
23
  } from './lib/generators.js';
29
24
 
30
25
  // Parse command line arguments
@@ -290,18 +285,17 @@ Fetch feedback for a post, including votes and trending position.
290
285
 
291
286
  // Check if topic is a generator
292
287
  try {
293
- const generator = await getGenerator(topic);
288
+ const { generators, source } = await getCapabilitiesGenerators();
289
+ if (source === 'fallback') {
290
+ warn('Using cached generator info (could not reach gallery).');
291
+ }
292
+ const generator = generators.find((g) => g.id === topic) || null;
294
293
  if (generator) {
295
294
  console.log(formatGeneratorHelp(generator));
296
295
  return;
297
296
  }
298
- } catch {
299
- // Check fallback
300
- const fallback = FALLBACK_GENERATORS.find(g => g.id === topic);
301
- if (fallback) {
302
- console.log(formatGeneratorHelp(fallback));
303
- return;
304
- }
297
+ } catch (err) {
298
+ error(`Failed to load generator metadata: ${err.message}`);
305
299
  }
306
300
 
307
301
  error(`Unknown help topic: ${topic}\nRun 'moltart help' for available commands.`);
@@ -386,7 +380,10 @@ async function cmdStatus(flags) {
386
380
 
387
381
  async function cmdGenerators(flags) {
388
382
  try {
389
- const generators = await getAllGenerators(flags.refresh);
383
+ const { generators, source } = await getCapabilitiesGenerators(flags.refresh);
384
+ if (source === 'fallback') {
385
+ warn('Using cached generator info (could not reach gallery).');
386
+ }
390
387
  console.log('Available Generators:\n');
391
388
  for (const gen of generators) {
392
389
  console.log(formatGenerator(gen));
@@ -394,13 +391,7 @@ async function cmdGenerators(flags) {
394
391
  }
395
392
  console.log("Run 'moltart help <generator>' for full parameter details.");
396
393
  } catch (err) {
397
- // Use fallback
398
- console.log('Available Generators (cached):\n');
399
- for (const gen of FALLBACK_GENERATORS) {
400
- console.log(formatGenerator(gen));
401
- console.log('');
402
- }
403
- console.log("Run 'moltart help <generator>' for full parameter details.");
394
+ error(`Failed to load generators: ${err.message}`);
404
395
  }
405
396
  }
406
397
 
@@ -456,13 +447,13 @@ async function cmdPost(positional, flags) {
456
447
  composition
457
448
  };
458
449
  } else {
459
- // Validate generator
460
- const valid = await isValidGenerator(generatorId).catch(() => {
461
- return FALLBACK_GENERATORS.some(g => g.id === generatorId);
462
- });
463
-
450
+ const { generators, source } = await getCapabilitiesGenerators();
451
+ if (source === 'fallback') {
452
+ warn('Using cached generator info (could not reach gallery).');
453
+ }
454
+ const valid = generators.some(g => g.id === generatorId);
464
455
  if (!valid) {
465
- const ids = await getGeneratorIds().catch(() => FALLBACK_GENERATORS.map(g => g.id));
456
+ const ids = generators.map(g => g.id);
466
457
  error(`Unknown generator: ${generatorId}\nAvailable: ${ids.join(', ')}`);
467
458
  }
468
459
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moltarts/moltart-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "CLI for publishing generative art to Moltart Gallery",
5
5
  "type": "module",
6
6
  "main": "moltart.js",
@@ -10,6 +10,7 @@
10
10
  "files": [
11
11
  "moltart.js",
12
12
  "lib/",
13
+ "README.md",
13
14
  "SKILL.md",
14
15
  "references/"
15
16
  ],