@plaiful/cli 0.15.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +179 -158
- package/package.json +21 -21
- package/src/cli.js +2164 -1751
- package/src/models.js +282 -35
package/src/cli.js
CHANGED
|
@@ -1,1751 +1,2164 @@
|
|
|
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 the platform docs (live): each doc, its summary, when it last changed
|
|
24
|
-
plaiful docs read <doc> one doc, current (--section "3.5" or a heading for one section)
|
|
25
|
-
plaiful docs search <words...> where the docs say it: each doc's best sections, with a snippet
|
|
26
|
-
plaiful docs changes [--since <date>] the docs changed since a date (default: the last 7 days)
|
|
27
|
-
plaiful docs pull write your product's own files (client-config.md) into docsDir; the platform
|
|
28
|
-
docs stay live (--copies also writes local copies, for offline work)
|
|
29
|
-
plaiful mcp an MCP server on stdio with the docs tools, signed in as you
|
|
30
|
-
(claude mcp add plaiful -- plaiful mcp)
|
|
31
|
-
plaiful ovid check [file] check your OVID declaration (default: <docsDir>/<product>-ovid-declaration.json)
|
|
32
|
-
plaiful ovid publish [file] check it and publish it; OVID reads it within about 5 minutes
|
|
33
|
-
plaiful ovid show the declaration OVID has now
|
|
34
|
-
plaiful seed world|lore|map|personas [paths] dry run: the rows your files make and what changes in dev
|
|
35
|
-
(default: every .json in resources/<store>/<product>/; personas = THESPIS
|
|
36
|
-
personas and situations)
|
|
37
|
-
--apply write them; --reset also put runtime state back to the files
|
|
38
|
-
--rows print every row
|
|
39
|
-
plaiful status what OVID and THESPIS have for your product in dev
|
|
40
|
-
plaiful
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
plaiful
|
|
44
|
-
plaiful
|
|
45
|
-
plaiful
|
|
46
|
-
plaiful lore
|
|
47
|
-
plaiful
|
|
48
|
-
plaiful
|
|
49
|
-
|
|
50
|
-
plaiful
|
|
51
|
-
plaiful world
|
|
52
|
-
plaiful
|
|
53
|
-
|
|
54
|
-
plaiful
|
|
55
|
-
plaiful
|
|
56
|
-
plaiful
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
plaiful
|
|
60
|
-
plaiful
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
plaiful events
|
|
65
|
-
|
|
66
|
-
plaiful events
|
|
67
|
-
|
|
68
|
-
plaiful
|
|
69
|
-
|
|
70
|
-
plaiful
|
|
71
|
-
plaiful
|
|
72
|
-
plaiful
|
|
73
|
-
|
|
74
|
-
plaiful agents
|
|
75
|
-
plaiful agents
|
|
76
|
-
plaiful agents
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
plaiful
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
plaiful midas
|
|
85
|
-
|
|
86
|
-
plaiful midas
|
|
87
|
-
plaiful midas
|
|
88
|
-
plaiful midas
|
|
89
|
-
|
|
90
|
-
plaiful midas
|
|
91
|
-
plaiful midas
|
|
92
|
-
plaiful midas
|
|
93
|
-
plaiful midas
|
|
94
|
-
plaiful midas
|
|
95
|
-
plaiful midas pricing
|
|
96
|
-
|
|
97
|
-
plaiful
|
|
98
|
-
plaiful
|
|
99
|
-
plaiful
|
|
100
|
-
|
|
101
|
-
plaiful
|
|
102
|
-
plaiful
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
plaiful
|
|
112
|
-
plaiful
|
|
113
|
-
|
|
114
|
-
plaiful
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
plaiful
|
|
119
|
-
plaiful
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
plaiful
|
|
128
|
-
|
|
129
|
-
plaiful
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
plaiful
|
|
133
|
-
plaiful
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
plaiful
|
|
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
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
ctx.
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
[`
|
|
276
|
-
[
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
const
|
|
375
|
-
if (
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
const
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
];
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if (
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
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
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
const
|
|
520
|
-
const
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
const
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
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
|
-
const
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
`
|
|
603
|
-
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
const
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
const
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
async function
|
|
664
|
-
|
|
665
|
-
const { data } = await ctx.call('GET',
|
|
666
|
-
|
|
667
|
-
const
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
ctx.
|
|
678
|
-
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
const
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
if (
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
lines.push(`
|
|
691
|
-
}
|
|
692
|
-
ctx.out(lines.join('\n'), data);
|
|
693
|
-
return 0;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
const
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
const
|
|
720
|
-
const lines =
|
|
721
|
-
for (const
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
const
|
|
732
|
-
const { data } = await ctx.call('POST', `/
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
const
|
|
751
|
-
const
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
async function
|
|
774
|
-
if (
|
|
775
|
-
const
|
|
776
|
-
const
|
|
777
|
-
const
|
|
778
|
-
const
|
|
779
|
-
const
|
|
780
|
-
if (
|
|
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
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
const
|
|
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
|
-
return
|
|
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
|
-
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
for
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
if (sub
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
if (
|
|
969
|
-
const
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
lines.
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
const
|
|
986
|
-
if (
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
const
|
|
997
|
-
const
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
const
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
const
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
const
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
if (
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
ctx.out(
|
|
1086
|
-
return 0;
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
if (
|
|
1095
|
-
if (
|
|
1096
|
-
return
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
async function
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
}
|
|
1134
|
-
return
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
const
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
const
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
for (const
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
}
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
return
|
|
1170
|
-
}
|
|
1171
|
-
if (sub === '
|
|
1172
|
-
|
|
1173
|
-
const
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
if (
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
const
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
if (
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
const
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
const
|
|
1227
|
-
|
|
1228
|
-
if (!
|
|
1229
|
-
if (
|
|
1230
|
-
const
|
|
1231
|
-
const
|
|
1232
|
-
if (
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
const
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
if (
|
|
1286
|
-
|
|
1287
|
-
if (ctx.flags.
|
|
1288
|
-
if (
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
if (
|
|
1295
|
-
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
const
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
if (!
|
|
1370
|
-
|
|
1371
|
-
ctx.
|
|
1372
|
-
return
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
return
|
|
1383
|
-
}
|
|
1384
|
-
if (
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
if (sub === '
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
const
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
const
|
|
1414
|
-
if (
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
return
|
|
1434
|
-
}
|
|
1435
|
-
if (sub === '
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
const
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
}
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
const
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
const
|
|
1528
|
-
|
|
1529
|
-
const
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
return
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
const
|
|
1585
|
-
|
|
1586
|
-
if (
|
|
1587
|
-
ctx.
|
|
1588
|
-
const
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
});
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
}
|
|
1620
|
-
|
|
1621
|
-
const
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
return
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
'
|
|
1649
|
-
'midas
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
'
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
};
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
const
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
}
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
}
|
|
1750
|
-
|
|
1751
|
-
|
|
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 the platform docs (live): each doc, its summary, when it last changed
|
|
24
|
+
plaiful docs read <doc> one doc, current (--section "3.5" or a heading for one section)
|
|
25
|
+
plaiful docs search <words...> where the docs say it: each doc's best sections, with a snippet
|
|
26
|
+
plaiful docs changes [--since <date>] the docs changed since a date (default: the last 7 days)
|
|
27
|
+
plaiful docs pull write your product's own files (client-config.md) into docsDir; the platform
|
|
28
|
+
docs stay live (--copies also writes local copies, for offline work)
|
|
29
|
+
plaiful mcp an MCP server on stdio with the docs tools, signed in as you
|
|
30
|
+
(claude mcp add plaiful -- plaiful mcp)
|
|
31
|
+
plaiful ovid check [file] check your OVID declaration (default: <docsDir>/<product>-ovid-declaration.json)
|
|
32
|
+
plaiful ovid publish [file] check it and publish it; OVID reads it within about 5 minutes
|
|
33
|
+
plaiful ovid show the declaration OVID has now
|
|
34
|
+
plaiful seed world|lore|map|personas [paths] dry run: the rows your files make and what changes in dev
|
|
35
|
+
(default: every .json in resources/<store>/<product>/; personas = THESPIS
|
|
36
|
+
personas and situations)
|
|
37
|
+
--apply write them; --reset also put runtime state back to the files
|
|
38
|
+
--rows print every row
|
|
39
|
+
plaiful status what OVID and THESPIS have for your product in dev
|
|
40
|
+
plaiful promote [--to staging] move the product from dev to staging: content, assets, settings and agents
|
|
41
|
+
--dry-run show what would change; write nothing
|
|
42
|
+
--no-wait start it and print its id (then: plaiful promote status <id>)
|
|
43
|
+
plaiful promote status <id> how a promotion is going, or how it ended
|
|
44
|
+
plaiful quests the quests OVID wrote: steps and what each pays (--track <id>, --series <id>)
|
|
45
|
+
plaiful quests show <id> one quest: its graph, steps, reward hint and price (--json: the whole record)
|
|
46
|
+
plaiful lore the lore sets, with known / hidden snippet counts
|
|
47
|
+
plaiful lore show <setId> one set's snippets
|
|
48
|
+
plaiful lore add <setId> --narrative "…" add a snippet at the end of a set (--hint, --title, --rarity, --known)
|
|
49
|
+
plaiful lore reveal <snippetId> make a snippet known to the world; lore hide <snippetId> hide it again
|
|
50
|
+
plaiful lore remove <setId> delete a set and its snippets (--force for official canon)
|
|
51
|
+
plaiful world the world's states and state events in story order, and the clock
|
|
52
|
+
plaiful world truth <id> --statement "…" add a world truth (--category foundational|cultural|historical|
|
|
53
|
+
cosmological|political|hidden_truth, --scope)
|
|
54
|
+
plaiful world faction <id> --name "…" add a faction (--description, --type, --homeland)
|
|
55
|
+
plaiful world var <id> <value> add a world variable (--description); world set <id> <value> --reason "…" set it
|
|
56
|
+
plaiful events edit <eventId> change an event (--title, --description, --category, --order <n>,
|
|
57
|
+
--directives <file.json>; --force for official canon)
|
|
58
|
+
plaiful events delete <eventId> delete an event and the events under it (--force for official canon)
|
|
59
|
+
plaiful quests delete <questId> delete a quest and its bindings (--force for official canon)
|
|
60
|
+
plaiful canon event|quest <id> official|draft|rejected set its canon status
|
|
61
|
+
plaiful events script write <eventId> ask OVID for a cinematic script for a state event (a new draft version;
|
|
62
|
+
--note "<what to change>", --wait to wait for it, --force to start over)
|
|
63
|
+
plaiful events script get <eventId> [version] the script as a screenplay page, its versions and the last request
|
|
64
|
+
plaiful events script export <eventId> [version] --fountain|--vo the screenplay (Fountain) or the voice-over
|
|
65
|
+
sheet (CSV); --out <file> to write it to a file
|
|
66
|
+
plaiful events script approve <eventId> <version> approve a version: the one the game gets (--retire to withdraw
|
|
67
|
+
it; --force for an official-canon event)
|
|
68
|
+
plaiful events storyboard draw <eventId> [version] --style <style> draw the script's storyboard, a frame per
|
|
69
|
+
shot (--aspect 16:9|4:3|1:1|9:16|21:9, --frame <id> to redraw one, --wait)
|
|
70
|
+
plaiful events storyboard get <eventId> [version] the frames and their captions (--out <dir> saves the images)
|
|
71
|
+
plaiful lists your product's SSM lists (NPC roles, SmartBuilder list values, ...)
|
|
72
|
+
plaiful lists get <name> one list (a name in your namespace, e.g. shop_type, or the full /path)
|
|
73
|
+
plaiful lists set <name> <values...> write a list (values as words, or one comma-separated argument)
|
|
74
|
+
plaiful agents your product's SmartBuilder agents in dev
|
|
75
|
+
plaiful agents show <name> one agent's deployed config
|
|
76
|
+
plaiful agents deploy [files...] deploy or redeploy agents from their config files (default: every .json in
|
|
77
|
+
resources/agents/<product>/); a redeploy keeps the agent's own settings
|
|
78
|
+
plaiful agents run <name> [key=value...] make one record (placeholder values as key=value)
|
|
79
|
+
plaiful agents batch <name> [file] start a batch (a batch body file, or --count <n>) → a job id
|
|
80
|
+
plaiful agents status <name> <jobId> a batch's progress
|
|
81
|
+
plaiful records import <agent> [file] dry run: records you wrote, into the agent's table (default file:
|
|
82
|
+
resources/records/<product>/<agent>.json; matched on the agent's duplicate field)
|
|
83
|
+
--apply write them; --no-render don't make new records' art or sound
|
|
84
|
+
plaiful midas check [file] check your MIDAS declaration: your economy's kinds, wallet, items, schedule
|
|
85
|
+
(default: <docsDir>/<product>-midas-declaration.json)
|
|
86
|
+
plaiful midas publish [file] check it and publish it
|
|
87
|
+
plaiful midas show the declaration MIDAS has, with its defaults filled in
|
|
88
|
+
plaiful midas health MIDAS's analysis of your economy: per kind, what quests make available (and with a
|
|
89
|
+
wallet, what players earn and spend)
|
|
90
|
+
plaiful midas balance what MIDAS flagged, and why (--all for everything it checked)
|
|
91
|
+
plaiful midas proposals what MIDAS proposes (--status pending|approved|applied|dismissed)
|
|
92
|
+
plaiful midas assess run MIDAS's analysis now
|
|
93
|
+
plaiful midas wallet <player> one player's balances and recent earning / spending (wallet "platform")
|
|
94
|
+
plaiful midas ledger check <file> would your game's report be accepted (wallet "game"): a dry run
|
|
95
|
+
plaiful midas pricing what MIDAS pays per quest, in your reward kinds (delivered in each quest's rewards)
|
|
96
|
+
plaiful midas pricing set <kind> --base <n> --per-effort <n> price a kind (either option alone keeps the other)
|
|
97
|
+
plaiful midas pricing unset <kind> stop pricing a kind
|
|
98
|
+
plaiful midas pricing weight <step> <n> how much a quest step counts (combat, gather, explore, ...)
|
|
99
|
+
plaiful midas pricing apply [file] replace it all from a file (default:
|
|
100
|
+
resources/midas/<product>/quest-pricing.json; { kinds, objective_weights, ... })
|
|
101
|
+
plaiful hermes strategy your studio's strategy, the one HERMES judges the market against
|
|
102
|
+
plaiful hermes strategy check [file] check it (default: <docsDir>/hermes-strategy.json)
|
|
103
|
+
plaiful hermes strategy publish [file] check it and publish it as a new version (the studio's admins)
|
|
104
|
+
plaiful studio list your studios, and your role in each
|
|
105
|
+
plaiful studio show [<studio>] a studio's people and products (its admins also see invites, seats and the
|
|
106
|
+
presets to invite as); plaiful studio alone shows yours
|
|
107
|
+
plaiful studio invite <email> --role admin|<preset> invite someone (presets: producer, developer, artist,
|
|
108
|
+
narrative-designer, game-designer, analyst, viewer); --products a,b (default all),
|
|
109
|
+
--area art=edit to adjust a preset. Prints the link to send them
|
|
110
|
+
plaiful studio invites the studio's invites, pending and expired
|
|
111
|
+
plaiful studio resend <inviteId> a new link and 7 more days; studio cancel <inviteId> cancel an invite
|
|
112
|
+
plaiful studio set <email> change someone: --role admin|member|<preset>, --products a,b|all,
|
|
113
|
+
--area art=edit (repeatable; =none takes an area away); the rest stays as it is
|
|
114
|
+
plaiful studio remove <email> take someone out of the studio; the product API keys they issued for its products
|
|
115
|
+
stop working too (asks first; --yes doesn't)
|
|
116
|
+
plaiful studio audit who changed what in the studio, newest first (--limit <n>, --before <id>)
|
|
117
|
+
--studio <id> which studio, when you're in more than one (an id, or its name)
|
|
118
|
+
plaiful assets per agent: records, and how many have their art made, pending, failed or none
|
|
119
|
+
plaiful assets <agent> its records: state, why a render failed, where the files are
|
|
120
|
+
plaiful assets regenerate <agent> [uuids...] re-render records with the table's Art Style, as the Library's
|
|
121
|
+
Regenerate does: a new picture (--all, or --state failed|none|made|step_failed)
|
|
122
|
+
--steps depth[,normal] | --steps all only re-run those steps on the current picture (Regenerate → Steps)
|
|
123
|
+
--model a 3D model from each record's current picture, with the table's 2d+3d Art Style
|
|
124
|
+
(Regenerate → 3D model; --state no_model: every record with a picture and no model;
|
|
125
|
+
at most 50 a run, each a paid build)
|
|
126
|
+
--state made|pending|failed|none --limit <n> (default 50)
|
|
127
|
+
plaiful animation sets the animation sets you can use (a set = a list of animation states, one sprite
|
|
128
|
+
sheet each, run together on a character): the built-ins, Plaiful's and yours
|
|
129
|
+
plaiful animation sets show <id> one set's states
|
|
130
|
+
plaiful animation sets save [files...] save your own sets from files (default: every .json in
|
|
131
|
+
resources/animation/<product>/; { id, name, states: [{ name, method, prompt }], style_ref? })
|
|
132
|
+
plaiful animation sets delete <id> delete one of your sets
|
|
133
|
+
plaiful animation run <set> <agent> [uuids...] run a set on an agent's records (--all: every record with its art
|
|
134
|
+
made; --style <sprite style>, else the set's; --force: make them again)
|
|
135
|
+
plaiful styles the art styles you can use: Plaiful's shared ones (read-only) and yours
|
|
136
|
+
plaiful styles show <id> one style as JSON, and its reference images (--out <file.json> writes it)
|
|
137
|
+
plaiful styles save [files...] dry run: what your style files would create or change (default: every .json in
|
|
138
|
+
resources/styles/<product>/; { id, name, prompt_prefix?, … }); --apply saves them
|
|
139
|
+
plaiful styles delete <id> delete one of your styles (--yes outside a terminal)
|
|
140
|
+
plaiful styles images add <id> <images...> add reference images (.png or .jpg) to one of yours (--caption)
|
|
141
|
+
plaiful styles images remove <id> <key> remove one (plaiful styles show lists the keys)
|
|
142
|
+
plaiful models the model registry (Plaiful staff for now): every release, its status and licence
|
|
143
|
+
plaiful models check <card|dir> check release cards and their files on disk (a dry run: nothing uploads)
|
|
144
|
+
plaiful models publish <card|dir> upload each card's files (checked against its sha256s) and publish the card;
|
|
145
|
+
a published release never changes, only its card can be corrected
|
|
146
|
+
(--files <folder> if the card has no archive_path; owner from .plaiful.json)
|
|
147
|
+
plaiful models show <task> <release> one release: card, files, status history
|
|
148
|
+
plaiful models status <task> <release> active|candidate|retired (--note "…"; retired, never deleted)
|
|
149
|
+
plaiful models pull <task> <release> download a release, every sha256 checked (--out <dir>, --role shipped)
|
|
150
|
+
plaiful models data push <task> <snapshot> <folder> store a training-data folder as a sealed snapshot
|
|
151
|
+
(--exclude <regex>, --source "…", --licence "…", --note "…", --releases a,b)
|
|
152
|
+
plaiful models data [list] the training-data snapshots; models data pull <task> <snapshot> [--out <dir>]
|
|
153
|
+
(--into <archive folder>: back at its archive path)
|
|
154
|
+
plaiful models archive push <folder> [<kind>[/<role>[/<name>]]] --games a,b push the plaiful-models archive: one
|
|
155
|
+
sealed snapshot per <kind>/<role>/<name>, with the licence its catalog, manifest
|
|
156
|
+
or README gives; corpora and experiments named <game>-…; big files in parts,
|
|
157
|
+
resumable; links and junctions not followed
|
|
158
|
+
plaiful models archive list [<folder>] what's in the registry (share-alike flagged), and what's not pushed yet
|
|
159
|
+
plaiful models archive pull <folder> [<kind>[/<role>[/<name>]]] bring snapshots back to the same layout
|
|
160
|
+
plaiful models train check is this machine ready to train on Google Cloud (gcloud, project, bucket, API)
|
|
161
|
+
plaiful models train submit <task> --code <folder> --entry "python train.py --data {data} --out {out}"
|
|
162
|
+
run it on a Google Cloud GPU (--gpu l4|t4|a100, --hours 12, --data <folders>,
|
|
163
|
+
--snapshot <task>/<snapshot>, --project, --region, --bucket, --image, --name)
|
|
164
|
+
plaiful models train list|status|logs|fetch|cancel [job] follow a job; fetch brings its output home (--out)
|
|
165
|
+
plaiful upload <files...> upload map tiles into your dev assets bucket (map-data/; --dest map-data)
|
|
166
|
+
plaiful clone [product] [dir] clone the game repo, write .env.development, docs pull, npm install, open Zed
|
|
167
|
+
--no-install --no-open
|
|
168
|
+
plaiful env (re)write .env.development from your dev client config (keeps your own lines)
|
|
169
|
+
|
|
170
|
+
Options: --json (machine-readable output) --product <id> --api <url> --no-browser (login)
|
|
171
|
+
Environment: PLAIFUL_API_URL, PLAIFUL_TOKEN (instead of login: CI, with a product API key from the CMS)
|
|
172
|
+
Docs: docs/plaiful/README.md after \`plaiful docs pull\``;
|
|
173
|
+
|
|
174
|
+
class UsageError extends Error {}
|
|
175
|
+
class ApiError extends Error {
|
|
176
|
+
constructor(status, body) {
|
|
177
|
+
super((body && body.error) || `the platform answered ${status}`);
|
|
178
|
+
this.status = status;
|
|
179
|
+
this.body = body;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Where an agent list's values come from: an SSM path, or the values kept in the agent ({ values: [...] }). */
|
|
184
|
+
function listSource(v) {
|
|
185
|
+
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 ? ', …' : ''})`;
|
|
186
|
+
if (v && typeof v === 'object') return v.path || JSON.stringify(v);
|
|
187
|
+
return String(v);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function parse(argv) {
|
|
191
|
+
const flags = {};
|
|
192
|
+
const args = [];
|
|
193
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
194
|
+
const a = argv[i];
|
|
195
|
+
if (['--json', '--no-browser', '--help', '-h', '--version', '--apply', '--reset', '--rows', '--no-install', '--no-open', '--copies', '--no-render', '--wait', '--force', '--fountain', '--vo', '--all', '--retire', '--known', '--model', '--yes', '--dry-run', '--no-wait'].includes(a)) flags[a.replace(/^-+/, '')] = true;
|
|
196
|
+
else if (['--product', '--api', '--dir', '--dest', '--count', '--base', '--per-effort', '--track', '--series', '--state', '--limit', '--section', '--since', '--note', '--out', '--style', '--aspect', '--frame', '--title', '--description', '--category', '--order', '--directives', '--narrative', '--hint', '--rarity', '--statement', '--name', '--reason', '--type', '--homeland', '--scope', '--status', '--steps', '--files', '--role', '--exclude', '--source', '--licence', '--releases', '--code', '--entry', '--data', '--snapshot', '--gpu', '--machine', '--hours', '--image', '--project', '--region', '--bucket', '--studio', '--products', '--before', '--to', '--into', '--games', '--caption'].includes(a)) {
|
|
197
|
+
if (argv[i + 1] === undefined) throw new UsageError(`${a} needs a value`);
|
|
198
|
+
flags[a.slice(2)] = argv[i += 1];
|
|
199
|
+
} else if (a === '--area') { // repeatable: --area art=edit --area content=view
|
|
200
|
+
if (argv[i + 1] === undefined) throw new UsageError(`${a} needs a value`);
|
|
201
|
+
flags.area = [...(flags.area || []), argv[i += 1]];
|
|
202
|
+
} else if (a.startsWith('--')) throw new UsageError(`unknown option ${a}`);
|
|
203
|
+
else args.push(a);
|
|
204
|
+
}
|
|
205
|
+
return { flags, args };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function makeContext(io, flags) {
|
|
209
|
+
const url = config.apiUrl(flags);
|
|
210
|
+
const out = (text, json) => io.stdout.write(`${flags.json ? JSON.stringify(json === undefined ? text : json, null, 2) : text}\n`);
|
|
211
|
+
async function call(method, route, body, { auth = true } = {}) {
|
|
212
|
+
const headers = { Accept: 'application/json' };
|
|
213
|
+
if (body !== undefined) headers['Content-Type'] = 'application/json';
|
|
214
|
+
if (auth) {
|
|
215
|
+
const token = config.tokenFor(url);
|
|
216
|
+
if (!token) throw new ApiError(401, { error: 'not signed in: run `plaiful login`', code: 'no_session' });
|
|
217
|
+
headers.Authorization = `Bearer ${token}`;
|
|
218
|
+
}
|
|
219
|
+
let res;
|
|
220
|
+
try {
|
|
221
|
+
res = await io.fetch(`${url}${route}`, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
|
|
222
|
+
} catch (e) {
|
|
223
|
+
throw new ApiError(0, { error: `can't reach the Plaiful API at ${url} (${e.message})`, code: 'network' });
|
|
224
|
+
}
|
|
225
|
+
let data = {};
|
|
226
|
+
try { data = await res.json(); } catch { /* empty body */ }
|
|
227
|
+
if (!res.ok && !(res.status === 422 || (res.status === 409 && data.errors))) throw new ApiError(res.status, data);
|
|
228
|
+
return { status: res.status, data };
|
|
229
|
+
}
|
|
230
|
+
return { url, flags, out, call, io };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function repo(ctx, { required = true } = {}) {
|
|
234
|
+
const found = config.findRepoConfig(ctx.io.cwd());
|
|
235
|
+
const product = ctx.flags.product || (found && found.config.product);
|
|
236
|
+
if (required && !product) throw new UsageError('no product: run `plaiful init <product>` in your repo, or pass --product');
|
|
237
|
+
const root = found ? found.root : ctx.io.cwd();
|
|
238
|
+
const docsDir = path.resolve(root, ctx.flags.dir || (found && found.config.docsDir) || config.DEFAULT_DOCS_DIR);
|
|
239
|
+
return { product, root, docsDir, found };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ── Commands ────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
243
|
+
|
|
244
|
+
async function login(ctx) {
|
|
245
|
+
const start = (await ctx.call('POST', '/partner/cli-login', undefined, { auth: false })).data;
|
|
246
|
+
ctx.io.stderr.write(`\nTo sign in, open:\n\n ${start.verification_url}\n\nand check the code matches: ${start.user_code}\n\n`);
|
|
247
|
+
if (!ctx.flags['no-browser']) ctx.io.openUrl(start.verification_url);
|
|
248
|
+
const deadline = Date.now() + start.expires_in * 1000;
|
|
249
|
+
let interval = (start.interval || 3) * 1000;
|
|
250
|
+
while (Date.now() < deadline) {
|
|
251
|
+
await ctx.io.sleep(interval);
|
|
252
|
+
const r = (await ctx.call('POST', '/partner/cli-login/token', { device_code: start.device_code }, { auth: false })).data;
|
|
253
|
+
if (r.status === 'approved') {
|
|
254
|
+
config.writeCredentials({ api_url: ctx.url, token: r.token, email: r.email, expires_at: r.expires_at });
|
|
255
|
+
ctx.out(`Signed in as ${r.email} until ${new Date(r.expires_at).toLocaleString()}.`, { success: true, email: r.email, expires_at: r.expires_at });
|
|
256
|
+
return 0;
|
|
257
|
+
}
|
|
258
|
+
interval = (r.interval || 3) * 1000;
|
|
259
|
+
}
|
|
260
|
+
throw new ApiError(410, { error: 'the sign-in wasn\'t approved in time; run `plaiful login` again', code: 'expired' });
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async function logout(ctx) {
|
|
264
|
+
if (config.tokenFor(ctx.url)) {
|
|
265
|
+
try { await ctx.call('POST', '/partner/logout'); } catch { /* the local sign-out is what matters */ }
|
|
266
|
+
}
|
|
267
|
+
config.clearCredentials();
|
|
268
|
+
ctx.out('Signed out.', { success: true });
|
|
269
|
+
return 0;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async function whoami(ctx) {
|
|
273
|
+
const { data } = await ctx.call('GET', '/partner/whoami');
|
|
274
|
+
const lines = data.key
|
|
275
|
+
? [`Product API key "${data.key.name}" for ${data.key.product} (${data.key.env}), issued by ${data.email}; scopes: ${data.key.scopes.join(', ')}`]
|
|
276
|
+
: [`${data.email}${data.staff ? ' (Plaiful staff)' : ''}, signed in until ${new Date(data.session_expires_at).toLocaleString()}`];
|
|
277
|
+
for (const st of data.studios || []) lines.push(`Studio: ${st.name} (${st.role}${st.preset ? `, ${st.preset}` : ''}${st.status !== 'active' ? `, ${st.status}` : ''})`);
|
|
278
|
+
lines.push(data.products.length ? 'Products:' : 'No products yet: create one in the CMS (Product deployment), or ask its owner to share it.');
|
|
279
|
+
for (const p of data.products) lines.push(` ${p.product_id} (${p.role})`);
|
|
280
|
+
ctx.out(lines.join('\n'), data);
|
|
281
|
+
return 0;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async function init(ctx, [product]) {
|
|
285
|
+
const { data } = await ctx.call('GET', '/partner/whoami');
|
|
286
|
+
const mine = data.products.map((p) => p.product_id);
|
|
287
|
+
const chosen = product || ctx.flags.product || (mine.length === 1 ? mine[0] : null);
|
|
288
|
+
if (!chosen) throw new UsageError(`which product? ${mine.length ? `yours: ${mine.join(', ')}` : 'you have none yet'} (plaiful init <product>)`);
|
|
289
|
+
if (!mine.includes(chosen)) throw new ApiError(403, { error: `${data.email} can't manage "${chosen}"${mine.length ? ` (yours: ${mine.join(', ')})` : ''}`, code: 'product_access' });
|
|
290
|
+
const existing = config.findRepoConfig(ctx.io.cwd());
|
|
291
|
+
const root = existing ? existing.root : ctx.io.cwd();
|
|
292
|
+
const next = { ...(existing ? existing.config : { env: 'dev', docsDir: config.DEFAULT_DOCS_DIR }), product: chosen };
|
|
293
|
+
const file = config.writeRepoConfig(root, next);
|
|
294
|
+
const made = makeLayout(root, chosen, next.docsDir);
|
|
295
|
+
const lines = [`Wrote ${path.relative(ctx.io.cwd(), file) || file}: product ${chosen}, docs in ${next.docsDir}.`];
|
|
296
|
+
if (made.length) lines.push(`Made ${made.length} folder(s): ${made.join(', ')}`);
|
|
297
|
+
lines.push('Next: plaiful docs pull');
|
|
298
|
+
ctx.out(lines.join('\n'), { success: true, file, config: next, made });
|
|
299
|
+
return 0;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ── Where things go (product-repo-template.md) ──────────────────────────────────────────────────────────────────
|
|
303
|
+
|
|
304
|
+
/** The repo folders the platform's steps read from: [folder, what goes there]. */
|
|
305
|
+
function layout(product, docsDir) {
|
|
306
|
+
return [
|
|
307
|
+
[`resources/${product}-resources`, 'SmartBuilder agent specs (one markdown file per agent, pasted into SmartBuilder)'],
|
|
308
|
+
[`resources/agents/${product}`, 'agent configs as JSON, for plaiful agents deploy'],
|
|
309
|
+
[`resources/records/${product}`, 'records you write by hand, one <agent>.json per agent, for plaiful records import'],
|
|
310
|
+
[`resources/world/${product}`, 'the narrative scaffold, for plaiful seed world'],
|
|
311
|
+
[`resources/lore/${product}`, 'lore sets, for plaiful seed lore'],
|
|
312
|
+
[`resources/map/${product}`, 'places, for plaiful seed map'],
|
|
313
|
+
[`resources/personas/${product}`, 'THESPIS personas and situations, for plaiful seed personas'],
|
|
314
|
+
[`resources/midas/${product}`, 'quest-pricing.json, for plaiful midas pricing apply'],
|
|
315
|
+
[`resources/styles/${product}`, 'art styles as JSON, one file per style, for plaiful styles save'],
|
|
316
|
+
[docsDir, `the pulled docs, and your ${product}-ovid-declaration.json (plaiful ovid check / publish)`],
|
|
317
|
+
];
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** Agent specs (markdown with agent_name and prompt_template) outside resources/<product>-resources/, under docs/ or
|
|
321
|
+
* resources/. → relative paths */
|
|
322
|
+
function misplacedSpecs(root, product, docsDir) {
|
|
323
|
+
const home = path.join(root, 'resources', `${product}-resources`);
|
|
324
|
+
const out = [];
|
|
325
|
+
const walk = (dir, depth) => {
|
|
326
|
+
if (depth > 6 || !fs.existsSync(dir)) return;
|
|
327
|
+
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
328
|
+
const full = path.join(dir, e.name);
|
|
329
|
+
if (e.isDirectory()) {
|
|
330
|
+
if (!['node_modules', '.git'].includes(e.name) && full !== home && full !== docsDir) walk(full, depth + 1);
|
|
331
|
+
} else if (e.name.endsWith('.md')) {
|
|
332
|
+
try {
|
|
333
|
+
const text = fs.readFileSync(full, 'utf8');
|
|
334
|
+
if (/\bagent_name\b/.test(text) && /\bprompt_template\b/.test(text)) out.push(path.relative(root, full).replace(/\\/g, '/'));
|
|
335
|
+
} catch { /* unreadable: skip */ }
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
walk(path.join(root, 'docs'), 0);
|
|
340
|
+
walk(path.join(root, 'resources'), 0);
|
|
341
|
+
return out;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** What to write in a folder's README when init makes it. */
|
|
345
|
+
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`;
|
|
346
|
+
|
|
347
|
+
/** The folders the platform's steps read from, each with a README saying what goes in it (an agent puts a file where
|
|
348
|
+
* a folder for it already exists). → the folders made */
|
|
349
|
+
function makeLayout(root, product, docsDir) {
|
|
350
|
+
const made = [];
|
|
351
|
+
for (const [folder, what] of layout(product, docsDir)) {
|
|
352
|
+
const dir = path.join(root, folder);
|
|
353
|
+
if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); made.push(folder); }
|
|
354
|
+
const readme = path.join(dir, 'README.md');
|
|
355
|
+
if (folder !== docsDir && !fs.existsSync(readme)) fs.writeFileSync(readme, folderReadme(folder, what));
|
|
356
|
+
}
|
|
357
|
+
return made;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function whereThingsGo(ctx, r) {
|
|
361
|
+
const lines = ['Where things go:'];
|
|
362
|
+
for (const [folder, what] of layout(r.product, path.relative(r.root, r.docsDir).replace(/\\/g, '/') || '.')) {
|
|
363
|
+
lines.push(` ${folder.padEnd(32)} ${what}${fs.existsSync(path.join(r.root, folder)) ? '' : ' (missing: plaiful init makes it)'}`);
|
|
364
|
+
}
|
|
365
|
+
const wrong = misplacedSpecs(r.root, r.product, r.docsDir);
|
|
366
|
+
if (wrong.length) {
|
|
367
|
+
lines.push(`! Agent specs outside resources/${r.product}-resources/ (move them there):`);
|
|
368
|
+
for (const f of wrong) lines.push(` ${f}`);
|
|
369
|
+
}
|
|
370
|
+
return { lines, misplaced: wrong };
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const safeName = (key) => {
|
|
374
|
+
const base = path.basename(String(key));
|
|
375
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*\.md$/.test(base)) return null;
|
|
376
|
+
return base;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// What docs pull leaves in docsDir when the platform docs are live (PLATFORM_DOCS_PORTAL.md §4).
|
|
380
|
+
const LIVE_DOCS_README = `# Plaiful docs
|
|
381
|
+
|
|
382
|
+
The platform docs are **live**, not copied here, so you always read the current version. Read them with the CLI, or
|
|
383
|
+
with the plaiful MCP tools in your coding assistant:
|
|
384
|
+
|
|
385
|
+
\`\`\`sh
|
|
386
|
+
plaiful docs # every doc, and when it last changed
|
|
387
|
+
plaiful docs read README # one doc (--section "3.5", or a heading, for one section)
|
|
388
|
+
plaiful docs search "batch template" # where the docs say it
|
|
389
|
+
plaiful docs changes --since 2026-10-20
|
|
390
|
+
plaiful mcp # the same as MCP tools: claude mcp add plaiful -- plaiful mcp
|
|
391
|
+
\`\`\`
|
|
392
|
+
|
|
393
|
+
Start with \`plaiful docs read README\`. Read a doc again when you start a task; don't keep a copy.
|
|
394
|
+
|
|
395
|
+
This folder holds your product's own files: \`client-config.md\` (your keys and endpoints: never commit it) and your
|
|
396
|
+
\`<product>-ovid-declaration.json\`. Written by \`plaiful docs pull\`.
|
|
397
|
+
`;
|
|
398
|
+
|
|
399
|
+
async function docsPull(ctx, r = repo(ctx)) {
|
|
400
|
+
const copies = !!ctx.flags.copies;
|
|
401
|
+
const { data } = await ctx.call('GET', `/partner/${encodeURIComponent(r.product)}/docs${copies ? '' : '?docs=none'}`);
|
|
402
|
+
fs.mkdirSync(r.docsDir, { recursive: true });
|
|
403
|
+
const platform = copies ? (data.docs || []) : [];
|
|
404
|
+
const files = [...platform, { key: data.client_config.key, title: 'Client config', content: data.client_config.content }];
|
|
405
|
+
const result = { written: [], unchanged: [], skipped: [], removed: [] };
|
|
406
|
+
// The platform-doc copies an earlier pull wrote ("replaced on every pull, never edit these"): gone, now they're live.
|
|
407
|
+
const indexFile = path.join(r.docsDir, '.plaiful-docs.json');
|
|
408
|
+
let before = [];
|
|
409
|
+
try { before = (JSON.parse(fs.readFileSync(indexFile, 'utf8')).docs || []).map((d) => d.file).filter(Boolean); } catch { before = []; }
|
|
410
|
+
const keep = new Set(files.map((f) => safeName(f.key)).filter(Boolean));
|
|
411
|
+
if (!copies) keep.add('README.md');
|
|
412
|
+
for (const name of before) {
|
|
413
|
+
const safe = safeName(name);
|
|
414
|
+
if (safe && !keep.has(safe) && fs.existsSync(path.join(r.docsDir, safe))) { fs.unlinkSync(path.join(r.docsDir, safe)); result.removed.push(safe); }
|
|
415
|
+
}
|
|
416
|
+
if (!copies) files.push({ key: 'README.md', title: 'Plaiful docs (live)', content: LIVE_DOCS_README });
|
|
417
|
+
for (const f of files) {
|
|
418
|
+
const name = safeName(f.key);
|
|
419
|
+
if (!name) { result.skipped.push(f.key); continue; }
|
|
420
|
+
const target = path.join(r.docsDir, name);
|
|
421
|
+
const prev = fs.existsSync(target) ? fs.readFileSync(target, 'utf8') : null;
|
|
422
|
+
if (prev === f.content) { result.unchanged.push(name); continue; }
|
|
423
|
+
fs.writeFileSync(target, f.content);
|
|
424
|
+
result.written.push(name);
|
|
425
|
+
}
|
|
426
|
+
const index = {
|
|
427
|
+
_note: copies
|
|
428
|
+
? 'Written by `plaiful docs pull --copies`: copies as of pulled_at; the live docs are `plaiful docs`. Replaced on every pull.'
|
|
429
|
+
: 'Written by `plaiful docs pull`. The platform docs are live (`plaiful docs`); this folder holds the product\'s own files.',
|
|
430
|
+
mode: copies ? 'copies' : 'live',
|
|
431
|
+
product: r.product, env: data.env, pulled_at: new Date().toISOString(),
|
|
432
|
+
docs: files.map((f) => ({ file: safeName(f.key), title: f.title, description: f.description || '' })).filter((f) => f.file),
|
|
433
|
+
};
|
|
434
|
+
fs.writeFileSync(indexFile, `${JSON.stringify(index, null, 2)}\n`);
|
|
435
|
+
const ignore = ignoreClientConfig(r.docsDir);
|
|
436
|
+
const rel = path.relative(ctx.io.cwd(), r.docsDir) || '.';
|
|
437
|
+
const lines = [
|
|
438
|
+
`${rel}: ${result.written.length} updated, ${result.unchanged.length} unchanged${result.skipped.length ? `, ${result.skipped.length} skipped` : ''}.`,
|
|
439
|
+
...result.written.map((n) => ` updated ${n}`),
|
|
440
|
+
...result.removed.map((n) => ` removed ${n} (a platform doc: read it live, plaiful docs read ${n.replace(/\.md$/, '')})`),
|
|
441
|
+
];
|
|
442
|
+
if (ignore.added.length) lines.push(` ${path.join(rel, '.gitignore')}: now keeps ${ignore.added.join(', ')} out of git`);
|
|
443
|
+
if (ignore.tracked.length) {
|
|
444
|
+
lines.push(`! Already committed, and holding your keys: ${ignore.tracked.join(', ')}. Take them out of git (the files stay):`);
|
|
445
|
+
lines.push(` git rm --cached ${ignore.tracked.map((f) => `"${path.relative(ctx.io.cwd(), path.join(r.docsDir, f)).replace(/\\/g, '/')}"`).join(' ')}`);
|
|
446
|
+
}
|
|
447
|
+
const where = whereThingsGo(ctx, r);
|
|
448
|
+
lines.push(...where.lines);
|
|
449
|
+
// The web template reads .env.development, which plaiful env writes (PLAI-202): say so when it's missing.
|
|
450
|
+
const needsEnv = fs.existsSync(path.join(r.root, `${ENV_FILE}.example`)) && !fs.existsSync(path.join(r.root, ENV_FILE));
|
|
451
|
+
if (needsEnv) {
|
|
452
|
+
lines.push(`No ${ENV_FILE} yet: run plaiful env to write it from ${r.product}'s dev config${fs.existsSync(path.join(r.root, '.env')) ? ' (the game doesn\'t read .env)' : ''}.`);
|
|
453
|
+
}
|
|
454
|
+
lines.push(copies ? 'Local copies as of now; the live docs are `plaiful docs`.' : 'The platform docs are live: plaiful docs (start with plaiful docs read README).');
|
|
455
|
+
ctx.out(lines.join('\n'), { success: true, dir: r.docsDir, ...result, gitignore: ignore, misplaced_specs: where.misplaced });
|
|
456
|
+
return 0;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// ── The live docs ─────────────────────────────────────────────────────────────────────────────────────────────────
|
|
460
|
+
|
|
461
|
+
const docsRoute = (rest = '', query = {}) => {
|
|
462
|
+
const qs = new URLSearchParams(Object.entries(query).filter(([, v]) => v !== undefined && v !== null && v !== ''));
|
|
463
|
+
return `/partner/platform/docs${rest}${qs.toString() ? `?${qs}` : ''}`;
|
|
464
|
+
};
|
|
465
|
+
const docName = (k) => String(k).replace(/\.md$/, '');
|
|
466
|
+
const day = (iso) => (iso ? String(iso).slice(0, 10) : ' ');
|
|
467
|
+
|
|
468
|
+
async function docsList(ctx) {
|
|
469
|
+
const { data } = await ctx.call('GET', docsRoute());
|
|
470
|
+
const docs = data.docs || [];
|
|
471
|
+
const lines = [`Plaiful docs (live): ${docs.length}. plaiful docs read <doc>`];
|
|
472
|
+
let section = null;
|
|
473
|
+
for (const d of [...docs].sort((a, b) => (a.order ?? 1e9) - (b.order ?? 1e9))) {
|
|
474
|
+
const s = d.section_title || d.category || 'Docs';
|
|
475
|
+
if (s !== section) { lines.push(`${s}:`); section = s; }
|
|
476
|
+
lines.push(` ${docName(d.key).padEnd(40)} ${day(d.updated_at)} ${d.label || d.title || ''}`);
|
|
477
|
+
}
|
|
478
|
+
ctx.out(lines.join('\n'), data);
|
|
479
|
+
return 0;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
async function docsRead(ctx, [name]) {
|
|
483
|
+
if (!name) throw new UsageError('which doc? plaiful docs read <doc> (plaiful docs lists them)');
|
|
484
|
+
const { data } = await ctx.call('GET', docsRoute(`/${encodeURIComponent(docName(name))}`, { section: ctx.flags.section }));
|
|
485
|
+
ctx.out(data.content, data);
|
|
486
|
+
return 0;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
async function docsSearch(ctx, words) {
|
|
490
|
+
const q = words.join(' ').trim();
|
|
491
|
+
if (!q) throw new UsageError('search for what? plaiful docs search <words...>');
|
|
492
|
+
const { data } = await ctx.call('GET', docsRoute('', { q, limit: ctx.flags.limit }));
|
|
493
|
+
const lines = data.results.length ? [`"${q}" in the docs:`] : [`Nothing in the docs mentions all of: ${q}`];
|
|
494
|
+
for (const r of data.results) {
|
|
495
|
+
lines.push(` ${docName(r.key)} (${r.title})`);
|
|
496
|
+
for (const sct of r.sections) lines.push(` § ${sct.heading || r.title}: ${sct.snippet}`);
|
|
497
|
+
}
|
|
498
|
+
if (data.results.length) lines.push('plaiful docs read <doc> --section "<heading>" for the whole section');
|
|
499
|
+
ctx.out(lines.join('\n'), data);
|
|
500
|
+
return 0;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
async function docsChanges(ctx) {
|
|
504
|
+
const since = ctx.flags.since || new Date(Date.now() - 7 * 864e5).toISOString().slice(0, 10);
|
|
505
|
+
const { data } = await ctx.call('GET', docsRoute('', { since }));
|
|
506
|
+
const lines = [data.docs.length ? `Changed since ${since}:` : `No doc changed since ${since}.`];
|
|
507
|
+
for (const d of data.docs) lines.push(` ${day(d.updated_at)} ${docName(d.key).padEnd(40)} ${d.title || ''}`);
|
|
508
|
+
ctx.out(lines.join('\n'), data);
|
|
509
|
+
return 0;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// client-config.md holds the product's keys and endpoints (the Firebase web key among them), so it never goes in git;
|
|
513
|
+
// nor do the older hand-made `<product>-client-config.md` copies.
|
|
514
|
+
const CLIENT_CONFIG_IGNORES = ['client-config.md', '*-client-config.md'];
|
|
515
|
+
|
|
516
|
+
function ignoreClientConfig(docsDir) {
|
|
517
|
+
const file = path.join(docsDir, '.gitignore');
|
|
518
|
+
const prev = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '';
|
|
519
|
+
const have = new Set(prev.split(/\r?\n/).map((l) => l.trim()));
|
|
520
|
+
const added = CLIENT_CONFIG_IGNORES.filter((p) => !have.has(p));
|
|
521
|
+
if (added.length) {
|
|
522
|
+
const head = prev ? `${prev.replace(/\s*$/, '')}\n` : '# Written by `plaiful docs pull`: these files hold your product\'s keys.\n';
|
|
523
|
+
fs.writeFileSync(file, `${head}${added.join('\n')}\n`);
|
|
524
|
+
}
|
|
525
|
+
// A .gitignore doesn't untrack what's already committed; say so rather than leave the keys in the repo.
|
|
526
|
+
const git = spawnSync('git', ['ls-files', '--', ...CLIENT_CONFIG_IGNORES], { cwd: docsDir, encoding: 'utf8' });
|
|
527
|
+
const tracked = git.status === 0 ? git.stdout.split('\n').map((l) => l.trim()).filter(Boolean) : [];
|
|
528
|
+
return { added, tracked };
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function readDeclaration(ctx, r, file, agent = 'ovid') {
|
|
532
|
+
const target = path.resolve(ctx.io.cwd(), file || path.join(r.docsDir, `${r.product}-${agent}-declaration.json`));
|
|
533
|
+
if (!fs.existsSync(target)) throw new UsageError(`no declaration at ${target} (write it first: ${agent}-declaration.md)`);
|
|
534
|
+
try { return { target, declaration: JSON.parse(fs.readFileSync(target, 'utf8')) }; } catch (e) {
|
|
535
|
+
throw new UsageError(`${target} isn't valid JSON: ${e.message}`);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function findingsText(data) {
|
|
540
|
+
const lines = [];
|
|
541
|
+
const where = (x) => `${x.file ? `${x.file} ` : ''}${x.path || '(top level)'}`;
|
|
542
|
+
for (const e of data.errors || []) lines.push(` ✗ ${where(e)}: ${e.message} [${e.doc}]`);
|
|
543
|
+
for (const w of data.warnings || []) lines.push(` ! ${where(w)}: ${w.message} [${w.doc}]`);
|
|
544
|
+
for (const n of data.notes || []) lines.push(` · ${n}`);
|
|
545
|
+
return lines;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
async function ovidCheck(ctx, [file]) {
|
|
549
|
+
const r = repo(ctx);
|
|
550
|
+
const { target, declaration } = readDeclaration(ctx, r, file);
|
|
551
|
+
const { data } = await ctx.call('POST', `/partner/${encodeURIComponent(r.product)}/ovid/declaration/check`, { declaration });
|
|
552
|
+
const head = data.ok
|
|
553
|
+
? `${path.basename(target)} is valid${(data.warnings || []).length ? `, with ${data.warnings.length} warning(s)` : ''}. Publish it with: plaiful ovid publish`
|
|
554
|
+
: `${path.basename(target)} has ${data.errors.length} error(s); fix them and check again.`;
|
|
555
|
+
ctx.out([head, ...findingsText(data)].join('\n'), data);
|
|
556
|
+
return data.ok ? 0 : 1;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
async function ovidPublish(ctx, [file]) {
|
|
560
|
+
const r = repo(ctx);
|
|
561
|
+
const { target, declaration } = readDeclaration(ctx, r, file);
|
|
562
|
+
const { data } = await ctx.call('PUT', `/partner/${encodeURIComponent(r.product)}/ovid/declaration`, { declaration });
|
|
563
|
+
if (!data.published) {
|
|
564
|
+
ctx.out([`Not published: ${data.error || `${path.basename(target)} has ${(data.errors || []).length} error(s)`}`, ...findingsText(data)].join('\n'), data);
|
|
565
|
+
return 1;
|
|
566
|
+
}
|
|
567
|
+
const lines = [`Published ${path.basename(target)} for ${r.product}; OVID reads it ${data.takes_effect}.`];
|
|
568
|
+
if (data.tabs && data.tabs.error) lines.push(` ! ${data.tabs.error}`);
|
|
569
|
+
lines.push(...findingsText(data));
|
|
570
|
+
lines.push('Check it took: GameMaster shows your tier labels, tracks and regions (plaiful ovid show prints what OVID has).');
|
|
571
|
+
ctx.out(lines.join('\n'), data);
|
|
572
|
+
return 0;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// ── The studio's HERMES strategy (hermes-strategy.md) ──
|
|
576
|
+
function readStrategy(ctx, r, file) {
|
|
577
|
+
const target = path.resolve(ctx.io.cwd(), file || path.join(r.docsDir, 'hermes-strategy.json'));
|
|
578
|
+
if (!fs.existsSync(target)) throw new UsageError(`no strategy at ${target} (write it first: hermes-strategy.md)`);
|
|
579
|
+
try { return { target, strategy: JSON.parse(fs.readFileSync(target, 'utf8')) }; } catch (e) {
|
|
580
|
+
throw new UsageError(`${target} isn't valid JSON: ${e.message}`);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const strategyErrors = (data) => (data.errors || []).map((e) => ` ✗ ${e.path}: ${e.message}`);
|
|
585
|
+
|
|
586
|
+
async function hermesStrategyCheck(ctx, [file]) {
|
|
587
|
+
const r = repo(ctx);
|
|
588
|
+
const { target, strategy } = readStrategy(ctx, r, file);
|
|
589
|
+
const { data } = await ctx.call('POST', `/partner/${encodeURIComponent(r.product)}/hermes/strategy/check`, { strategy });
|
|
590
|
+
const head = data.success
|
|
591
|
+
? `${path.basename(target)} is valid. Publish it with: plaiful hermes strategy publish`
|
|
592
|
+
: `${path.basename(target)} has ${(data.errors || []).length} error(s); fix them and check again.`;
|
|
593
|
+
ctx.out([head, ...strategyErrors(data)].join('\n'), data);
|
|
594
|
+
return data.success ? 0 : 1;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
async function hermesStrategyPublish(ctx, [file]) {
|
|
598
|
+
const r = repo(ctx);
|
|
599
|
+
const { target, strategy } = readStrategy(ctx, r, file);
|
|
600
|
+
const { data } = await ctx.call('PUT', `/partner/${encodeURIComponent(r.product)}/hermes/strategy`, { strategy });
|
|
601
|
+
if (!data.published) {
|
|
602
|
+
ctx.out([`Not published: ${data.error || `${path.basename(target)} has ${(data.errors || []).length} error(s)`}`, ...strategyErrors(data)].join('\n'), data);
|
|
603
|
+
return 1;
|
|
604
|
+
}
|
|
605
|
+
ctx.out(`Published ${path.basename(target)} as version ${data.strategy.version} of studio ${data.studio_id}'s strategy; HERMES uses it within about 5 minutes.`, data);
|
|
606
|
+
return 0;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
async function hermesStrategyShow(ctx, rest) {
|
|
610
|
+
if (rest.length) throw new UsageError(`plaiful hermes strategy, or strategy check | publish (not "${rest[0]}")`);
|
|
611
|
+
const r = repo(ctx);
|
|
612
|
+
const { data } = await ctx.call('GET', `/partner/${encodeURIComponent(r.product)}/hermes/strategy`);
|
|
613
|
+
if (ctx.flags.json) { ctx.out(data); return 0; }
|
|
614
|
+
const studio = data.studio_name || data.studio_id;
|
|
615
|
+
if (!data.strategy) ctx.out(`${studio} has no strategy yet: HERMES says so, and judges the market without one. Write <docsDir>/hermes-strategy.json, then plaiful hermes strategy publish.`);
|
|
616
|
+
else ctx.out(`${studio}'s strategy, version ${data.strategy.version} (${data.strategy.updated_at} by ${data.strategy.updated_by}):\n${JSON.stringify(data.strategy.strategy, null, 2)}`);
|
|
617
|
+
return 0;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// ── A studio's team (release plan §8.2-8.3, PLAI-138): what the CMS's studio Members page does ──
|
|
621
|
+
const studioRoute = (id, rest = '') => `/partner/studios/${encodeURIComponent(id)}${rest}`;
|
|
622
|
+
const roleText = (x) => (x.role === 'admin' ? 'admin' : x.preset || 'member');
|
|
623
|
+
const productsText = (p) => (p === 'all' || !Array.isArray(p) ? 'all products' : p.length ? p.join(', ') : 'no products');
|
|
624
|
+
const areasText = (areas) => Object.entries(areas || {}).map(([a, l]) => `${a} ${l}`).join(', ');
|
|
625
|
+
|
|
626
|
+
/** The studio a command is about: the one named (an id, or one of your studios' names), else your only studio. */
|
|
627
|
+
async function studioIdOf(ctx, given) {
|
|
628
|
+
const named = given || ctx.flags.studio;
|
|
629
|
+
if (named && /^std_/.test(named)) return named;
|
|
630
|
+
const { data } = await ctx.call('GET', '/partner/studios');
|
|
631
|
+
const mine = data.studios || [];
|
|
632
|
+
if (named) {
|
|
633
|
+
const hit = mine.find((st) => String(st.name).toLowerCase() === String(named).toLowerCase());
|
|
634
|
+
if (hit) return hit.studio_id;
|
|
635
|
+
return named; // the API says whether it exists and is yours
|
|
636
|
+
}
|
|
637
|
+
if (mine.length === 1) return mine[0].studio_id;
|
|
638
|
+
if (!mine.length) throw new ApiError(404, { error: 'you aren\'t in a studio yet: ask a studio\'s admin to invite you', code: 'no_studio' });
|
|
639
|
+
throw new UsageError(`you're in ${mine.length} studios: say which with --studio <id> (${mine.map((st) => `${st.studio_id} ${st.name}`).join('; ')})`);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/** --role admin | member | <preset>, --area art=edit[,content=view] (none takes an area away), --products a,b | all. */
|
|
643
|
+
function memberFields(ctx) {
|
|
644
|
+
const out = {};
|
|
645
|
+
const role = ctx.flags.role;
|
|
646
|
+
if (role === 'admin' || role === 'member') out.role = role;
|
|
647
|
+
else if (role) Object.assign(out, { role: 'member', preset: role });
|
|
648
|
+
if (ctx.flags.area) {
|
|
649
|
+
out.areas = {};
|
|
650
|
+
for (const pair of ctx.flags.area.flatMap((x) => String(x).split(','))) {
|
|
651
|
+
const m = /^\s*([a-z-]+)\s*=\s*(view|edit|manage|none)\s*$/.exec(pair);
|
|
652
|
+
if (!m) throw new UsageError(`--area takes area=level (view, edit, manage or none), e.g. art=edit; not "${pair}"`);
|
|
653
|
+
out.areas[m[1]] = m[2] === 'none' ? null : m[2];
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (ctx.flags.products !== undefined) {
|
|
657
|
+
const list = String(ctx.flags.products).split(',').map((p) => p.trim()).filter(Boolean);
|
|
658
|
+
out.products = !list.length || (list.length === 1 && list[0] === 'all') ? 'all' : list;
|
|
659
|
+
}
|
|
660
|
+
return out;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
async function studioList(ctx, rest) {
|
|
664
|
+
if (rest.length) throw new UsageError(`plaiful studio list takes nothing more (not "${rest[0]}")`);
|
|
665
|
+
const { data } = await ctx.call('GET', '/partner/studios');
|
|
666
|
+
const mine = data.studios || [];
|
|
667
|
+
const lines = mine.length ? ['Your studios:'] : ['You aren\'t in a studio yet: ask a studio\'s admin to invite you.'];
|
|
668
|
+
for (const st of mine) lines.push(` ${st.studio_id} ${st.name} (${roleText(st)}${st.status && st.status !== 'active' ? `, ${st.status}` : ''})`);
|
|
669
|
+
ctx.out(lines.join('\n'), data);
|
|
670
|
+
return 0;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
async function studioShow(ctx, [given, ...rest]) {
|
|
674
|
+
if (rest.length) throw new UsageError(`plaiful studio show [<studio>] (not "${rest.join(' ')}")`);
|
|
675
|
+
const id = await studioIdOf(ctx, given);
|
|
676
|
+
const { data } = await ctx.call('GET', studioRoute(id));
|
|
677
|
+
if (ctx.flags.json) { ctx.out(data); return 0; }
|
|
678
|
+
const st = data.studio;
|
|
679
|
+
const lines = [`${st.name} (${st.studio_id})${st.plan ? `, plan ${st.plan}` : ''}${st.status && st.status !== 'active' ? `, ${st.status}` : ''}. You: ${data.role === 'staff' ? 'Plaiful staff' : roleText(data)}.`];
|
|
680
|
+
lines.push(`Products: ${data.products.length ? data.products.join(', ') : 'none yet'}`);
|
|
681
|
+
lines.push(`Members (${data.members.length}):`);
|
|
682
|
+
for (const m of data.members) {
|
|
683
|
+
const seen = data.invites ? `; last seen ${m.last_seen_at ? day(m.last_seen_at) : 'never'}` : '';
|
|
684
|
+
lines.push(` ${m.email} ${roleText(m)}${m.role === 'admin' ? '' : `, ${productsText(m.products)}; ${areasText(m.areas)}`}${seen}`);
|
|
685
|
+
}
|
|
686
|
+
if (data.invites) {
|
|
687
|
+
const pending = data.invites.filter((i) => !i.expired);
|
|
688
|
+
lines.push(`Seats: ${data.seats.used} used, ${data.seats.pending} invited.`);
|
|
689
|
+
if (data.invites.length) lines.push(`Invites: ${pending.length} pending${data.invites.length > pending.length ? `, ${data.invites.length - pending.length} expired` : ''} (plaiful studio invites)`);
|
|
690
|
+
lines.push(`Roles to invite as: admin, or a preset: ${Object.keys(data.presets || {}).join(', ')}. Areas: ${(data.areas || []).join(', ')}.`);
|
|
691
|
+
}
|
|
692
|
+
ctx.out(lines.join('\n'), data);
|
|
693
|
+
return 0;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/** The link and what to do with it, for a new or resent invite. */
|
|
697
|
+
function inviteLines(data, did) {
|
|
698
|
+
const inv = data.invite;
|
|
699
|
+
return [
|
|
700
|
+
`${did} ${inv.email} as ${roleText(inv)}${inv.role === 'admin' ? '' : `, ${productsText(inv.products)}`}. The invite expires ${day(inv.expires_at)} (${inv.invite_id}).`,
|
|
701
|
+
data.emailed ? `Emailed it to ${inv.email}.` : data.email_note || 'It wasn\'t emailed: send them the link.',
|
|
702
|
+
`Link: ${data.link}`,
|
|
703
|
+
];
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
async function studioInvite(ctx, [email, ...rest]) {
|
|
707
|
+
if (!email || rest.length) throw new UsageError('plaiful studio invite <email> --role admin|<preset> [--products a,b] [--area art=edit]');
|
|
708
|
+
const fields = memberFields(ctx);
|
|
709
|
+
if (!fields.role && !fields.areas) throw new UsageError('say what they\'ll be: --role admin, or --role <preset> (plaiful studio show lists the presets)');
|
|
710
|
+
const id = await studioIdOf(ctx);
|
|
711
|
+
const { data } = await ctx.call('POST', studioRoute(id, '/invites'), { email, ...fields });
|
|
712
|
+
ctx.out(inviteLines(data, 'Invited').join('\n'), data);
|
|
713
|
+
return 0;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
async function studioInvites(ctx, rest) {
|
|
717
|
+
if (rest.length) throw new UsageError(`plaiful studio invites takes nothing more (not "${rest[0]}")`);
|
|
718
|
+
const id = await studioIdOf(ctx);
|
|
719
|
+
const { data } = await ctx.call('GET', studioRoute(id, '/invites'));
|
|
720
|
+
const lines = data.invites.length ? [`Invites to ${id}:`] : [`No invites waiting in ${id}.`];
|
|
721
|
+
for (const i of data.invites) {
|
|
722
|
+
lines.push(` ${i.invite_id} ${i.email} ${roleText(i)} ${i.expired ? 'expired' : `until ${day(i.expires_at)}`} (by ${i.invited_by})`);
|
|
723
|
+
}
|
|
724
|
+
if (data.invites.some((i) => i.expired)) lines.push('An expired invite can be sent again: plaiful studio resend <inviteId>');
|
|
725
|
+
ctx.out(lines.join('\n'), data);
|
|
726
|
+
return 0;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
async function studioResend(ctx, [inviteId, ...rest]) {
|
|
730
|
+
if (!inviteId || rest.length) throw new UsageError('plaiful studio resend <inviteId> (plaiful studio invites lists them)');
|
|
731
|
+
const id = await studioIdOf(ctx);
|
|
732
|
+
const { data } = await ctx.call('POST', studioRoute(id, `/invites/${encodeURIComponent(inviteId)}/resend`));
|
|
733
|
+
ctx.out([...inviteLines(data, 'Sent a new invite to'), 'The old link no longer works.'].join('\n'), data);
|
|
734
|
+
return 0;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
async function studioCancel(ctx, [inviteId, ...rest]) {
|
|
738
|
+
if (!inviteId || rest.length) throw new UsageError('plaiful studio cancel <inviteId> (plaiful studio invites lists them)');
|
|
739
|
+
const id = await studioIdOf(ctx);
|
|
740
|
+
const { data } = await ctx.call('DELETE', studioRoute(id, `/invites/${encodeURIComponent(inviteId)}`));
|
|
741
|
+
ctx.out(`Cancelled the invite to ${data.email}: its link no longer works.`, data);
|
|
742
|
+
return 0;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
async function studioSet(ctx, [email, ...rest]) {
|
|
746
|
+
if (!email || rest.length) throw new UsageError('plaiful studio set <email> [--role admin|member|<preset>] [--products a,b|all] [--area art=edit]');
|
|
747
|
+
const fields = memberFields(ctx);
|
|
748
|
+
if (!Object.keys(fields).length) throw new UsageError('say what to change: --role, --products or --area');
|
|
749
|
+
const id = await studioIdOf(ctx);
|
|
750
|
+
const { data } = await ctx.call('PUT', studioRoute(id, `/members/${encodeURIComponent(email)}`), fields);
|
|
751
|
+
const m = data.member;
|
|
752
|
+
ctx.out(`${data.added ? 'Added' : 'Changed'} ${m.email}: ${roleText(m)}${m.role === 'admin' ? ' (every area, every product)' : `, ${productsText(m.products)}; ${areasText(m.areas)}`}.`, data);
|
|
753
|
+
return 0;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
async function studioRemove(ctx, [email, ...rest]) {
|
|
757
|
+
if (!email || rest.length) throw new UsageError('plaiful studio remove <email> [--yes]');
|
|
758
|
+
const id = await studioIdOf(ctx);
|
|
759
|
+
if (!ctx.flags.yes) {
|
|
760
|
+
if (!ctx.io.ask) throw new UsageError('nothing to ask in here: pass --yes to remove them');
|
|
761
|
+
const answer = await ctx.io.ask(`Remove ${email} from ${id}? The product API keys they issued for its products stop working too. [y/N] `);
|
|
762
|
+
if (!/^y(es)?$/i.test(String(answer || '').trim())) { ctx.out('Not removed.', { success: false, removed: null }); return 1; }
|
|
763
|
+
}
|
|
764
|
+
const { data } = await ctx.call('DELETE', studioRoute(id, `/members/${encodeURIComponent(email)}`));
|
|
765
|
+
const keys = data.revoked_keys || [];
|
|
766
|
+
ctx.out([`Removed ${data.removed} from ${id}.`, keys.length ? `Revoked the product API keys they issued: ${keys.join(', ')}` : 'They had no product API keys for the studio\'s products.'].join('\n'), data);
|
|
767
|
+
return 0;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
const auditDetail = (d) => Object.entries(d || {}).filter(([, v]) => v !== null && v !== undefined && !(typeof v === 'object' && !Array.isArray(v)))
|
|
771
|
+
.map(([k, v]) => `${k} ${Array.isArray(v) ? v.join(',') : v}`).join(', ');
|
|
772
|
+
|
|
773
|
+
async function studioAudit(ctx, rest) {
|
|
774
|
+
if (rest.length) throw new UsageError(`plaiful studio audit takes nothing more (not "${rest[0]}")`);
|
|
775
|
+
const id = await studioIdOf(ctx);
|
|
776
|
+
const query = new URLSearchParams({ ...(ctx.flags.limit ? { limit: ctx.flags.limit } : {}), ...(ctx.flags.before ? { before: ctx.flags.before } : {}) }).toString();
|
|
777
|
+
const { data } = await ctx.call('GET', studioRoute(id, `/audit${query ? `?${query}` : ''}`));
|
|
778
|
+
const lines = data.entries.length ? [`${id}, newest first:`] : [`Nothing in ${id}'s log${ctx.flags.before ? ' before that' : ''}.`];
|
|
779
|
+
for (const e of data.entries) lines.push(` ${String(e.at).slice(0, 19).replace('T', ' ')} ${e.by}${e.staff ? ' (Plaiful staff)' : ''} ${e.action} ${auditDetail(e.detail)}`);
|
|
780
|
+
if (data.next) lines.push(`More: plaiful studio audit --before ${data.next}`);
|
|
781
|
+
ctx.out(lines.join('\n'), data);
|
|
782
|
+
return 0;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
async function ovidShow(ctx) {
|
|
786
|
+
const r = repo(ctx);
|
|
787
|
+
const { data } = await ctx.call('GET', `/partner/${encodeURIComponent(r.product)}/ovid/declaration`);
|
|
788
|
+
if (ctx.flags.json) { ctx.out(data); return 0; }
|
|
789
|
+
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).`);
|
|
790
|
+
else ctx.out(`Published ${data.updated_at || '(date unknown)'}${data.published_by ? ` by ${data.published_by}` : ''}:\n${JSON.stringify(data.declaration, null, 2)}`);
|
|
791
|
+
return 0;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// ── The MIDAS declaration (docs/agents/midas/multi-product-economy-plan.md §3) ──────────────────────────────────
|
|
795
|
+
|
|
796
|
+
const midasDeclRoute = (r, rest = '') => `/partner/${encodeURIComponent(r.product)}/midas/declaration${rest}`;
|
|
797
|
+
|
|
798
|
+
/** "scrap, ore, xp (only builds up)" */
|
|
799
|
+
const kindsText = (kinds) => (kinds || []).map((k) => `${k.label && k.label !== k.id ? `${k.label} (${k.id})` : k.id}${k.spendable === false ? ', only builds up' : ''}`).join('; ') || 'none';
|
|
800
|
+
|
|
801
|
+
function midasEffectiveText(e) {
|
|
802
|
+
if (!e) return [];
|
|
803
|
+
const items = e.items && e.items.enabled ? `on: ${e.items.collections.map((c) => c.collection).join(', ')}` : 'off';
|
|
804
|
+
return [
|
|
805
|
+
` kinds ${kindsText(e.kinds)}${e.kinds_from === 'ovid' ? ' (from your OVID reward kinds)' : ''}`,
|
|
806
|
+
` wallet ${e.wallet}`,
|
|
807
|
+
` items ${items}`,
|
|
808
|
+
` schedule ${e.analysis && e.analysis.schedule === 'daily' ? 'daily' : 'off (Assess Now)'}`,
|
|
809
|
+
];
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
async function midasCheck(ctx, [file]) {
|
|
813
|
+
const r = repo(ctx);
|
|
814
|
+
const { target, declaration } = readDeclaration(ctx, r, file, 'midas');
|
|
815
|
+
const { data } = await ctx.call('POST', midasDeclRoute(r, '/check'), { declaration });
|
|
816
|
+
const head = data.ok
|
|
817
|
+
? `${path.basename(target)} is valid${(data.warnings || []).length ? `, with ${data.warnings.length} warning(s)` : ''}. Publish it with: plaiful midas publish`
|
|
818
|
+
: `${path.basename(target)} has ${data.errors.length} error(s); fix them and check again.`;
|
|
819
|
+
ctx.out([head, ...(data.ok ? midasEffectiveText(data.effective) : []), ...findingsText(data)].join('\n'), data);
|
|
820
|
+
return data.ok ? 0 : 1;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
async function midasPublish(ctx, [file]) {
|
|
824
|
+
const r = repo(ctx);
|
|
825
|
+
const { target, declaration } = readDeclaration(ctx, r, file, 'midas');
|
|
826
|
+
const { data } = await ctx.call('PUT', midasDeclRoute(r), { declaration });
|
|
827
|
+
if (!data.published) {
|
|
828
|
+
ctx.out([`Not published: ${data.error || `${path.basename(target)} has ${(data.errors || []).length} error(s)`}`, ...findingsText(data)].join('\n'), data);
|
|
829
|
+
return 1;
|
|
830
|
+
}
|
|
831
|
+
ctx.out([`Published ${path.basename(target)} for ${r.product}.`, ...midasEffectiveText(data.effective), ...findingsText(data),
|
|
832
|
+
'Check it took: plaiful midas show'].join('\n'), data);
|
|
833
|
+
return 0;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
async function midasShow(ctx) {
|
|
837
|
+
const r = repo(ctx);
|
|
838
|
+
const { data } = await ctx.call('GET', midasDeclRoute(r));
|
|
839
|
+
if (ctx.flags.json) { ctx.out(data); return 0; }
|
|
840
|
+
const head = data.declaration
|
|
841
|
+
? `${r.product}'s MIDAS declaration, published ${data.updated_at || '(date unknown)'}${data.published_by ? ` by ${data.published_by}` : ''}:`
|
|
842
|
+
: `${r.product} has no MIDAS declaration yet; MIDAS uses its defaults:`;
|
|
843
|
+
ctx.out([head, ...midasEffectiveText(data.effective), ...findingsText({ warnings: data.warnings })].join('\n'));
|
|
844
|
+
return 0;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// ── MIDAS's analysis of the game (multi-product-economy-plan.md §9.1; the plaiful-economy-review skill) ──────────
|
|
848
|
+
|
|
849
|
+
const num = (v) => (v == null ? '—' : Number(v).toLocaleString('en-US', { maximumFractionDigits: 1 }));
|
|
850
|
+
const HEALTH_WORDS = { green: 'healthy', amber: 'needs a look', red: 'out of balance' };
|
|
851
|
+
|
|
852
|
+
/** What a flag means, in plain words (the CMS's Balance tab says the same). */
|
|
853
|
+
function flagWords(f) {
|
|
854
|
+
const k = f.kind || '';
|
|
855
|
+
switch (f.metric) {
|
|
856
|
+
case 'unpaidKind': return f.priced ? `no quest pays ${k} (it's priced: check OVID's rewards.types)` : `no quest pays ${k}: it has no quest price`;
|
|
857
|
+
case 'neverSpent': return `${num(f.value)} ${k} earned, none spent`;
|
|
858
|
+
case 'earnExceedsSpend': return `players earn ${f.value}× the ${k} they spend`;
|
|
859
|
+
case 'spendExceedsEarn': return `players spend ${f.value}× the ${k} they earn`;
|
|
860
|
+
case 'noReward': return 'pays nothing (no step carries effort)';
|
|
861
|
+
case 'rewardOutlier': return `pays ${num(f.value)} ${k}, over ${Math.round(f.value / f.median)}× the median quest (${num(f.median)})`;
|
|
862
|
+
case 'itemValueOutlier': return `worth ${num(f.value)} ${k}, ${f.direction} its group's median (${num(f.median)})`;
|
|
863
|
+
case 'unaffordable': return `costs ${num(f.value)} typical quests' ${k}`;
|
|
864
|
+
case 'trivialCost': return `costs under a quarter of one typical quest's ${k}`;
|
|
865
|
+
default: return f.metric;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
async function midasHealth(ctx) {
|
|
870
|
+
const r = repo(ctx);
|
|
871
|
+
const { data } = await ctx.call('GET', `/partner/${encodeURIComponent(r.product)}/midas/health`);
|
|
872
|
+
if (ctx.flags.json) { ctx.out(data); return 0; }
|
|
873
|
+
const s = data.summary;
|
|
874
|
+
if (!s || data.error) { ctx.out(`${r.product} has no economy analysis yet. Run one: plaiful midas assess`); return 0; }
|
|
875
|
+
const lines = [`${r.product}'s economy (dev): ${HEALTH_WORDS[s.overallHealth] || s.overallHealth}. ${s.flaggedItems} of ${s.totalItems} flagged; analyzed ${data.analyzedAt || '?'}`];
|
|
876
|
+
if (!s.priced) lines.push(' ! quests aren\'t priced yet: plaiful midas pricing set <kind> --base <n> --per-effort <n>');
|
|
877
|
+
for (const k of s.kinds || []) {
|
|
878
|
+
lines.push(` ${k.label}${k.label !== k.id ? ` (${k.id})` : ''}${k.spendable ? '' : ', builds up'}: ${num(k.supply)} from quests, median ${num(k.medianReward)} per quest, ${k.questsPaying} quests pay it`
|
|
879
|
+
+ (s.wallet && s.wallet !== 'none' ? `; last 30 days earned ${num(k.earned)}, spent ${num(k.spent)}` : '')
|
|
880
|
+
+ (k.held !== undefined ? `; players hold ${num(k.held)} (${k.holders} of ${k.players})` : ''));
|
|
881
|
+
}
|
|
882
|
+
lines.push('Details: plaiful midas balance; proposals: plaiful midas proposals');
|
|
883
|
+
ctx.out(lines.join('\n'), data);
|
|
884
|
+
return 0;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
async function midasBalance(ctx) {
|
|
888
|
+
const r = repo(ctx);
|
|
889
|
+
const { data } = await ctx.call('GET', `/partner/${encodeURIComponent(r.product)}/midas/balance`);
|
|
890
|
+
if (ctx.flags.json) { ctx.out(data); return 0; }
|
|
891
|
+
const items = (data.items || []).filter((si) => ctx.flags.all || !si.healthy);
|
|
892
|
+
if (!data.items || data.error) { ctx.out(`${r.product} has no economy analysis yet. Run one: plaiful midas assess`); return 0; }
|
|
893
|
+
const lines = [`${r.product}: ${items.length} ${ctx.flags.all ? 'checked' : 'flagged'} of ${data.items.length}${ctx.flags.all ? '' : ' (--all for everything)'}`];
|
|
894
|
+
for (const si of items) {
|
|
895
|
+
const it = si.item;
|
|
896
|
+
lines.push(` ${si.healthy ? '·' : si.severity === 'high' ? '✗' : '!'} ${it.name} [${it.category}]${si.flags.length ? ` ${si.flags.map(flagWords).join('; ')}` : ''}`);
|
|
897
|
+
}
|
|
898
|
+
ctx.out(lines.join('\n'), data);
|
|
899
|
+
return 0;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
async function midasProposals(ctx) {
|
|
903
|
+
const r = repo(ctx);
|
|
904
|
+
const qs = ctx.flags.status ? `?status=${encodeURIComponent(ctx.flags.status)}` : '';
|
|
905
|
+
const { data } = await ctx.call('GET', `/partner/${encodeURIComponent(r.product)}/midas/proposals${qs}`);
|
|
906
|
+
if (ctx.flags.json) { ctx.out(data); return 0; }
|
|
907
|
+
const list = data.proposals || [];
|
|
908
|
+
const lines = [`${r.product}: ${list.length} ${data.status || 'pending'} proposal(s)${list.length ? '. An editor approves them on the Economy page in the CMS (Proposals).' : ''}`];
|
|
909
|
+
for (const p of list) {
|
|
910
|
+
const change = p.proposedValue == null ? 'for the team to act on'
|
|
911
|
+
: `${p.field || 'value'}: ${p.currentValue == null ? 'none' : p.currentValue} → ${p.proposedValue}`;
|
|
912
|
+
lines.push(` [${p.severity}] ${p.type.replace(/_/g, ' ').toLowerCase()} · ${p.targetName}: ${change}`);
|
|
913
|
+
if (p.rationale) lines.push(` ${p.rationale}`);
|
|
914
|
+
}
|
|
915
|
+
ctx.out(lines.join('\n'), data);
|
|
916
|
+
return 0;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/** `plaiful midas wallet <player>`: one player's balances and recent earning and spending (wallet "platform"). */
|
|
920
|
+
async function midasWallet(ctx, [player]) {
|
|
921
|
+
const r = repo(ctx);
|
|
922
|
+
if (!player) throw new UsageError('which player? plaiful midas wallet <player id> (their Firebase uid)');
|
|
923
|
+
const { data } = await ctx.call('GET', `/partner/${encodeURIComponent(r.product)}/midas/wallet/${encodeURIComponent(player)}`);
|
|
924
|
+
if (ctx.flags.json) { ctx.out(data); return 0; }
|
|
925
|
+
const label = Object.fromEntries((data.kinds || []).map((k) => [k.id, k.label]));
|
|
926
|
+
const lines = [`${player} in ${r.product} (dev): ${Object.entries(data.balances || {}).map(([k, v]) => `${num(v)} ${label[k] || k}`).join(' · ') || 'nothing yet'}`];
|
|
927
|
+
for (const e of data.history || []) lines.push(` ${e.ts} ${e.delta > 0 ? '+' : ''}${num(e.delta)} ${label[e.kind] || e.kind} ${e.reason}${e.source_id ? ` (${e.source_id})` : ''}`);
|
|
928
|
+
ctx.out(lines.join('\n'), data);
|
|
929
|
+
return 0;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/** `plaiful midas ledger check <file>`: would POST /game/wallet/report accept these entries (wallet "game")? */
|
|
933
|
+
async function midasLedger(ctx, [sub, file]) {
|
|
934
|
+
if (sub !== 'check' || !file) throw new UsageError('plaiful midas ledger check <file.json> (a list of { kind, delta, reason, idempotency_key }, or { "entries": [...] })');
|
|
935
|
+
const r = repo(ctx);
|
|
936
|
+
const { json } = readJsonFile(ctx, file);
|
|
937
|
+
const entries = Array.isArray(json) ? json : json && json.entries;
|
|
938
|
+
const { data } = await ctx.call('POST', `/partner/${encodeURIComponent(r.product)}/midas/ledger/check`, { entries });
|
|
939
|
+
if (ctx.flags.json) { ctx.out(data); return data.success ? 0 : 1; }
|
|
940
|
+
const lines = [data.success ? `${data.count} entries: all valid. Your game sends them with POST /game/wallet/report.` : `${(data.problems || []).length} problem(s):`];
|
|
941
|
+
for (const p of data.problems || []) lines.push(` ✗ ${p}`);
|
|
942
|
+
if (data.note) lines.push(` ! ${data.note}`);
|
|
943
|
+
ctx.out(lines.join('\n'), data);
|
|
944
|
+
return data.success ? 0 : 1;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
async function midasAssess(ctx) {
|
|
948
|
+
const r = repo(ctx);
|
|
949
|
+
const { data } = await ctx.call('POST', `/partner/${encodeURIComponent(r.product)}/midas/assess`, {});
|
|
950
|
+
ctx.out(`MIDAS is analyzing ${r.product}'s economy (about a minute). Then: plaiful midas health`, data);
|
|
951
|
+
return 0;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
// ── Promotion (PLAI-139) ───────────────────────────────────────────────────────────────────────────────────────
|
|
955
|
+
|
|
956
|
+
const PROMOTION_POLL_MS = 5000;
|
|
957
|
+
const PROMOTION_DONE = ['done', 'failed', 'blocked'];
|
|
958
|
+
|
|
959
|
+
function describePromotion(product, item, dryRun) {
|
|
960
|
+
const lines = [];
|
|
961
|
+
if (item.status === 'blocked') {
|
|
962
|
+
lines.push(`staging isn't ready for ${product}, so nothing was written:`);
|
|
963
|
+
for (const c of ((item.readiness || {}).checks || []).filter((x) => !x.ok)) lines.push(` ! ${c.check}: ${c.detail}`);
|
|
964
|
+
lines.push('Ask Plaiful to finish setting up the product\'s staging environment.');
|
|
965
|
+
return lines.join('\n');
|
|
966
|
+
}
|
|
967
|
+
if (item.status === 'failed') return `the promotion failed: ${item.error || 'no reason given'}`;
|
|
968
|
+
if (!PROMOTION_DONE.includes(item.status)) return `${product}: ${item.status}`;
|
|
969
|
+
const s = item.summary || {};
|
|
970
|
+
const t = s.totals || {};
|
|
971
|
+
const files = (s.s3Summaries || []).reduce((a, x) => ({ copy: a.copy + (x.copy || 0), del: a.del + (x.delete || 0) }), { copy: 0, del: 0 });
|
|
972
|
+
lines.push(dryRun ? `Preview: promoting ${product} to staging would change` : `${product} is in staging:`);
|
|
973
|
+
lines.push(` content rows ${t.add || 0} new, ${t.update || 0} changed, ${t.remove || 0} removed`);
|
|
974
|
+
if ((s.s3Summaries || []).length) lines.push(` asset files ${files.copy} to copy, ${files.del} to remove`);
|
|
975
|
+
if (s.agentTotals) lines.push(` agents ${s.agentTotals.add || 0} new, ${s.agentTotals.update || 0} changed, ${s.agentTotals.noop || 0} unchanged`);
|
|
976
|
+
if (dryRun) lines.push('Nothing was written. Promote for real: plaiful promote');
|
|
977
|
+
return lines.join('\n');
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
async function promotionStatus(ctx, product, id) {
|
|
981
|
+
return (await ctx.call('GET', `/partner/${encodeURIComponent(product)}/promotions/${encodeURIComponent(id)}`)).data;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
async function promote(ctx, rest) {
|
|
985
|
+
const r = repo(ctx);
|
|
986
|
+
if (rest[0] === 'status') {
|
|
987
|
+
if (!rest[1]) throw new UsageError('which promotion? plaiful promote status <id>');
|
|
988
|
+
const item = await promotionStatus(ctx, r.product, rest[1]);
|
|
989
|
+
ctx.out(describePromotion(r.product, item, !!item.dryRun), item);
|
|
990
|
+
return item.status === 'failed' || item.status === 'blocked' ? 1 : 0;
|
|
991
|
+
}
|
|
992
|
+
if (rest.length) throw new UsageError(`unknown argument "${rest[0]}" (plaiful promote [--to staging] [--dry-run])`);
|
|
993
|
+
const to = ctx.flags.to || 'staging';
|
|
994
|
+
if (to !== 'staging') throw new UsageError('studios promote dev to staging; Plaiful runs prod during the beta');
|
|
995
|
+
const dryRun = !!ctx.flags['dry-run'];
|
|
996
|
+
const { data } = await ctx.call('POST', `/partner/${encodeURIComponent(r.product)}/promote`, { to, dry_run: dryRun });
|
|
997
|
+
const id = data.promotionId;
|
|
998
|
+
if (ctx.flags['no-wait']) {
|
|
999
|
+
ctx.out(`${dryRun ? 'Preview' : 'Promotion'} of ${r.product} to staging started: ${id}\nThen: plaiful promote status ${id}`, data);
|
|
1000
|
+
return 0;
|
|
1001
|
+
}
|
|
1002
|
+
if (!ctx.flags.json) ctx.io.stderr.write(`${dryRun ? 'Working out what would change' : `Promoting ${r.product} to staging`} (${id}); this can take a few minutes…\n`);
|
|
1003
|
+
let item = { status: data.status };
|
|
1004
|
+
while (!PROMOTION_DONE.includes(item.status)) {
|
|
1005
|
+
await ctx.io.sleep(PROMOTION_POLL_MS);
|
|
1006
|
+
item = await promotionStatus(ctx, r.product, id);
|
|
1007
|
+
}
|
|
1008
|
+
ctx.out(describePromotion(r.product, item, dryRun), item);
|
|
1009
|
+
return item.status === 'done' ? 0 : 1;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
// ── Seeding (phase 2) ──────────────────────────────────────────────────────────────────────────────────────────
|
|
1013
|
+
|
|
1014
|
+
const STORES = ['world', 'lore', 'map', 'personas'];
|
|
1015
|
+
const SEED_ROUTE = { world: 'ovid/world', lore: 'ovid/lore', map: 'ovid/map', personas: 'thespis/personas' };
|
|
1016
|
+
const MARK = { create: '+', update: '~', remove: '-', keep: '=' };
|
|
1017
|
+
|
|
1018
|
+
/** The JSON files to send: the paths given (files or folders), else resources/<store>/<product>/. */
|
|
1019
|
+
function seedFiles(ctx, r, store, paths) {
|
|
1020
|
+
const targets = paths.length ? paths.map((x) => path.resolve(ctx.io.cwd(), x)) : [path.join(r.root, 'resources', store, r.product)];
|
|
1021
|
+
const files = [];
|
|
1022
|
+
for (const t of targets) {
|
|
1023
|
+
if (!fs.existsSync(t)) throw new UsageError(`${t} doesn't exist${paths.length ? '' : ` (put your ${store} files there, or pass their paths)`}`);
|
|
1024
|
+
const list = fs.statSync(t).isDirectory()
|
|
1025
|
+
? fs.readdirSync(t).filter((n) => n.toLowerCase().endsWith('.json')).sort().map((n) => path.join(t, n))
|
|
1026
|
+
: [t];
|
|
1027
|
+
for (const file of list) {
|
|
1028
|
+
let content;
|
|
1029
|
+
try { content = JSON.parse(fs.readFileSync(file, 'utf8')); } catch (e) { throw new UsageError(`${file} isn't valid JSON: ${e.message}`); }
|
|
1030
|
+
files.push({ name: path.relative(r.root, file).replace(/\\/g, '/'), content });
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
if (!files.length) throw new UsageError(`no .json files in ${targets.join(', ')}`);
|
|
1034
|
+
return files;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
async function seedStore(ctx, store, paths) {
|
|
1038
|
+
if (!STORES.includes(store)) throw new UsageError(`seed what? world, lore, map or personas (plaiful seed ${STORES.join('|')})`);
|
|
1039
|
+
const r = repo(ctx);
|
|
1040
|
+
const files = seedFiles(ctx, r, store, paths);
|
|
1041
|
+
const apply = !!ctx.flags.apply;
|
|
1042
|
+
const reset = !!ctx.flags.reset;
|
|
1043
|
+
const { data } = await ctx.call('POST', `/partner/${encodeURIComponent(r.product)}/${SEED_ROUTE[store]}/seed`, { files, apply, reset, rows: !!ctx.flags.rows });
|
|
1044
|
+
if (ctx.flags.json) { ctx.out(data); return data.ok ? 0 : 1; }
|
|
1045
|
+
const lines = [];
|
|
1046
|
+
if (!data.ok) {
|
|
1047
|
+
lines.push(`${files.length} ${store} file(s) have ${data.errors.length} error(s); nothing was ${apply ? 'written' : 'planned'}. Fix them and run it again.`);
|
|
1048
|
+
lines.push(...findingsText(data));
|
|
1049
|
+
ctx.out(lines.join('\n'));
|
|
1050
|
+
return 1;
|
|
1051
|
+
}
|
|
1052
|
+
const s = data.summary;
|
|
1053
|
+
const counts = Object.entries(data.counts || {}).map(([k, v]) => `${v} ${k}`).join(', ');
|
|
1054
|
+
lines.push(`${store} for ${r.product} (dev, ${data.table}): ${counts}.`);
|
|
1055
|
+
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` : ''}.`);
|
|
1056
|
+
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.`);
|
|
1057
|
+
const shown = data.items.slice(0, 40);
|
|
1058
|
+
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})` : ''}`);
|
|
1059
|
+
if (data.items.length > shown.length) lines.push(` … and ${data.items.length - shown.length} more (--json lists them all)`);
|
|
1060
|
+
lines.push(...findingsText(data));
|
|
1061
|
+
if (ctx.flags.rows) lines.push(JSON.stringify(data.rows, null, 2));
|
|
1062
|
+
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.');
|
|
1063
|
+
else if (data.writes) lines.push('Check it with: plaiful status');
|
|
1064
|
+
ctx.out(lines.join('\n'));
|
|
1065
|
+
return 0;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
async function status(ctx) {
|
|
1069
|
+
const r = repo(ctx);
|
|
1070
|
+
const { data } = await ctx.call('GET', `/partner/${encodeURIComponent(r.product)}/status`);
|
|
1071
|
+
if (ctx.flags.json) { ctx.out(data); return 0; }
|
|
1072
|
+
const w = data.world || {};
|
|
1073
|
+
const l = data.lore || {};
|
|
1074
|
+
const m = data.map || {};
|
|
1075
|
+
const d = data.declaration || {};
|
|
1076
|
+
const err = (x) => (x.error ? ` ${x.error}` : null);
|
|
1077
|
+
const lines = [`${r.product} in dev:`];
|
|
1078
|
+
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`}`);
|
|
1079
|
+
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)'}`);
|
|
1080
|
+
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` : ''}`}`);
|
|
1081
|
+
lines.push(` map ${err(m) || `${m.locations} locations, ${m.settlements} settlements (${m.settlements_with_npcs} with NPCs), ${m.seeded} seeded`}`);
|
|
1082
|
+
const t = data.thespis || {};
|
|
1083
|
+
lines.push(` thespis ${err(t) || `${t.personas} personas (${t.active_personas} active), ${t.situations} situations, ${t.seeded} seeded`}`);
|
|
1084
|
+
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)'}`);
|
|
1085
|
+
ctx.out(lines.join('\n'));
|
|
1086
|
+
return 0;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
// ── Lists and uploads (phase 3) ──────────────────────────────────────────────────────────────────────────────────
|
|
1090
|
+
|
|
1091
|
+
/** The route for a list: a name in the namespace goes in the path; a full /path goes in ?path=. */
|
|
1092
|
+
function listRoute(r, name) {
|
|
1093
|
+
const base = `/partner/${encodeURIComponent(r.product)}/lists`;
|
|
1094
|
+
if (!name) return base;
|
|
1095
|
+
if (name.startsWith('/')) return `${base}?path=${encodeURIComponent(name)}`;
|
|
1096
|
+
return `${base}/${name.split('/').map(encodeURIComponent).join('/')}`;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
async function lists(ctx, [sub, name, ...values]) {
|
|
1100
|
+
const r = repo(ctx);
|
|
1101
|
+
if (!sub) {
|
|
1102
|
+
const { data } = await ctx.call('GET', listRoute(r));
|
|
1103
|
+
const lines = [`${r.product}'s lists in dev (${data.namespace}):`];
|
|
1104
|
+
if (!data.lists.length) lines.push(' none yet (plaiful lists set <name> <values...>)');
|
|
1105
|
+
for (const l of data.lists) lines.push(` ${l.name}${l.type === 'String' ? ' (a setting)' : ''} ${l.values.join(', ')}`);
|
|
1106
|
+
ctx.out(lines.join('\n'), data);
|
|
1107
|
+
return 0;
|
|
1108
|
+
}
|
|
1109
|
+
if (sub === 'get') {
|
|
1110
|
+
if (!name) throw new UsageError('which list? plaiful lists get <name>');
|
|
1111
|
+
const { data } = await ctx.call('GET', listRoute(r, name));
|
|
1112
|
+
ctx.out(`${data.name}: ${data.values.join(', ')}`, data);
|
|
1113
|
+
return 0;
|
|
1114
|
+
}
|
|
1115
|
+
if (sub === 'set') {
|
|
1116
|
+
if (!name || !values.length) throw new UsageError('plaiful lists set <name> <values...> (e.g. plaiful lists set shop_type tavern blacksmith healer)');
|
|
1117
|
+
const parsed = (values.length === 1 ? values[0].split(',') : values).map((v) => v.trim()).filter(Boolean);
|
|
1118
|
+
const { data } = await ctx.call('PUT', listRoute(r, name), { values: parsed });
|
|
1119
|
+
const was = data.previous === null ? 'new' : `was: ${data.previous.join(', ')}`;
|
|
1120
|
+
ctx.out(`${data.name} = ${data.values.join(', ')} (${was})`, data);
|
|
1121
|
+
return 0;
|
|
1122
|
+
}
|
|
1123
|
+
throw new UsageError(`plaiful lists, lists get <name> or lists set <name> <values...> (not "${sub}")`);
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
// ── SmartBuilder agents ─────────────────────────────────────────────────────────────────────────────────────
|
|
1127
|
+
|
|
1128
|
+
const agentRoute = (r, rest = '') => `/partner/${encodeURIComponent(r.product)}/agents${rest}`;
|
|
1129
|
+
const AGENT_NAME = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
1130
|
+
|
|
1131
|
+
function readJsonFile(ctx, f) {
|
|
1132
|
+
const file = path.resolve(ctx.io.cwd(), f);
|
|
1133
|
+
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) throw new UsageError(`${file} isn't a file`);
|
|
1134
|
+
try { return { file, json: JSON.parse(fs.readFileSync(file, 'utf8')) }; } catch (e) { throw new UsageError(`${file} isn't valid JSON (${e.message})`); }
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
/** The config files to deploy: the ones named, or every .json in resources/agents/<product>/. */
|
|
1138
|
+
function agentFiles(ctx, r, files) {
|
|
1139
|
+
if (files.length) return files;
|
|
1140
|
+
const dir = path.join(ctx.io.cwd(), 'resources', 'agents', r.product);
|
|
1141
|
+
if (!fs.existsSync(dir)) throw new UsageError(`no files named, and no ${path.relative(ctx.io.cwd(), dir)}/ folder: plaiful agents deploy <file.json>`);
|
|
1142
|
+
const found = fs.readdirSync(dir).filter((n) => n.endsWith('.json')).map((n) => path.join(dir, n));
|
|
1143
|
+
if (!found.length) throw new UsageError(`${path.relative(ctx.io.cwd(), dir)}/ has no .json agent configs`);
|
|
1144
|
+
return found;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
async function agents(ctx, [sub, name, ...rest]) {
|
|
1148
|
+
const r = repo(ctx);
|
|
1149
|
+
if (!sub) {
|
|
1150
|
+
const { data } = await ctx.call('GET', agentRoute(r));
|
|
1151
|
+
const list = data.agents || [];
|
|
1152
|
+
const lines = [`${r.product}'s SmartBuilder agents in dev:`];
|
|
1153
|
+
if (!list.length) lines.push(' none yet (plaiful agents deploy <file.json>, or SmartBuilder in the CMS)');
|
|
1154
|
+
for (const a of list) lines.push(` ${a.name || a.agent_name}${a.display_name ? ` ${a.display_name}` : ''}${a.business_purpose ? ` (${a.business_purpose})` : ''}`);
|
|
1155
|
+
ctx.out(lines.join('\n'), data);
|
|
1156
|
+
return 0;
|
|
1157
|
+
}
|
|
1158
|
+
if (sub === 'show') {
|
|
1159
|
+
if (!name) throw new UsageError('which agent? plaiful agents show <name>');
|
|
1160
|
+
const { data } = await ctx.call('GET', agentRoute(r, `/${encodeURIComponent(name)}`));
|
|
1161
|
+
const a = data.agent || {};
|
|
1162
|
+
const lines = [`${a.agent_name || name}: ${a.display_name || ''}`.trim(),
|
|
1163
|
+
` table ${(a.storage || {}).table_name || '?'}, version ${(a.metadata || {}).version || '?'}, ${(a.metadata || {}).business_purpose || 'content'}`,
|
|
1164
|
+
` fields ${(a.output_fields || []).join(', ')}`,
|
|
1165
|
+
` lists ${Object.entries(a.ssm_parameters || {}).map(([k, v]) => `${k} ← ${listSource(v)}`).join('; ') || 'none'}`,
|
|
1166
|
+
` dedup ${a.duplicate_detection && a.duplicate_detection.enabled !== false ? `on ${[].concat(a.duplicate_detection.field || 'name').join(', ')}` : 'off'}`,
|
|
1167
|
+
' (--json prints the whole config)'];
|
|
1168
|
+
ctx.out(lines.join('\n'), data);
|
|
1169
|
+
return 0;
|
|
1170
|
+
}
|
|
1171
|
+
if (sub === 'deploy') {
|
|
1172
|
+
const files = agentFiles(ctx, r, [name, ...rest].filter(Boolean));
|
|
1173
|
+
const done = [];
|
|
1174
|
+
for (const f of files) {
|
|
1175
|
+
const { file, json } = readJsonFile(ctx, f);
|
|
1176
|
+
const agentName = json.agent_name || path.basename(file, '.json');
|
|
1177
|
+
if (!AGENT_NAME.test(agentName)) throw new UsageError(`${path.basename(file)}: "${agentName}" isn't an agent name (lowercase letters, digits, hyphens)`);
|
|
1178
|
+
const { data } = await ctx.call('POST', agentRoute(r, `/${agentName}`), { config: json });
|
|
1179
|
+
done.push(data);
|
|
1180
|
+
if (!ctx.flags.json) ctx.out(`${data.redeployed ? 'redeployed' : 'deployed'} ${data.agent_name}: table ${data.table_name}${data.table === 'created' ? ' (new)' : ''}, version ${data.version}`);
|
|
1181
|
+
}
|
|
1182
|
+
if (ctx.flags.json) ctx.out('', { success: true, product: r.product, deployed: done });
|
|
1183
|
+
return 0;
|
|
1184
|
+
}
|
|
1185
|
+
if (sub === 'run') {
|
|
1186
|
+
if (!name) throw new UsageError('which agent? plaiful agents run <name> [key=value...]');
|
|
1187
|
+
const body = {};
|
|
1188
|
+
for (const kv of rest) {
|
|
1189
|
+
const i = kv.indexOf('=');
|
|
1190
|
+
if (i < 1) throw new UsageError(`"${kv}" isn't key=value`);
|
|
1191
|
+
body[kv.slice(0, i)] = kv.slice(i + 1);
|
|
1192
|
+
}
|
|
1193
|
+
const { data } = await ctx.call('POST', agentRoute(r, `/${encodeURIComponent(name)}/run`), body);
|
|
1194
|
+
const rec = data.item || data.record || data;
|
|
1195
|
+
ctx.out(`made ${rec.uuid || 'a record'}${rec.name ? `: ${rec.name}` : ''}`, data);
|
|
1196
|
+
return 0;
|
|
1197
|
+
}
|
|
1198
|
+
if (sub === 'batch') {
|
|
1199
|
+
if (!name) throw new UsageError('which agent? plaiful agents batch <name> [batch-body.json] (or --count <n>)');
|
|
1200
|
+
let body;
|
|
1201
|
+
if (rest[0]) body = readJsonFile(ctx, rest[0]).json;
|
|
1202
|
+
else if (ctx.flags.count) body = { count: Number(ctx.flags.count) };
|
|
1203
|
+
else throw new UsageError('give a batch body file, or --count <n>');
|
|
1204
|
+
const { data } = await ctx.call('POST', agentRoute(r, `/${encodeURIComponent(name)}/batch`), body);
|
|
1205
|
+
ctx.out(`started batch ${data.job_id} (${data.total_items || '?'} records). plaiful agents status ${name} ${data.job_id}`, data);
|
|
1206
|
+
return 0;
|
|
1207
|
+
}
|
|
1208
|
+
if (sub === 'status') {
|
|
1209
|
+
const [jobId] = rest;
|
|
1210
|
+
if (!name || !jobId) throw new UsageError('plaiful agents status <name> <jobId>');
|
|
1211
|
+
const { data } = await ctx.call('GET', agentRoute(r, `/${encodeURIComponent(name)}/batch/${encodeURIComponent(jobId)}`));
|
|
1212
|
+
ctx.out(`${data.status || '?'}: ${data.completed_items ?? '?'} done, ${data.failed_items ?? 0} failed of ${data.total_items ?? '?'}`, data);
|
|
1213
|
+
return 0;
|
|
1214
|
+
}
|
|
1215
|
+
throw new UsageError(`plaiful agents, or agents show | deploy | run | batch | status (not "${sub}")`);
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
/** `plaiful records import <agent> [file]`: records written by hand into the agent's table, saved as the agent saves
|
|
1219
|
+
* the ones it makes; a dry run unless --apply. The file: a list of records, or { "records": [...] }. */
|
|
1220
|
+
async function records(ctx, [sub, name, file]) {
|
|
1221
|
+
if (sub !== 'import') throw new UsageError(`plaiful records import <agent> [file] (not "${sub || ''}")`);
|
|
1222
|
+
const r = repo(ctx);
|
|
1223
|
+
if (!name) throw new UsageError('which agent? plaiful records import <agent> [file] (default file: resources/records/<product>/<agent>.json)');
|
|
1224
|
+
if (!AGENT_NAME.test(name)) throw new UsageError(`"${name}" isn't an agent name (lowercase letters, digits, hyphens)`);
|
|
1225
|
+
const f = file || path.join(path.relative(ctx.io.cwd(), r.root) || '.', 'resources', 'records', r.product, `${name}.json`);
|
|
1226
|
+
const { json } = readJsonFile(ctx, f);
|
|
1227
|
+
const list = Array.isArray(json) ? json : json && Array.isArray(json.records) ? json.records : null;
|
|
1228
|
+
if (!list) throw new UsageError(`${f}: give a list of records, or { "records": [...] }`);
|
|
1229
|
+
if (!list.length) throw new UsageError(`${f} has no records`);
|
|
1230
|
+
const apply = !!ctx.flags.apply;
|
|
1231
|
+
const { data } = await ctx.call('POST', agentRoute(r, `/${encodeURIComponent(name)}/import`), { records: list, apply, render: !ctx.flags['no-render'] });
|
|
1232
|
+
if (ctx.flags.json) { ctx.out(data); return data.success ? 0 : 1; }
|
|
1233
|
+
const lines = [];
|
|
1234
|
+
if (!data.success) {
|
|
1235
|
+
lines.push(`${data.error || 'the import was refused'}. Fix them and run it again.`);
|
|
1236
|
+
for (const e of data.errors || []) lines.push(` ✗ ${e.error}`);
|
|
1237
|
+
ctx.out(lines.join('\n'));
|
|
1238
|
+
return 1;
|
|
1239
|
+
}
|
|
1240
|
+
const s = data.summary;
|
|
1241
|
+
lines.push(`${name} for ${r.product} (dev, ${data.table_name})${data.key_field ? `, matched on ${data.key_field}` : ''}:`);
|
|
1242
|
+
lines.push(`${data.applied ? 'Wrote' : 'Would write'}: ${s.create} new, ${s.update} changed, ${s.unchanged} unchanged.`);
|
|
1243
|
+
const shown = data.records.filter((x) => x.action !== 'unchanged').slice(0, 40);
|
|
1244
|
+
const label = (x) => (x.key !== null && x.key !== undefined ? x.key : x.uuid);
|
|
1245
|
+
for (const x of shown) lines.push(` ${MARK[x.action]} ${x.action === 'create' ? 'new ' : 'change'} ${label(x)}${x.action === 'update' ? ` (${x.changed.join(', ')})` : ''}`);
|
|
1246
|
+
const more = s.create + s.update - shown.length;
|
|
1247
|
+
if (more > 0) lines.push(` … and ${more} more (--json lists them all)`);
|
|
1248
|
+
for (const w of data.warnings || []) lines.push(` ! ${w}`);
|
|
1249
|
+
const stale = data.records.filter((x) => x.stale_art).map(label);
|
|
1250
|
+
if (stale.length) lines.push(` ! ${stale.length} changed record(s) keep the art or sound made from their old text (${stale.slice(0, 5).join(', ')}${stale.length > 5 ? ', …' : ''}): make it again in the CMS Library.`);
|
|
1251
|
+
if (!data.applied) {
|
|
1252
|
+
lines.push(s.create + s.update ? `Dry run: nothing written. Write it with: plaiful records import ${name}${file ? ` ${file}` : ''} --apply` : 'Dry run: the table already matches your file.');
|
|
1253
|
+
} else if (data.rendering) lines.push(`Making the art or sound for ${data.rendering} new record(s): plaiful assets ${name}`);
|
|
1254
|
+
ctx.out(lines.join('\n'));
|
|
1255
|
+
return 0;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
// ── What OVID has: quests, lore, the world ──────────────────────────────────────────────────────────────────────
|
|
1259
|
+
|
|
1260
|
+
const ovidRoute = (r, rest) => `/partner/${encodeURIComponent(r.product)}/ovid/${rest}`;
|
|
1261
|
+
const priceText = (p) => (p && Object.keys(p).length ? Object.entries(p).map(([k, v]) => `${v} ${k}`).join(', ') : '');
|
|
1262
|
+
|
|
1263
|
+
async function quests(ctx, [sub, id]) {
|
|
1264
|
+
const r = repo(ctx);
|
|
1265
|
+
if (sub === 'delete') {
|
|
1266
|
+
if (!id) throw new UsageError('which quest? plaiful quests delete <questId>');
|
|
1267
|
+
return ovidEdit(ctx, 'delete_quest', { quest_id: id }, `Deleted quest ${id}.`);
|
|
1268
|
+
}
|
|
1269
|
+
if (sub === 'show') {
|
|
1270
|
+
if (!id) throw new UsageError('which quest? plaiful quests show <id>');
|
|
1271
|
+
const { data } = await ctx.call('GET', ovidRoute(r, `quests/${encodeURIComponent(id)}`));
|
|
1272
|
+
const q = data.quest || {};
|
|
1273
|
+
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 || '?'})`];
|
|
1274
|
+
if (q.narrative_desc || q.description) lines.push(` ${q.narrative_desc || q.description}`);
|
|
1275
|
+
for (const st of data.steps_detail || []) {
|
|
1276
|
+
const n = (q.nodes || {})[st.id] || {};
|
|
1277
|
+
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) || '';
|
|
1278
|
+
lines.push(` ${st.unreached ? '(unreached) ' : ''}${st.id}: ${st.type}${st.count > 1 ? `×${st.count}` : ''}${say ? ` "${String(say).slice(0, 90)}${String(say).length > 90 ? '…' : ''}"` : ''}`);
|
|
1279
|
+
}
|
|
1280
|
+
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(', ')}` : ''}`);
|
|
1281
|
+
lines.push(' (--json prints the whole record)');
|
|
1282
|
+
ctx.out(lines.join('\n'), data);
|
|
1283
|
+
return 0;
|
|
1284
|
+
}
|
|
1285
|
+
if (sub) throw new UsageError(`plaiful quests, or quests show | delete <id> (not "${sub}")`);
|
|
1286
|
+
const qs = new URLSearchParams();
|
|
1287
|
+
if (ctx.flags.track) qs.set('track', ctx.flags.track);
|
|
1288
|
+
if (ctx.flags.series) qs.set('series', ctx.flags.series);
|
|
1289
|
+
const { data } = await ctx.call('GET', `${ovidRoute(r, 'quests')}${qs.toString() ? `?${qs}` : ''}`);
|
|
1290
|
+
const lines = [`${r.product}'s quests in dev: ${data.count}${data.priced ? '' : ' (not priced yet: plaiful midas pricing)'}`];
|
|
1291
|
+
let group = null;
|
|
1292
|
+
for (const q of data.quests) {
|
|
1293
|
+
const g = `${q.quest_track || '?'}${q.series ? ` · ${q.series.series_title || q.series.series_id}` : ''}`;
|
|
1294
|
+
if (g !== group) { lines.push(` ${g}`); group = g; }
|
|
1295
|
+
const pays = priceText(q.price);
|
|
1296
|
+
lines.push(` ${q.series ? `${q.series.series_order}. ` : ''}${q.title} [${q.questType || '?'}] ${q.steps.join(' → ')}${pays ? ` pays ${pays}` : ''} ${q.quest_id}`);
|
|
1297
|
+
}
|
|
1298
|
+
if (data.truncated) lines.push(' (cut off: more quests than one read returns)');
|
|
1299
|
+
ctx.out(lines.join('\n'), data);
|
|
1300
|
+
return 0;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
async function lore(ctx, [sub, id]) {
|
|
1304
|
+
const r = repo(ctx);
|
|
1305
|
+
if (['add', 'reveal', 'hide', 'remove'].includes(sub)) return loreEdit(ctx, sub, id);
|
|
1306
|
+
if (sub === 'show') {
|
|
1307
|
+
if (!id) throw new UsageError('which set? plaiful lore show <setId>');
|
|
1308
|
+
const { data } = await ctx.call('GET', ovidRoute(r, `lore/${encodeURIComponent(id)}`));
|
|
1309
|
+
const lines = [`${data.title || id}${data.category ? ` (${data.category})` : ''}`];
|
|
1310
|
+
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 ? '…' : ''}` : ''}`);
|
|
1311
|
+
ctx.out(lines.join('\n'), data);
|
|
1312
|
+
return 0;
|
|
1313
|
+
}
|
|
1314
|
+
if (sub) throw new UsageError(`plaiful lore, or lore show | add | reveal | hide | remove (not "${sub}")`);
|
|
1315
|
+
const { data } = await ctx.call('GET', ovidRoute(r, 'lore'));
|
|
1316
|
+
const lines = [`${r.product}'s lore in dev: ${data.sets.length} sets`];
|
|
1317
|
+
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}` : ''}`);
|
|
1318
|
+
ctx.out(lines.join('\n'), data);
|
|
1319
|
+
return 0;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
async function world(ctx, [sub, ...rest] = []) {
|
|
1323
|
+
if (sub) {
|
|
1324
|
+
if (!['truth', 'faction', 'var', 'set'].includes(sub)) throw new UsageError(`plaiful world, or world truth | faction | var | set (not "${sub}")`);
|
|
1325
|
+
return worldEdit(ctx, sub, rest);
|
|
1326
|
+
}
|
|
1327
|
+
const r = repo(ctx);
|
|
1328
|
+
const { data } = await ctx.call('GET', ovidRoute(r, 'world'));
|
|
1329
|
+
const c = data.clock;
|
|
1330
|
+
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'}`];
|
|
1331
|
+
const indent = { macro: ' ', meso: ' ', micro: ' ' };
|
|
1332
|
+
for (const e of data.events) {
|
|
1333
|
+
const pad = e.kind === 'event' ? ' ' : (indent[e.scope] || ' ');
|
|
1334
|
+
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}`);
|
|
1335
|
+
}
|
|
1336
|
+
if (data.truncated) lines.push(' (cut off: more rows than one read returns)');
|
|
1337
|
+
ctx.out(lines.join('\n'), data);
|
|
1338
|
+
return 0;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
// ── OVID's edits (shared/ovid/edit-ops.js, the list OVID's chat tools use) ──────────────────────────────────────
|
|
1342
|
+
|
|
1343
|
+
/** A value typed on the command line: true / false, a number, or the word itself. */
|
|
1344
|
+
const typedValue = (v) => (v === 'true' ? true : v === 'false' ? false : v !== '' && !Number.isNaN(Number(v)) ? Number(v) : v);
|
|
1345
|
+
|
|
1346
|
+
async function ovidEdit(ctx, op, params, done) {
|
|
1347
|
+
const r = repo(ctx);
|
|
1348
|
+
const { data } = await ctx.call('POST', ovidRoute(r, 'edit'), { op, ...params, ...(ctx.flags.force ? { force: true } : {}) });
|
|
1349
|
+
ctx.out(`${done}${data.message ? ` (${data.message})` : ''}`, data);
|
|
1350
|
+
return 0;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
async function eventsEdit(ctx, [eventId]) {
|
|
1354
|
+
if (!eventId) throw new UsageError('which event? plaiful events edit <eventId> --title "…" (plaiful world lists them)');
|
|
1355
|
+
const params = { event_id: eventId };
|
|
1356
|
+
for (const [flag, key] of [['title', 'title'], ['description', 'description'], ['category', 'category']]) if (ctx.flags[flag] !== undefined) params[key] = ctx.flags[flag];
|
|
1357
|
+
if (ctx.flags.order !== undefined) params.sort_order = Number(ctx.flags.order);
|
|
1358
|
+
if (ctx.flags.directives) params.directives = readJsonFile(ctx, ctx.flags.directives).json;
|
|
1359
|
+
if (Object.keys(params).length === 1) throw new UsageError('what to change? --title, --description, --category, --order or --directives <file.json>');
|
|
1360
|
+
return ovidEdit(ctx, 'update_event', params, `Updated ${eventId}.`);
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
async function eventsDelete(ctx, [eventId]) {
|
|
1364
|
+
if (!eventId) throw new UsageError('which event? plaiful events delete <eventId>');
|
|
1365
|
+
return ovidEdit(ctx, 'delete_event', { event_id: eventId }, `Deleted ${eventId} and the events under it.`);
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
async function loreEdit(ctx, sub, id) {
|
|
1369
|
+
if (!id) throw new UsageError(`plaiful lore ${sub} <${sub === 'add' || sub === 'remove' ? 'setId' : 'snippetId'}>`);
|
|
1370
|
+
if (sub === 'add') {
|
|
1371
|
+
if (!ctx.flags.narrative) throw new UsageError('--narrative "…" is required: the lore itself');
|
|
1372
|
+
return ovidEdit(ctx, 'add_lore_snippet', { lore_set_id: id, narrative: ctx.flags.narrative, hint: ctx.flags.hint, title: ctx.flags.title, rarity: ctx.flags.rarity, ...(ctx.flags.known ? { world_known: true } : {}) }, `Added a snippet to ${id}.`);
|
|
1373
|
+
}
|
|
1374
|
+
if (sub === 'reveal') return ovidEdit(ctx, 'reveal_lore', { snippet_id: id }, `${id} is known to the world now.`);
|
|
1375
|
+
if (sub === 'hide') return ovidEdit(ctx, 'hide_lore', { snippet_id: id }, `${id} is hidden again (players keep what they found).`);
|
|
1376
|
+
return ovidEdit(ctx, 'remove_lore_set', { lore_set_id: id }, `Removed ${id} and its snippets.`);
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
async function worldEdit(ctx, sub, [id, value]) {
|
|
1380
|
+
if (sub === 'truth') {
|
|
1381
|
+
if (!id || !ctx.flags.statement) throw new UsageError('plaiful world truth <id> --statement "…"');
|
|
1382
|
+
return ovidEdit(ctx, 'add_truth', { truth_id: id, statement: ctx.flags.statement, category: ctx.flags.category, scope: ctx.flags.scope }, `Added truth ${id}.`);
|
|
1383
|
+
}
|
|
1384
|
+
if (sub === 'faction') {
|
|
1385
|
+
if (!id || !ctx.flags.name) throw new UsageError('plaiful world faction <id> --name "…"');
|
|
1386
|
+
return ovidEdit(ctx, 'add_faction', { faction_id: id, name: ctx.flags.name, description: ctx.flags.description, type: ctx.flags.type, homeland: ctx.flags.homeland }, `Added faction ${id}.`);
|
|
1387
|
+
}
|
|
1388
|
+
if (!id || value === undefined) throw new UsageError(`plaiful world ${sub} <id> <value>${sub === 'set' ? ' --reason "…"' : ''}`);
|
|
1389
|
+
if (sub === 'var') return ovidEdit(ctx, 'add_world_variable', { variable_id: id, value: typedValue(value), description: ctx.flags.description }, `Added world variable ${id} = ${value}.`);
|
|
1390
|
+
if (!ctx.flags.reason) throw new UsageError('--reason "…" is required: why the world changed');
|
|
1391
|
+
return ovidEdit(ctx, 'set_world_variable', { variable_id: id, value: typedValue(value), reason: ctx.flags.reason }, `Set ${id} = ${value}.`);
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
async function canon(ctx, [kind, id, status]) {
|
|
1395
|
+
if (!['event', 'quest'].includes(kind) || !id || !['official', 'draft', 'rejected'].includes(status)) {
|
|
1396
|
+
throw new UsageError('plaiful canon event|quest <id> official|draft|rejected');
|
|
1397
|
+
}
|
|
1398
|
+
return ovidEdit(ctx, 'set_canon_status', { kind, id, status }, `${kind} ${id} is ${status} now.`);
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
// ── Event scripts: OVID's cinematic for a state event ────────────────────────────────────────────────────────────
|
|
1402
|
+
|
|
1403
|
+
const SCRIPT_WAIT_MS = 5 * 60 * 1000;
|
|
1404
|
+
const SCRIPT_POLL_MS = 5000;
|
|
1405
|
+
|
|
1406
|
+
function scriptHeader(data) {
|
|
1407
|
+
const s = data.script;
|
|
1408
|
+
const vs = (data.versions || []).map((v) => v.version);
|
|
1409
|
+
const head = s
|
|
1410
|
+
? `${s.title || data.event_id}: v${s.version} ${s.status}, ${s.runtime_sec} s, ${(s.lines || []).length} lines${vs.length > 1 ? ` (versions ${vs.join(', ')})` : ''}`
|
|
1411
|
+
: `${data.event_id}: no script yet`;
|
|
1412
|
+
const j = data.job;
|
|
1413
|
+
const lines = [head];
|
|
1414
|
+
if (j && j.status !== 'done') lines.push(` last request: ${j.status}${j.requestedAt ? ` (${j.requestedAt})` : ''}${j.message ? `: ${j.message}` : ''}`);
|
|
1415
|
+
if (j && j.status !== 'done' && (j.lastErrors || []).length) for (const e of j.lastErrors) lines.push(` - ${e}`);
|
|
1416
|
+
if (s && s.soter && ((s.soter.changes || []).length || (s.soter.flags || []).length)) {
|
|
1417
|
+
lines.push(` Soter (${s.soter.mode}): ${(s.soter.changes || []).length} change(s), ${(s.soter.flags || []).length} flag(s)${s.soter.mode === 'shadow' ? ' it would make; nothing was changed' : ''}`);
|
|
1418
|
+
for (const f of s.soter.flags || []) lines.push(` flag ${f.beat || ''}: ${f.why}`);
|
|
1419
|
+
}
|
|
1420
|
+
return lines;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
async function eventsScript(ctx, [sub, eventId, version]) {
|
|
1424
|
+
const r = repo(ctx);
|
|
1425
|
+
if (!['write', 'get', 'export', 'approve'].includes(sub)) throw new UsageError(`plaiful events script write | get | export | approve <eventId> (not "${sub || ''}")`);
|
|
1426
|
+
if (!eventId) throw new UsageError(`which event? plaiful events script ${sub} <eventId> (plaiful world lists them)`);
|
|
1427
|
+
if (version !== undefined && !/^\d+$/.test(version)) throw new UsageError(`the version is a number (not "${version}")`);
|
|
1428
|
+
const route = ovidRoute(r, `events/${encodeURIComponent(eventId)}/script`);
|
|
1429
|
+
const get = async (format) => {
|
|
1430
|
+
const qs = new URLSearchParams();
|
|
1431
|
+
if (format) qs.set('format', format);
|
|
1432
|
+
if (version) qs.set('version', version);
|
|
1433
|
+
return (await ctx.call('GET', `${route}${qs.toString() ? `?${qs}` : ''}`)).data;
|
|
1434
|
+
};
|
|
1435
|
+
if (sub === 'approve') {
|
|
1436
|
+
if (!version) throw new UsageError(`which version? plaiful events script approve ${eventId} <version> (plaiful events script get ${eventId} lists them)`);
|
|
1437
|
+
const { data } = await ctx.call('POST', `${route}/approve`, { version: Number(version), ...(ctx.flags.retire ? { retire: true } : {}), ...(ctx.flags.force ? { force: true } : {}) });
|
|
1438
|
+
ctx.out(data.status === 'approved' ? `Approved ${eventId} v${version}: the game gets this version.` : `Retired ${eventId} v${version}.`, data);
|
|
1439
|
+
return 0;
|
|
1440
|
+
}
|
|
1441
|
+
if (sub === 'write') {
|
|
1442
|
+
if (version !== undefined) throw new UsageError('write makes a new version; it takes no version number');
|
|
1443
|
+
const { data } = await ctx.call('POST', route, { ...(ctx.flags.note ? { note: ctx.flags.note } : {}), ...(ctx.flags.force ? { force: true } : {}) });
|
|
1444
|
+
const job = data.job || {};
|
|
1445
|
+
if (!ctx.flags.wait) {
|
|
1446
|
+
ctx.out(`${data.already ? 'OVID is already writing' : 'Asked OVID for'} a script for ${eventId} (job ${job.jobId}). It takes a minute or two: plaiful events script get ${eventId}`, data);
|
|
1447
|
+
return 0;
|
|
1448
|
+
}
|
|
1449
|
+
const until = Date.now() + SCRIPT_WAIT_MS;
|
|
1450
|
+
let now = null;
|
|
1451
|
+
while (Date.now() < until) {
|
|
1452
|
+
await ctx.io.sleep(SCRIPT_POLL_MS);
|
|
1453
|
+
now = await get('fountain');
|
|
1454
|
+
if (now.job && now.job.jobId === job.jobId && now.job.status !== 'running') break;
|
|
1455
|
+
}
|
|
1456
|
+
const done = now && now.job && now.job.jobId === job.jobId && now.job.status === 'done';
|
|
1457
|
+
const lines = now ? scriptHeader(now) : [`${eventId}: no answer yet`];
|
|
1458
|
+
if (!now || !now.job || now.job.status === 'running') lines.push(` still writing after ${SCRIPT_WAIT_MS / 60000} minutes: plaiful events script get ${eventId}`);
|
|
1459
|
+
if (done && now.text) lines.push('', now.text);
|
|
1460
|
+
ctx.out(lines.join('\n'), now || data);
|
|
1461
|
+
return done ? 0 : 1;
|
|
1462
|
+
}
|
|
1463
|
+
if (sub === 'get') {
|
|
1464
|
+
const data = await get('fountain');
|
|
1465
|
+
const lines = scriptHeader(data);
|
|
1466
|
+
if (data.text) lines.push('', data.text);
|
|
1467
|
+
ctx.out(lines.join('\n'), data);
|
|
1468
|
+
return 0;
|
|
1469
|
+
}
|
|
1470
|
+
const fmt = ctx.flags.vo ? 'vo' : ctx.flags.fountain ? 'fountain' : null;
|
|
1471
|
+
if (!fmt || (ctx.flags.vo && ctx.flags.fountain)) throw new UsageError('export as --fountain (the screenplay) or --vo (the voice-over sheet)');
|
|
1472
|
+
const data = await get(fmt);
|
|
1473
|
+
if (!data.script) throw new ApiError(404, { error: `${eventId} has no script yet: plaiful events script write ${eventId}`, code: 'no_script' });
|
|
1474
|
+
if (ctx.flags.out) {
|
|
1475
|
+
const file = path.resolve(ctx.io.cwd(), ctx.flags.out);
|
|
1476
|
+
fs.writeFileSync(file, data.text, 'utf8');
|
|
1477
|
+
ctx.out(`wrote ${eventId} v${data.script.version} (${fmt === 'vo' ? 'voice-over sheet' : 'screenplay'}) to ${file}`, { ...data, file });
|
|
1478
|
+
return 0;
|
|
1479
|
+
}
|
|
1480
|
+
if (ctx.flags.json) ctx.out('', data);
|
|
1481
|
+
else ctx.io.stdout.write(data.text.endsWith('\n') ? data.text : `${data.text}\n`);
|
|
1482
|
+
return 0;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
// ── Storyboards (SPRITE_ANIMATION.md §13) ──────────────────────────────────────────────────────────────────────
|
|
1486
|
+
|
|
1487
|
+
const frameLines = (board) => (board.frames || []).map((f) => ` ${f.id.padEnd(6)} ${String(f.framing || '').padEnd(8)} ${(f.caption || '').split('\n')[0].slice(0, 90)}`);
|
|
1488
|
+
|
|
1489
|
+
async function eventsStoryboard(ctx, [sub, eventId, version]) {
|
|
1490
|
+
const r = repo(ctx);
|
|
1491
|
+
if (!['draw', 'get'].includes(sub)) throw new UsageError(`plaiful events storyboard draw | get <eventId> (not "${sub || ''}")`);
|
|
1492
|
+
if (!eventId) throw new UsageError(`which event? plaiful events storyboard ${sub} <eventId>`);
|
|
1493
|
+
if (version !== undefined && !/^\d+$/.test(version)) throw new UsageError(`the version is a number (not "${version}")`);
|
|
1494
|
+
const route = ovidRoute(r, `events/${encodeURIComponent(eventId)}/storyboard`);
|
|
1495
|
+
const read = async (v) => (await ctx.call('GET', `${route}${v ? `?version=${v}` : ''}`)).data;
|
|
1496
|
+
if (sub === 'draw') {
|
|
1497
|
+
if (!ctx.flags.style) throw new UsageError('--style <style> is required: the image style to draw in');
|
|
1498
|
+
const { data } = await ctx.call('POST', route, { style: ctx.flags.style, ...(version ? { version: Number(version) } : {}),
|
|
1499
|
+
...(ctx.flags.aspect ? { aspect: ctx.flags.aspect } : {}), ...(ctx.flags.frame ? { only: [ctx.flags.frame] } : {}) });
|
|
1500
|
+
const lines = [`Drawing ${eventId} v${data.version}: ${ctx.flags.frame ? `frame ${ctx.flags.frame}` : `${data.frames.length} frames`} (job ${data.job_id}).`];
|
|
1501
|
+
if ((data.cast_without_art || []).length) lines.push(` no art to match for ${data.cast_without_art.join(', ')}: drawn from the script's words`);
|
|
1502
|
+
if (!ctx.flags.wait) {
|
|
1503
|
+
lines.push(`It takes a few minutes: plaiful events storyboard get ${eventId} ${data.version}`);
|
|
1504
|
+
ctx.out(lines.join('\n'), data);
|
|
1505
|
+
return 0;
|
|
1506
|
+
}
|
|
1507
|
+
const until = Date.now() + SCRIPT_WAIT_MS * 2;
|
|
1508
|
+
let now = null;
|
|
1509
|
+
while (Date.now() < until) {
|
|
1510
|
+
await ctx.io.sleep(SCRIPT_POLL_MS);
|
|
1511
|
+
now = await read(data.version);
|
|
1512
|
+
if (now.storyboard && now.storyboard.job_id === data.job_id) break;
|
|
1513
|
+
}
|
|
1514
|
+
const done = now && now.storyboard && now.storyboard.job_id === data.job_id;
|
|
1515
|
+
lines.push(done ? `Done: ${now.storyboard.frames.length} frames.` : 'Still drawing; plaiful events storyboard get shows it when it lands.');
|
|
1516
|
+
if (done) lines.push(...frameLines(now.storyboard));
|
|
1517
|
+
ctx.out(lines.join('\n'), now || data);
|
|
1518
|
+
return done ? 0 : 1;
|
|
1519
|
+
}
|
|
1520
|
+
const data = await read(version);
|
|
1521
|
+
if (!data.storyboard) {
|
|
1522
|
+
ctx.out(`${eventId} v${data.version}: no storyboard yet${data.job ? ` (one was started ${data.job.at})` : ''}: plaiful events storyboard draw ${eventId} --style <style>`, data);
|
|
1523
|
+
return 0;
|
|
1524
|
+
}
|
|
1525
|
+
const lines = [`${eventId} v${data.version}: ${data.storyboard.frames.length} frames, style ${data.storyboard.style_ref}, ${data.storyboard.aspect}`, ...frameLines(data.storyboard)];
|
|
1526
|
+
if (ctx.flags.out) {
|
|
1527
|
+
const dir = path.resolve(ctx.io.cwd(), ctx.flags.out);
|
|
1528
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
1529
|
+
for (const f of data.storyboard.frames) {
|
|
1530
|
+
if (!f.url) continue;
|
|
1531
|
+
const res = await ctx.io.fetch(f.url, { method: 'GET', headers: {} });
|
|
1532
|
+
if (!res.ok) throw new ApiError(res.status, { error: `couldn't download ${f.id}` });
|
|
1533
|
+
fs.writeFileSync(path.join(dir, `${f.id}.png`), Buffer.from(await res.arrayBuffer()));
|
|
1534
|
+
}
|
|
1535
|
+
lines.push(`saved the frames to ${dir}`);
|
|
1536
|
+
}
|
|
1537
|
+
ctx.out(lines.join('\n'), data);
|
|
1538
|
+
return 0;
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
// ── What the agents made ────────────────────────────────────────────────────────────────────────────────────────
|
|
1542
|
+
|
|
1543
|
+
const countsText = (a) => `${a.records} records: ${a.made} made, ${a.pending} pending, ${a.failed} failed, ${a.none} none yet${a.step_failed ? `; ${a.step_failed} with a failed step` : ''}${a.truncated ? ' (first 2000)' : ''}`;
|
|
1544
|
+
|
|
1545
|
+
async function assetsRegenerate(ctx, [agent, ...uuids]) {
|
|
1546
|
+
if (!agent) throw new UsageError('which agent? plaiful assets regenerate <agent> [uuids...] (or --all, --state <state>)');
|
|
1547
|
+
const r = repo(ctx);
|
|
1548
|
+
const body = {};
|
|
1549
|
+
if (uuids.length) body.records = uuids;
|
|
1550
|
+
if (ctx.flags.all) body.all = true;
|
|
1551
|
+
if (ctx.flags.state) body.state = String(ctx.flags.state);
|
|
1552
|
+
if (!body.records && !body.all && !body.state) throw new UsageError('which records? list their uuids, or --all, or --state failed|none|made|step_failed (with --model, also no_model)');
|
|
1553
|
+
if (ctx.flags.model) {
|
|
1554
|
+
if (ctx.flags.steps !== undefined) throw new UsageError('--model and --steps are separate runs: one or the other');
|
|
1555
|
+
body.model = true;
|
|
1556
|
+
}
|
|
1557
|
+
if (ctx.flags.steps !== undefined) {
|
|
1558
|
+
if (ctx.flags.steps === true) throw new UsageError('--steps takes step names (--steps depth,normal) or all');
|
|
1559
|
+
body.steps = String(ctx.flags.steps) === 'all' ? 'all' : String(ctx.flags.steps).split(',').map((x) => x.trim()).filter(Boolean);
|
|
1560
|
+
}
|
|
1561
|
+
const { data } = await ctx.call('POST', `/partner/${encodeURIComponent(r.product)}/assets/${encodeURIComponent(agent)}/regenerate`, body);
|
|
1562
|
+
const what = data.mode === 'steps' ? `the ${data.steps.join(', ')} step${data.steps.length !== 1 ? 's' : ''} of ${data.style}`
|
|
1563
|
+
: data.mode === 'model' ? `a 3D model with ${data.style}` : `a new picture in ${data.style}`;
|
|
1564
|
+
const lines = [`Started ${what} for ${data.records} ${agent} record${data.records !== 1 ? 's' : ''}. They ${data.mode === 'model' ? 'build' : 'render'} in the background: plaiful assets ${agent} shows each one as it lands.`];
|
|
1565
|
+
for (const s of data.skipped || []) lines.push(` skipped ${s.uuid}: ${s.reason}`);
|
|
1566
|
+
ctx.out(lines.join('\n'), data);
|
|
1567
|
+
return data.records ? 0 : 1;
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
async function assets(ctx, [agent, ...rest]) {
|
|
1571
|
+
if (agent === 'regenerate') return assetsRegenerate(ctx, rest);
|
|
1572
|
+
const r = repo(ctx);
|
|
1573
|
+
const base = `/partner/${encodeURIComponent(r.product)}/assets`;
|
|
1574
|
+
if (!agent) {
|
|
1575
|
+
const { data } = await ctx.call('GET', base);
|
|
1576
|
+
const lines = [`${r.product}'s agents in dev${data.cdn ? ` (files on https://${data.cdn}/)` : ''}:`];
|
|
1577
|
+
if (!data.agents.length) lines.push(' none yet (plaiful agents deploy)');
|
|
1578
|
+
for (const a of data.agents) {
|
|
1579
|
+
lines.push(` ${a.name.padEnd(24)} ${a.error ? `couldn't read: ${a.error}` : a.makes_art ? countsText(a) : '(makes no art)'}`);
|
|
1580
|
+
}
|
|
1581
|
+
ctx.out(lines.join('\n'), data);
|
|
1582
|
+
return 0;
|
|
1583
|
+
}
|
|
1584
|
+
const qs = new URLSearchParams();
|
|
1585
|
+
if (ctx.flags.state) qs.set('state', ctx.flags.state);
|
|
1586
|
+
if (ctx.flags.limit) qs.set('limit', ctx.flags.limit);
|
|
1587
|
+
const { data } = await ctx.call('GET', `${base}/${encodeURIComponent(agent)}${qs.toString() ? `?${qs}` : ''}`);
|
|
1588
|
+
const lines = [`${agent}: ${countsText(data.counts)}${ctx.flags.state ? `; ${data.matching} ${ctx.flags.state}` : ''}${data.shown < data.matching ? `, showing ${data.shown} (--limit)` : ''}`];
|
|
1589
|
+
for (const rec of data.records) {
|
|
1590
|
+
const why = rec.render_error || Object.entries(rec.media || {}).filter(([, m]) => m.error).map(([k, m]) => `${k}: ${m.error}`).join('; ');
|
|
1591
|
+
const files = [rec.files && `${rec.files.base}.{${rec.files.try.join('|')}}`, ...Object.values(rec.media_files || {})].filter(Boolean);
|
|
1592
|
+
const where = rec.state === 'made' ? files.join(' ') : '';
|
|
1593
|
+
lines.push(` ${rec.state.padEnd(8)} ${rec.name || '(unnamed)'} ${rec.uuid}${why ? ` ${why}` : ''}${where ? ` ${where}` : ''}`);
|
|
1594
|
+
// A step that failed (a depth map): the art is made, the step's file isn't. Re-run it in the Library: Regenerate → Steps.
|
|
1595
|
+
for (const [step, err] of Object.entries(rec.step_errors || {})) lines.push(` ! step ${step} failed: ${err}`);
|
|
1596
|
+
if (rec.depth_match_error) lines.push(` ! depth not matched to the overview: ${rec.depth_match_error}`);
|
|
1597
|
+
}
|
|
1598
|
+
ctx.out(lines.join('\n'), data);
|
|
1599
|
+
return 0;
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
// ── MIDAS quest pricing ─────────────────────────────────────────────────────────────────────────────────────────
|
|
1603
|
+
|
|
1604
|
+
const pricingRoute = (r) => `/partner/${encodeURIComponent(r.product)}/midas/pricing`;
|
|
1605
|
+
|
|
1606
|
+
function nonNegative(v, what) {
|
|
1607
|
+
const n = Number(v);
|
|
1608
|
+
if (v === undefined || v === true || !Number.isFinite(n) || n < 0) throw new UsageError(`${what} must be a number, 0 or more`);
|
|
1609
|
+
return n;
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
function pricingLines(product, data) {
|
|
1613
|
+
const qp = data.quest_pricing || {};
|
|
1614
|
+
const kinds = qp.kinds || {};
|
|
1615
|
+
const declared = ((data.rewards || {}).types || []).filter((k) => k !== 'lore');
|
|
1616
|
+
const names = [...new Set([...declared, ...Object.keys(kinds)])];
|
|
1617
|
+
const d = data.defaults || {};
|
|
1618
|
+
const weights = { ...(d.objective_weights || {}), ...(qp.objective_weights || {}) };
|
|
1619
|
+
const lines = [`${product}'s quest pricing in dev: price = base + per-effort × the quest's effort`];
|
|
1620
|
+
if (!names.length) lines.push(' no reward kinds declared (settings.rewards.types in your OVID declaration)');
|
|
1621
|
+
for (const k of names) {
|
|
1622
|
+
const p = kinds[k];
|
|
1623
|
+
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>)'}`);
|
|
1624
|
+
}
|
|
1625
|
+
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})`);
|
|
1626
|
+
lines.push(` weights: ${Object.entries(weights).map(([t, w]) => `${t} ${w}`).join(', ')}`);
|
|
1627
|
+
for (const w of data.warnings || []) lines.push(` note: ${w}`);
|
|
1628
|
+
return lines;
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
async function midasPricing(ctx, [sub, name, value]) {
|
|
1632
|
+
const r = repo(ctx);
|
|
1633
|
+
if (!sub) {
|
|
1634
|
+
const { data } = await ctx.call('GET', pricingRoute(r));
|
|
1635
|
+
ctx.out(pricingLines(r.product, data).join('\n'), data);
|
|
1636
|
+
return 0;
|
|
1637
|
+
}
|
|
1638
|
+
const save = async (qp) => {
|
|
1639
|
+
const { data } = await ctx.call('PUT', pricingRoute(r), { quest_pricing: qp });
|
|
1640
|
+
ctx.out([...pricingLines(r.product, data), ` ${data.note || 'saved'}`].join('\n'), data);
|
|
1641
|
+
return 0;
|
|
1642
|
+
};
|
|
1643
|
+
if (sub === 'apply') {
|
|
1644
|
+
const f = name || path.join('resources', 'midas', r.product, 'quest-pricing.json');
|
|
1645
|
+
const { json } = readJsonFile(ctx, f);
|
|
1646
|
+
return save(json.quest_pricing !== undefined ? json.quest_pricing : json);
|
|
1647
|
+
}
|
|
1648
|
+
if (!['set', 'unset', 'weight'].includes(sub)) throw new UsageError(`plaiful midas pricing, or pricing set | unset | weight | apply (not "${sub}")`);
|
|
1649
|
+
if (!name) throw new UsageError(sub === 'weight' ? 'plaiful midas pricing weight <step> <n>' : `which kind? plaiful midas pricing ${sub} <kind>`);
|
|
1650
|
+
const { data } = await ctx.call('GET', pricingRoute(r));
|
|
1651
|
+
const qp = JSON.parse(JSON.stringify(data.quest_pricing || {}));
|
|
1652
|
+
if (sub === 'weight') {
|
|
1653
|
+
qp.objective_weights = { ...(qp.objective_weights || {}), [name]: nonNegative(value, 'the weight') };
|
|
1654
|
+
} else if (sub === 'unset') {
|
|
1655
|
+
if (!qp.kinds || !qp.kinds[name]) throw new UsageError(`${name} isn't priced`);
|
|
1656
|
+
delete qp.kinds[name];
|
|
1657
|
+
} else {
|
|
1658
|
+
if (ctx.flags.base === undefined && ctx.flags['per-effort'] === undefined) throw new UsageError(`plaiful midas pricing set ${name} --base <n> --per-effort <n>`);
|
|
1659
|
+
const cur = (qp.kinds && qp.kinds[name]) || { base: 0, per_objective: 0 };
|
|
1660
|
+
qp.kinds = {
|
|
1661
|
+
...(qp.kinds || {}),
|
|
1662
|
+
[name]: {
|
|
1663
|
+
base: ctx.flags.base === undefined ? cur.base : nonNegative(ctx.flags.base, '--base'),
|
|
1664
|
+
per_objective: ctx.flags['per-effort'] === undefined ? cur.per_objective : nonNegative(ctx.flags['per-effort'], '--per-effort'),
|
|
1665
|
+
},
|
|
1666
|
+
};
|
|
1667
|
+
}
|
|
1668
|
+
return save(qp);
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
// ── Animation sets (SPRITE_ANIMATION.md §5) ─────────────────────────────────────────────────────────────────────
|
|
1672
|
+
|
|
1673
|
+
const animationRoute = (r, rest = '') => `/partner/${encodeURIComponent(r.product)}/animation${rest}`;
|
|
1674
|
+
const setLine = (x) => ` ${x.id.padEnd(22)} ${x.name}: ${x.states.length} states${x.builtin ? ' (built-in)' : x.yours ? ' (yours)' : ''}${x.style_ref ? `, style ${x.style_ref}` : ''}`;
|
|
1675
|
+
|
|
1676
|
+
async function animationSets(ctx, [sub, ...rest]) {
|
|
1677
|
+
const r = repo(ctx);
|
|
1678
|
+
if (!sub) {
|
|
1679
|
+
const { data } = await ctx.call('GET', animationRoute(r, '/sets'));
|
|
1680
|
+
const lines = [`Animation sets ${r.product} can use:`, ...data.sets.map(setLine),
|
|
1681
|
+
`Sprite styles: ${data.sprite_styles.length ? data.sprite_styles.map((st) => st.id).join(', ') : 'none yet (make one in the CMS Styles tab, media Sprite animation)'}`];
|
|
1682
|
+
ctx.out(lines.join('\n'), data);
|
|
1683
|
+
return 0;
|
|
1684
|
+
}
|
|
1685
|
+
if (sub === 'show') {
|
|
1686
|
+
if (!rest[0]) throw new UsageError('plaiful animation sets show <id>');
|
|
1687
|
+
const { data } = await ctx.call('GET', animationRoute(r, `/sets/${encodeURIComponent(rest[0])}`));
|
|
1688
|
+
const x = data.set;
|
|
1689
|
+
const lines = [`${x.name} (${x.id})${x.description ? `: ${x.description}` : ''}`, ...x.states.map((st) => ` ${st.name.padEnd(14)} ${st.method.padEnd(6)} ${st.prompt || ''}`)];
|
|
1690
|
+
ctx.out(lines.join('\n'), data);
|
|
1691
|
+
return 0;
|
|
1692
|
+
}
|
|
1693
|
+
if (sub === 'delete') {
|
|
1694
|
+
if (!rest[0]) throw new UsageError('plaiful animation sets delete <id>');
|
|
1695
|
+
const { data } = await ctx.call('DELETE', animationRoute(r, `/sets/${encodeURIComponent(rest[0])}`));
|
|
1696
|
+
ctx.out(`Deleted ${rest[0]}. Records keep the sheets it made.`, data);
|
|
1697
|
+
return 0;
|
|
1698
|
+
}
|
|
1699
|
+
if (sub === 'save') {
|
|
1700
|
+
let files = rest;
|
|
1701
|
+
if (!files.length) {
|
|
1702
|
+
const dir = path.join(ctx.io.cwd(), 'resources', 'animation', r.product);
|
|
1703
|
+
if (!fs.existsSync(dir)) throw new UsageError(`no files named, and no ${path.relative(ctx.io.cwd(), dir)}/ folder: plaiful animation sets save <file.json>`);
|
|
1704
|
+
files = fs.readdirSync(dir).filter((n) => n.endsWith('.json')).map((n) => path.join(dir, n));
|
|
1705
|
+
if (!files.length) throw new UsageError(`${path.relative(ctx.io.cwd(), dir)}/ has no .json sets`);
|
|
1706
|
+
}
|
|
1707
|
+
for (const f of files) {
|
|
1708
|
+
const { file, json } = readJsonFile(ctx, f);
|
|
1709
|
+
if (!json.id) throw new UsageError(`${file}: a set needs an id (lowercase letters, digits and -)`);
|
|
1710
|
+
const { status, data } = await ctx.call('PUT', animationRoute(r, `/sets/${encodeURIComponent(json.id)}`), json);
|
|
1711
|
+
if (status >= 400) throw new ApiError(status, data);
|
|
1712
|
+
ctx.out(`Saved ${json.id}: ${(data.set && data.set.states.length) || 0} states.`, data);
|
|
1713
|
+
}
|
|
1714
|
+
return 0;
|
|
1715
|
+
}
|
|
1716
|
+
throw new UsageError(`plaiful animation sets, or sets show | save | delete (not "${sub}")`);
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
async function animationRun(ctx, [setId, agent, ...uuids]) {
|
|
1720
|
+
const r = repo(ctx);
|
|
1721
|
+
if (!setId || !agent) throw new UsageError('plaiful animation run <set> <agent> [uuids...] (or --all)');
|
|
1722
|
+
if (!uuids.length && !ctx.flags.all) throw new UsageError('name the records (uuids), or --all for every record with its art made');
|
|
1723
|
+
const { data } = await ctx.call('POST', animationRoute(r, '/run'), {
|
|
1724
|
+
set: setId, agent, ...(ctx.flags.all ? { all: true } : { records: uuids }), ...(ctx.flags.style ? { style: ctx.flags.style } : {}), ...(ctx.flags.force ? { force: true } : {}),
|
|
1725
|
+
});
|
|
1726
|
+
const jobs = data.jobs || [];
|
|
1727
|
+
const lines = [`${setId} on ${agent} (style ${data.style}): ${jobs.length} sheet${jobs.length === 1 ? '' : 's'} started, ${(data.skipped || []).length} already made or running`];
|
|
1728
|
+
for (const x of (data.invalid || []).slice(0, 20)) lines.push(` skipped ${x.uuid || '?'}${x.state ? ` ${x.state}` : ''}: ${x.error}`);
|
|
1729
|
+
if (jobs.length) lines.push('They take a minute or two each; plaiful assets <agent> shows the records.');
|
|
1730
|
+
ctx.out(lines.join('\n'), data);
|
|
1731
|
+
return 0;
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
// ── Art styles (PLAI-201; docs/agents/argo/STYLE_SYSTEM.md) ───────────────────────────────────────────────────────
|
|
1735
|
+
|
|
1736
|
+
const styleRoute = (r, rest = '') => `/partner/${encodeURIComponent(r.product)}/styles${rest}`;
|
|
1737
|
+
const styleLine = (st) => ` ${st.id.padEnd(26)} ${st.name}${st.yours ? ' (yours)' : ''}: ${st.media}${st.extends ? `, extends ${st.extends}` : ''}`
|
|
1738
|
+
+ `${st.steps.length ? `, steps ${st.steps.join(' → ')}` : ''}${st.reference_images ? `, ${st.reference_images} reference image${st.reference_images === 1 ? '' : 's'}` : ''}`;
|
|
1739
|
+
const CHANGE_WORDS = { set: 'set', changed: 'changed', removed: 'removed' };
|
|
1740
|
+
|
|
1741
|
+
/** The style files to save: the ones named, or every .json in resources/styles/<product>/. */
|
|
1742
|
+
function styleFiles(ctx, r, files) {
|
|
1743
|
+
if (files.length) return files;
|
|
1744
|
+
const dir = path.join(ctx.io.cwd(), 'resources', 'styles', r.product);
|
|
1745
|
+
if (!fs.existsSync(dir)) throw new UsageError(`no files named, and no ${path.relative(ctx.io.cwd(), dir)}/ folder: plaiful styles save <file.json>`);
|
|
1746
|
+
const found = fs.readdirSync(dir).filter((n) => n.endsWith('.json')).map((n) => path.join(dir, n));
|
|
1747
|
+
if (!found.length) throw new UsageError(`${path.relative(ctx.io.cwd(), dir)}/ has no .json styles`);
|
|
1748
|
+
return found;
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
async function styles(ctx, [sub, ...rest]) {
|
|
1752
|
+
const r = repo(ctx);
|
|
1753
|
+
if (!sub) {
|
|
1754
|
+
const { data } = await ctx.call('GET', styleRoute(r));
|
|
1755
|
+
const lines = [`Art styles ${r.product} can use:`, ...data.styles.map(styleLine),
|
|
1756
|
+
`Yours are saved from resources/styles/${r.product}/ (plaiful styles save). Plaiful's shared ones are read-only: start from one with "extends".`];
|
|
1757
|
+
ctx.out(lines.join('\n'), data);
|
|
1758
|
+
return 0;
|
|
1759
|
+
}
|
|
1760
|
+
if (sub === 'show') {
|
|
1761
|
+
if (!rest[0]) throw new UsageError('plaiful styles show <id> [--out <file.json>]');
|
|
1762
|
+
const { data } = await ctx.call('GET', styleRoute(r, `/${encodeURIComponent(rest[0])}`));
|
|
1763
|
+
const json = `${JSON.stringify(data.style, null, 2)}\n`;
|
|
1764
|
+
if (ctx.flags.out) {
|
|
1765
|
+
const file = path.resolve(ctx.io.cwd(), ctx.flags.out);
|
|
1766
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
1767
|
+
fs.writeFileSync(file, json);
|
|
1768
|
+
}
|
|
1769
|
+
const images = data.reference_images || [];
|
|
1770
|
+
const lines = [`${data.style.name} (${data.style.id})${data.yours ? ', yours' : ', Plaiful\'s shared style (read-only)'}`,
|
|
1771
|
+
`Reference images: ${images.length ? '' : 'none'}`, ...images.map((im) => ` ${im.key}${im.caption ? ` ${im.caption}` : ''}`)];
|
|
1772
|
+
lines.push(ctx.flags.out ? `Wrote it to ${path.relative(ctx.io.cwd(), path.resolve(ctx.io.cwd(), ctx.flags.out))}.` : json.trimEnd());
|
|
1773
|
+
ctx.out(lines.join('\n'), data);
|
|
1774
|
+
return 0;
|
|
1775
|
+
}
|
|
1776
|
+
if (sub === 'save') {
|
|
1777
|
+
const apply = !!ctx.flags.apply;
|
|
1778
|
+
const results = [];
|
|
1779
|
+
const lines = [];
|
|
1780
|
+
for (const f of styleFiles(ctx, r, rest)) {
|
|
1781
|
+
const { file, json } = readJsonFile(ctx, f);
|
|
1782
|
+
const rel = path.relative(ctx.io.cwd(), file);
|
|
1783
|
+
const id = json.id || path.basename(file, '.json');
|
|
1784
|
+
try {
|
|
1785
|
+
const { data } = await ctx.call('PUT', styleRoute(r, `/${encodeURIComponent(id)}`), { style: { ...json, id }, apply });
|
|
1786
|
+
results.push({ file: rel, ...data });
|
|
1787
|
+
const what = data.plan === 'create' ? 'a new style'
|
|
1788
|
+
: data.plan === 'unchanged' ? 'unchanged'
|
|
1789
|
+
: data.changes.map((x) => `${x.field} ${CHANGE_WORDS[x.change]}`).join(', ');
|
|
1790
|
+
lines.push(` ${{ create: '+', update: '~', unchanged: '=' }[data.plan]} ${id}: ${what}`);
|
|
1791
|
+
} catch (e) {
|
|
1792
|
+
if (!(e instanceof ApiError)) throw e;
|
|
1793
|
+
results.push({ file: rel, id, success: false, status: e.status, error: e.message });
|
|
1794
|
+
lines.push(` ✗ ${id} (${rel}): ${e.message}`);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
const failed = results.filter((x) => x.success === false).length;
|
|
1798
|
+
const pending = results.filter((x) => x.plan === 'create' || x.plan === 'update').length;
|
|
1799
|
+
lines.unshift(apply ? `Saved ${r.product}'s styles in dev:` : `Dry run against ${r.product}'s styles in dev:`);
|
|
1800
|
+
if (!apply && pending) lines.push('Nothing saved yet: plaiful styles save --apply saves it.');
|
|
1801
|
+
if (failed) lines.push(`${failed} file${failed === 1 ? '' : 's'} refused; fix ${failed === 1 ? 'it' : 'them'} and run it again.`);
|
|
1802
|
+
ctx.out(lines.join('\n'), { success: !failed, product: r.product, apply, results });
|
|
1803
|
+
return failed ? 1 : 0;
|
|
1804
|
+
}
|
|
1805
|
+
if (sub === 'delete') {
|
|
1806
|
+
const [id, ...more] = rest;
|
|
1807
|
+
if (!id || more.length) throw new UsageError('plaiful styles delete <id> [--yes]');
|
|
1808
|
+
if (!ctx.flags.yes) {
|
|
1809
|
+
if (!ctx.io.ask) throw new UsageError('nothing to ask in here: pass --yes to delete it');
|
|
1810
|
+
const answer = await ctx.io.ask(`Delete the style ${id}? Tables using it have no Art Style until you pick another; pictures already made stay. [y/N] `);
|
|
1811
|
+
if (!/^y(es)?$/i.test(String(answer || '').trim())) { ctx.out('Not deleted.', { success: false, deleted: null }); return 1; }
|
|
1812
|
+
}
|
|
1813
|
+
const { data } = await ctx.call('DELETE', styleRoute(r, `/${encodeURIComponent(id)}`));
|
|
1814
|
+
ctx.out(`Deleted ${id}. Pictures it already made stay.`, data);
|
|
1815
|
+
return 0;
|
|
1816
|
+
}
|
|
1817
|
+
throw new UsageError(`plaiful styles, or styles show | save | delete | images (not "${sub}")`);
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
async function styleImages(ctx, [sub, id, ...rest]) {
|
|
1821
|
+
const r = repo(ctx);
|
|
1822
|
+
if (sub === 'add') {
|
|
1823
|
+
if (!id || !rest.length) throw new UsageError('plaiful styles images add <id> <images...> (.png or .jpg)');
|
|
1824
|
+
const added = [];
|
|
1825
|
+
for (const f of rest) {
|
|
1826
|
+
const file = path.resolve(ctx.io.cwd(), f);
|
|
1827
|
+
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) throw new UsageError(`${file} isn't a file`);
|
|
1828
|
+
const body = fs.readFileSync(file);
|
|
1829
|
+
const { data } = await ctx.call('POST', styleRoute(r, `/${encodeURIComponent(id)}/images/upload`), { name: path.basename(file), size: body.length });
|
|
1830
|
+
let res;
|
|
1831
|
+
try {
|
|
1832
|
+
res = await ctx.io.fetch(data.url, { method: data.method || 'PUT', headers: data.headers, body });
|
|
1833
|
+
} catch (e) {
|
|
1834
|
+
throw new ApiError(0, { error: `the upload of ${path.basename(file)} didn't go through (${e.message})`, code: 'network' });
|
|
1835
|
+
}
|
|
1836
|
+
if (!res.ok) throw new ApiError(res.status, { error: `storage refused ${path.basename(file)} (${res.status}); run it again`, code: 'upload_failed' });
|
|
1837
|
+
const { data: done } = await ctx.call('POST', styleRoute(r, `/${encodeURIComponent(id)}/images`), { key: data.key, ...(ctx.flags.caption ? { caption: ctx.flags.caption } : {}) });
|
|
1838
|
+
added.push({ file: path.basename(file), key: data.key, total: done.reference_images });
|
|
1839
|
+
}
|
|
1840
|
+
const total = added.length ? added[added.length - 1].total : 0;
|
|
1841
|
+
ctx.out([`Added ${added.length} reference image${added.length === 1 ? '' : 's'} to ${id} (${total} now):`, ...added.map((x) => ` ${x.file} → ${x.key}`)].join('\n'), { success: true, id, added });
|
|
1842
|
+
return 0;
|
|
1843
|
+
}
|
|
1844
|
+
if (sub === 'remove') {
|
|
1845
|
+
const [key] = rest;
|
|
1846
|
+
if (!id || !key) throw new UsageError('plaiful styles images remove <id> <key> (plaiful styles show <id> lists the keys)');
|
|
1847
|
+
const { data } = await ctx.call('DELETE', `${styleRoute(r, `/${encodeURIComponent(id)}/images`)}?key=${encodeURIComponent(key)}`);
|
|
1848
|
+
ctx.out(`Removed ${key} from ${id}.`, data);
|
|
1849
|
+
return 0;
|
|
1850
|
+
}
|
|
1851
|
+
throw new UsageError('plaiful styles images add <id> <images...>, or styles images remove <id> <key>');
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
async function upload(ctx, files) {
|
|
1855
|
+
const r = repo(ctx);
|
|
1856
|
+
if (!files.length) throw new UsageError('upload what? plaiful upload <files...> (map tiles: ovid-map-*.json)');
|
|
1857
|
+
const dest = ctx.flags.dest || 'map-data';
|
|
1858
|
+
const done = [];
|
|
1859
|
+
for (const f of files) {
|
|
1860
|
+
const file = path.resolve(ctx.io.cwd(), f);
|
|
1861
|
+
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) throw new UsageError(`${file} isn't a file`);
|
|
1862
|
+
const body = fs.readFileSync(file);
|
|
1863
|
+
const { data } = await ctx.call('POST', `/partner/${encodeURIComponent(r.product)}/uploads`, { dest, name: path.basename(file), size: body.length });
|
|
1864
|
+
let res;
|
|
1865
|
+
try {
|
|
1866
|
+
res = await ctx.io.fetch(data.url, { method: data.method || 'PUT', headers: data.headers, body });
|
|
1867
|
+
} catch (e) {
|
|
1868
|
+
throw new ApiError(0, { error: `the upload of ${path.basename(file)} didn't go through (${e.message})`, code: 'network' });
|
|
1869
|
+
}
|
|
1870
|
+
if (!res.ok) throw new ApiError(res.status, { error: `storage refused ${path.basename(file)} (${res.status}); run the upload again`, code: 'upload_failed' });
|
|
1871
|
+
done.push({ file: path.basename(file), bucket: data.bucket, key: data.key, size: body.length });
|
|
1872
|
+
}
|
|
1873
|
+
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 });
|
|
1874
|
+
return 0;
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
// ── The model registry and training (models.js, train.js) ──────────────────────────────────────────────────────
|
|
1878
|
+
|
|
1879
|
+
const modelsCmd = require('./models').makeModels({ UsageError, ApiError, repo });
|
|
1880
|
+
const trainCmd = require('./train').makeTrain({ UsageError, ApiError, repo, models: modelsCmd });
|
|
1881
|
+
|
|
1882
|
+
function modelsData(ctx, [sub, ...rest]) {
|
|
1883
|
+
if (sub === 'push') return modelsCmd.dataPush(ctx, rest);
|
|
1884
|
+
if (sub === 'pull') return modelsCmd.dataPull(ctx, rest);
|
|
1885
|
+
if (!sub || sub === 'list') return modelsCmd.dataList(ctx, rest);
|
|
1886
|
+
throw new UsageError(`plaiful models data list | push | pull (not "${sub}")`);
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
function modelsArchive(ctx, [sub, ...rest]) {
|
|
1890
|
+
if (sub === 'push') return modelsCmd.archivePush(ctx, rest);
|
|
1891
|
+
if (sub === 'pull') return modelsCmd.archivePull(ctx, rest);
|
|
1892
|
+
if (!sub || sub === 'list') return modelsCmd.archiveList(ctx, rest);
|
|
1893
|
+
throw new UsageError(`plaiful models archive list | push | pull (not "${sub}")`);
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
function modelsTrain(ctx, [sub, ...rest]) {
|
|
1897
|
+
const run = { check: trainCmd.check, submit: trainCmd.submit, list: trainCmd.list, status: trainCmd.status, logs: trainCmd.logs, fetch: trainCmd.fetch, cancel: trainCmd.cancel }[sub || 'list'];
|
|
1898
|
+
if (!run) throw new UsageError(`plaiful models train check | submit | list | status | logs | fetch | cancel (not "${sub}")`);
|
|
1899
|
+
return run(ctx, rest);
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
// ── Clone and .env (the New-Game Flow) ───────────────────────────────────────────────────────────────────────────
|
|
1903
|
+
|
|
1904
|
+
/** The game template's .env variables (plaiful-kit packages/client config.ts ENV_KEYS) ← the client config. */
|
|
1905
|
+
const ENV_FROM_CONFIG = {
|
|
1906
|
+
VITE_PLAIFUL_PRODUCT: (c) => c.productId,
|
|
1907
|
+
VITE_PLAIFUL_ENV: (c) => c.environment,
|
|
1908
|
+
VITE_PLAIFUL_API_BASE: (c) => c.apiBaseUrl,
|
|
1909
|
+
VITE_PLAIFUL_CDN_BASE: (c) => c.assetCdnUrl,
|
|
1910
|
+
VITE_FIREBASE_PROJECT_ID: (c) => c.firebase && c.firebase.projectId,
|
|
1911
|
+
VITE_FIREBASE_API_KEY: (c) => c.firebase && c.firebase.webApiKey,
|
|
1912
|
+
VITE_FIREBASE_AUTH_DOMAIN: (c) => c.firebase && c.firebase.authDomain,
|
|
1913
|
+
VITE_PLAIFUL_OVID_BASE: (c) => c.ovidApiUrl,
|
|
1914
|
+
VITE_PLAIFUL_PRISM_WS_URL: (c) => c.prismWsUrl,
|
|
1915
|
+
VITE_PLAIFUL_ANALYTICS_INGEST: (c) => c.analyticsIngestUrl,
|
|
1916
|
+
VITE_PLAIFUL_ANALYTICS_KEY: (c, game) => game.analytics_ingest_key,
|
|
1917
|
+
};
|
|
1918
|
+
const ENV_FILE = '.env.development';
|
|
1919
|
+
// "(pending)", "(not deployed ...)" and "<...>" placeholders aren't values (the template's config.ts treats them as missing).
|
|
1920
|
+
const usable = (v) => typeof v === 'string' && v !== '' && !/^\(|not deployed|^</.test(v);
|
|
1921
|
+
|
|
1922
|
+
/**
|
|
1923
|
+
* Write .env.development in `root` from the game's dev client config: start from the file as it is (or the
|
|
1924
|
+
* template's .env.development.example), set the variables the platform knows, keep every other line.
|
|
1925
|
+
* → { file, set: [names], missing: [names] } or null when the repo has neither file (not the web template).
|
|
1926
|
+
*/
|
|
1927
|
+
function writeEnv(root, game) {
|
|
1928
|
+
const file = path.join(root, ENV_FILE);
|
|
1929
|
+
const example = path.join(root, `${ENV_FILE}.example`);
|
|
1930
|
+
const base = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : fs.existsSync(example) ? fs.readFileSync(example, 'utf8') : null;
|
|
1931
|
+
if (base === null) return null;
|
|
1932
|
+
const set = [];
|
|
1933
|
+
const missing = [];
|
|
1934
|
+
const lines = base.split(/\r?\n/).map((line) => {
|
|
1935
|
+
const m = /^\s*([A-Z0-9_]+)\s*=(.*)$/.exec(line);
|
|
1936
|
+
if (!m || !ENV_FROM_CONFIG[m[1]]) return line;
|
|
1937
|
+
const v = ENV_FROM_CONFIG[m[1]](game.client_config || {}, game);
|
|
1938
|
+
if (!usable(v)) { if (!m[2].trim()) missing.push(m[1]); return line; }
|
|
1939
|
+
set.push(m[1]);
|
|
1940
|
+
return `${m[1]}=${v}`;
|
|
1941
|
+
});
|
|
1942
|
+
fs.writeFileSync(file, lines.join('\n'));
|
|
1943
|
+
return { file, set, missing };
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
function envLines(env, game) {
|
|
1947
|
+
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)`];
|
|
1948
|
+
const out = [` ${ENV_FILE}: ${env.set.length} value(s) from your dev client config`];
|
|
1949
|
+
if (env.missing.length) {
|
|
1950
|
+
const why = game.analytics_ingest_key_note && env.missing.includes('VITE_PLAIFUL_ANALYTICS_KEY') ? ` (the analytics key: ${game.analytics_ingest_key_note})` : '';
|
|
1951
|
+
out.push(` ! still empty: ${env.missing.join(', ')}${why}`);
|
|
1952
|
+
}
|
|
1953
|
+
return out;
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
async function envCmd(ctx) {
|
|
1957
|
+
const r = repo(ctx);
|
|
1958
|
+
const { data } = await ctx.call('GET', `/partner/${encodeURIComponent(r.product)}/game`);
|
|
1959
|
+
const env = writeEnv(r.root, data);
|
|
1960
|
+
if (!env) throw new UsageError(`no ${ENV_FILE} or ${ENV_FILE}.example in ${r.root}: this repo isn't the web game template`);
|
|
1961
|
+
ctx.out([`${r.product} (dev):`, ...envLines(env, data)].join('\n'), { success: true, ...env });
|
|
1962
|
+
return 0;
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
async function clone(ctx, [productArg, dirArg]) {
|
|
1966
|
+
let product = productArg || ctx.flags.product;
|
|
1967
|
+
if (!product) {
|
|
1968
|
+
const { data } = await ctx.call('GET', '/partner/whoami');
|
|
1969
|
+
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>)`);
|
|
1970
|
+
product = data.products[0].product_id;
|
|
1971
|
+
}
|
|
1972
|
+
const { data: game } = await ctx.call('GET', `/partner/${encodeURIComponent(product)}/game`);
|
|
1973
|
+
if (!game.clone_url) throw new ApiError(409, { error: `${product} has no repo to clone yet: ${game.summary}`, code: 'no_repo' });
|
|
1974
|
+
const repoLabel = (game.game_repo && game.game_repo.repo) || game.clone_url;
|
|
1975
|
+
const repoName = String((game.game_repo && game.game_repo.repo) || product).split('/').pop().replace(/\.git$/, '');
|
|
1976
|
+
const dir = path.resolve(ctx.io.cwd(), dirArg || repoName);
|
|
1977
|
+
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>`);
|
|
1978
|
+
ctx.io.stderr.write(`Cloning ${game.clone_url} into ${dir}...\n`);
|
|
1979
|
+
const git = ctx.io.run('git', ['clone', game.clone_url, dir], { cwd: ctx.io.cwd() });
|
|
1980
|
+
if (git.status !== 0) {
|
|
1981
|
+
throw new ApiError(1, {
|
|
1982
|
+
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).`,
|
|
1983
|
+
code: 'clone_failed',
|
|
1984
|
+
});
|
|
1985
|
+
}
|
|
1986
|
+
const rel = path.relative(ctx.io.cwd(), dir) || '.';
|
|
1987
|
+
const steps = [`Cloned ${repoLabel} into ${rel}.`];
|
|
1988
|
+
const existing = config.findRepoConfig(dir);
|
|
1989
|
+
const own = existing && existing.root === dir ? existing.config : null;
|
|
1990
|
+
if (!own) config.writeRepoConfig(dir, { product, env: 'dev', docsDir: config.DEFAULT_DOCS_DIR });
|
|
1991
|
+
const made = makeLayout(dir, product, (own && own.docsDir) || config.DEFAULT_DOCS_DIR);
|
|
1992
|
+
if (made.length) steps.push(`Made ${made.length} folder(s) your files go in: ${made.join(', ')}`);
|
|
1993
|
+
const r = { product, root: dir, docsDir: path.resolve(dir, (own && own.docsDir) || config.DEFAULT_DOCS_DIR) };
|
|
1994
|
+
steps.push(...envLines(writeEnv(dir, game), game));
|
|
1995
|
+
await docsPull({ ...ctx, out: () => {} }, r);
|
|
1996
|
+
steps.push(` ${path.relative(dir, r.docsDir).replace(/\\/g, '/')}: the onboarding docs and client-config.md`);
|
|
1997
|
+
if (fs.existsSync(path.join(dir, 'package.json')) && !ctx.flags['no-install']) {
|
|
1998
|
+
ctx.io.stderr.write('npm install...\n');
|
|
1999
|
+
const npm = ctx.io.run('npm', ['install'], { cwd: dir });
|
|
2000
|
+
steps.push(npm.status === 0 ? ' npm install: done'
|
|
2001
|
+
: ' ! npm install failed. The @plaiful packages need npm access to the plaiful org (npm login; ask Plaiful), then run npm install there.');
|
|
2002
|
+
}
|
|
2003
|
+
if (!ctx.flags['no-open']) {
|
|
2004
|
+
const zed = ctx.io.run('zed', [dir], { cwd: dir, detached: true });
|
|
2005
|
+
steps.push(zed.status === 0 ? ' opened in Zed' : ' open it in your editor (Zed isn\'t installed)');
|
|
2006
|
+
}
|
|
2007
|
+
steps.push(`Next: cd ${rel}, npm run dev. docs/plaiful/README.md is the guide.`);
|
|
2008
|
+
ctx.out(steps.join('\n'), { success: true, product, dir, clone_url: game.clone_url, game_repo: game.game_repo });
|
|
2009
|
+
return 0;
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
const COMMANDS = {
|
|
2013
|
+
login: (ctx) => login(ctx),
|
|
2014
|
+
logout: (ctx) => logout(ctx),
|
|
2015
|
+
whoami: (ctx) => whoami(ctx),
|
|
2016
|
+
promote: (ctx, rest) => promote(ctx, rest),
|
|
2017
|
+
init: (ctx, rest) => init(ctx, rest),
|
|
2018
|
+
'docs pull': (ctx) => docsPull(ctx),
|
|
2019
|
+
'docs read': (ctx, rest) => docsRead(ctx, rest),
|
|
2020
|
+
'docs search': (ctx, rest) => docsSearch(ctx, rest),
|
|
2021
|
+
'docs changes': (ctx) => docsChanges(ctx),
|
|
2022
|
+
docs: (ctx, rest) => {
|
|
2023
|
+
if (rest.length) throw new UsageError(`plaiful docs, or docs read | search | changes | pull (not "${rest[0]}")`);
|
|
2024
|
+
return docsList(ctx);
|
|
2025
|
+
},
|
|
2026
|
+
mcp: (ctx) => require('./mcp').serve(ctx),
|
|
2027
|
+
'ovid check': (ctx, rest) => ovidCheck(ctx, rest),
|
|
2028
|
+
'ovid publish': (ctx, rest) => ovidPublish(ctx, rest),
|
|
2029
|
+
'ovid show': (ctx) => ovidShow(ctx),
|
|
2030
|
+
'hermes strategy': (ctx, [sub, ...rest]) => {
|
|
2031
|
+
if (sub === 'check') return hermesStrategyCheck(ctx, rest);
|
|
2032
|
+
if (sub === 'publish') return hermesStrategyPublish(ctx, rest);
|
|
2033
|
+
return hermesStrategyShow(ctx, sub ? [sub, ...rest] : []);
|
|
2034
|
+
},
|
|
2035
|
+
'studio list': (ctx, rest) => studioList(ctx, rest),
|
|
2036
|
+
'studio show': (ctx, rest) => studioShow(ctx, rest),
|
|
2037
|
+
'studio invite': (ctx, rest) => studioInvite(ctx, rest),
|
|
2038
|
+
'studio invites': (ctx, rest) => studioInvites(ctx, rest),
|
|
2039
|
+
'studio resend': (ctx, rest) => studioResend(ctx, rest),
|
|
2040
|
+
'studio cancel': (ctx, rest) => studioCancel(ctx, rest),
|
|
2041
|
+
'studio set': (ctx, rest) => studioSet(ctx, rest),
|
|
2042
|
+
'studio remove': (ctx, rest) => studioRemove(ctx, rest),
|
|
2043
|
+
'studio audit': (ctx, rest) => studioAudit(ctx, rest),
|
|
2044
|
+
studio: (ctx, rest) => {
|
|
2045
|
+
if (rest.length) throw new UsageError(`plaiful studio, or studio list | show | invite | invites | resend | cancel | set | remove | audit (not "${rest[0]}")`);
|
|
2046
|
+
return studioShow(ctx, []);
|
|
2047
|
+
},
|
|
2048
|
+
seed: (ctx, [store, ...paths]) => seedStore(ctx, store, paths),
|
|
2049
|
+
status: (ctx) => status(ctx),
|
|
2050
|
+
lists: (ctx, rest) => lists(ctx, rest),
|
|
2051
|
+
agents: (ctx, rest) => agents(ctx, rest),
|
|
2052
|
+
records: (ctx, rest) => records(ctx, rest),
|
|
2053
|
+
'midas pricing': (ctx, rest) => midasPricing(ctx, rest),
|
|
2054
|
+
'midas check': (ctx, rest) => midasCheck(ctx, rest),
|
|
2055
|
+
'midas publish': (ctx, rest) => midasPublish(ctx, rest),
|
|
2056
|
+
'midas show': (ctx) => midasShow(ctx),
|
|
2057
|
+
'midas health': (ctx) => midasHealth(ctx),
|
|
2058
|
+
'midas balance': (ctx) => midasBalance(ctx),
|
|
2059
|
+
'midas proposals': (ctx) => midasProposals(ctx),
|
|
2060
|
+
'midas assess': (ctx) => midasAssess(ctx),
|
|
2061
|
+
'midas wallet': (ctx, rest) => midasWallet(ctx, rest),
|
|
2062
|
+
'midas ledger': (ctx, rest) => midasLedger(ctx, rest),
|
|
2063
|
+
quests: (ctx, rest) => quests(ctx, rest),
|
|
2064
|
+
assets: (ctx, rest) => assets(ctx, rest),
|
|
2065
|
+
lore: (ctx, rest) => lore(ctx, rest),
|
|
2066
|
+
world: (ctx, rest) => world(ctx, rest),
|
|
2067
|
+
'events edit': (ctx, rest) => eventsEdit(ctx, rest),
|
|
2068
|
+
'events delete': (ctx, rest) => eventsDelete(ctx, rest),
|
|
2069
|
+
canon: (ctx, rest) => canon(ctx, rest),
|
|
2070
|
+
'events script': (ctx, rest) => eventsScript(ctx, rest),
|
|
2071
|
+
'events storyboard': (ctx, rest) => eventsStoryboard(ctx, rest),
|
|
2072
|
+
'animation sets': (ctx, rest) => animationSets(ctx, rest),
|
|
2073
|
+
'animation run': (ctx, rest) => animationRun(ctx, rest),
|
|
2074
|
+
'styles images': (ctx, rest) => styleImages(ctx, rest),
|
|
2075
|
+
styles: (ctx, rest) => styles(ctx, rest),
|
|
2076
|
+
'models check': (ctx, rest) => modelsCmd.publish(ctx, rest, { apply: false }),
|
|
2077
|
+
'models publish': (ctx, rest) => modelsCmd.publish(ctx, rest, { apply: true }),
|
|
2078
|
+
'models list': (ctx, rest) => modelsCmd.list(ctx, rest),
|
|
2079
|
+
'models show': (ctx, rest) => modelsCmd.show(ctx, rest),
|
|
2080
|
+
'models status': (ctx, rest) => modelsCmd.status(ctx, rest),
|
|
2081
|
+
'models pull': (ctx, rest) => modelsCmd.pull(ctx, rest),
|
|
2082
|
+
'models data': (ctx, rest) => modelsData(ctx, rest),
|
|
2083
|
+
'models archive': (ctx, rest) => modelsArchive(ctx, rest),
|
|
2084
|
+
'models train': (ctx, rest) => modelsTrain(ctx, rest),
|
|
2085
|
+
models: (ctx, rest) => modelsCmd.list(ctx, rest),
|
|
2086
|
+
upload: (ctx, files) => upload(ctx, files),
|
|
2087
|
+
clone: (ctx, rest) => clone(ctx, rest),
|
|
2088
|
+
env: (ctx) => envCmd(ctx),
|
|
2089
|
+
};
|
|
2090
|
+
|
|
2091
|
+
function defaultIo() {
|
|
2092
|
+
return {
|
|
2093
|
+
fetch: (...a) => fetch(...a),
|
|
2094
|
+
stdout: process.stdout,
|
|
2095
|
+
stderr: process.stderr,
|
|
2096
|
+
cwd: () => process.cwd(),
|
|
2097
|
+
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
2098
|
+
// A yes/no question (`plaiful studio remove`), only in a terminal: elsewhere the command needs --yes.
|
|
2099
|
+
ask: process.stdin.isTTY ? (question) => new Promise((resolve) => {
|
|
2100
|
+
const rl = require('readline').createInterface({ input: process.stdin, output: process.stderr });
|
|
2101
|
+
rl.question(question, (answer) => { rl.close(); resolve(answer); });
|
|
2102
|
+
}) : undefined,
|
|
2103
|
+
// git, npm and zed for `plaiful clone`, attached to the terminal so their output and prompts show. → { status }
|
|
2104
|
+
run: (cmd, args, { cwd, detached = false } = {}) => {
|
|
2105
|
+
const shell = process.platform === 'win32'; // npm and zed are .cmd shims on Windows
|
|
2106
|
+
try {
|
|
2107
|
+
if (detached) {
|
|
2108
|
+
const probe = spawnSync(cmd, ['--version'], { shell, stdio: 'ignore' });
|
|
2109
|
+
if (probe.status !== 0) return { status: probe.status === null ? 1 : probe.status };
|
|
2110
|
+
spawn(cmd, args, { cwd, shell, stdio: 'ignore', detached: true }).on('error', () => {}).unref();
|
|
2111
|
+
return { status: 0 };
|
|
2112
|
+
}
|
|
2113
|
+
const r = spawnSync(cmd, args, { cwd, shell, stdio: 'inherit' });
|
|
2114
|
+
return { status: r.status === null ? 1 : r.status };
|
|
2115
|
+
} catch { return { status: 1 }; }
|
|
2116
|
+
},
|
|
2117
|
+
// gcloud for `plaiful models train`: its output captured (or shown, with `inherit`). On Windows gcloud is a .cmd,
|
|
2118
|
+
// which needs a shell, so arguments with spaces are quoted. → { status, stdout, stderr }
|
|
2119
|
+
exec: (cmd, args, { inherit = false } = {}) => {
|
|
2120
|
+
const shell = process.platform === 'win32';
|
|
2121
|
+
const argv = shell ? args.map((a) => (/^[A-Za-z0-9_./:=@,-]+$/.test(a) ? a : `"${String(a).replace(/"/g, '\\"')}"`)) : args;
|
|
2122
|
+
try {
|
|
2123
|
+
const r = spawnSync(cmd, argv, { shell, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: inherit ? 'inherit' : 'pipe' });
|
|
2124
|
+
return { status: r.status === null ? 1 : r.status, stdout: r.stdout || '', stderr: r.stderr || '' };
|
|
2125
|
+
} catch (e) { return { status: 1, stdout: '', stderr: e.message }; }
|
|
2126
|
+
},
|
|
2127
|
+
openUrl: (url) => {
|
|
2128
|
+
const [cmd, args] = process.platform === 'win32' ? ['rundll32', ['url.dll,FileProtocolHandler', url]]
|
|
2129
|
+
: process.platform === 'darwin' ? ['open', [url]] : ['xdg-open', [url]];
|
|
2130
|
+
try { spawn(cmd, args, { stdio: 'ignore', detached: true }).on('error', () => {}).unref(); } catch { /* print-only */ }
|
|
2131
|
+
},
|
|
2132
|
+
};
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
async function main(argv, io = defaultIo()) {
|
|
2136
|
+
let flags = {};
|
|
2137
|
+
try {
|
|
2138
|
+
const parsed = parse(argv);
|
|
2139
|
+
flags = parsed.flags;
|
|
2140
|
+
if (flags.version) { io.stdout.write(`${version}\n`); return 0; }
|
|
2141
|
+
const [a, b, ...rest] = parsed.args;
|
|
2142
|
+
if (flags.help || !a || a === 'help') { io.stdout.write(`${HELP}\n`); return 0; }
|
|
2143
|
+
const two = COMMANDS[`${a} ${b}`];
|
|
2144
|
+
const one = COMMANDS[a];
|
|
2145
|
+
const ctx = makeContext(io, flags);
|
|
2146
|
+
if (two) return await two(ctx, rest);
|
|
2147
|
+
if (one && !['ovid', 'midas', 'events', 'animation'].includes(a)) return await one(ctx, b === undefined ? rest : [b, ...rest]);
|
|
2148
|
+
throw new UsageError(`unknown command "${parsed.args.join(' ')}"`);
|
|
2149
|
+
} catch (e) {
|
|
2150
|
+
if (e instanceof UsageError) {
|
|
2151
|
+
io.stderr.write(`plaiful: ${e.message}\n(plaiful help lists the commands)\n`);
|
|
2152
|
+
return 2;
|
|
2153
|
+
}
|
|
2154
|
+
if (e instanceof ApiError) {
|
|
2155
|
+
if (flags.json) io.stdout.write(`${JSON.stringify({ success: false, status: e.status, ...(e.body || {}), error: e.message }, null, 2)}\n`);
|
|
2156
|
+
else io.stderr.write(`plaiful: ${e.message}\n`);
|
|
2157
|
+
return 1;
|
|
2158
|
+
}
|
|
2159
|
+
io.stderr.write(`plaiful: ${e.stack || e.message}\n`);
|
|
2160
|
+
return 1;
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
module.exports = { main, parse };
|