@plaiful/cli 0.1.0 → 0.3.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.
Files changed (3) hide show
  1. package/README.md +7 -0
  2. package/package.json +21 -21
  3. package/src/cli.js +303 -3
package/README.md CHANGED
@@ -34,8 +34,15 @@ plaiful seed world # dry run: what resources/world/roadforge/*.json m
34
34
  plaiful seed world --apply # write it (then lore, then map); --reset also puts the clock, reveals and NPC bindings back
35
35
  plaiful seed personas # THESPIS personas and situations from resources/personas/roadforge/ (same dry run / --apply)
36
36
  plaiful status # what OVID and THESPIS have in dev: counts per store, the clock, the declaration
37
+ plaiful assets # per agent: records, and how many have art made / pending / failed / none yet
38
+ plaiful assets crew-portrait --state failed # one agent's records: state, why a render failed, where the files are
39
+ plaiful quests # the quests OVID wrote: steps, and what each pays (--track, --series); quests show <id>
40
+ plaiful lore # the lore sets (lore show <setId>: a set's snippets)
41
+ plaiful world # the world's states and events in story order, and the clock
37
42
  plaiful lists # the product's SSM lists
38
43
  plaiful lists set shop_type tavern blacksmith healer # write one (lists get shop_type reads it)
44
+ plaiful midas pricing # what each quest pays, in your reward kinds (MIDAS); delivered in the quest's rewards
45
+ plaiful midas pricing set scrap --base 20 --per-effort 10 # price a kind (unset <kind>, weight <step> <n>, apply [file])
39
46
  plaiful upload ovid-map-biomes-tiles.json ovid-map-kingdoms-tiles.json ovid-map-colors.json # map tiles → map-data/
40
47
  plaiful whoami # who you are (or which key), and your products
41
48
  plaiful logout
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
- {
2
- "name": "@plaiful/cli",
3
- "version": "0.1.0",
4
- "description": "The Plaiful CLI: work on your Plaiful product from your game repo, with no AWS access",
5
- "bin": {
6
- "plaiful": "bin/plaiful.js"
7
- },
8
- "files": [
9
- "bin",
10
- "src",
11
- "README.md"
12
- ],
13
- "engines": {
14
- "node": ">=18"
15
- },
16
- "license": "UNLICENSED",
17
- "publishConfig": {
18
- "registry": "https://registry.npmjs.org/",
19
- "access": "public"
20
- }
21
- }
1
+ {
2
+ "name": "@plaiful/cli",
3
+ "version": "0.3.0",
4
+ "description": "The Plaiful CLI: work on your Plaiful product from your game repo, with no AWS access",
5
+ "bin": {
6
+ "plaiful": "bin/plaiful.js"
7
+ },
8
+ "files": [
9
+ "bin",
10
+ "src",
11
+ "README.md"
12
+ ],
13
+ "engines": {
14
+ "node": ">=18"
15
+ },
16
+ "license": "UNLICENSED",
17
+ "publishConfig": {
18
+ "registry": "https://registry.npmjs.org/",
19
+ "access": "public"
20
+ }
21
+ }
package/src/cli.js CHANGED
@@ -29,9 +29,30 @@ const HELP = `plaiful ${version}: work on your Plaiful product from your game re
29
29
  --apply write them; --reset also put runtime state back to the files
30
30
  --rows print every row
31
31
  plaiful status what OVID and THESPIS have for your product in dev
32
+ plaiful quests the quests OVID wrote: steps and what each pays (--track <id>, --series <id>)
33
+ plaiful quests show <id> one quest: its graph, steps, reward hint and price (--json: the whole record)
34
+ plaiful lore the lore sets, with known / hidden snippet counts
35
+ plaiful lore show <setId> one set's snippets
36
+ plaiful world the world's states and state events in story order, and the clock
32
37
  plaiful lists your product's SSM lists (NPC roles, SmartBuilder list values, ...)
33
38
  plaiful lists get <name> one list (a name in your namespace, e.g. shop_type, or the full /path)
34
39
  plaiful lists set <name> <values...> write a list (values as words, or one comma-separated argument)
40
+ plaiful agents your product's SmartBuilder agents in dev
41
+ plaiful agents show <name> one agent's deployed config
42
+ plaiful agents deploy [files...] deploy or redeploy agents from their config files (default: every .json in
43
+ resources/agents/<product>/); a redeploy keeps the agent's own settings
44
+ plaiful agents run <name> [key=value...] make one record (placeholder values as key=value)
45
+ plaiful agents batch <name> [file] start a batch (a batch body file, or --count <n>) → a job id
46
+ plaiful agents status <name> <jobId> a batch's progress
47
+ plaiful midas pricing what MIDAS pays per quest, in your reward kinds (delivered in each quest's rewards)
48
+ plaiful midas pricing set <kind> --base <n> --per-effort <n> price a kind (either option alone keeps the other)
49
+ plaiful midas pricing unset <kind> stop pricing a kind
50
+ plaiful midas pricing weight <step> <n> how much a quest step counts (combat, gather, explore, ...)
51
+ plaiful midas pricing apply [file] replace it all from a file (default:
52
+ resources/midas/<product>/quest-pricing.json; { kinds, objective_weights, ... })
53
+ plaiful assets per agent: records, and how many have their art made, pending, failed or none
54
+ plaiful assets <agent> its records: state, why a render failed, where the files are
55
+ --state made|pending|failed|none --limit <n> (default 50)
35
56
  plaiful upload <files...> upload map tiles into your dev assets bucket (map-data/; --dest map-data)
36
57
  plaiful clone [product] [dir] clone the game repo, write .env.development, docs pull, npm install, open Zed
37
58
  --no-install --no-open
@@ -50,13 +71,20 @@ class ApiError extends Error {
50
71
  }
51
72
  }
52
73
 
74
+ /** Where an agent list's values come from: an SSM path, or the values kept in the agent ({ values: [...] }). */
75
+ function listSource(v) {
76
+ if (v && typeof v === 'object' && Array.isArray(v.values)) return `in the agent (${v.values.length}: ${v.values.slice(0, 4).join(', ')}${v.values.length > 4 ? ', …' : ''})`;
77
+ if (v && typeof v === 'object') return v.path || JSON.stringify(v);
78
+ return String(v);
79
+ }
80
+
53
81
  function parse(argv) {
54
82
  const flags = {};
55
83
  const args = [];
56
84
  for (let i = 0; i < argv.length; i += 1) {
57
85
  const a = argv[i];
58
86
  if (['--json', '--no-browser', '--help', '-h', '--version', '--apply', '--reset', '--rows', '--no-install', '--no-open'].includes(a)) flags[a.replace(/^-+/, '')] = true;
59
- else if (a === '--product' || a === '--api' || a === '--dir' || a === '--dest') {
87
+ else if (['--product', '--api', '--dir', '--dest', '--count', '--base', '--per-effort', '--track', '--series', '--state', '--limit'].includes(a)) {
60
88
  if (argv[i + 1] === undefined) throw new UsageError(`${a} needs a value`);
61
89
  flags[a.slice(2)] = argv[i += 1];
62
90
  } else if (a.startsWith('--')) throw new UsageError(`unknown option ${a}`);
@@ -335,7 +363,7 @@ async function status(ctx) {
335
363
  const d = data.declaration || {};
336
364
  const err = (x) => (x.error ? ` ${x.error}` : null);
337
365
  const lines = [`${r.product} in dev:`];
338
- lines.push(` world ${err(w) || `${w.events} events (${w.macro} macro, ${w.meso} meso, ${w.micro} micro), ${w.seeded} seeded`}`);
366
+ lines.push(` world ${err(w) || `${w.events} events (${w.macro} macro, ${w.meso} meso, ${w.micro} micro${w.state_events ? `, ${w.state_events} state events` : ''}), ${w.seeded} seeded`}`);
339
367
  if (!w.error) lines.push(` clock: ${w.clock ? `${w.clock.mode}, at ${w.clock.currentMicro} (${w.clock.chapterTitle})` : 'not set (seed a worldClock, or set it in GameMaster)'}`);
340
368
  lines.push(` lore ${err(l) || `${l.sets} sets, ${l.snippets} snippets (${l.known} known, ${l.hidden} hidden), ${l.seeded} rows seeded${l.without_product ? `; ${l.without_product} snippets lack "product" and never reach a character` : ''}`}`);
341
369
  lines.push(` map ${err(m) || `${m.locations} locations, ${m.settlements} settlements (${m.settlements_with_npcs} with NPCs), ${m.seeded} seeded`}`);
@@ -383,6 +411,272 @@ async function lists(ctx, [sub, name, ...values]) {
383
411
  throw new UsageError(`plaiful lists, lists get <name> or lists set <name> <values...> (not "${sub}")`);
384
412
  }
385
413
 
414
+ // ── SmartBuilder agents ─────────────────────────────────────────────────────────────────────────────────────
415
+
416
+ const agentRoute = (r, rest = '') => `/partner/${encodeURIComponent(r.product)}/agents${rest}`;
417
+ const AGENT_NAME = /^[a-z0-9][a-z0-9-]{0,62}$/;
418
+
419
+ function readJsonFile(ctx, f) {
420
+ const file = path.resolve(ctx.io.cwd(), f);
421
+ if (!fs.existsSync(file) || !fs.statSync(file).isFile()) throw new UsageError(`${file} isn't a file`);
422
+ try { return { file, json: JSON.parse(fs.readFileSync(file, 'utf8')) }; } catch (e) { throw new UsageError(`${file} isn't valid JSON (${e.message})`); }
423
+ }
424
+
425
+ /** The config files to deploy: the ones named, or every .json in resources/agents/<product>/. */
426
+ function agentFiles(ctx, r, files) {
427
+ if (files.length) return files;
428
+ const dir = path.join(ctx.io.cwd(), 'resources', 'agents', r.product);
429
+ if (!fs.existsSync(dir)) throw new UsageError(`no files named, and no ${path.relative(ctx.io.cwd(), dir)}/ folder: plaiful agents deploy <file.json>`);
430
+ const found = fs.readdirSync(dir).filter((n) => n.endsWith('.json')).map((n) => path.join(dir, n));
431
+ if (!found.length) throw new UsageError(`${path.relative(ctx.io.cwd(), dir)}/ has no .json agent configs`);
432
+ return found;
433
+ }
434
+
435
+ async function agents(ctx, [sub, name, ...rest]) {
436
+ const r = repo(ctx);
437
+ if (!sub) {
438
+ const { data } = await ctx.call('GET', agentRoute(r));
439
+ const list = data.agents || [];
440
+ const lines = [`${r.product}'s SmartBuilder agents in dev:`];
441
+ if (!list.length) lines.push(' none yet (plaiful agents deploy <file.json>, or SmartBuilder in the CMS)');
442
+ for (const a of list) lines.push(` ${a.name || a.agent_name}${a.display_name ? ` ${a.display_name}` : ''}${a.business_purpose ? ` (${a.business_purpose})` : ''}`);
443
+ ctx.out(lines.join('\n'), data);
444
+ return 0;
445
+ }
446
+ if (sub === 'show') {
447
+ if (!name) throw new UsageError('which agent? plaiful agents show <name>');
448
+ const { data } = await ctx.call('GET', agentRoute(r, `/${encodeURIComponent(name)}`));
449
+ const a = data.agent || {};
450
+ const lines = [`${a.agent_name || name}: ${a.display_name || ''}`.trim(),
451
+ ` table ${(a.storage || {}).table_name || '?'}, version ${(a.metadata || {}).version || '?'}, ${(a.metadata || {}).business_purpose || 'content'}`,
452
+ ` fields ${(a.output_fields || []).join(', ')}`,
453
+ ` lists ${Object.entries(a.ssm_parameters || {}).map(([k, v]) => `${k} ← ${listSource(v)}`).join('; ') || 'none'}`,
454
+ ` dedup ${a.duplicate_detection && a.duplicate_detection.enabled !== false ? `on ${[].concat(a.duplicate_detection.field || 'name').join(', ')}` : 'off'}`,
455
+ ' (--json prints the whole config)'];
456
+ ctx.out(lines.join('\n'), data);
457
+ return 0;
458
+ }
459
+ if (sub === 'deploy') {
460
+ const files = agentFiles(ctx, r, [name, ...rest].filter(Boolean));
461
+ const done = [];
462
+ for (const f of files) {
463
+ const { file, json } = readJsonFile(ctx, f);
464
+ const agentName = json.agent_name || path.basename(file, '.json');
465
+ if (!AGENT_NAME.test(agentName)) throw new UsageError(`${path.basename(file)}: "${agentName}" isn't an agent name (lowercase letters, digits, hyphens)`);
466
+ const { data } = await ctx.call('POST', agentRoute(r, `/${agentName}`), { config: json });
467
+ done.push(data);
468
+ if (!ctx.flags.json) ctx.out(`${data.redeployed ? 'redeployed' : 'deployed'} ${data.agent_name}: table ${data.table_name}${data.table === 'created' ? ' (new)' : ''}, version ${data.version}`);
469
+ }
470
+ if (ctx.flags.json) ctx.out('', { success: true, product: r.product, deployed: done });
471
+ return 0;
472
+ }
473
+ if (sub === 'run') {
474
+ if (!name) throw new UsageError('which agent? plaiful agents run <name> [key=value...]');
475
+ const body = {};
476
+ for (const kv of rest) {
477
+ const i = kv.indexOf('=');
478
+ if (i < 1) throw new UsageError(`"${kv}" isn't key=value`);
479
+ body[kv.slice(0, i)] = kv.slice(i + 1);
480
+ }
481
+ const { data } = await ctx.call('POST', agentRoute(r, `/${encodeURIComponent(name)}/run`), body);
482
+ const rec = data.item || data.record || data;
483
+ ctx.out(`made ${rec.uuid || 'a record'}${rec.name ? `: ${rec.name}` : ''}`, data);
484
+ return 0;
485
+ }
486
+ if (sub === 'batch') {
487
+ if (!name) throw new UsageError('which agent? plaiful agents batch <name> [batch-body.json] (or --count <n>)');
488
+ let body;
489
+ if (rest[0]) body = readJsonFile(ctx, rest[0]).json;
490
+ else if (ctx.flags.count) body = { count: Number(ctx.flags.count) };
491
+ else throw new UsageError('give a batch body file, or --count <n>');
492
+ const { data } = await ctx.call('POST', agentRoute(r, `/${encodeURIComponent(name)}/batch`), body);
493
+ ctx.out(`started batch ${data.job_id} (${data.total_items || '?'} records). plaiful agents status ${name} ${data.job_id}`, data);
494
+ return 0;
495
+ }
496
+ if (sub === 'status') {
497
+ const [jobId] = rest;
498
+ if (!name || !jobId) throw new UsageError('plaiful agents status <name> <jobId>');
499
+ const { data } = await ctx.call('GET', agentRoute(r, `/${encodeURIComponent(name)}/batch/${encodeURIComponent(jobId)}`));
500
+ ctx.out(`${data.status || '?'}: ${data.completed_items ?? '?'} done, ${data.failed_items ?? 0} failed of ${data.total_items ?? '?'}`, data);
501
+ return 0;
502
+ }
503
+ throw new UsageError(`plaiful agents, or agents show | deploy | run | batch | status (not "${sub}")`);
504
+ }
505
+
506
+ // ── What OVID has: quests, lore, the world ──────────────────────────────────────────────────────────────────────
507
+
508
+ const ovidRoute = (r, rest) => `/partner/${encodeURIComponent(r.product)}/ovid/${rest}`;
509
+ const priceText = (p) => (p && Object.keys(p).length ? Object.entries(p).map(([k, v]) => `${v} ${k}`).join(', ') : '');
510
+
511
+ async function quests(ctx, [sub, id]) {
512
+ const r = repo(ctx);
513
+ if (sub === 'show') {
514
+ if (!id) throw new UsageError('which quest? plaiful quests show <id>');
515
+ const { data } = await ctx.call('GET', ovidRoute(r, `quests/${encodeURIComponent(id)}`));
516
+ const q = data.quest || {};
517
+ const lines = [`${data.title || id} [${data.questType || '?'}] track ${data.quest_track || '?'}${data.series ? `, ${data.series.series_title || data.series.series_id} #${data.series.series_order}` : ''} (${data.status || '?'})`];
518
+ if (q.narrative_desc || q.description) lines.push(` ${q.narrative_desc || q.description}`);
519
+ for (const st of data.steps_detail || []) {
520
+ const n = (q.nodes || {})[st.id] || {};
521
+ const say = n.close || n.narrative_desc || (n.dialogue_tree && n.dialogue_tree.nodes && Object.values(n.dialogue_tree.nodes)[0] && Object.values(n.dialogue_tree.nodes)[0].text) || '';
522
+ lines.push(` ${st.unreached ? '(unreached) ' : ''}${st.id}: ${st.type}${st.count > 1 ? `×${st.count}` : ''}${say ? ` "${String(say).slice(0, 90)}${String(say).length > 90 ? '…' : ''}"` : ''}`);
523
+ }
524
+ lines.push(` pays: ${priceText(data.price) || (data.priced ? 'nothing (no step carries effort)' : 'not priced yet (plaiful midas pricing)')}${data.reward_hint ? `; hint: ${data.reward_hint.kinds.join(', ')}` : ''}`);
525
+ lines.push(' (--json prints the whole record)');
526
+ ctx.out(lines.join('\n'), data);
527
+ return 0;
528
+ }
529
+ if (sub) throw new UsageError(`plaiful quests, or quests show <id> (not "${sub}")`);
530
+ const qs = new URLSearchParams();
531
+ if (ctx.flags.track) qs.set('track', ctx.flags.track);
532
+ if (ctx.flags.series) qs.set('series', ctx.flags.series);
533
+ const { data } = await ctx.call('GET', `${ovidRoute(r, 'quests')}${qs.toString() ? `?${qs}` : ''}`);
534
+ const lines = [`${r.product}'s quests in dev: ${data.count}${data.priced ? '' : ' (not priced yet: plaiful midas pricing)'}`];
535
+ let group = null;
536
+ for (const q of data.quests) {
537
+ const g = `${q.quest_track || '?'}${q.series ? ` · ${q.series.series_title || q.series.series_id}` : ''}`;
538
+ if (g !== group) { lines.push(` ${g}`); group = g; }
539
+ const pays = priceText(q.price);
540
+ lines.push(` ${q.series ? `${q.series.series_order}. ` : ''}${q.title} [${q.questType || '?'}] ${q.steps.join(' → ')}${pays ? ` pays ${pays}` : ''} ${q.quest_id}`);
541
+ }
542
+ if (data.truncated) lines.push(' (cut off: more quests than one read returns)');
543
+ ctx.out(lines.join('\n'), data);
544
+ return 0;
545
+ }
546
+
547
+ async function lore(ctx, [sub, id]) {
548
+ const r = repo(ctx);
549
+ if (sub === 'show') {
550
+ if (!id) throw new UsageError('which set? plaiful lore show <setId>');
551
+ const { data } = await ctx.call('GET', ovidRoute(r, `lore/${encodeURIComponent(id)}`));
552
+ const lines = [`${data.title || id}${data.category ? ` (${data.category})` : ''}`];
553
+ for (const sn of data.snippets || []) lines.push(` ${sn.world_known ? 'known ' : 'hidden'} ${sn.title || sn.snippet_id}${sn.narrative ? `: ${String(sn.narrative).slice(0, 100)}${String(sn.narrative).length > 100 ? '…' : ''}` : ''}`);
554
+ ctx.out(lines.join('\n'), data);
555
+ return 0;
556
+ }
557
+ if (sub) throw new UsageError(`plaiful lore, or lore show <setId> (not "${sub}")`);
558
+ const { data } = await ctx.call('GET', ovidRoute(r, 'lore'));
559
+ const lines = [`${r.product}'s lore in dev: ${data.sets.length} sets`];
560
+ for (const st of data.sets) lines.push(` ${st.lore_set_id} ${st.title || ''} ${st.snippets} snippets (${st.known} known, ${st.hidden} hidden)${st.source === 'plaiful-seed' ? '' : st.source ? ` from ${st.source}` : ''}`);
561
+ ctx.out(lines.join('\n'), data);
562
+ return 0;
563
+ }
564
+
565
+ async function world(ctx) {
566
+ const r = repo(ctx);
567
+ const { data } = await ctx.call('GET', ovidRoute(r, 'world'));
568
+ const c = data.clock;
569
+ const lines = [`${r.product}'s world in dev: ${data.events.length} states and events; clock ${c ? `${c.mode || '?'}, at ${c.currentMicro || '?'}${c.chapterTitle ? ` (${c.chapterTitle})` : ''}` : 'not set'}`];
570
+ const indent = { macro: ' ', meso: ' ', micro: ' ' };
571
+ for (const e of data.events) {
572
+ const pad = e.kind === 'event' ? ' ' : (indent[e.scope] || ' ');
573
+ lines.push(`${pad}${e.kind === 'event' ? '· ' : ''}${e.title || e.event_id} ${e.scope || e.kind}${e.faction ? `, ${e.faction}` : ''}${e.advances ? ', advances' : ''}${c && e.event_id === c.currentMicro ? ' ← now' : ''} ${e.event_id}`);
574
+ }
575
+ if (data.truncated) lines.push(' (cut off: more rows than one read returns)');
576
+ ctx.out(lines.join('\n'), data);
577
+ return 0;
578
+ }
579
+
580
+ // ── What the agents made ────────────────────────────────────────────────────────────────────────────────────────
581
+
582
+ const countsText = (a) => `${a.records} records: ${a.made} made, ${a.pending} pending, ${a.failed} failed, ${a.none} none yet${a.truncated ? ' (first 2000)' : ''}`;
583
+
584
+ async function assets(ctx, [agent]) {
585
+ const r = repo(ctx);
586
+ const base = `/partner/${encodeURIComponent(r.product)}/assets`;
587
+ if (!agent) {
588
+ const { data } = await ctx.call('GET', base);
589
+ const lines = [`${r.product}'s agents in dev${data.cdn ? ` (files on https://${data.cdn}/)` : ''}:`];
590
+ if (!data.agents.length) lines.push(' none yet (plaiful agents deploy)');
591
+ for (const a of data.agents) {
592
+ lines.push(` ${a.name.padEnd(24)} ${a.error ? `couldn't read: ${a.error}` : a.makes_art ? countsText(a) : '(makes no art)'}`);
593
+ }
594
+ ctx.out(lines.join('\n'), data);
595
+ return 0;
596
+ }
597
+ const qs = new URLSearchParams();
598
+ if (ctx.flags.state) qs.set('state', ctx.flags.state);
599
+ if (ctx.flags.limit) qs.set('limit', ctx.flags.limit);
600
+ const { data } = await ctx.call('GET', `${base}/${encodeURIComponent(agent)}${qs.toString() ? `?${qs}` : ''}`);
601
+ const lines = [`${agent}: ${countsText(data.counts)}${ctx.flags.state ? `; ${data.matching} ${ctx.flags.state}` : ''}${data.shown < data.matching ? `, showing ${data.shown} (--limit)` : ''}`];
602
+ for (const rec of data.records) {
603
+ const why = rec.render_error || Object.entries(rec.media || {}).filter(([, m]) => m.error).map(([k, m]) => `${k}: ${m.error}`).join('; ');
604
+ const where = rec.state === 'made' && rec.files ? `${rec.files.base}.{${rec.files.try.join('|')}}` : '';
605
+ lines.push(` ${rec.state.padEnd(8)} ${rec.name || '(unnamed)'} ${rec.uuid}${why ? ` ${why}` : ''}${where ? ` ${where}` : ''}`);
606
+ }
607
+ ctx.out(lines.join('\n'), data);
608
+ return 0;
609
+ }
610
+
611
+ // ── MIDAS quest pricing ─────────────────────────────────────────────────────────────────────────────────────────
612
+
613
+ const pricingRoute = (r) => `/partner/${encodeURIComponent(r.product)}/midas/pricing`;
614
+
615
+ function nonNegative(v, what) {
616
+ const n = Number(v);
617
+ if (v === undefined || v === true || !Number.isFinite(n) || n < 0) throw new UsageError(`${what} must be a number, 0 or more`);
618
+ return n;
619
+ }
620
+
621
+ function pricingLines(product, data) {
622
+ const qp = data.quest_pricing || {};
623
+ const kinds = qp.kinds || {};
624
+ const declared = ((data.rewards || {}).types || []).filter((k) => k !== 'lore');
625
+ const names = [...new Set([...declared, ...Object.keys(kinds)])];
626
+ const d = data.defaults || {};
627
+ const weights = { ...(d.objective_weights || {}), ...(qp.objective_weights || {}) };
628
+ const lines = [`${product}'s quest pricing in dev: price = base + per-effort × the quest's effort`];
629
+ if (!names.length) lines.push(' no reward kinds declared (settings.rewards.types in your OVID declaration)');
630
+ for (const k of names) {
631
+ const p = kinds[k];
632
+ lines.push(` ${k.padEnd(12)} ${p ? `base ${p.base ?? 0}, per effort ${p.per_objective ?? 0}` : 'not priced (plaiful midas pricing set ' + k + ' --base <n> --per-effort <n>)'}`);
633
+ }
634
+ lines.push(` effort: each step's weight, +${qp.count_effort ?? d.count_effort} of it per extra unit (units counted up to ${qp.count_cap ?? d.count_cap})`);
635
+ lines.push(` weights: ${Object.entries(weights).map(([t, w]) => `${t} ${w}`).join(', ')}`);
636
+ for (const w of data.warnings || []) lines.push(` note: ${w}`);
637
+ return lines;
638
+ }
639
+
640
+ async function midasPricing(ctx, [sub, name, value]) {
641
+ const r = repo(ctx);
642
+ if (!sub) {
643
+ const { data } = await ctx.call('GET', pricingRoute(r));
644
+ ctx.out(pricingLines(r.product, data).join('\n'), data);
645
+ return 0;
646
+ }
647
+ const save = async (qp) => {
648
+ const { data } = await ctx.call('PUT', pricingRoute(r), { quest_pricing: qp });
649
+ ctx.out([...pricingLines(r.product, data), ` ${data.note || 'saved'}`].join('\n'), data);
650
+ return 0;
651
+ };
652
+ if (sub === 'apply') {
653
+ const f = name || path.join('resources', 'midas', r.product, 'quest-pricing.json');
654
+ const { json } = readJsonFile(ctx, f);
655
+ return save(json.quest_pricing !== undefined ? json.quest_pricing : json);
656
+ }
657
+ if (!['set', 'unset', 'weight'].includes(sub)) throw new UsageError(`plaiful midas pricing, or pricing set | unset | weight | apply (not "${sub}")`);
658
+ if (!name) throw new UsageError(sub === 'weight' ? 'plaiful midas pricing weight <step> <n>' : `which kind? plaiful midas pricing ${sub} <kind>`);
659
+ const { data } = await ctx.call('GET', pricingRoute(r));
660
+ const qp = JSON.parse(JSON.stringify(data.quest_pricing || {}));
661
+ if (sub === 'weight') {
662
+ qp.objective_weights = { ...(qp.objective_weights || {}), [name]: nonNegative(value, 'the weight') };
663
+ } else if (sub === 'unset') {
664
+ if (!qp.kinds || !qp.kinds[name]) throw new UsageError(`${name} isn't priced`);
665
+ delete qp.kinds[name];
666
+ } else {
667
+ if (ctx.flags.base === undefined && ctx.flags['per-effort'] === undefined) throw new UsageError(`plaiful midas pricing set ${name} --base <n> --per-effort <n>`);
668
+ const cur = (qp.kinds && qp.kinds[name]) || { base: 0, per_objective: 0 };
669
+ qp.kinds = {
670
+ ...(qp.kinds || {}),
671
+ [name]: {
672
+ base: ctx.flags.base === undefined ? cur.base : nonNegative(ctx.flags.base, '--base'),
673
+ per_objective: ctx.flags['per-effort'] === undefined ? cur.per_objective : nonNegative(ctx.flags['per-effort'], '--per-effort'),
674
+ },
675
+ };
676
+ }
677
+ return save(qp);
678
+ }
679
+
386
680
  async function upload(ctx, files) {
387
681
  const r = repo(ctx);
388
682
  if (!files.length) throw new UsageError('upload what? plaiful upload <files...> (map tiles: ovid-map-*.json)');
@@ -526,6 +820,12 @@ const COMMANDS = {
526
820
  seed: (ctx, [store, ...paths]) => seedStore(ctx, store, paths),
527
821
  status: (ctx) => status(ctx),
528
822
  lists: (ctx, rest) => lists(ctx, rest),
823
+ agents: (ctx, rest) => agents(ctx, rest),
824
+ 'midas pricing': (ctx, rest) => midasPricing(ctx, rest),
825
+ quests: (ctx, rest) => quests(ctx, rest),
826
+ assets: (ctx, rest) => assets(ctx, rest),
827
+ lore: (ctx, rest) => lore(ctx, rest),
828
+ world: (ctx) => world(ctx),
529
829
  upload: (ctx, files) => upload(ctx, files),
530
830
  clone: (ctx, rest) => clone(ctx, rest),
531
831
  env: (ctx) => envCmd(ctx),
@@ -572,7 +872,7 @@ async function main(argv, io = defaultIo()) {
572
872
  const one = COMMANDS[a];
573
873
  const ctx = makeContext(io, flags);
574
874
  if (two) return await two(ctx, rest);
575
- if (one && !['docs', 'ovid'].includes(a)) return await one(ctx, b === undefined ? rest : [b, ...rest]);
875
+ if (one && !['docs', 'ovid', 'midas'].includes(a)) return await one(ctx, b === undefined ? rest : [b, ...rest]);
576
876
  throw new UsageError(`unknown command "${parsed.args.join(' ')}"`);
577
877
  } catch (e) {
578
878
  if (e instanceof UsageError) {