@plaiful/cli 0.2.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 +1 -1
  3. package/src/cli.js +204 -4
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaiful/cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "The Plaiful CLI: work on your Plaiful product from your game repo, with no AWS access",
5
5
  "bin": {
6
6
  "plaiful": "bin/plaiful.js"
package/src/cli.js CHANGED
@@ -29,6 +29,11 @@ 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)
@@ -39,6 +44,15 @@ const HELP = `plaiful ${version}: work on your Plaiful product from your game re
39
44
  plaiful agents run <name> [key=value...] make one record (placeholder values as key=value)
40
45
  plaiful agents batch <name> [file] start a batch (a batch body file, or --count <n>) → a job id
41
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)
42
56
  plaiful upload <files...> upload map tiles into your dev assets bucket (map-data/; --dest map-data)
43
57
  plaiful clone [product] [dir] clone the game repo, write .env.development, docs pull, npm install, open Zed
44
58
  --no-install --no-open
@@ -57,13 +71,20 @@ class ApiError extends Error {
57
71
  }
58
72
  }
59
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
+
60
81
  function parse(argv) {
61
82
  const flags = {};
62
83
  const args = [];
63
84
  for (let i = 0; i < argv.length; i += 1) {
64
85
  const a = argv[i];
65
86
  if (['--json', '--no-browser', '--help', '-h', '--version', '--apply', '--reset', '--rows', '--no-install', '--no-open'].includes(a)) flags[a.replace(/^-+/, '')] = true;
66
- else if (a === '--product' || a === '--api' || a === '--dir' || a === '--dest' || a === '--count') {
87
+ else if (['--product', '--api', '--dir', '--dest', '--count', '--base', '--per-effort', '--track', '--series', '--state', '--limit'].includes(a)) {
67
88
  if (argv[i + 1] === undefined) throw new UsageError(`${a} needs a value`);
68
89
  flags[a.slice(2)] = argv[i += 1];
69
90
  } else if (a.startsWith('--')) throw new UsageError(`unknown option ${a}`);
@@ -342,7 +363,7 @@ async function status(ctx) {
342
363
  const d = data.declaration || {};
343
364
  const err = (x) => (x.error ? ` ${x.error}` : null);
344
365
  const lines = [`${r.product} in dev:`];
345
- 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`}`);
346
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)'}`);
347
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` : ''}`}`);
348
369
  lines.push(` map ${err(m) || `${m.locations} locations, ${m.settlements} settlements (${m.settlements_with_npcs} with NPCs), ${m.seeded} seeded`}`);
@@ -429,7 +450,7 @@ async function agents(ctx, [sub, name, ...rest]) {
429
450
  const lines = [`${a.agent_name || name}: ${a.display_name || ''}`.trim(),
430
451
  ` table ${(a.storage || {}).table_name || '?'}, version ${(a.metadata || {}).version || '?'}, ${(a.metadata || {}).business_purpose || 'content'}`,
431
452
  ` fields ${(a.output_fields || []).join(', ')}`,
432
- ` lists ${Object.entries(a.ssm_parameters || {}).map(([k, v]) => `${k} ← ${v}`).join('; ') || 'none'}`,
453
+ ` lists ${Object.entries(a.ssm_parameters || {}).map(([k, v]) => `${k} ← ${listSource(v)}`).join('; ') || 'none'}`,
433
454
  ` dedup ${a.duplicate_detection && a.duplicate_detection.enabled !== false ? `on ${[].concat(a.duplicate_detection.field || 'name').join(', ')}` : 'off'}`,
434
455
  ' (--json prints the whole config)'];
435
456
  ctx.out(lines.join('\n'), data);
@@ -482,6 +503,180 @@ async function agents(ctx, [sub, name, ...rest]) {
482
503
  throw new UsageError(`plaiful agents, or agents show | deploy | run | batch | status (not "${sub}")`);
483
504
  }
484
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
+
485
680
  async function upload(ctx, files) {
486
681
  const r = repo(ctx);
487
682
  if (!files.length) throw new UsageError('upload what? plaiful upload <files...> (map tiles: ovid-map-*.json)');
@@ -626,6 +821,11 @@ const COMMANDS = {
626
821
  status: (ctx) => status(ctx),
627
822
  lists: (ctx, rest) => lists(ctx, rest),
628
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),
629
829
  upload: (ctx, files) => upload(ctx, files),
630
830
  clone: (ctx, rest) => clone(ctx, rest),
631
831
  env: (ctx) => envCmd(ctx),
@@ -672,7 +872,7 @@ async function main(argv, io = defaultIo()) {
672
872
  const one = COMMANDS[a];
673
873
  const ctx = makeContext(io, flags);
674
874
  if (two) return await two(ctx, rest);
675
- 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]);
676
876
  throw new UsageError(`unknown command "${parsed.args.join(' ')}"`);
677
877
  } catch (e) {
678
878
  if (e instanceof UsageError) {