@plaiful/cli 0.3.0 → 0.4.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/README.md +80 -80
- package/package.json +21 -21
- package/src/cli.js +970 -892
package/src/cli.js
CHANGED
|
@@ -1,892 +1,970 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The Plaiful CLI (PlaifulCMS docs/system/product/PARTNER_API_AND_CLI.md §4). Every command talks to the partner API
|
|
5
|
-
* as the signed-in person; nothing needs AWS. `--json` prints the API's answer as JSON, for agents.
|
|
6
|
-
*
|
|
7
|
-
* Exit codes: 0 done; 1 the platform said no (invalid, denied, not signed in); 2 the command was wrong.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const fs = require('fs');
|
|
11
|
-
const path = require('path');
|
|
12
|
-
const { spawn, spawnSync } = require('child_process');
|
|
13
|
-
const config = require('./config');
|
|
14
|
-
const { version } = require('../package.json');
|
|
15
|
-
|
|
16
|
-
const HELP = `plaiful ${version}: work on your Plaiful product from your game repo
|
|
17
|
-
|
|
18
|
-
plaiful login sign in (opens the CMS to approve; 12 hours)
|
|
19
|
-
plaiful logout sign out
|
|
20
|
-
plaiful whoami who you're signed in as, your studio, and the products you may manage
|
|
21
|
-
plaiful init [product] write .plaiful.json in this repo (product, env, docsDir)
|
|
22
|
-
|
|
23
|
-
plaiful
|
|
24
|
-
plaiful ovid
|
|
25
|
-
plaiful ovid
|
|
26
|
-
plaiful
|
|
27
|
-
|
|
28
|
-
personas
|
|
29
|
-
|
|
30
|
-
--
|
|
31
|
-
|
|
32
|
-
plaiful
|
|
33
|
-
plaiful quests
|
|
34
|
-
plaiful
|
|
35
|
-
plaiful lore
|
|
36
|
-
plaiful
|
|
37
|
-
plaiful
|
|
38
|
-
plaiful lists
|
|
39
|
-
plaiful lists
|
|
40
|
-
plaiful
|
|
41
|
-
plaiful agents
|
|
42
|
-
plaiful agents
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
plaiful agents
|
|
46
|
-
plaiful agents
|
|
47
|
-
plaiful
|
|
48
|
-
plaiful midas pricing
|
|
49
|
-
plaiful midas pricing
|
|
50
|
-
plaiful midas pricing
|
|
51
|
-
plaiful midas pricing
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
plaiful assets
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
plaiful
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
class
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (v && typeof v === 'object') return v.
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
else
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
ctx.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
if (!
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const { data } = await ctx.call('
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
ctx
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
if (
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
const
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
if (
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
if (
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
return 0;
|
|
472
|
-
}
|
|
473
|
-
if (sub === '
|
|
474
|
-
if (!name) throw new UsageError('which
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
const
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
async function
|
|
512
|
-
const r = repo(ctx);
|
|
513
|
-
if (sub
|
|
514
|
-
|
|
515
|
-
const
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
const
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
if (sub === '
|
|
550
|
-
if (!
|
|
551
|
-
const
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
if (!
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
ctx.
|
|
608
|
-
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
const
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
lines
|
|
636
|
-
for (const
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
}
|
|
647
|
-
const
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
const
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
const
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
const
|
|
760
|
-
const
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
return
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
const
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The Plaiful CLI (PlaifulCMS docs/system/product/PARTNER_API_AND_CLI.md §4). Every command talks to the partner API
|
|
5
|
+
* as the signed-in person; nothing needs AWS. `--json` prints the API's answer as JSON, for agents.
|
|
6
|
+
*
|
|
7
|
+
* Exit codes: 0 done; 1 the platform said no (invalid, denied, not signed in); 2 the command was wrong.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const { spawn, spawnSync } = require('child_process');
|
|
13
|
+
const config = require('./config');
|
|
14
|
+
const { version } = require('../package.json');
|
|
15
|
+
|
|
16
|
+
const HELP = `plaiful ${version}: work on your Plaiful product from your game repo
|
|
17
|
+
|
|
18
|
+
plaiful login sign in (opens the CMS to approve; 12 hours)
|
|
19
|
+
plaiful logout sign out
|
|
20
|
+
plaiful whoami who you're signed in as, your studio, and the products you may manage
|
|
21
|
+
plaiful init [product] write .plaiful.json in this repo (product, env, docsDir) and make the folders
|
|
22
|
+
your files go in (resources/world/<product>/, …), each with a README
|
|
23
|
+
plaiful docs pull write the latest onboarding docs + your client config into docsDir
|
|
24
|
+
plaiful ovid check [file] check your OVID declaration (default: <docsDir>/<product>-ovid-declaration.json)
|
|
25
|
+
plaiful ovid publish [file] check it and publish it; OVID reads it within about 5 minutes
|
|
26
|
+
plaiful ovid show the declaration OVID has now
|
|
27
|
+
plaiful seed world|lore|map|personas [paths] dry run: the rows your files make and what changes in dev
|
|
28
|
+
(default: every .json in resources/<store>/<product>/; personas = THESPIS
|
|
29
|
+
personas and situations)
|
|
30
|
+
--apply write them; --reset also put runtime state back to the files
|
|
31
|
+
--rows print every row
|
|
32
|
+
plaiful status what OVID and THESPIS have for your product in dev
|
|
33
|
+
plaiful quests the quests OVID wrote: steps and what each pays (--track <id>, --series <id>)
|
|
34
|
+
plaiful quests show <id> one quest: its graph, steps, reward hint and price (--json: the whole record)
|
|
35
|
+
plaiful lore the lore sets, with known / hidden snippet counts
|
|
36
|
+
plaiful lore show <setId> one set's snippets
|
|
37
|
+
plaiful world the world's states and state events in story order, and the clock
|
|
38
|
+
plaiful lists your product's SSM lists (NPC roles, SmartBuilder list values, ...)
|
|
39
|
+
plaiful lists get <name> one list (a name in your namespace, e.g. shop_type, or the full /path)
|
|
40
|
+
plaiful lists set <name> <values...> write a list (values as words, or one comma-separated argument)
|
|
41
|
+
plaiful agents your product's SmartBuilder agents in dev
|
|
42
|
+
plaiful agents show <name> one agent's deployed config
|
|
43
|
+
plaiful agents deploy [files...] deploy or redeploy agents from their config files (default: every .json in
|
|
44
|
+
resources/agents/<product>/); a redeploy keeps the agent's own settings
|
|
45
|
+
plaiful agents run <name> [key=value...] make one record (placeholder values as key=value)
|
|
46
|
+
plaiful agents batch <name> [file] start a batch (a batch body file, or --count <n>) → a job id
|
|
47
|
+
plaiful agents status <name> <jobId> a batch's progress
|
|
48
|
+
plaiful midas pricing what MIDAS pays per quest, in your reward kinds (delivered in each quest's rewards)
|
|
49
|
+
plaiful midas pricing set <kind> --base <n> --per-effort <n> price a kind (either option alone keeps the other)
|
|
50
|
+
plaiful midas pricing unset <kind> stop pricing a kind
|
|
51
|
+
plaiful midas pricing weight <step> <n> how much a quest step counts (combat, gather, explore, ...)
|
|
52
|
+
plaiful midas pricing apply [file] replace it all from a file (default:
|
|
53
|
+
resources/midas/<product>/quest-pricing.json; { kinds, objective_weights, ... })
|
|
54
|
+
plaiful assets per agent: records, and how many have their art made, pending, failed or none
|
|
55
|
+
plaiful assets <agent> its records: state, why a render failed, where the files are
|
|
56
|
+
--state made|pending|failed|none --limit <n> (default 50)
|
|
57
|
+
plaiful upload <files...> upload map tiles into your dev assets bucket (map-data/; --dest map-data)
|
|
58
|
+
plaiful clone [product] [dir] clone the game repo, write .env.development, docs pull, npm install, open Zed
|
|
59
|
+
--no-install --no-open
|
|
60
|
+
plaiful env (re)write .env.development from your dev client config (keeps your own lines)
|
|
61
|
+
|
|
62
|
+
Options: --json (machine-readable output) --product <id> --api <url> --no-browser (login)
|
|
63
|
+
Environment: PLAIFUL_API_URL, PLAIFUL_TOKEN (instead of login: CI, with a product API key from the CMS)
|
|
64
|
+
Docs: docs/plaiful/README.md after \`plaiful docs pull\``;
|
|
65
|
+
|
|
66
|
+
class UsageError extends Error {}
|
|
67
|
+
class ApiError extends Error {
|
|
68
|
+
constructor(status, body) {
|
|
69
|
+
super((body && body.error) || `the platform answered ${status}`);
|
|
70
|
+
this.status = status;
|
|
71
|
+
this.body = body;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Where an agent list's values come from: an SSM path, or the values kept in the agent ({ values: [...] }). */
|
|
76
|
+
function listSource(v) {
|
|
77
|
+
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 ? ', …' : ''})`;
|
|
78
|
+
if (v && typeof v === 'object') return v.path || JSON.stringify(v);
|
|
79
|
+
return String(v);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function parse(argv) {
|
|
83
|
+
const flags = {};
|
|
84
|
+
const args = [];
|
|
85
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
86
|
+
const a = argv[i];
|
|
87
|
+
if (['--json', '--no-browser', '--help', '-h', '--version', '--apply', '--reset', '--rows', '--no-install', '--no-open'].includes(a)) flags[a.replace(/^-+/, '')] = true;
|
|
88
|
+
else if (['--product', '--api', '--dir', '--dest', '--count', '--base', '--per-effort', '--track', '--series', '--state', '--limit'].includes(a)) {
|
|
89
|
+
if (argv[i + 1] === undefined) throw new UsageError(`${a} needs a value`);
|
|
90
|
+
flags[a.slice(2)] = argv[i += 1];
|
|
91
|
+
} else if (a.startsWith('--')) throw new UsageError(`unknown option ${a}`);
|
|
92
|
+
else args.push(a);
|
|
93
|
+
}
|
|
94
|
+
return { flags, args };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function makeContext(io, flags) {
|
|
98
|
+
const url = config.apiUrl(flags);
|
|
99
|
+
const out = (text, json) => io.stdout.write(`${flags.json ? JSON.stringify(json === undefined ? text : json, null, 2) : text}\n`);
|
|
100
|
+
async function call(method, route, body, { auth = true } = {}) {
|
|
101
|
+
const headers = { Accept: 'application/json' };
|
|
102
|
+
if (body !== undefined) headers['Content-Type'] = 'application/json';
|
|
103
|
+
if (auth) {
|
|
104
|
+
const token = config.tokenFor(url);
|
|
105
|
+
if (!token) throw new ApiError(401, { error: 'not signed in: run `plaiful login`', code: 'no_session' });
|
|
106
|
+
headers.Authorization = `Bearer ${token}`;
|
|
107
|
+
}
|
|
108
|
+
let res;
|
|
109
|
+
try {
|
|
110
|
+
res = await io.fetch(`${url}${route}`, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
|
|
111
|
+
} catch (e) {
|
|
112
|
+
throw new ApiError(0, { error: `can't reach the Plaiful API at ${url} (${e.message})`, code: 'network' });
|
|
113
|
+
}
|
|
114
|
+
let data = {};
|
|
115
|
+
try { data = await res.json(); } catch { /* empty body */ }
|
|
116
|
+
if (!res.ok && !(res.status === 422 || (res.status === 409 && data.errors))) throw new ApiError(res.status, data);
|
|
117
|
+
return { status: res.status, data };
|
|
118
|
+
}
|
|
119
|
+
return { url, flags, out, call, io };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function repo(ctx, { required = true } = {}) {
|
|
123
|
+
const found = config.findRepoConfig(ctx.io.cwd());
|
|
124
|
+
const product = ctx.flags.product || (found && found.config.product);
|
|
125
|
+
if (required && !product) throw new UsageError('no product: run `plaiful init <product>` in your repo, or pass --product');
|
|
126
|
+
const root = found ? found.root : ctx.io.cwd();
|
|
127
|
+
const docsDir = path.resolve(root, ctx.flags.dir || (found && found.config.docsDir) || config.DEFAULT_DOCS_DIR);
|
|
128
|
+
return { product, root, docsDir, found };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ── Commands ────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
132
|
+
|
|
133
|
+
async function login(ctx) {
|
|
134
|
+
const start = (await ctx.call('POST', '/partner/cli-login', undefined, { auth: false })).data;
|
|
135
|
+
ctx.io.stderr.write(`\nTo sign in, open:\n\n ${start.verification_url}\n\nand check the code matches: ${start.user_code}\n\n`);
|
|
136
|
+
if (!ctx.flags['no-browser']) ctx.io.openUrl(start.verification_url);
|
|
137
|
+
const deadline = Date.now() + start.expires_in * 1000;
|
|
138
|
+
let interval = (start.interval || 3) * 1000;
|
|
139
|
+
while (Date.now() < deadline) {
|
|
140
|
+
await ctx.io.sleep(interval);
|
|
141
|
+
const r = (await ctx.call('POST', '/partner/cli-login/token', { device_code: start.device_code }, { auth: false })).data;
|
|
142
|
+
if (r.status === 'approved') {
|
|
143
|
+
config.writeCredentials({ api_url: ctx.url, token: r.token, email: r.email, expires_at: r.expires_at });
|
|
144
|
+
ctx.out(`Signed in as ${r.email} until ${new Date(r.expires_at).toLocaleString()}.`, { success: true, email: r.email, expires_at: r.expires_at });
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
interval = (r.interval || 3) * 1000;
|
|
148
|
+
}
|
|
149
|
+
throw new ApiError(410, { error: 'the sign-in wasn\'t approved in time; run `plaiful login` again', code: 'expired' });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function logout(ctx) {
|
|
153
|
+
if (config.tokenFor(ctx.url)) {
|
|
154
|
+
try { await ctx.call('POST', '/partner/logout'); } catch { /* the local sign-out is what matters */ }
|
|
155
|
+
}
|
|
156
|
+
config.clearCredentials();
|
|
157
|
+
ctx.out('Signed out.', { success: true });
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function whoami(ctx) {
|
|
162
|
+
const { data } = await ctx.call('GET', '/partner/whoami');
|
|
163
|
+
const lines = data.key
|
|
164
|
+
? [`Product API key "${data.key.name}" for ${data.key.product} (${data.key.env}), issued by ${data.email}; scopes: ${data.key.scopes.join(', ')}`]
|
|
165
|
+
: [`${data.email}${data.staff ? ' (Plaiful staff)' : ''}, signed in until ${new Date(data.session_expires_at).toLocaleString()}`];
|
|
166
|
+
for (const st of data.studios || []) lines.push(`Studio: ${st.name} (${st.role}${st.preset ? `, ${st.preset}` : ''}${st.status !== 'active' ? `, ${st.status}` : ''})`);
|
|
167
|
+
lines.push(data.products.length ? 'Products:' : 'No products yet: create one in the CMS (Product deployment), or ask its owner to share it.');
|
|
168
|
+
for (const p of data.products) lines.push(` ${p.product_id} (${p.role})`);
|
|
169
|
+
ctx.out(lines.join('\n'), data);
|
|
170
|
+
return 0;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function init(ctx, [product]) {
|
|
174
|
+
const { data } = await ctx.call('GET', '/partner/whoami');
|
|
175
|
+
const mine = data.products.map((p) => p.product_id);
|
|
176
|
+
const chosen = product || ctx.flags.product || (mine.length === 1 ? mine[0] : null);
|
|
177
|
+
if (!chosen) throw new UsageError(`which product? ${mine.length ? `yours: ${mine.join(', ')}` : 'you have none yet'} (plaiful init <product>)`);
|
|
178
|
+
if (!mine.includes(chosen)) throw new ApiError(403, { error: `${data.email} can't manage "${chosen}"${mine.length ? ` (yours: ${mine.join(', ')})` : ''}`, code: 'product_access' });
|
|
179
|
+
const existing = config.findRepoConfig(ctx.io.cwd());
|
|
180
|
+
const root = existing ? existing.root : ctx.io.cwd();
|
|
181
|
+
const next = { ...(existing ? existing.config : { env: 'dev', docsDir: config.DEFAULT_DOCS_DIR }), product: chosen };
|
|
182
|
+
const file = config.writeRepoConfig(root, next);
|
|
183
|
+
const made = makeLayout(root, chosen, next.docsDir);
|
|
184
|
+
const lines = [`Wrote ${path.relative(ctx.io.cwd(), file) || file}: product ${chosen}, docs in ${next.docsDir}.`];
|
|
185
|
+
if (made.length) lines.push(`Made ${made.length} folder(s): ${made.join(', ')}`);
|
|
186
|
+
lines.push('Next: plaiful docs pull');
|
|
187
|
+
ctx.out(lines.join('\n'), { success: true, file, config: next, made });
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ── Where things go (product-repo-template.md) ──────────────────────────────────────────────────────────────────
|
|
192
|
+
|
|
193
|
+
/** The repo folders the platform's steps read from: [folder, what goes there]. */
|
|
194
|
+
function layout(product, docsDir) {
|
|
195
|
+
return [
|
|
196
|
+
[`resources/${product}-resources`, 'SmartBuilder agent specs (one markdown file per agent, pasted into SmartBuilder)'],
|
|
197
|
+
[`resources/agents/${product}`, 'agent configs as JSON, for plaiful agents deploy'],
|
|
198
|
+
[`resources/world/${product}`, 'the narrative scaffold, for plaiful seed world'],
|
|
199
|
+
[`resources/lore/${product}`, 'lore sets, for plaiful seed lore'],
|
|
200
|
+
[`resources/map/${product}`, 'places, for plaiful seed map'],
|
|
201
|
+
[`resources/personas/${product}`, 'THESPIS personas and situations, for plaiful seed personas'],
|
|
202
|
+
[`resources/midas/${product}`, 'quest-pricing.json, for plaiful midas pricing apply'],
|
|
203
|
+
[docsDir, `the pulled docs, and your ${product}-ovid-declaration.json (plaiful ovid check / publish)`],
|
|
204
|
+
];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Agent specs (markdown with agent_name and prompt_template) outside resources/<product>-resources/, under docs/ or
|
|
208
|
+
* resources/. → relative paths */
|
|
209
|
+
function misplacedSpecs(root, product, docsDir) {
|
|
210
|
+
const home = path.join(root, 'resources', `${product}-resources`);
|
|
211
|
+
const out = [];
|
|
212
|
+
const walk = (dir, depth) => {
|
|
213
|
+
if (depth > 6 || !fs.existsSync(dir)) return;
|
|
214
|
+
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
215
|
+
const full = path.join(dir, e.name);
|
|
216
|
+
if (e.isDirectory()) {
|
|
217
|
+
if (!['node_modules', '.git'].includes(e.name) && full !== home && full !== docsDir) walk(full, depth + 1);
|
|
218
|
+
} else if (e.name.endsWith('.md')) {
|
|
219
|
+
try {
|
|
220
|
+
const text = fs.readFileSync(full, 'utf8');
|
|
221
|
+
if (/\bagent_name\b/.test(text) && /\bprompt_template\b/.test(text)) out.push(path.relative(root, full).replace(/\\/g, '/'));
|
|
222
|
+
} catch { /* unreadable: skip */ }
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
walk(path.join(root, 'docs'), 0);
|
|
227
|
+
walk(path.join(root, 'resources'), 0);
|
|
228
|
+
return out;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** What to write in a folder's README when init makes it. */
|
|
232
|
+
const folderReadme = (folder, what) => `# ${folder}\n\n${what[0].toUpperCase()}${what.slice(1)}.\nMade by \`plaiful init\`; see docs/plaiful/product-repo-template.md.\n`;
|
|
233
|
+
|
|
234
|
+
/** The folders the platform's steps read from, each with a README saying what goes in it (an agent puts a file where
|
|
235
|
+
* a folder for it already exists). → the folders made */
|
|
236
|
+
function makeLayout(root, product, docsDir) {
|
|
237
|
+
const made = [];
|
|
238
|
+
for (const [folder, what] of layout(product, docsDir)) {
|
|
239
|
+
const dir = path.join(root, folder);
|
|
240
|
+
if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); made.push(folder); }
|
|
241
|
+
const readme = path.join(dir, 'README.md');
|
|
242
|
+
if (folder !== docsDir && !fs.existsSync(readme)) fs.writeFileSync(readme, folderReadme(folder, what));
|
|
243
|
+
}
|
|
244
|
+
return made;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function whereThingsGo(ctx, r) {
|
|
248
|
+
const lines = ['Where things go:'];
|
|
249
|
+
for (const [folder, what] of layout(r.product, path.relative(r.root, r.docsDir).replace(/\\/g, '/') || '.')) {
|
|
250
|
+
lines.push(` ${folder.padEnd(32)} ${what}${fs.existsSync(path.join(r.root, folder)) ? '' : ' (missing: plaiful init makes it)'}`);
|
|
251
|
+
}
|
|
252
|
+
const wrong = misplacedSpecs(r.root, r.product, r.docsDir);
|
|
253
|
+
if (wrong.length) {
|
|
254
|
+
lines.push(`! Agent specs outside resources/${r.product}-resources/ (move them there):`);
|
|
255
|
+
for (const f of wrong) lines.push(` ${f}`);
|
|
256
|
+
}
|
|
257
|
+
return { lines, misplaced: wrong };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const safeName = (key) => {
|
|
261
|
+
const base = path.basename(String(key));
|
|
262
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*\.md$/.test(base)) return null;
|
|
263
|
+
return base;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
async function docsPull(ctx, r = repo(ctx)) {
|
|
267
|
+
const { data } = await ctx.call('GET', `/partner/${encodeURIComponent(r.product)}/docs`);
|
|
268
|
+
fs.mkdirSync(r.docsDir, { recursive: true });
|
|
269
|
+
const files = [...data.docs, { key: data.client_config.key, title: 'Client config', content: data.client_config.content }];
|
|
270
|
+
const result = { written: [], unchanged: [], skipped: [] };
|
|
271
|
+
for (const f of files) {
|
|
272
|
+
const name = safeName(f.key);
|
|
273
|
+
if (!name) { result.skipped.push(f.key); continue; }
|
|
274
|
+
const target = path.join(r.docsDir, name);
|
|
275
|
+
const prev = fs.existsSync(target) ? fs.readFileSync(target, 'utf8') : null;
|
|
276
|
+
if (prev === f.content) { result.unchanged.push(name); continue; }
|
|
277
|
+
fs.writeFileSync(target, f.content);
|
|
278
|
+
result.written.push(name);
|
|
279
|
+
}
|
|
280
|
+
const index = {
|
|
281
|
+
_note: 'Written by `plaiful docs pull`. These files are replaced on every pull; keep your own files beside them under other names.',
|
|
282
|
+
product: r.product, env: data.env, pulled_at: new Date().toISOString(),
|
|
283
|
+
docs: files.map((f) => ({ file: safeName(f.key), title: f.title, description: f.description || '' })).filter((f) => f.file),
|
|
284
|
+
};
|
|
285
|
+
fs.writeFileSync(path.join(r.docsDir, '.plaiful-docs.json'), `${JSON.stringify(index, null, 2)}\n`);
|
|
286
|
+
const ignore = ignoreClientConfig(r.docsDir);
|
|
287
|
+
const rel = path.relative(ctx.io.cwd(), r.docsDir) || '.';
|
|
288
|
+
const lines = [
|
|
289
|
+
`${rel}: ${result.written.length} updated, ${result.unchanged.length} unchanged${result.skipped.length ? `, ${result.skipped.length} skipped` : ''}.`,
|
|
290
|
+
...result.written.map((n) => ` updated ${n}`),
|
|
291
|
+
];
|
|
292
|
+
if (ignore.added.length) lines.push(` ${path.join(rel, '.gitignore')}: now keeps ${ignore.added.join(', ')} out of git`);
|
|
293
|
+
if (ignore.tracked.length) {
|
|
294
|
+
lines.push(`! Already committed, and holding your keys: ${ignore.tracked.join(', ')}. Take them out of git (the files stay):`);
|
|
295
|
+
lines.push(` git rm --cached ${ignore.tracked.map((f) => `"${path.relative(ctx.io.cwd(), path.join(r.docsDir, f)).replace(/\\/g, '/')}"`).join(' ')}`);
|
|
296
|
+
}
|
|
297
|
+
const where = whereThingsGo(ctx, r);
|
|
298
|
+
lines.push(...where.lines);
|
|
299
|
+
lines.push('Start with README.md; each doc says where its files go.');
|
|
300
|
+
ctx.out(lines.join('\n'), { success: true, dir: r.docsDir, ...result, gitignore: ignore, misplaced_specs: where.misplaced });
|
|
301
|
+
return 0;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// client-config.md holds the product's keys and endpoints (the Firebase web key among them), so it never goes in git;
|
|
305
|
+
// nor do the older hand-made `<product>-client-config.md` copies.
|
|
306
|
+
const CLIENT_CONFIG_IGNORES = ['client-config.md', '*-client-config.md'];
|
|
307
|
+
|
|
308
|
+
function ignoreClientConfig(docsDir) {
|
|
309
|
+
const file = path.join(docsDir, '.gitignore');
|
|
310
|
+
const prev = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '';
|
|
311
|
+
const have = new Set(prev.split(/\r?\n/).map((l) => l.trim()));
|
|
312
|
+
const added = CLIENT_CONFIG_IGNORES.filter((p) => !have.has(p));
|
|
313
|
+
if (added.length) {
|
|
314
|
+
const head = prev ? `${prev.replace(/\s*$/, '')}\n` : '# Written by `plaiful docs pull`: these files hold your product\'s keys.\n';
|
|
315
|
+
fs.writeFileSync(file, `${head}${added.join('\n')}\n`);
|
|
316
|
+
}
|
|
317
|
+
// A .gitignore doesn't untrack what's already committed; say so rather than leave the keys in the repo.
|
|
318
|
+
const git = spawnSync('git', ['ls-files', '--', ...CLIENT_CONFIG_IGNORES], { cwd: docsDir, encoding: 'utf8' });
|
|
319
|
+
const tracked = git.status === 0 ? git.stdout.split('\n').map((l) => l.trim()).filter(Boolean) : [];
|
|
320
|
+
return { added, tracked };
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function readDeclaration(ctx, r, file) {
|
|
324
|
+
const target = path.resolve(ctx.io.cwd(), file || path.join(r.docsDir, `${r.product}-ovid-declaration.json`));
|
|
325
|
+
if (!fs.existsSync(target)) throw new UsageError(`no declaration at ${target} (write it first: ovid-declaration.md)`);
|
|
326
|
+
try { return { target, declaration: JSON.parse(fs.readFileSync(target, 'utf8')) }; } catch (e) {
|
|
327
|
+
throw new UsageError(`${target} isn't valid JSON: ${e.message}`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function findingsText(data) {
|
|
332
|
+
const lines = [];
|
|
333
|
+
const where = (x) => `${x.file ? `${x.file} ` : ''}${x.path || '(top level)'}`;
|
|
334
|
+
for (const e of data.errors || []) lines.push(` ✗ ${where(e)}: ${e.message} [${e.doc}]`);
|
|
335
|
+
for (const w of data.warnings || []) lines.push(` ! ${where(w)}: ${w.message} [${w.doc}]`);
|
|
336
|
+
for (const n of data.notes || []) lines.push(` · ${n}`);
|
|
337
|
+
return lines;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
async function ovidCheck(ctx, [file]) {
|
|
341
|
+
const r = repo(ctx);
|
|
342
|
+
const { target, declaration } = readDeclaration(ctx, r, file);
|
|
343
|
+
const { data } = await ctx.call('POST', `/partner/${encodeURIComponent(r.product)}/ovid/declaration/check`, { declaration });
|
|
344
|
+
const head = data.ok
|
|
345
|
+
? `${path.basename(target)} is valid${(data.warnings || []).length ? `, with ${data.warnings.length} warning(s)` : ''}. Publish it with: plaiful ovid publish`
|
|
346
|
+
: `${path.basename(target)} has ${data.errors.length} error(s); fix them and check again.`;
|
|
347
|
+
ctx.out([head, ...findingsText(data)].join('\n'), data);
|
|
348
|
+
return data.ok ? 0 : 1;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async function ovidPublish(ctx, [file]) {
|
|
352
|
+
const r = repo(ctx);
|
|
353
|
+
const { target, declaration } = readDeclaration(ctx, r, file);
|
|
354
|
+
const { data } = await ctx.call('PUT', `/partner/${encodeURIComponent(r.product)}/ovid/declaration`, { declaration });
|
|
355
|
+
if (!data.published) {
|
|
356
|
+
ctx.out([`Not published: ${data.error || `${path.basename(target)} has ${(data.errors || []).length} error(s)`}`, ...findingsText(data)].join('\n'), data);
|
|
357
|
+
return 1;
|
|
358
|
+
}
|
|
359
|
+
const lines = [`Published ${path.basename(target)} for ${r.product}; OVID reads it ${data.takes_effect}.`];
|
|
360
|
+
if (data.tabs && data.tabs.error) lines.push(` ! ${data.tabs.error}`);
|
|
361
|
+
lines.push(...findingsText(data));
|
|
362
|
+
lines.push('Check it took: GameMaster shows your tier labels, tracks and regions (plaiful ovid show prints what OVID has).');
|
|
363
|
+
ctx.out(lines.join('\n'), data);
|
|
364
|
+
return 0;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
async function ovidShow(ctx) {
|
|
368
|
+
const r = repo(ctx);
|
|
369
|
+
const { data } = await ctx.call('GET', `/partner/${encodeURIComponent(r.product)}/ovid/declaration`);
|
|
370
|
+
if (ctx.flags.json) { ctx.out(data); return 0; }
|
|
371
|
+
if (!data.declaration) ctx.out(data.packaged ? `${r.product}'s declaration is packaged: ${data.packaged}` : `${r.product} has no OVID declaration yet (OVID uses its defaults).`);
|
|
372
|
+
else ctx.out(`Published ${data.updated_at || '(date unknown)'}${data.published_by ? ` by ${data.published_by}` : ''}:\n${JSON.stringify(data.declaration, null, 2)}`);
|
|
373
|
+
return 0;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// ── Seeding (phase 2) ──────────────────────────────────────────────────────────────────────────────────────────
|
|
377
|
+
|
|
378
|
+
const STORES = ['world', 'lore', 'map', 'personas'];
|
|
379
|
+
const SEED_ROUTE = { world: 'ovid/world', lore: 'ovid/lore', map: 'ovid/map', personas: 'thespis/personas' };
|
|
380
|
+
const MARK = { create: '+', update: '~', remove: '-', keep: '=' };
|
|
381
|
+
|
|
382
|
+
/** The JSON files to send: the paths given (files or folders), else resources/<store>/<product>/. */
|
|
383
|
+
function seedFiles(ctx, r, store, paths) {
|
|
384
|
+
const targets = paths.length ? paths.map((x) => path.resolve(ctx.io.cwd(), x)) : [path.join(r.root, 'resources', store, r.product)];
|
|
385
|
+
const files = [];
|
|
386
|
+
for (const t of targets) {
|
|
387
|
+
if (!fs.existsSync(t)) throw new UsageError(`${t} doesn't exist${paths.length ? '' : ` (put your ${store} files there, or pass their paths)`}`);
|
|
388
|
+
const list = fs.statSync(t).isDirectory()
|
|
389
|
+
? fs.readdirSync(t).filter((n) => n.toLowerCase().endsWith('.json')).sort().map((n) => path.join(t, n))
|
|
390
|
+
: [t];
|
|
391
|
+
for (const file of list) {
|
|
392
|
+
let content;
|
|
393
|
+
try { content = JSON.parse(fs.readFileSync(file, 'utf8')); } catch (e) { throw new UsageError(`${file} isn't valid JSON: ${e.message}`); }
|
|
394
|
+
files.push({ name: path.relative(r.root, file).replace(/\\/g, '/'), content });
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (!files.length) throw new UsageError(`no .json files in ${targets.join(', ')}`);
|
|
398
|
+
return files;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
async function seedStore(ctx, store, paths) {
|
|
402
|
+
if (!STORES.includes(store)) throw new UsageError(`seed what? world, lore, map or personas (plaiful seed ${STORES.join('|')})`);
|
|
403
|
+
const r = repo(ctx);
|
|
404
|
+
const files = seedFiles(ctx, r, store, paths);
|
|
405
|
+
const apply = !!ctx.flags.apply;
|
|
406
|
+
const reset = !!ctx.flags.reset;
|
|
407
|
+
const { data } = await ctx.call('POST', `/partner/${encodeURIComponent(r.product)}/${SEED_ROUTE[store]}/seed`, { files, apply, reset, rows: !!ctx.flags.rows });
|
|
408
|
+
if (ctx.flags.json) { ctx.out(data); return data.ok ? 0 : 1; }
|
|
409
|
+
const lines = [];
|
|
410
|
+
if (!data.ok) {
|
|
411
|
+
lines.push(`${files.length} ${store} file(s) have ${data.errors.length} error(s); nothing was ${apply ? 'written' : 'planned'}. Fix them and run it again.`);
|
|
412
|
+
lines.push(...findingsText(data));
|
|
413
|
+
ctx.out(lines.join('\n'));
|
|
414
|
+
return 1;
|
|
415
|
+
}
|
|
416
|
+
const s = data.summary;
|
|
417
|
+
const counts = Object.entries(data.counts || {}).map(([k, v]) => `${v} ${k}`).join(', ');
|
|
418
|
+
lines.push(`${store} for ${r.product} (dev, ${data.table}): ${counts}.`);
|
|
419
|
+
lines.push(`${apply ? 'Wrote' : 'Would write'}: ${s.create} new, ${s.update} changed, ${s.remove} removed, ${s.unchanged} unchanged${s.kept ? `, ${s.kept} kept as they are` : ''}.`);
|
|
420
|
+
if (data.unmanaged) lines.push(` · ${data.unmanaged} row(s) there weren't written by plaiful seed (${store === 'personas' ? 'the Tuning Studio\'s' : 'OVID\'s, the CMS\'s'}, or an older seeder's): left alone.`);
|
|
421
|
+
const shown = data.items.slice(0, 40);
|
|
422
|
+
for (const i of shown) lines.push(` ${MARK[i.action] || '?'} ${i.action.padEnd(6)} ${String(i.kind).padEnd(14)} ${i.id}${i.note ? ` (${i.note})` : ''}`);
|
|
423
|
+
if (data.items.length > shown.length) lines.push(` … and ${data.items.length - shown.length} more (--json lists them all)`);
|
|
424
|
+
lines.push(...findingsText(data));
|
|
425
|
+
if (ctx.flags.rows) lines.push(JSON.stringify(data.rows, null, 2));
|
|
426
|
+
if (!apply) lines.push(data.writes ? `Dry run: nothing written. Write it with: plaiful seed ${store}${paths.length ? ` ${paths.join(' ')}` : ''}${reset ? ' --reset' : ''} --apply` : 'Dry run: dev already matches your files.');
|
|
427
|
+
else if (data.writes) lines.push('Check it with: plaiful status');
|
|
428
|
+
ctx.out(lines.join('\n'));
|
|
429
|
+
return 0;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
async function status(ctx) {
|
|
433
|
+
const r = repo(ctx);
|
|
434
|
+
const { data } = await ctx.call('GET', `/partner/${encodeURIComponent(r.product)}/status`);
|
|
435
|
+
if (ctx.flags.json) { ctx.out(data); return 0; }
|
|
436
|
+
const w = data.world || {};
|
|
437
|
+
const l = data.lore || {};
|
|
438
|
+
const m = data.map || {};
|
|
439
|
+
const d = data.declaration || {};
|
|
440
|
+
const err = (x) => (x.error ? ` ${x.error}` : null);
|
|
441
|
+
const lines = [`${r.product} in dev:`];
|
|
442
|
+
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`}`);
|
|
443
|
+
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)'}`);
|
|
444
|
+
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` : ''}`}`);
|
|
445
|
+
lines.push(` map ${err(m) || `${m.locations} locations, ${m.settlements} settlements (${m.settlements_with_npcs} with NPCs), ${m.seeded} seeded`}`);
|
|
446
|
+
const t = data.thespis || {};
|
|
447
|
+
lines.push(` thespis ${err(t) || `${t.personas} personas (${t.active_personas} active), ${t.situations} situations, ${t.seeded} seeded`}`);
|
|
448
|
+
lines.push(` declaration ${d.declared ? `published ${d.updated_at || ''}: tiers ${d.timeline ? [d.timeline.macro, d.timeline.meso, d.timeline.micro].join(' / ') : '(defaults)'}; regions ${(d.regions || []).join(', ') || 'none'}; tracks ${(d.tracks || []).join(', ') || '(default)'}` : 'none yet (plaiful ovid publish)'}`);
|
|
449
|
+
ctx.out(lines.join('\n'));
|
|
450
|
+
return 0;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// ── Lists and uploads (phase 3) ──────────────────────────────────────────────────────────────────────────────────
|
|
454
|
+
|
|
455
|
+
/** The route for a list: a name in the namespace goes in the path; a full /path goes in ?path=. */
|
|
456
|
+
function listRoute(r, name) {
|
|
457
|
+
const base = `/partner/${encodeURIComponent(r.product)}/lists`;
|
|
458
|
+
if (!name) return base;
|
|
459
|
+
if (name.startsWith('/')) return `${base}?path=${encodeURIComponent(name)}`;
|
|
460
|
+
return `${base}/${name.split('/').map(encodeURIComponent).join('/')}`;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
async function lists(ctx, [sub, name, ...values]) {
|
|
464
|
+
const r = repo(ctx);
|
|
465
|
+
if (!sub) {
|
|
466
|
+
const { data } = await ctx.call('GET', listRoute(r));
|
|
467
|
+
const lines = [`${r.product}'s lists in dev (${data.namespace}):`];
|
|
468
|
+
if (!data.lists.length) lines.push(' none yet (plaiful lists set <name> <values...>)');
|
|
469
|
+
for (const l of data.lists) lines.push(` ${l.name}${l.type === 'String' ? ' (a setting)' : ''} ${l.values.join(', ')}`);
|
|
470
|
+
ctx.out(lines.join('\n'), data);
|
|
471
|
+
return 0;
|
|
472
|
+
}
|
|
473
|
+
if (sub === 'get') {
|
|
474
|
+
if (!name) throw new UsageError('which list? plaiful lists get <name>');
|
|
475
|
+
const { data } = await ctx.call('GET', listRoute(r, name));
|
|
476
|
+
ctx.out(`${data.name}: ${data.values.join(', ')}`, data);
|
|
477
|
+
return 0;
|
|
478
|
+
}
|
|
479
|
+
if (sub === 'set') {
|
|
480
|
+
if (!name || !values.length) throw new UsageError('plaiful lists set <name> <values...> (e.g. plaiful lists set shop_type tavern blacksmith healer)');
|
|
481
|
+
const parsed = (values.length === 1 ? values[0].split(',') : values).map((v) => v.trim()).filter(Boolean);
|
|
482
|
+
const { data } = await ctx.call('PUT', listRoute(r, name), { values: parsed });
|
|
483
|
+
const was = data.previous === null ? 'new' : `was: ${data.previous.join(', ')}`;
|
|
484
|
+
ctx.out(`${data.name} = ${data.values.join(', ')} (${was})`, data);
|
|
485
|
+
return 0;
|
|
486
|
+
}
|
|
487
|
+
throw new UsageError(`plaiful lists, lists get <name> or lists set <name> <values...> (not "${sub}")`);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// ── SmartBuilder agents ─────────────────────────────────────────────────────────────────────────────────────
|
|
491
|
+
|
|
492
|
+
const agentRoute = (r, rest = '') => `/partner/${encodeURIComponent(r.product)}/agents${rest}`;
|
|
493
|
+
const AGENT_NAME = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
494
|
+
|
|
495
|
+
function readJsonFile(ctx, f) {
|
|
496
|
+
const file = path.resolve(ctx.io.cwd(), f);
|
|
497
|
+
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) throw new UsageError(`${file} isn't a file`);
|
|
498
|
+
try { return { file, json: JSON.parse(fs.readFileSync(file, 'utf8')) }; } catch (e) { throw new UsageError(`${file} isn't valid JSON (${e.message})`); }
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/** The config files to deploy: the ones named, or every .json in resources/agents/<product>/. */
|
|
502
|
+
function agentFiles(ctx, r, files) {
|
|
503
|
+
if (files.length) return files;
|
|
504
|
+
const dir = path.join(ctx.io.cwd(), 'resources', 'agents', r.product);
|
|
505
|
+
if (!fs.existsSync(dir)) throw new UsageError(`no files named, and no ${path.relative(ctx.io.cwd(), dir)}/ folder: plaiful agents deploy <file.json>`);
|
|
506
|
+
const found = fs.readdirSync(dir).filter((n) => n.endsWith('.json')).map((n) => path.join(dir, n));
|
|
507
|
+
if (!found.length) throw new UsageError(`${path.relative(ctx.io.cwd(), dir)}/ has no .json agent configs`);
|
|
508
|
+
return found;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
async function agents(ctx, [sub, name, ...rest]) {
|
|
512
|
+
const r = repo(ctx);
|
|
513
|
+
if (!sub) {
|
|
514
|
+
const { data } = await ctx.call('GET', agentRoute(r));
|
|
515
|
+
const list = data.agents || [];
|
|
516
|
+
const lines = [`${r.product}'s SmartBuilder agents in dev:`];
|
|
517
|
+
if (!list.length) lines.push(' none yet (plaiful agents deploy <file.json>, or SmartBuilder in the CMS)');
|
|
518
|
+
for (const a of list) lines.push(` ${a.name || a.agent_name}${a.display_name ? ` ${a.display_name}` : ''}${a.business_purpose ? ` (${a.business_purpose})` : ''}`);
|
|
519
|
+
ctx.out(lines.join('\n'), data);
|
|
520
|
+
return 0;
|
|
521
|
+
}
|
|
522
|
+
if (sub === 'show') {
|
|
523
|
+
if (!name) throw new UsageError('which agent? plaiful agents show <name>');
|
|
524
|
+
const { data } = await ctx.call('GET', agentRoute(r, `/${encodeURIComponent(name)}`));
|
|
525
|
+
const a = data.agent || {};
|
|
526
|
+
const lines = [`${a.agent_name || name}: ${a.display_name || ''}`.trim(),
|
|
527
|
+
` table ${(a.storage || {}).table_name || '?'}, version ${(a.metadata || {}).version || '?'}, ${(a.metadata || {}).business_purpose || 'content'}`,
|
|
528
|
+
` fields ${(a.output_fields || []).join(', ')}`,
|
|
529
|
+
` lists ${Object.entries(a.ssm_parameters || {}).map(([k, v]) => `${k} ← ${listSource(v)}`).join('; ') || 'none'}`,
|
|
530
|
+
` dedup ${a.duplicate_detection && a.duplicate_detection.enabled !== false ? `on ${[].concat(a.duplicate_detection.field || 'name').join(', ')}` : 'off'}`,
|
|
531
|
+
' (--json prints the whole config)'];
|
|
532
|
+
ctx.out(lines.join('\n'), data);
|
|
533
|
+
return 0;
|
|
534
|
+
}
|
|
535
|
+
if (sub === 'deploy') {
|
|
536
|
+
const files = agentFiles(ctx, r, [name, ...rest].filter(Boolean));
|
|
537
|
+
const done = [];
|
|
538
|
+
for (const f of files) {
|
|
539
|
+
const { file, json } = readJsonFile(ctx, f);
|
|
540
|
+
const agentName = json.agent_name || path.basename(file, '.json');
|
|
541
|
+
if (!AGENT_NAME.test(agentName)) throw new UsageError(`${path.basename(file)}: "${agentName}" isn't an agent name (lowercase letters, digits, hyphens)`);
|
|
542
|
+
const { data } = await ctx.call('POST', agentRoute(r, `/${agentName}`), { config: json });
|
|
543
|
+
done.push(data);
|
|
544
|
+
if (!ctx.flags.json) ctx.out(`${data.redeployed ? 'redeployed' : 'deployed'} ${data.agent_name}: table ${data.table_name}${data.table === 'created' ? ' (new)' : ''}, version ${data.version}`);
|
|
545
|
+
}
|
|
546
|
+
if (ctx.flags.json) ctx.out('', { success: true, product: r.product, deployed: done });
|
|
547
|
+
return 0;
|
|
548
|
+
}
|
|
549
|
+
if (sub === 'run') {
|
|
550
|
+
if (!name) throw new UsageError('which agent? plaiful agents run <name> [key=value...]');
|
|
551
|
+
const body = {};
|
|
552
|
+
for (const kv of rest) {
|
|
553
|
+
const i = kv.indexOf('=');
|
|
554
|
+
if (i < 1) throw new UsageError(`"${kv}" isn't key=value`);
|
|
555
|
+
body[kv.slice(0, i)] = kv.slice(i + 1);
|
|
556
|
+
}
|
|
557
|
+
const { data } = await ctx.call('POST', agentRoute(r, `/${encodeURIComponent(name)}/run`), body);
|
|
558
|
+
const rec = data.item || data.record || data;
|
|
559
|
+
ctx.out(`made ${rec.uuid || 'a record'}${rec.name ? `: ${rec.name}` : ''}`, data);
|
|
560
|
+
return 0;
|
|
561
|
+
}
|
|
562
|
+
if (sub === 'batch') {
|
|
563
|
+
if (!name) throw new UsageError('which agent? plaiful agents batch <name> [batch-body.json] (or --count <n>)');
|
|
564
|
+
let body;
|
|
565
|
+
if (rest[0]) body = readJsonFile(ctx, rest[0]).json;
|
|
566
|
+
else if (ctx.flags.count) body = { count: Number(ctx.flags.count) };
|
|
567
|
+
else throw new UsageError('give a batch body file, or --count <n>');
|
|
568
|
+
const { data } = await ctx.call('POST', agentRoute(r, `/${encodeURIComponent(name)}/batch`), body);
|
|
569
|
+
ctx.out(`started batch ${data.job_id} (${data.total_items || '?'} records). plaiful agents status ${name} ${data.job_id}`, data);
|
|
570
|
+
return 0;
|
|
571
|
+
}
|
|
572
|
+
if (sub === 'status') {
|
|
573
|
+
const [jobId] = rest;
|
|
574
|
+
if (!name || !jobId) throw new UsageError('plaiful agents status <name> <jobId>');
|
|
575
|
+
const { data } = await ctx.call('GET', agentRoute(r, `/${encodeURIComponent(name)}/batch/${encodeURIComponent(jobId)}`));
|
|
576
|
+
ctx.out(`${data.status || '?'}: ${data.completed_items ?? '?'} done, ${data.failed_items ?? 0} failed of ${data.total_items ?? '?'}`, data);
|
|
577
|
+
return 0;
|
|
578
|
+
}
|
|
579
|
+
throw new UsageError(`plaiful agents, or agents show | deploy | run | batch | status (not "${sub}")`);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// ── What OVID has: quests, lore, the world ──────────────────────────────────────────────────────────────────────
|
|
583
|
+
|
|
584
|
+
const ovidRoute = (r, rest) => `/partner/${encodeURIComponent(r.product)}/ovid/${rest}`;
|
|
585
|
+
const priceText = (p) => (p && Object.keys(p).length ? Object.entries(p).map(([k, v]) => `${v} ${k}`).join(', ') : '');
|
|
586
|
+
|
|
587
|
+
async function quests(ctx, [sub, id]) {
|
|
588
|
+
const r = repo(ctx);
|
|
589
|
+
if (sub === 'show') {
|
|
590
|
+
if (!id) throw new UsageError('which quest? plaiful quests show <id>');
|
|
591
|
+
const { data } = await ctx.call('GET', ovidRoute(r, `quests/${encodeURIComponent(id)}`));
|
|
592
|
+
const q = data.quest || {};
|
|
593
|
+
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 || '?'})`];
|
|
594
|
+
if (q.narrative_desc || q.description) lines.push(` ${q.narrative_desc || q.description}`);
|
|
595
|
+
for (const st of data.steps_detail || []) {
|
|
596
|
+
const n = (q.nodes || {})[st.id] || {};
|
|
597
|
+
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) || '';
|
|
598
|
+
lines.push(` ${st.unreached ? '(unreached) ' : ''}${st.id}: ${st.type}${st.count > 1 ? `×${st.count}` : ''}${say ? ` "${String(say).slice(0, 90)}${String(say).length > 90 ? '…' : ''}"` : ''}`);
|
|
599
|
+
}
|
|
600
|
+
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(', ')}` : ''}`);
|
|
601
|
+
lines.push(' (--json prints the whole record)');
|
|
602
|
+
ctx.out(lines.join('\n'), data);
|
|
603
|
+
return 0;
|
|
604
|
+
}
|
|
605
|
+
if (sub) throw new UsageError(`plaiful quests, or quests show <id> (not "${sub}")`);
|
|
606
|
+
const qs = new URLSearchParams();
|
|
607
|
+
if (ctx.flags.track) qs.set('track', ctx.flags.track);
|
|
608
|
+
if (ctx.flags.series) qs.set('series', ctx.flags.series);
|
|
609
|
+
const { data } = await ctx.call('GET', `${ovidRoute(r, 'quests')}${qs.toString() ? `?${qs}` : ''}`);
|
|
610
|
+
const lines = [`${r.product}'s quests in dev: ${data.count}${data.priced ? '' : ' (not priced yet: plaiful midas pricing)'}`];
|
|
611
|
+
let group = null;
|
|
612
|
+
for (const q of data.quests) {
|
|
613
|
+
const g = `${q.quest_track || '?'}${q.series ? ` · ${q.series.series_title || q.series.series_id}` : ''}`;
|
|
614
|
+
if (g !== group) { lines.push(` ${g}`); group = g; }
|
|
615
|
+
const pays = priceText(q.price);
|
|
616
|
+
lines.push(` ${q.series ? `${q.series.series_order}. ` : ''}${q.title} [${q.questType || '?'}] ${q.steps.join(' → ')}${pays ? ` pays ${pays}` : ''} ${q.quest_id}`);
|
|
617
|
+
}
|
|
618
|
+
if (data.truncated) lines.push(' (cut off: more quests than one read returns)');
|
|
619
|
+
ctx.out(lines.join('\n'), data);
|
|
620
|
+
return 0;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
async function lore(ctx, [sub, id]) {
|
|
624
|
+
const r = repo(ctx);
|
|
625
|
+
if (sub === 'show') {
|
|
626
|
+
if (!id) throw new UsageError('which set? plaiful lore show <setId>');
|
|
627
|
+
const { data } = await ctx.call('GET', ovidRoute(r, `lore/${encodeURIComponent(id)}`));
|
|
628
|
+
const lines = [`${data.title || id}${data.category ? ` (${data.category})` : ''}`];
|
|
629
|
+
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 ? '…' : ''}` : ''}`);
|
|
630
|
+
ctx.out(lines.join('\n'), data);
|
|
631
|
+
return 0;
|
|
632
|
+
}
|
|
633
|
+
if (sub) throw new UsageError(`plaiful lore, or lore show <setId> (not "${sub}")`);
|
|
634
|
+
const { data } = await ctx.call('GET', ovidRoute(r, 'lore'));
|
|
635
|
+
const lines = [`${r.product}'s lore in dev: ${data.sets.length} sets`];
|
|
636
|
+
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}` : ''}`);
|
|
637
|
+
ctx.out(lines.join('\n'), data);
|
|
638
|
+
return 0;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
async function world(ctx) {
|
|
642
|
+
const r = repo(ctx);
|
|
643
|
+
const { data } = await ctx.call('GET', ovidRoute(r, 'world'));
|
|
644
|
+
const c = data.clock;
|
|
645
|
+
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'}`];
|
|
646
|
+
const indent = { macro: ' ', meso: ' ', micro: ' ' };
|
|
647
|
+
for (const e of data.events) {
|
|
648
|
+
const pad = e.kind === 'event' ? ' ' : (indent[e.scope] || ' ');
|
|
649
|
+
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}`);
|
|
650
|
+
}
|
|
651
|
+
if (data.truncated) lines.push(' (cut off: more rows than one read returns)');
|
|
652
|
+
ctx.out(lines.join('\n'), data);
|
|
653
|
+
return 0;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// ── What the agents made ────────────────────────────────────────────────────────────────────────────────────────
|
|
657
|
+
|
|
658
|
+
const countsText = (a) => `${a.records} records: ${a.made} made, ${a.pending} pending, ${a.failed} failed, ${a.none} none yet${a.truncated ? ' (first 2000)' : ''}`;
|
|
659
|
+
|
|
660
|
+
async function assets(ctx, [agent]) {
|
|
661
|
+
const r = repo(ctx);
|
|
662
|
+
const base = `/partner/${encodeURIComponent(r.product)}/assets`;
|
|
663
|
+
if (!agent) {
|
|
664
|
+
const { data } = await ctx.call('GET', base);
|
|
665
|
+
const lines = [`${r.product}'s agents in dev${data.cdn ? ` (files on https://${data.cdn}/)` : ''}:`];
|
|
666
|
+
if (!data.agents.length) lines.push(' none yet (plaiful agents deploy)');
|
|
667
|
+
for (const a of data.agents) {
|
|
668
|
+
lines.push(` ${a.name.padEnd(24)} ${a.error ? `couldn't read: ${a.error}` : a.makes_art ? countsText(a) : '(makes no art)'}`);
|
|
669
|
+
}
|
|
670
|
+
ctx.out(lines.join('\n'), data);
|
|
671
|
+
return 0;
|
|
672
|
+
}
|
|
673
|
+
const qs = new URLSearchParams();
|
|
674
|
+
if (ctx.flags.state) qs.set('state', ctx.flags.state);
|
|
675
|
+
if (ctx.flags.limit) qs.set('limit', ctx.flags.limit);
|
|
676
|
+
const { data } = await ctx.call('GET', `${base}/${encodeURIComponent(agent)}${qs.toString() ? `?${qs}` : ''}`);
|
|
677
|
+
const lines = [`${agent}: ${countsText(data.counts)}${ctx.flags.state ? `; ${data.matching} ${ctx.flags.state}` : ''}${data.shown < data.matching ? `, showing ${data.shown} (--limit)` : ''}`];
|
|
678
|
+
for (const rec of data.records) {
|
|
679
|
+
const why = rec.render_error || Object.entries(rec.media || {}).filter(([, m]) => m.error).map(([k, m]) => `${k}: ${m.error}`).join('; ');
|
|
680
|
+
const where = rec.state === 'made' && rec.files ? `${rec.files.base}.{${rec.files.try.join('|')}}` : '';
|
|
681
|
+
lines.push(` ${rec.state.padEnd(8)} ${rec.name || '(unnamed)'} ${rec.uuid}${why ? ` ${why}` : ''}${where ? ` ${where}` : ''}`);
|
|
682
|
+
}
|
|
683
|
+
ctx.out(lines.join('\n'), data);
|
|
684
|
+
return 0;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// ── MIDAS quest pricing ─────────────────────────────────────────────────────────────────────────────────────────
|
|
688
|
+
|
|
689
|
+
const pricingRoute = (r) => `/partner/${encodeURIComponent(r.product)}/midas/pricing`;
|
|
690
|
+
|
|
691
|
+
function nonNegative(v, what) {
|
|
692
|
+
const n = Number(v);
|
|
693
|
+
if (v === undefined || v === true || !Number.isFinite(n) || n < 0) throw new UsageError(`${what} must be a number, 0 or more`);
|
|
694
|
+
return n;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
function pricingLines(product, data) {
|
|
698
|
+
const qp = data.quest_pricing || {};
|
|
699
|
+
const kinds = qp.kinds || {};
|
|
700
|
+
const declared = ((data.rewards || {}).types || []).filter((k) => k !== 'lore');
|
|
701
|
+
const names = [...new Set([...declared, ...Object.keys(kinds)])];
|
|
702
|
+
const d = data.defaults || {};
|
|
703
|
+
const weights = { ...(d.objective_weights || {}), ...(qp.objective_weights || {}) };
|
|
704
|
+
const lines = [`${product}'s quest pricing in dev: price = base + per-effort × the quest's effort`];
|
|
705
|
+
if (!names.length) lines.push(' no reward kinds declared (settings.rewards.types in your OVID declaration)');
|
|
706
|
+
for (const k of names) {
|
|
707
|
+
const p = kinds[k];
|
|
708
|
+
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>)'}`);
|
|
709
|
+
}
|
|
710
|
+
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})`);
|
|
711
|
+
lines.push(` weights: ${Object.entries(weights).map(([t, w]) => `${t} ${w}`).join(', ')}`);
|
|
712
|
+
for (const w of data.warnings || []) lines.push(` note: ${w}`);
|
|
713
|
+
return lines;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
async function midasPricing(ctx, [sub, name, value]) {
|
|
717
|
+
const r = repo(ctx);
|
|
718
|
+
if (!sub) {
|
|
719
|
+
const { data } = await ctx.call('GET', pricingRoute(r));
|
|
720
|
+
ctx.out(pricingLines(r.product, data).join('\n'), data);
|
|
721
|
+
return 0;
|
|
722
|
+
}
|
|
723
|
+
const save = async (qp) => {
|
|
724
|
+
const { data } = await ctx.call('PUT', pricingRoute(r), { quest_pricing: qp });
|
|
725
|
+
ctx.out([...pricingLines(r.product, data), ` ${data.note || 'saved'}`].join('\n'), data);
|
|
726
|
+
return 0;
|
|
727
|
+
};
|
|
728
|
+
if (sub === 'apply') {
|
|
729
|
+
const f = name || path.join('resources', 'midas', r.product, 'quest-pricing.json');
|
|
730
|
+
const { json } = readJsonFile(ctx, f);
|
|
731
|
+
return save(json.quest_pricing !== undefined ? json.quest_pricing : json);
|
|
732
|
+
}
|
|
733
|
+
if (!['set', 'unset', 'weight'].includes(sub)) throw new UsageError(`plaiful midas pricing, or pricing set | unset | weight | apply (not "${sub}")`);
|
|
734
|
+
if (!name) throw new UsageError(sub === 'weight' ? 'plaiful midas pricing weight <step> <n>' : `which kind? plaiful midas pricing ${sub} <kind>`);
|
|
735
|
+
const { data } = await ctx.call('GET', pricingRoute(r));
|
|
736
|
+
const qp = JSON.parse(JSON.stringify(data.quest_pricing || {}));
|
|
737
|
+
if (sub === 'weight') {
|
|
738
|
+
qp.objective_weights = { ...(qp.objective_weights || {}), [name]: nonNegative(value, 'the weight') };
|
|
739
|
+
} else if (sub === 'unset') {
|
|
740
|
+
if (!qp.kinds || !qp.kinds[name]) throw new UsageError(`${name} isn't priced`);
|
|
741
|
+
delete qp.kinds[name];
|
|
742
|
+
} else {
|
|
743
|
+
if (ctx.flags.base === undefined && ctx.flags['per-effort'] === undefined) throw new UsageError(`plaiful midas pricing set ${name} --base <n> --per-effort <n>`);
|
|
744
|
+
const cur = (qp.kinds && qp.kinds[name]) || { base: 0, per_objective: 0 };
|
|
745
|
+
qp.kinds = {
|
|
746
|
+
...(qp.kinds || {}),
|
|
747
|
+
[name]: {
|
|
748
|
+
base: ctx.flags.base === undefined ? cur.base : nonNegative(ctx.flags.base, '--base'),
|
|
749
|
+
per_objective: ctx.flags['per-effort'] === undefined ? cur.per_objective : nonNegative(ctx.flags['per-effort'], '--per-effort'),
|
|
750
|
+
},
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
return save(qp);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
async function upload(ctx, files) {
|
|
757
|
+
const r = repo(ctx);
|
|
758
|
+
if (!files.length) throw new UsageError('upload what? plaiful upload <files...> (map tiles: ovid-map-*.json)');
|
|
759
|
+
const dest = ctx.flags.dest || 'map-data';
|
|
760
|
+
const done = [];
|
|
761
|
+
for (const f of files) {
|
|
762
|
+
const file = path.resolve(ctx.io.cwd(), f);
|
|
763
|
+
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) throw new UsageError(`${file} isn't a file`);
|
|
764
|
+
const body = fs.readFileSync(file);
|
|
765
|
+
const { data } = await ctx.call('POST', `/partner/${encodeURIComponent(r.product)}/uploads`, { dest, name: path.basename(file), size: body.length });
|
|
766
|
+
let res;
|
|
767
|
+
try {
|
|
768
|
+
res = await ctx.io.fetch(data.url, { method: data.method || 'PUT', headers: data.headers, body });
|
|
769
|
+
} catch (e) {
|
|
770
|
+
throw new ApiError(0, { error: `the upload of ${path.basename(file)} didn't go through (${e.message})`, code: 'network' });
|
|
771
|
+
}
|
|
772
|
+
if (!res.ok) throw new ApiError(res.status, { error: `storage refused ${path.basename(file)} (${res.status}); run the upload again`, code: 'upload_failed' });
|
|
773
|
+
done.push({ file: path.basename(file), bucket: data.bucket, key: data.key, size: body.length });
|
|
774
|
+
}
|
|
775
|
+
ctx.out([`Uploaded ${done.length} file(s) to ${r.product}'s dev assets:`, ...done.map((d) => ` ${d.file} → s3://${d.bucket}/${d.key} (${d.size} bytes)`)].join('\n'), { success: true, uploaded: done });
|
|
776
|
+
return 0;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// ── Clone and .env (the New-Game Flow) ───────────────────────────────────────────────────────────────────────────
|
|
780
|
+
|
|
781
|
+
/** The game template's .env variables (plaiful-kit packages/client config.ts ENV_KEYS) ← the client config. */
|
|
782
|
+
const ENV_FROM_CONFIG = {
|
|
783
|
+
VITE_PLAIFUL_PRODUCT: (c) => c.productId,
|
|
784
|
+
VITE_PLAIFUL_ENV: (c) => c.environment,
|
|
785
|
+
VITE_PLAIFUL_API_BASE: (c) => c.apiBaseUrl,
|
|
786
|
+
VITE_PLAIFUL_CDN_BASE: (c) => c.assetCdnUrl,
|
|
787
|
+
VITE_FIREBASE_PROJECT_ID: (c) => c.firebase && c.firebase.projectId,
|
|
788
|
+
VITE_FIREBASE_API_KEY: (c) => c.firebase && c.firebase.webApiKey,
|
|
789
|
+
VITE_FIREBASE_AUTH_DOMAIN: (c) => c.firebase && c.firebase.authDomain,
|
|
790
|
+
VITE_PLAIFUL_OVID_BASE: (c) => c.ovidApiUrl,
|
|
791
|
+
VITE_PLAIFUL_PRISM_WS_URL: (c) => c.prismWsUrl,
|
|
792
|
+
VITE_PLAIFUL_ANALYTICS_INGEST: (c) => c.analyticsIngestUrl,
|
|
793
|
+
VITE_PLAIFUL_ANALYTICS_KEY: (c, game) => game.analytics_ingest_key,
|
|
794
|
+
};
|
|
795
|
+
const ENV_FILE = '.env.development';
|
|
796
|
+
// "(pending)", "(not deployed ...)" and "<...>" placeholders aren't values (the template's config.ts treats them as missing).
|
|
797
|
+
const usable = (v) => typeof v === 'string' && v !== '' && !/^\(|not deployed|^</.test(v);
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* Write .env.development in `root` from the game's dev client config: start from the file as it is (or the
|
|
801
|
+
* template's .env.development.example), set the variables the platform knows, keep every other line.
|
|
802
|
+
* → { file, set: [names], missing: [names] } or null when the repo has neither file (not the web template).
|
|
803
|
+
*/
|
|
804
|
+
function writeEnv(root, game) {
|
|
805
|
+
const file = path.join(root, ENV_FILE);
|
|
806
|
+
const example = path.join(root, `${ENV_FILE}.example`);
|
|
807
|
+
const base = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : fs.existsSync(example) ? fs.readFileSync(example, 'utf8') : null;
|
|
808
|
+
if (base === null) return null;
|
|
809
|
+
const set = [];
|
|
810
|
+
const missing = [];
|
|
811
|
+
const lines = base.split(/\r?\n/).map((line) => {
|
|
812
|
+
const m = /^\s*([A-Z0-9_]+)\s*=(.*)$/.exec(line);
|
|
813
|
+
if (!m || !ENV_FROM_CONFIG[m[1]]) return line;
|
|
814
|
+
const v = ENV_FROM_CONFIG[m[1]](game.client_config || {}, game);
|
|
815
|
+
if (!usable(v)) { if (!m[2].trim()) missing.push(m[1]); return line; }
|
|
816
|
+
set.push(m[1]);
|
|
817
|
+
return `${m[1]}=${v}`;
|
|
818
|
+
});
|
|
819
|
+
fs.writeFileSync(file, lines.join('\n'));
|
|
820
|
+
return { file, set, missing };
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
function envLines(env, game) {
|
|
824
|
+
if (!env) return [` · no ${ENV_FILE}(.example) here: not the web game template, so no .env was written (the client config is in docs/plaiful/client-config.md)`];
|
|
825
|
+
const out = [` ${ENV_FILE}: ${env.set.length} value(s) from your dev client config`];
|
|
826
|
+
if (env.missing.length) {
|
|
827
|
+
const why = game.analytics_ingest_key_note && env.missing.includes('VITE_PLAIFUL_ANALYTICS_KEY') ? ` (the analytics key: ${game.analytics_ingest_key_note})` : '';
|
|
828
|
+
out.push(` ! still empty: ${env.missing.join(', ')}${why}`);
|
|
829
|
+
}
|
|
830
|
+
return out;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
async function envCmd(ctx) {
|
|
834
|
+
const r = repo(ctx);
|
|
835
|
+
const { data } = await ctx.call('GET', `/partner/${encodeURIComponent(r.product)}/game`);
|
|
836
|
+
const env = writeEnv(r.root, data);
|
|
837
|
+
if (!env) throw new UsageError(`no ${ENV_FILE} or ${ENV_FILE}.example in ${r.root}: this repo isn't the web game template`);
|
|
838
|
+
ctx.out([`${r.product} (dev):`, ...envLines(env, data)].join('\n'), { success: true, ...env });
|
|
839
|
+
return 0;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
async function clone(ctx, [productArg, dirArg]) {
|
|
843
|
+
let product = productArg || ctx.flags.product;
|
|
844
|
+
if (!product) {
|
|
845
|
+
const { data } = await ctx.call('GET', '/partner/whoami');
|
|
846
|
+
if (data.products.length !== 1) throw new UsageError(`which game? ${data.products.length ? `yours: ${data.products.map((p) => p.product_id).join(', ')}` : 'you have none yet'} (plaiful clone <product>)`);
|
|
847
|
+
product = data.products[0].product_id;
|
|
848
|
+
}
|
|
849
|
+
const { data: game } = await ctx.call('GET', `/partner/${encodeURIComponent(product)}/game`);
|
|
850
|
+
if (!game.clone_url) throw new ApiError(409, { error: `${product} has no repo to clone yet: ${game.summary}`, code: 'no_repo' });
|
|
851
|
+
const repoLabel = (game.game_repo && game.game_repo.repo) || game.clone_url;
|
|
852
|
+
const repoName = String((game.game_repo && game.game_repo.repo) || product).split('/').pop().replace(/\.git$/, '');
|
|
853
|
+
const dir = path.resolve(ctx.io.cwd(), dirArg || repoName);
|
|
854
|
+
if (fs.existsSync(dir) && fs.readdirSync(dir).length) throw new UsageError(`${dir} already exists and isn't empty; pass another folder: plaiful clone ${product} <dir>`);
|
|
855
|
+
ctx.io.stderr.write(`Cloning ${game.clone_url} into ${dir}...\n`);
|
|
856
|
+
const git = ctx.io.run('git', ['clone', game.clone_url, dir], { cwd: ctx.io.cwd() });
|
|
857
|
+
if (git.status !== 0) {
|
|
858
|
+
throw new ApiError(1, {
|
|
859
|
+
error: `git couldn't clone ${repoLabel}. You need access to it on GitHub (ask the product's owner, or Plaiful, to add your account) and git signed in to GitHub (gh auth login, or Git Credential Manager).`,
|
|
860
|
+
code: 'clone_failed',
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
const rel = path.relative(ctx.io.cwd(), dir) || '.';
|
|
864
|
+
const steps = [`Cloned ${repoLabel} into ${rel}.`];
|
|
865
|
+
const existing = config.findRepoConfig(dir);
|
|
866
|
+
const own = existing && existing.root === dir ? existing.config : null;
|
|
867
|
+
if (!own) config.writeRepoConfig(dir, { product, env: 'dev', docsDir: config.DEFAULT_DOCS_DIR });
|
|
868
|
+
const made = makeLayout(dir, product, (own && own.docsDir) || config.DEFAULT_DOCS_DIR);
|
|
869
|
+
if (made.length) steps.push(`Made ${made.length} folder(s) your files go in: ${made.join(', ')}`);
|
|
870
|
+
const r = { product, root: dir, docsDir: path.resolve(dir, (own && own.docsDir) || config.DEFAULT_DOCS_DIR) };
|
|
871
|
+
steps.push(...envLines(writeEnv(dir, game), game));
|
|
872
|
+
await docsPull({ ...ctx, out: () => {} }, r);
|
|
873
|
+
steps.push(` ${path.relative(dir, r.docsDir).replace(/\\/g, '/')}: the onboarding docs and client-config.md`);
|
|
874
|
+
if (fs.existsSync(path.join(dir, 'package.json')) && !ctx.flags['no-install']) {
|
|
875
|
+
ctx.io.stderr.write('npm install...\n');
|
|
876
|
+
const npm = ctx.io.run('npm', ['install'], { cwd: dir });
|
|
877
|
+
steps.push(npm.status === 0 ? ' npm install: done'
|
|
878
|
+
: ' ! npm install failed. The @plaiful packages need npm access to the plaiful org (npm login; ask Plaiful), then run npm install there.');
|
|
879
|
+
}
|
|
880
|
+
if (!ctx.flags['no-open']) {
|
|
881
|
+
const zed = ctx.io.run('zed', [dir], { cwd: dir, detached: true });
|
|
882
|
+
steps.push(zed.status === 0 ? ' opened in Zed' : ' open it in your editor (Zed isn\'t installed)');
|
|
883
|
+
}
|
|
884
|
+
steps.push(`Next: cd ${rel}, npm run dev. docs/plaiful/README.md is the guide.`);
|
|
885
|
+
ctx.out(steps.join('\n'), { success: true, product, dir, clone_url: game.clone_url, game_repo: game.game_repo });
|
|
886
|
+
return 0;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
const COMMANDS = {
|
|
890
|
+
login: (ctx) => login(ctx),
|
|
891
|
+
logout: (ctx) => logout(ctx),
|
|
892
|
+
whoami: (ctx) => whoami(ctx),
|
|
893
|
+
init: (ctx, rest) => init(ctx, rest),
|
|
894
|
+
'docs pull': (ctx) => docsPull(ctx),
|
|
895
|
+
'ovid check': (ctx, rest) => ovidCheck(ctx, rest),
|
|
896
|
+
'ovid publish': (ctx, rest) => ovidPublish(ctx, rest),
|
|
897
|
+
'ovid show': (ctx) => ovidShow(ctx),
|
|
898
|
+
seed: (ctx, [store, ...paths]) => seedStore(ctx, store, paths),
|
|
899
|
+
status: (ctx) => status(ctx),
|
|
900
|
+
lists: (ctx, rest) => lists(ctx, rest),
|
|
901
|
+
agents: (ctx, rest) => agents(ctx, rest),
|
|
902
|
+
'midas pricing': (ctx, rest) => midasPricing(ctx, rest),
|
|
903
|
+
quests: (ctx, rest) => quests(ctx, rest),
|
|
904
|
+
assets: (ctx, rest) => assets(ctx, rest),
|
|
905
|
+
lore: (ctx, rest) => lore(ctx, rest),
|
|
906
|
+
world: (ctx) => world(ctx),
|
|
907
|
+
upload: (ctx, files) => upload(ctx, files),
|
|
908
|
+
clone: (ctx, rest) => clone(ctx, rest),
|
|
909
|
+
env: (ctx) => envCmd(ctx),
|
|
910
|
+
};
|
|
911
|
+
|
|
912
|
+
function defaultIo() {
|
|
913
|
+
return {
|
|
914
|
+
fetch: (...a) => fetch(...a),
|
|
915
|
+
stdout: process.stdout,
|
|
916
|
+
stderr: process.stderr,
|
|
917
|
+
cwd: () => process.cwd(),
|
|
918
|
+
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
919
|
+
// git, npm and zed for `plaiful clone`, attached to the terminal so their output and prompts show. → { status }
|
|
920
|
+
run: (cmd, args, { cwd, detached = false } = {}) => {
|
|
921
|
+
const shell = process.platform === 'win32'; // npm and zed are .cmd shims on Windows
|
|
922
|
+
try {
|
|
923
|
+
if (detached) {
|
|
924
|
+
const probe = spawnSync(cmd, ['--version'], { shell, stdio: 'ignore' });
|
|
925
|
+
if (probe.status !== 0) return { status: probe.status === null ? 1 : probe.status };
|
|
926
|
+
spawn(cmd, args, { cwd, shell, stdio: 'ignore', detached: true }).on('error', () => {}).unref();
|
|
927
|
+
return { status: 0 };
|
|
928
|
+
}
|
|
929
|
+
const r = spawnSync(cmd, args, { cwd, shell, stdio: 'inherit' });
|
|
930
|
+
return { status: r.status === null ? 1 : r.status };
|
|
931
|
+
} catch { return { status: 1 }; }
|
|
932
|
+
},
|
|
933
|
+
openUrl: (url) => {
|
|
934
|
+
const [cmd, args] = process.platform === 'win32' ? ['rundll32', ['url.dll,FileProtocolHandler', url]]
|
|
935
|
+
: process.platform === 'darwin' ? ['open', [url]] : ['xdg-open', [url]];
|
|
936
|
+
try { spawn(cmd, args, { stdio: 'ignore', detached: true }).on('error', () => {}).unref(); } catch { /* print-only */ }
|
|
937
|
+
},
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
async function main(argv, io = defaultIo()) {
|
|
942
|
+
let flags = {};
|
|
943
|
+
try {
|
|
944
|
+
const parsed = parse(argv);
|
|
945
|
+
flags = parsed.flags;
|
|
946
|
+
if (flags.version) { io.stdout.write(`${version}\n`); return 0; }
|
|
947
|
+
const [a, b, ...rest] = parsed.args;
|
|
948
|
+
if (flags.help || !a || a === 'help') { io.stdout.write(`${HELP}\n`); return 0; }
|
|
949
|
+
const two = COMMANDS[`${a} ${b}`];
|
|
950
|
+
const one = COMMANDS[a];
|
|
951
|
+
const ctx = makeContext(io, flags);
|
|
952
|
+
if (two) return await two(ctx, rest);
|
|
953
|
+
if (one && !['docs', 'ovid', 'midas'].includes(a)) return await one(ctx, b === undefined ? rest : [b, ...rest]);
|
|
954
|
+
throw new UsageError(`unknown command "${parsed.args.join(' ')}"`);
|
|
955
|
+
} catch (e) {
|
|
956
|
+
if (e instanceof UsageError) {
|
|
957
|
+
io.stderr.write(`plaiful: ${e.message}\n(plaiful help lists the commands)\n`);
|
|
958
|
+
return 2;
|
|
959
|
+
}
|
|
960
|
+
if (e instanceof ApiError) {
|
|
961
|
+
if (flags.json) io.stdout.write(`${JSON.stringify({ success: false, status: e.status, ...(e.body || {}), error: e.message }, null, 2)}\n`);
|
|
962
|
+
else io.stderr.write(`plaiful: ${e.message}\n`);
|
|
963
|
+
return 1;
|
|
964
|
+
}
|
|
965
|
+
io.stderr.write(`plaiful: ${e.stack || e.message}\n`);
|
|
966
|
+
return 1;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
module.exports = { main, parse };
|