recess-cli 3.28.0 → 3.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -143,8 +143,197 @@ function requireAnyFlag(parsed, names) {
143
143
  throw new CliError("invalid_arguments", `Pass at least one of ${names.map((name) => `--${name}`).join(", ")}.`);
144
144
  }
145
145
  }
146
+ /**
147
+ * The kid-config field a `--path` names (guardian aliases like `texts.me`
148
+ * resolved, `.subKey` allowed), refused when locked or read-only. Its
149
+ * `confirm` says whether `set` applies at once or previews first.
150
+ */
151
+ function pickConfigField(view, raw, scope) {
152
+ const ids = view.aliases ?? {};
153
+ const path = raw
154
+ .trim()
155
+ .split(".")
156
+ .map((part) => ids[part.toLowerCase()] ?? part)
157
+ .join(".");
158
+ const field = view.fields.find((candidate) => candidate.path === path) ??
159
+ view.fields
160
+ .filter((candidate) => path.startsWith(`${candidate.path}.`))
161
+ .sort((a, b) => b.path.length - a.path.length)[0];
162
+ if (!field) {
163
+ throw new CliError("unknown_path", `No ${scope} setting "${raw}". Read \`${scope} config\` for the paths; never guess one.`);
164
+ }
165
+ if (field.locked) {
166
+ throw new CliError("locked", `${field.label} is locked by ${field.locked.byName ?? "the kid's guide"}. Nothing was changed.`);
167
+ }
168
+ if (!field.editable) {
169
+ throw new CliError("read_only", `${field.label}: ${field.reason ?? "read-only here."} Nothing was changed.`);
170
+ }
171
+ return field;
172
+ }
173
+ /** A config write's outcome without the refreshed view. */
174
+ function configWriteResult(set, who) {
175
+ return {
176
+ status: set.result.status,
177
+ ...who,
178
+ whatChanged: set.result.whatChanged,
179
+ changeId: set.result.changeId,
180
+ change: set.change ?? null,
181
+ };
182
+ }
183
+ const ISO_WITH_OFFSET = /[zZ]|[+-]\d{2}:?\d{2}$/;
184
+ /**
185
+ * A kid's progress without the per-skill squares (a few hundred KB on a big
186
+ * skill map): per subject the on-track numbers, topic counts, and challenges.
187
+ */
188
+ function compactProgress(body) {
189
+ const topics = (list) => list.map(({ title, mastered, total }) => ({ title, mastered, total }));
190
+ const challenges = (list) => list.map((c) => ({
191
+ id: c.id,
192
+ title: c.title,
193
+ status: c.status,
194
+ progressPercent: c.progressPercent,
195
+ estFinishDate: c.estFinishDate,
196
+ }));
197
+ return {
198
+ headline: body.headline,
199
+ subjects: body.subjects.map((s) => ({
200
+ key: s.key,
201
+ label: s.label,
202
+ grade: s.grade,
203
+ percent: s.percent,
204
+ expectedPercent: s.expectedPercent,
205
+ weeksAhead: s.weeksAhead,
206
+ status: s.status,
207
+ finishDate: s.finishDate,
208
+ pacePerWeek: s.pacePerWeek,
209
+ newThisWeek: s.newThisWeek.map((skill) => skill.title),
210
+ topics: topics(s.topics),
211
+ challenges: challenges(s.challenges),
212
+ })),
213
+ exploring: body.exploring.map((area) => ({
214
+ key: area.key,
215
+ label: area.label,
216
+ skills: area.skills,
217
+ newThisWeek: area.newThisWeek.map((skill) => skill.title),
218
+ topics: topics(area.topics),
219
+ challenges: challenges(area.challenges),
220
+ })),
221
+ };
222
+ }
223
+ const short = (text, max) => text.length > max ? `${text.slice(0, max - 1)}…` : text;
224
+ /**
225
+ * Library challenges one kid (or, without `kidId`, you) can join here: the
226
+ * kid's For you picks or a search, filtered to the ones `join-challenge`
227
+ * accepts (visible to them, a fixed setup). Compact: at most 6.
228
+ */
229
+ async function browseChallenges(api, input) {
230
+ const { kidId, query } = input;
231
+ const listed = query
232
+ ? unwrap(await api.client.GET("/ai/goal-templates/", {
233
+ params: {
234
+ query: {
235
+ query,
236
+ view: "card",
237
+ limit: 6,
238
+ ...(kidId ? { studentId: kidId } : {}),
239
+ },
240
+ },
241
+ })).items
242
+ : unwrap(await api.client.GET("/ai/goal-templates/for-you", {
243
+ params: { query: kidId ? { studentId: kidId } : {} },
244
+ })).items;
245
+ const ids = listed.map((item) => item.id);
246
+ const joinable = ids.length
247
+ ? new Set(unwrap(await api.client.GET("/parent-v2/challenges/joinable/", {
248
+ params: {
249
+ query: { ids: ids.join(","), ...(kidId ? { kidId } : {}) },
250
+ },
251
+ })).ids)
252
+ : new Set();
253
+ const items = listed.filter((item) => joinable.has(item.id)).slice(0, 6);
254
+ if (items.length === 0)
255
+ return {
256
+ challenges: [],
257
+ note: input.forKid
258
+ ? "Nothing joinable here for that. Their guide can set one up, if the parent wants."
259
+ : "Nothing joinable here for that.",
260
+ };
261
+ return {
262
+ challenges: items.map((item) => ({
263
+ id: item.id,
264
+ title: item.title,
265
+ emoji: item.emoji ?? null,
266
+ description: item.description ? short(item.description, 140) : null,
267
+ category: item.category ?? null,
268
+ reason: "reason" in item ? item.reason : null,
269
+ alreadyIn: item.participationStatus ?? null,
270
+ })),
271
+ };
272
+ }
273
+ /** `join-challenge` for a kid or yourself: the needs-answers / already-in shapes. */
274
+ function joinOutcome(result, who) {
275
+ if (result.status === "needs_answers") {
276
+ return {
277
+ status: "needs_answers",
278
+ questions: result.steps.map((step) => ({
279
+ key: step.key,
280
+ kind: step.kind,
281
+ label: "label" in step ? (step.label ?? null) : null,
282
+ })),
283
+ note: `Answer these, then run it again with --answers '{"<key>": <value>}'. Nothing was added yet.`,
284
+ };
285
+ }
286
+ if (result.alreadyJoined && !result.restored) {
287
+ return {
288
+ status: "no_change",
289
+ reason: `${who} already in "${result.template.title}".`,
290
+ goalId: result.goalId,
291
+ };
292
+ }
293
+ return result;
294
+ }
295
+ function parseAnswers(parsed) {
296
+ const answersText = flagString(parsed, "answers");
297
+ if (answersText === undefined)
298
+ return undefined;
299
+ let answers;
300
+ try {
301
+ answers = JSON.parse(answersText);
302
+ }
303
+ catch {
304
+ answers = undefined;
305
+ }
306
+ if (!answers || typeof answers !== "object" || Array.isArray(answers)) {
307
+ throw new CliError("invalid_arguments", "--answers must be a JSON object.");
308
+ }
309
+ return answers;
310
+ }
311
+ function repeatBody(parsed) {
312
+ const title = flagString(parsed, "title", { required: true }).trim();
313
+ if (!title || title.length > 200)
314
+ throw new CliError("invalid_arguments", "--title must be 1-200 characters.");
315
+ const days = flagString(parsed, "days", { required: true }).trim();
316
+ const weeks = flagInteger(parsed, "weeks", { min: 1, max: 4 });
317
+ const start = flagDate(parsed, "start");
318
+ const minutes = flagInteger(parsed, "minutes", { min: 1, max: 600 });
319
+ const url = flagString(parsed, "url")?.trim();
320
+ if (url !== undefined && !/^https?:\/\/\S+$/.test(url)) {
321
+ throw new CliError("invalid_arguments", "--url must be an http(s) URL.");
322
+ }
323
+ return {
324
+ title,
325
+ days,
326
+ ...(weeks !== undefined ? { weeks } : {}),
327
+ ...(start !== undefined ? { start } : {}),
328
+ ...(minutes !== undefined ? { minutes } : {}),
329
+ ...(url !== undefined ? { url } : {}),
330
+ };
331
+ }
146
332
  export async function runFamilyCommand({ parsed, api, writeCommand, }) {
147
333
  const verb = parsed.positionals[1];
334
+ // Undoable writes logged to the family change log apply at once, like
335
+ // Parent Rocky (undo: `family undo`); everything else previews first.
336
+ const writeNow = (p, preview, execute) => writeCommand(p, preview, execute, { ungated: true });
148
337
  if (verb === "kids") {
149
338
  // School families see no money here: drop credits and membership pricing.
150
339
  const kids = await listFamilyKids(api);
@@ -315,6 +504,59 @@ export async function runFamilyCommand({ parsed, api, writeCommand, }) {
315
504
  if (verb === "guardians") {
316
505
  return unwrap(await api.client.GET("/family/guardians/"));
317
506
  }
507
+ if (verb === "changes") {
508
+ const kid = hasFlag(parsed, "student")
509
+ ? await resolveFamilyKid(api, parsed)
510
+ : undefined;
511
+ return unwrap(await api.client.GET("/parent-v2/change-log/", {
512
+ params: { query: kid ? { studentId: kid.id } : {} },
513
+ }));
514
+ }
515
+ if (verb === "undo") {
516
+ // No --change: your own most recent undoable change (last 7 days).
517
+ const changeId = flagUuid(parsed, "change");
518
+ return writeCommand(parsed, {
519
+ action: changeId
520
+ ? "undo one family change"
521
+ : "undo your most recent change",
522
+ target: { change: changeId ?? "latest" },
523
+ request: {},
524
+ details: {
525
+ consequence: "Puts that change back the way it was (from family changes); the undo is logged too.",
526
+ },
527
+ }, async () => changeId
528
+ ? unwrap(await api.client.POST("/parent-v2/change-log/{id}/undo/", {
529
+ params: { path: { id: changeId } },
530
+ }))
531
+ : unwrap(await api.client.POST("/parent-v2/change-log/undo-latest/")), {
532
+ ungated: true,
533
+ // A later --confirm rerun of the undone write applies it again.
534
+ undoneChange: (result) => result.id,
535
+ });
536
+ }
537
+ if (verb === "billing") {
538
+ return unwrap(await api.client.GET("/parent-v2/billing/"));
539
+ }
540
+ if (verb === "billing-link") {
541
+ return {
542
+ url: `${api.config.webOrigin}/ai/settings/billing`,
543
+ note: "Opens the billing page (cards, plan) once they're signed in; it is not a pre-signed link.",
544
+ };
545
+ }
546
+ if (verb === "calendar") {
547
+ return unwrap(await api.client.GET("/parent-v2/calendar/"));
548
+ }
549
+ if (verb === "login-link") {
550
+ // Sends an email; nothing in the family changes, so no confirm.
551
+ return writeNow(parsed, {
552
+ action: "email you a fresh sign-in link and code",
553
+ target: { user: "@me" },
554
+ request: {},
555
+ details: {
556
+ consequence: "An email to your own address with a sign-in link and code; nothing changes.",
557
+ },
558
+ }, async () => unwrap(await api.client.POST("/parent-v2/login-link/")));
559
+ }
318
560
  if (verb === "school-classes") {
319
561
  return unwrap(await api.client.GET("/family/school-classes"));
320
562
  }
@@ -406,18 +648,306 @@ export async function runFamilyCommand({ parsed, api, writeCommand, }) {
406
648
  },
407
649
  }, async () => unwrap(await api.client.POST("/family/school-classes/register", { body })));
408
650
  }
409
- throw new CliError("invalid_arguments", "Use family kids|today|schedule|tutor|account|set-name|set-notifications|set-phone|set-timezone|guardians|school-classes|school-class-options|drop-class|restore-class|swap-class|register-class.");
651
+ if (verb === "remind") {
652
+ const at = flagString(parsed, "at", { required: true }).trim();
653
+ const offset = ISO_WITH_OFFSET.test(at);
654
+ if (!offset && !/^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}$/.test(at)) {
655
+ throw new CliError("invalid_arguments", '--at must be "YYYY-MM-DD HH:mm" in your timezone.');
656
+ }
657
+ const text = flagString(parsed, "body", { required: true }).trim();
658
+ if (!text)
659
+ throw new CliError("invalid_arguments", "--body cannot be empty.");
660
+ const kid = hasFlag(parsed, "student")
661
+ ? await resolveFamilyKid(api, parsed)
662
+ : undefined;
663
+ const body = {
664
+ body: text,
665
+ ...(offset ? { sendAt: at } : { at }),
666
+ ...(kid ? { studentId: kid.id } : {}),
667
+ };
668
+ return writeNow(parsed, {
669
+ action: `text you "${text}" at ${at}`,
670
+ target: { user: "@me", ...(kid ? kidTarget(kid) : {}) },
671
+ request: body,
672
+ details: {
673
+ consequence: "Rocky texts you then (your timezone). Cancel with family cancel-reminder or family undo.",
674
+ },
675
+ }, async () => unwrap(await api.client.POST("/parent-v2/reminders/", { body })));
676
+ }
677
+ if (verb === "reminders") {
678
+ return unwrap(await api.client.GET("/parent-v2/reminders/"));
679
+ }
680
+ if (verb === "cancel-reminder") {
681
+ const id = flagUuid(parsed, "reminder", { required: true });
682
+ return writeNow(parsed, {
683
+ action: "cancel one of your upcoming reminders",
684
+ target: { reminder: id },
685
+ request: {},
686
+ details: { consequence: "It won't be texted (undo: family undo)." },
687
+ }, async () => unwrap(await api.client.DELETE("/parent-v2/reminders/{id}/", {
688
+ params: { path: { id } },
689
+ })));
690
+ }
691
+ if (verb === "config") {
692
+ const view = unwrap(await api.client.GET("/kid-config/family/", {
693
+ params: { query: { surface: "parent", format: "lines" } },
694
+ }));
695
+ return {
696
+ settings: view.lines ?? "",
697
+ change: "family set --path <path> --value <value>",
698
+ };
699
+ }
700
+ if (verb === "set") {
701
+ const raw = flagString(parsed, "path", { required: true });
702
+ const value = flagString(parsed, "value", { required: true });
703
+ const field = pickConfigField(unwrap(await api.client.GET("/kid-config/family/", {
704
+ params: { query: { surface: "all", format: "lines" } },
705
+ })), raw, "family");
706
+ const write = field.confirm === "immediate" ? writeNow : writeCommand;
707
+ return write(parsed, {
708
+ action: `change the family's ${field.label.toLowerCase()} to ${value}`,
709
+ target: { family: "@me", path: raw },
710
+ request: { path: raw, value },
711
+ details: {
712
+ before: field.display,
713
+ consequence: "Applies to the whole family (undo: family undo).",
714
+ },
715
+ }, async () => configWriteResult(unwrap(await api.client.PATCH("/kid-config/family/", {
716
+ params: { query: { surface: "parent" } },
717
+ body: { path: raw, value },
718
+ })), {}));
719
+ }
720
+ if (verb === "feedback") {
721
+ const kind = assertChoice(flagString(parsed, "kind", { required: true }).trim().toLowerCase(), ["wrong", "too-much", "wanted", "loved", "cant-do", "other"], "--kind");
722
+ const quote = flagString(parsed, "quote", { required: true }).trim();
723
+ if (!quote)
724
+ throw new CliError("invalid_arguments", "--quote cannot be empty.");
725
+ const about = flagString(parsed, "about")?.trim();
726
+ const kid = hasFlag(parsed, "student")
727
+ ? await resolveFamilyKid(api, parsed)
728
+ : undefined;
729
+ const body = {
730
+ kind,
731
+ quote: quote.slice(0, 2000),
732
+ ...(about ? { about: about.slice(0, 200) } : {}),
733
+ ...(kid ? { studentId: kid.id } : {}),
734
+ };
735
+ // Not a change to the family: nothing to undo, so no confirm.
736
+ return writeNow(parsed, {
737
+ action: `pass on your feedback (${kind})`,
738
+ target: { user: "@me", ...(kid ? kidTarget(kid) : {}) },
739
+ request: body,
740
+ details: { consequence: "The Recess team reads it; nothing changes." },
741
+ }, async () => unwrap(await api.client.POST("/parent-v2/feedback/", { body })));
742
+ }
743
+ if (verb === "pause") {
744
+ const kid = await resolveFamilyKid(api, parsed);
745
+ const pauseWeeks = flagInteger(parsed, "weeks", {
746
+ required: true,
747
+ min: 1,
748
+ max: 6,
749
+ });
750
+ const enrollmentId = flagUuid(parsed, "enrollment");
751
+ const body = {
752
+ kidId: kid.id,
753
+ pauseWeeks,
754
+ ...(enrollmentId ? { enrollmentId } : {}),
755
+ };
756
+ return writeCommand(parsed, {
757
+ action: `pause billing for ${kidName(kid)}'s weekly class${enrollmentId ? "" : "es"} for ${pauseWeeks} week${pauseWeeks === 1 ? "" : "s"}`,
758
+ target: {
759
+ ...kidTarget(kid),
760
+ ...(enrollmentId ? { enrollmentId } : {}),
761
+ },
762
+ request: body,
763
+ details: {
764
+ consequence: "Weekly class subscriptions only: no charges or class reminders from the coming Sunday, then billing restarts on its own (undo: family undo restarts it now).",
765
+ },
766
+ }, async () => unwrap(await api.client.POST("/courses/course-pause-enrollment", { body })));
767
+ }
768
+ if (verb === "add-guardian") {
769
+ const firstName = flagString(parsed, "first-name", {
770
+ required: true,
771
+ }).trim();
772
+ const lastName = flagString(parsed, "last-name")?.trim() || null;
773
+ const email = flagString(parsed, "email", { required: true })
774
+ .trim()
775
+ .toLowerCase();
776
+ if (!firstName || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email))
777
+ throw new CliError("invalid_arguments", "Pass --first-name and a valid --email.");
778
+ const body = { firstName, lastName, email };
779
+ const name = [firstName, lastName].filter(Boolean).join(" ");
780
+ return writeCommand(parsed, {
781
+ action: `add ${name} (${email}) as a guardian on your family`,
782
+ target: { family: "@me", email },
783
+ request: body,
784
+ details: {
785
+ consequence: "They get their own login with full parent access (dashboard, Rocky, settings) and an invite email. It can't be undone here: removing a guardian goes through support.",
786
+ },
787
+ }, async () => unwrap(await api.client.POST("/family/guardians/", { body })));
788
+ }
789
+ if (verb === "context") {
790
+ const kid = hasFlag(parsed, "student")
791
+ ? await resolveFamilyKid(api, parsed)
792
+ : undefined;
793
+ return unwrap(await api.client.GET("/parent-v2/account-context/", {
794
+ params: { query: kid ? { kidId: kid.id } : {} },
795
+ }));
796
+ }
797
+ if (verb === "memory") {
798
+ const sub = parsed.positionals[2];
799
+ if (!sub) {
800
+ const date = flagDate(parsed, "date");
801
+ const query = flagString(parsed, "query")?.trim();
802
+ return unwrap(await api.client.GET("/parent-v2/family-memory/", {
803
+ params: {
804
+ query: {
805
+ recent: 3,
806
+ ...(date ? { date } : {}),
807
+ ...(query ? { query } : {}),
808
+ },
809
+ },
810
+ }));
811
+ }
812
+ const file = flagString(parsed, "in");
813
+ if (sub === "save") {
814
+ const text = flagString(parsed, "text", { required: true }).trim();
815
+ const body = {
816
+ text,
817
+ ...(file
818
+ ? {
819
+ file: assertChoice(file, ["journal", "family", "me"], "--in"),
820
+ }
821
+ : {}),
822
+ };
823
+ // Rocky's notebook, not a family change: forget a line to take it back.
824
+ return writeNow(parsed, {
825
+ action: `save to the family memory (${body.file ?? "journal"}): "${text.slice(0, 80)}"`,
826
+ target: { family: "@me" },
827
+ request: body,
828
+ details: {
829
+ consequence: "One line, with your name on journal entries. Take it back with family memory forget.",
830
+ },
831
+ }, async () => unwrap(await api.client.POST("/parent-v2/family-memory/save/", { body })));
832
+ }
833
+ if (sub === "rewrite") {
834
+ const body = {
835
+ file: assertChoice(file ?? "", ["family", "me"], "--in"),
836
+ text: flagString(parsed, "text", { required: true }).trim(),
837
+ };
838
+ return writeNow(parsed, {
839
+ action: `rewrite the family memory's ${body.file === "family" ? "family.md" : "notes about you"}`,
840
+ target: { family: "@me" },
841
+ request: body,
842
+ details: {
843
+ consequence: "Replaces that file whole (at most 1,500 words); the journal is untouched.",
844
+ },
845
+ }, async () => unwrap(await api.client.POST("/parent-v2/family-memory/rewrite/", {
846
+ body,
847
+ })));
848
+ }
849
+ if (sub === "forget") {
850
+ const date = flagDate(parsed, "date");
851
+ const body = {
852
+ file: assertChoice(file ?? "", ["journal", "family", "me"], "--in"),
853
+ line: flagString(parsed, "line", { required: true }).trim(),
854
+ ...(date ? { date } : {}),
855
+ };
856
+ if (body.file === "journal" && !date)
857
+ throw new CliError("invalid_arguments", "A journal line needs --date YYYY-MM-DD (its day).");
858
+ return writeNow(parsed, {
859
+ action: `forget one line of the family memory (${body.file})`,
860
+ target: { family: "@me" },
861
+ request: body,
862
+ details: { consequence: "That exact line is removed." },
863
+ }, async () => unwrap(await api.client.POST("/parent-v2/family-memory/forget/", { body })));
864
+ }
865
+ throw new CliError("invalid_arguments", "Use family memory [--query TEXT] [--date YYYY-MM-DD] | save | rewrite | forget.");
866
+ }
867
+ if (verb === "message-guide") {
868
+ const text = flagString(parsed, "text", { required: true }).trim();
869
+ if (!text || text.length > 4000)
870
+ throw new CliError("invalid_arguments", "--text must be 1-4000 characters.");
871
+ // Each kid has their own guide: name one unless there's only one.
872
+ const kids = hasFlag(parsed, "student") ? [] : await listFamilyKids(api);
873
+ if (!hasFlag(parsed, "student") && kids.length !== 1)
874
+ throw new CliError("ambiguous_student", "Pass --student: each kid has their own guide.", 1, { candidates: kids.map((k) => ({ id: k.id, name: kidName(k) })) });
875
+ const kid = hasFlag(parsed, "student")
876
+ ? await resolveFamilyKid(api, parsed)
877
+ : kids[0];
878
+ const body = { text, studentId: kid.id };
879
+ return writeCommand(parsed, {
880
+ action: `message ${kidName(kid)}'s guide: "${text.slice(0, 120)}"`,
881
+ target: { family: "@me", ...kidTarget(kid) },
882
+ request: body,
883
+ details: {
884
+ consequence: "The guide gets it on Slack and in your chat with them in the Recess app, and answers there. It can't be unsent.",
885
+ },
886
+ }, async () => unwrap(await api.client.POST("/parent-v2/message-guide/", { body })));
887
+ }
888
+ if (verb === "report-bug") {
889
+ const text = flagString(parsed, "text", { required: true }).trim();
890
+ const summary = flagString(parsed, "summary")?.trim();
891
+ const todoId = flagUuid(parsed, "todo");
892
+ const kid = hasFlag(parsed, "student")
893
+ ? await resolveFamilyKid(api, parsed)
894
+ : undefined;
895
+ const body = {
896
+ text,
897
+ ...(summary ? { summary } : {}),
898
+ ...(kid ? { studentId: kid.id } : {}),
899
+ ...(todoId ? { todoId } : {}),
900
+ };
901
+ // Goes to the engineering team; nothing in the family changes.
902
+ return writeNow(parsed, {
903
+ action: `report a bug to the Recess team: "${(summary ?? text).slice(0, 80)}"`,
904
+ target: { user: "@me", ...(kid ? kidTarget(kid) : {}) },
905
+ request: body,
906
+ details: {
907
+ consequence: "The engineering team gets it; nothing changes.",
908
+ },
909
+ }, async () => unwrap(await api.client.POST("/parent-v2/report-bug/", { body })));
910
+ }
911
+ throw new CliError("invalid_arguments", "Use family kids|today|schedule|tutor|account|set-name|set-notifications|set-phone|set-timezone|guardians|changes|undo|remind|reminders|cancel-reminder|config|set|feedback|pause|add-guardian|billing|billing-link|calendar|login-link|school-classes|school-class-options|drop-class|restore-class|swap-class|register-class|context|memory|message-guide|report-bug.");
410
912
  }
411
913
  export async function runKidCommand({ parsed, api, writeCommand, }) {
412
914
  const verb = parsed.positionals[1];
413
915
  const kid = await resolveFamilyKid(api, parsed);
414
916
  const kidId = kid.id;
415
917
  const name = kidName(kid);
918
+ // Undoable writes logged to the family change log apply at once, like
919
+ // Parent Rocky (undo: `family undo`); everything else previews first.
920
+ const writeNow = (p, preview, execute) => writeCommand(p, preview, execute, { ungated: true });
416
921
  if (verb === "today") {
922
+ // Default day: the kid's local today (the route's own default is UTC's).
417
923
  const date = flagDate(parsed, "date");
418
- return unwrap(await api.client.GET("/parent/kid/{kidId}/today/", {
419
- params: { path: { kidId }, query: date ? { date } : {} },
924
+ const today = unwrap(await api.client.GET("/parent/kid/{kidId}/today/", {
925
+ params: { path: { kidId }, query: date ? { date } : { zone: "kid" } },
420
926
  }));
927
+ // What a reader needs to answer, not the whole dashboard card.
928
+ return {
929
+ date: date ?? today.date ?? null,
930
+ kid: today.kid,
931
+ todos: today.todos.map((todo) => ({
932
+ id: todo.id,
933
+ title: todo.title,
934
+ status: todo.status,
935
+ goalTitle: todo.goalTitle,
936
+ // false = an extra the kid picked, beyond the day's plan.
937
+ required: todo.required,
938
+ minutes: todo.estimatedTimeInMins,
939
+ type: todo.type,
940
+ completedAt: todo.completedAt,
941
+ })),
942
+ stats: today.stats,
943
+ // The day's written update and its wins/struggles.
944
+ summary: {
945
+ text: today.summary.text,
946
+ fullUpdate: today.summary.fullUpdate,
947
+ },
948
+ wins: today.insights.wins,
949
+ struggles: today.insights.struggles,
950
+ };
421
951
  }
422
952
  if (verb === "goals") {
423
953
  return unwrap(await api.client.GET("/parent/kid/{kidId}/goals/", {
@@ -807,19 +1337,40 @@ export async function runKidCommand({ parsed, api, writeCommand, }) {
807
1337
  }
808
1338
  if (verb === "excuse") {
809
1339
  const eventId = flagUuid(parsed, "event", { required: true });
810
- const reason = flagString(parsed, "note")?.trim();
811
- if (reason !== undefined && reason.length > 500) {
1340
+ const note = flagString(parsed, "note")?.trim();
1341
+ if (note !== undefined && note.length > 500) {
812
1342
  throw new CliError("invalid_arguments", "--note must be 500 characters or fewer.");
813
1343
  }
814
- const body = reason ? { reason } : {};
815
- return writeCommand(parsed, {
816
- action: `excuse ${name} from event ${eventId}`,
1344
+ const weekly = hasFlag(parsed, "weekly");
1345
+ const body = {
1346
+ eventId,
1347
+ ...(note ? { note } : {}),
1348
+ ...(weekly ? { weekly } : {}),
1349
+ };
1350
+ return writeNow(parsed, {
1351
+ action: weekly
1352
+ ? `excuse ${name} from that class every week on event ${eventId}'s weekday`
1353
+ : `excuse ${name} from event ${eventId}`,
817
1354
  target: { ...kidTarget(kid), eventId },
818
1355
  request: body,
819
1356
  details: {
820
- consequence: "Attendance is marked EXCUSED and the class's guides are notified (with the note).",
1357
+ consequence: "Attendance is marked EXCUSED (an upcoming session, or one up to 14 days back; --weekly: an upcoming one, and that weekday every week from then) and the class's guides are notified with the note (undo: family undo).",
1358
+ },
1359
+ }, async () => unwrap(await api.client.POST("/parent-v2/kid/{kidId}/class-excuses/", {
1360
+ params: { path: { kidId } },
1361
+ body,
1362
+ })));
1363
+ }
1364
+ if (verb === "unexcuse-weekly") {
1365
+ const eventId = flagUuid(parsed, "event", { required: true });
1366
+ return writeNow(parsed, {
1367
+ action: `stop ${name}'s weekly excuse for event ${eventId}'s class and weekday`,
1368
+ target: { ...kidTarget(kid), eventId },
1369
+ request: { eventId },
1370
+ details: {
1371
+ consequence: "That weekday stops being excused every week; upcoming sessions it excused go back to normal (undo: family undo).",
821
1372
  },
822
- }, async () => unwrap(await api.client.POST("/parent/kid/{kidId}/events/{eventId}/excuse/", { params: { path: { kidId, eventId } }, body })));
1373
+ }, async () => unwrap(await api.client.POST("/parent-v2/kid/{kidId}/class-excuses/stop-weekly/", { params: { path: { kidId } }, body: { eventId } })));
823
1374
  }
824
1375
  if (verb === "cowork") {
825
1376
  const [current, pods] = await Promise.all([
@@ -965,7 +1516,7 @@ export async function runKidCommand({ parsed, api, writeCommand, }) {
965
1516
  ...(schedule !== undefined ? { schedule } : {}),
966
1517
  ...(status !== undefined ? { status } : {}),
967
1518
  };
968
- return writeCommand(parsed, {
1519
+ return writeNow(parsed, {
969
1520
  action: schedule !== undefined
970
1521
  ? `change the schedule of ${name}'s goal "${goal.title}"`
971
1522
  : `${status === "PAUSED" ? "pause" : "resume"} ${name}'s goal "${goal.title}"`,
@@ -1011,7 +1562,7 @@ export async function runKidCommand({ parsed, api, writeCommand, }) {
1011
1562
  const current = unwrap(await api.client.GET("/parent/kid/{kidId}/goals/{goalId}/note/", {
1012
1563
  params: { path: { kidId, goalId } },
1013
1564
  }));
1014
- return writeCommand(parsed, {
1565
+ return writeNow(parsed, {
1015
1566
  action: clear
1016
1567
  ? `clear the guidance note on ${name}'s goal "${current.title}"`
1017
1568
  : `set the guidance note on ${name}'s goal "${current.title}"`,
@@ -1046,12 +1597,13 @@ export async function runKidCommand({ parsed, api, writeCommand, }) {
1046
1597
  ...(url !== undefined ? { url } : {}),
1047
1598
  ...(targetDurationInMins !== undefined ? { targetDurationInMins } : {}),
1048
1599
  };
1049
- return writeCommand(parsed, {
1600
+ return writeNow(parsed, {
1050
1601
  action: `add the todo "${title}" for ${name}`,
1051
1602
  target: kidTarget(kid),
1052
1603
  request: body,
1053
1604
  details: {
1054
- consequence: "A one-off todo appears in the kid's list (on its due day) and the kid gets a notification.",
1605
+ dueDate: dueDate ?? "today (the kid's local date)",
1606
+ consequence: `A one-off todo appears in the kid's list on ${dueDate ?? "today (the kid's local date)"} and the kid gets a notification.`,
1055
1607
  },
1056
1608
  }, async () => unwrap(await api.client.POST("/parent/kid/{kidId}/todos/", {
1057
1609
  params: { path: { kidId } },
@@ -1079,7 +1631,7 @@ export async function runKidCommand({ parsed, api, writeCommand, }) {
1079
1631
  todo.activeSession) {
1080
1632
  throw new CliError("invalid_arguments", `"${todo.title}" is ${todo.activeSession ? "in a session" : todo.status}; only a todo the kid hasn't started can be moved.`);
1081
1633
  }
1082
- return writeCommand(parsed, {
1634
+ return writeNow(parsed, {
1083
1635
  action: `move ${name}'s todo "${todo.title}" to ${dueDate}`,
1084
1636
  target: { ...kidTarget(kid), todoId },
1085
1637
  request: { dueDate },
@@ -1106,6 +1658,716 @@ export async function runKidCommand({ parsed, api, writeCommand, }) {
1106
1658
  },
1107
1659
  }, async () => unwrap(await api.client.POST("/parent/kid/{kidId}/todos/{todoId}/end-session/", { params: { path: { kidId, todoId } } })));
1108
1660
  }
1109
- throw new CliError("invalid_arguments", "Use kid today|goals|xp|map-scores|classes|profile|set-profile|texts|set-texts|set-rooms|feed-lock|set-feed-lock|logins|reveal-login|add-login|edit-login|remove-login|excuse|cowork|switch-cowork|friends|friend-parent|pair-device|goal-schedule|pause-goal|resume-goal|goal-note|set-goal-note|add-todo|todo|move-todo|end-session.");
1661
+ if (verb === "remove-todo") {
1662
+ const todoId = flagUuid(parsed, "todo", { required: true });
1663
+ const allowStarted = hasFlag(parsed, "allow-started");
1664
+ return writeNow(parsed, {
1665
+ action: `remove todo ${todoId} from ${name}'s list`,
1666
+ target: { ...kidTarget(kid), todoId },
1667
+ request: allowStarted ? { allowStarted: true } : {},
1668
+ details: {
1669
+ consequence: "It comes off the kid's list (undo: family undo). Completed work, work awaiting review and a live session are never removed; started work only with --allow-started.",
1670
+ },
1671
+ }, async () => unwrap(await api.client.DELETE("/parent-v2/kid/{kidId}/todos/{todoId}/", {
1672
+ params: {
1673
+ path: { kidId, todoId },
1674
+ query: allowStarted ? { allowStarted: "true" } : {},
1675
+ },
1676
+ })));
1677
+ }
1678
+ if (verb === "edit-todo") {
1679
+ const todoId = flagUuid(parsed, "todo", { required: true });
1680
+ requireAnyFlag(parsed, ["title", "minutes", "url"]);
1681
+ const title = flagString(parsed, "title")?.trim();
1682
+ if (title === "")
1683
+ throw new CliError("invalid_arguments", "--title cannot be empty.");
1684
+ const targetDurationInMins = flagInteger(parsed, "minutes", {
1685
+ min: 1,
1686
+ max: 600,
1687
+ });
1688
+ const url = flagString(parsed, "url")?.trim();
1689
+ if (url !== undefined && !/^https?:\/\/\S+$/.test(url)) {
1690
+ throw new CliError("invalid_arguments", "--url must be an http(s) URL.");
1691
+ }
1692
+ const body = {
1693
+ ...(title !== undefined ? { title } : {}),
1694
+ ...(targetDurationInMins !== undefined ? { targetDurationInMins } : {}),
1695
+ ...(url !== undefined ? { url } : {}),
1696
+ };
1697
+ return writeNow(parsed, {
1698
+ action: `edit ${name}'s todo ${todoId}`,
1699
+ target: { ...kidTarget(kid), todoId },
1700
+ request: body,
1701
+ details: {
1702
+ consequence: "Only a todo the kid hasn't started changes (undo: family undo).",
1703
+ },
1704
+ }, async () => {
1705
+ const result = unwrap(await api.client.PATCH("/parent-v2/kid/{kidId}/todos/{todoId}/", {
1706
+ params: { path: { kidId, todoId } },
1707
+ body,
1708
+ }));
1709
+ return result.changes?.length === 0
1710
+ ? {
1711
+ status: "no_change",
1712
+ reason: `"${result.title}" already reads that way.`,
1713
+ id: result.id,
1714
+ }
1715
+ : result;
1716
+ });
1717
+ }
1718
+ if (verb === "join-challenge") {
1719
+ const templateId = flagUuid(parsed, "challenge", { required: true });
1720
+ const answers = parseAnswers(parsed);
1721
+ const body = { templateId, ...(answers ? { answers } : {}) };
1722
+ return writeNow(parsed, {
1723
+ action: `join ${name} to challenge ${templateId}`,
1724
+ target: { ...kidTarget(kid), templateId },
1725
+ request: body,
1726
+ details: {
1727
+ consequence: "It shows up in the kid's plan from the next day (undo: family undo).",
1728
+ },
1729
+ }, async () => joinOutcome(unwrap(await api.client.POST("/parent-v2/kid/{kidId}/challenges/join/", {
1730
+ params: { path: { kidId } },
1731
+ body,
1732
+ })), `${name} is`));
1733
+ }
1734
+ if (verb === "leave-challenge") {
1735
+ const goalId = flagUuid(parsed, "goal", { required: true });
1736
+ const { goals } = unwrap(await api.client.GET("/parent/kid/{kidId}/goals/", {
1737
+ params: { path: { kidId } },
1738
+ }));
1739
+ const goal = goals.find((candidate) => candidate.id === goalId);
1740
+ if (!goal) {
1741
+ throw new CliError("not_found", `${name} has no goal ${goalId}. Run \`kid goals\` for their goals.`);
1742
+ }
1743
+ if (goal.status === "COMPLETED") {
1744
+ return {
1745
+ skipped: true,
1746
+ reason: `"${goal.title}" is already finished.`,
1747
+ };
1748
+ }
1749
+ // Refuse before asking for a confirm, not after.
1750
+ if (goal.leavable === false) {
1751
+ throw new CliError("refused", `A guide set "${goal.title}" up, so it can't be left here. Pause it, or message the guide.`);
1752
+ }
1753
+ return writeCommand(parsed, {
1754
+ action: `take ${name} off the challenge "${goal.title}"`,
1755
+ target: { ...kidTarget(kid), goalId },
1756
+ request: {},
1757
+ details: {
1758
+ consequence: "It drops out of the plan; progress is kept and family undo (or joining it again) brings it back. A guide's challenge can't be left here.",
1759
+ },
1760
+ }, async () => unwrap(await api.client.POST("/parent-v2/kid/{kidId}/challenges/{goalId}/leave/", { params: { path: { kidId, goalId } } })));
1761
+ }
1762
+ if (verb === "set-goal-games" || verb === "set-goal-required") {
1763
+ const goalId = flagUuid(parsed, "goal", { required: true });
1764
+ const value = assertChoice(flagString(parsed, "value", { required: true }).trim().toLowerCase(), ["on", "off"], "--value");
1765
+ const on = value === "on";
1766
+ if (verb === "set-goal-games") {
1767
+ return writeNow(parsed, {
1768
+ action: `turn practice games ${value} for ${name}'s challenge ${goalId}`,
1769
+ target: { ...kidTarget(kid), goalId },
1770
+ request: { on },
1771
+ details: {
1772
+ consequence: "Practice games (applets, extra exercises) after that challenge's lessons (undo: family undo).",
1773
+ },
1774
+ }, async () => {
1775
+ const result = unwrap(await api.client.PATCH("/parent-v2/kid/{kidId}/challenges/{goalId}/games/", { params: { path: { kidId, goalId } }, body: { on } }));
1776
+ return result.changeLogId
1777
+ ? result
1778
+ : {
1779
+ status: "no_change",
1780
+ reason: `Practice games are already ${value} for that challenge.`,
1781
+ goalId,
1782
+ on: result.on,
1783
+ };
1784
+ });
1785
+ }
1786
+ return writeNow(parsed, {
1787
+ action: `make ${name}'s challenge ${goalId} ${on ? "required" : "optional"}`,
1788
+ target: { ...kidTarget(kid), goalId },
1789
+ request: { required: on },
1790
+ details: {
1791
+ consequence: on
1792
+ ? "The kid can't drop it on their own (undo: family undo)."
1793
+ : "The kid can leave it if they want (undo: family undo).",
1794
+ },
1795
+ }, async () => {
1796
+ const result = unwrap(await api.client.PATCH("/parent-v2/kid/{kidId}/challenges/{goalId}/required/", { params: { path: { kidId, goalId } }, body: { required: on } }));
1797
+ return result.change
1798
+ ? result
1799
+ : {
1800
+ status: "no_change",
1801
+ reason: `"${result.title}" is already ${on ? "required" : "optional"}.`,
1802
+ goalId,
1803
+ required: result.required,
1804
+ };
1805
+ });
1806
+ }
1807
+ if (verb === "set-goal-days") {
1808
+ const goalId = flagUuid(parsed, "goal", { required: true });
1809
+ const days = flagString(parsed, "days", { required: true }).trim();
1810
+ return writeNow(parsed, {
1811
+ action: `set ${name}'s challenge ${goalId} to run ${days}`,
1812
+ target: { ...kidTarget(kid), goalId },
1813
+ request: { days },
1814
+ details: {
1815
+ consequence: 'Writes a "Days: …" line into the challenge\'s description (the daily plan reads days from there), from the next plan on (undo: family undo).',
1816
+ },
1817
+ }, async () => {
1818
+ const result = unwrap(await api.client.PATCH("/parent-v2/kid/{kidId}/challenges/{goalId}/days/", { params: { path: { kidId, goalId } }, body: { days } }));
1819
+ return result.change
1820
+ ? result
1821
+ : {
1822
+ status: "no_change",
1823
+ reason: `"${result.title}" already runs ${result.days}.`,
1824
+ goalId,
1825
+ days: result.days,
1826
+ };
1827
+ });
1828
+ }
1829
+ if (verb === "help") {
1830
+ const date = flagDate(parsed, "date");
1831
+ const result = await api.client.GET("/parent-v2/kid/{kidId}/digest/", {
1832
+ params: {
1833
+ path: { kidId },
1834
+ query: { kind: "DAILY", ...(date ? { date } : {}) },
1835
+ },
1836
+ });
1837
+ if (result.response.status === 404) {
1838
+ return {
1839
+ date: date ?? "today",
1840
+ helpItems: [],
1841
+ note: "No daily summary for that day yet.",
1842
+ };
1843
+ }
1844
+ const digest = unwrap(result);
1845
+ return {
1846
+ date: date ?? "today",
1847
+ helpItems: digest.helpItems.map((item) => ({
1848
+ id: item.id,
1849
+ title: item.title,
1850
+ detail: item.detail,
1851
+ tryAsking: item.prompts,
1852
+ done: Boolean(item.doneAt),
1853
+ })),
1854
+ };
1855
+ }
1856
+ if (verb === "help-done") {
1857
+ const helpItemId = flagString(parsed, "item", { required: true }).trim();
1858
+ const date = flagDate(parsed, "date");
1859
+ return writeNow(parsed, {
1860
+ action: `mark ${name}'s help item ${helpItemId} done`,
1861
+ target: { ...kidTarget(kid), helpItemId },
1862
+ request: date ? { date } : {},
1863
+ details: {
1864
+ consequence: "Ticks it on that day's summary and tells the kid's Rocky, who brings it up (undo: family undo).",
1865
+ },
1866
+ }, async () => {
1867
+ const result = unwrap(await api.client.POST("/parent-v2/help/{helpItemId}/done/", {
1868
+ params: { path: { helpItemId } },
1869
+ body: { studentId: kidId, ...(date ? { date } : {}) },
1870
+ }));
1871
+ return result.alreadyDone
1872
+ ? {
1873
+ status: "no_change",
1874
+ reason: "That help item is already marked done.",
1875
+ helpItemId,
1876
+ }
1877
+ : result;
1878
+ });
1879
+ }
1880
+ if (verb === "excuse-days" || verb === "unexcuse-days") {
1881
+ const from = flagDate(parsed, "from");
1882
+ if (!from)
1883
+ throw new CliError("invalid_arguments", "Missing required --from.");
1884
+ const to = flagDate(parsed, "to") ?? from;
1885
+ if (to < from) {
1886
+ throw new CliError("invalid_arguments", "--to is before --from.");
1887
+ }
1888
+ const range = from === to ? from : `${from} to ${to}`;
1889
+ if (verb === "unexcuse-days") {
1890
+ return writeNow(parsed, {
1891
+ action: `make ${range} regular school days for ${name} again`,
1892
+ target: kidTarget(kid),
1893
+ request: { from, to },
1894
+ details: {
1895
+ consequence: "Excused days in that range are cleared; todos moved off them stay where they went (undo: family undo).",
1896
+ },
1897
+ }, async () => {
1898
+ const result = await api.client.DELETE("/parent-v2/kid/{kidId}/excused-days/{date}/", {
1899
+ params: {
1900
+ path: { kidId, date: from },
1901
+ query: to !== from ? { to } : {},
1902
+ },
1903
+ });
1904
+ if (result.response.status === 404) {
1905
+ return {
1906
+ status: "no_change",
1907
+ reason: `No excused days for ${name} in that range.`,
1908
+ };
1909
+ }
1910
+ return unwrap(result);
1911
+ });
1912
+ }
1913
+ const reason = assertChoice(flagString(parsed, "reason", { required: true }).trim().toUpperCase(), ["SICK", "VACATION", "PAUSE", "OTHER"], "--reason");
1914
+ const note = flagString(parsed, "note")?.trim();
1915
+ const body = { from, to, reason, ...(note ? { note } : {}) };
1916
+ return writeNow(parsed, {
1917
+ action: `excuse ${name} ${range} (${reason.toLowerCase()})`,
1918
+ target: kidTarget(kid),
1919
+ request: body,
1920
+ details: {
1921
+ consequence: "Those days are off: their open todos move to the next school day and none are planned on them (undo: family undo).",
1922
+ },
1923
+ }, async () => unwrap(await api.client.POST("/parent-v2/kid/{kidId}/excused-days/", {
1924
+ params: { path: { kidId } },
1925
+ body,
1926
+ })));
1927
+ }
1928
+ if (verb === "excused-days") {
1929
+ const from = flagDate(parsed, "from");
1930
+ const to = flagDate(parsed, "to");
1931
+ return unwrap(await api.client.GET("/parent-v2/kid/{kidId}/excused-days/", {
1932
+ params: {
1933
+ path: { kidId },
1934
+ query: { ...(from ? { from } : {}), ...(to ? { to } : {}) },
1935
+ },
1936
+ }));
1937
+ }
1938
+ if (verb === "moments") {
1939
+ const since = flagDate(parsed, "since");
1940
+ const { moments } = unwrap(await api.client.GET("/voice/moments/", {
1941
+ params: {
1942
+ query: {
1943
+ studentId: kidId,
1944
+ ...(since ? { since: `${since}T00:00:00.000Z` } : {}),
1945
+ },
1946
+ },
1947
+ }));
1948
+ return {
1949
+ moments: moments.slice(0, 8).map((moment) => ({
1950
+ id: moment.id,
1951
+ source: moment.source,
1952
+ title: moment.title,
1953
+ blurb: moment.blurb,
1954
+ sessionDate: moment.sessionDate,
1955
+ skill: moment.skill,
1956
+ shareUrl: moment.shareUrl,
1957
+ })),
1958
+ };
1959
+ }
1960
+ if (verb === "config") {
1961
+ const view = unwrap(await api.client.GET("/kid-config/kid/{kidId}/", {
1962
+ params: {
1963
+ path: { kidId },
1964
+ query: { surface: "parent", format: "lines" },
1965
+ },
1966
+ }));
1967
+ return {
1968
+ kid: name,
1969
+ settings: view.lines ?? "",
1970
+ change: `kid set --student ${kidId} --path <path> --value <value>`,
1971
+ };
1972
+ }
1973
+ if (verb === "set") {
1974
+ const raw = flagString(parsed, "path", { required: true });
1975
+ const value = flagString(parsed, "value", { required: true });
1976
+ const field = pickConfigField(unwrap(await api.client.GET("/kid-config/kid/{kidId}/", {
1977
+ params: {
1978
+ path: { kidId },
1979
+ query: { surface: "all", format: "lines" },
1980
+ },
1981
+ })), raw, "kid");
1982
+ const write = field.confirm === "immediate" ? writeNow : writeCommand;
1983
+ return write(parsed, {
1984
+ action: `change ${name}'s ${field.label.toLowerCase()} to ${value}`,
1985
+ target: { ...kidTarget(kid), path: raw },
1986
+ request: { path: raw, value },
1987
+ details: {
1988
+ before: field.display,
1989
+ consequence: "Changes that setting for this kid (undo: family undo).",
1990
+ },
1991
+ }, async () => configWriteResult(unwrap(await api.client.PATCH("/kid-config/kid/{kidId}/", {
1992
+ params: { path: { kidId }, query: { surface: "parent" } },
1993
+ body: { path: raw, value },
1994
+ })), { kid: name }));
1995
+ }
1996
+ if (verb === "repeat-todo") {
1997
+ const body = repeatBody(parsed);
1998
+ const { title, days, weeks } = body;
1999
+ return writeNow(parsed, {
2000
+ action: `add "${title}" to ${name}'s list on ${days} for ${weeks ?? 2} week${weeks === 1 ? "" : "s"}`,
2001
+ target: kidTarget(kid),
2002
+ request: body,
2003
+ details: {
2004
+ consequence: "One-off copies on each matching day (from tomorrow unless --start), skipping days off (undo: family undo removes the ones not started).",
2005
+ },
2006
+ }, async () => unwrap(await api.client.POST("/parent-v2/kid/{kidId}/todos/repeat/", {
2007
+ params: { path: { kidId } },
2008
+ body,
2009
+ })));
2010
+ }
2011
+ if (verb === "complete-challenge") {
2012
+ const goalId = flagUuid(parsed, "goal", { required: true });
2013
+ return writeCommand(parsed, {
2014
+ action: `mark ${name}'s challenge ${goalId} finished`,
2015
+ target: { ...kidTarget(kid), goalId },
2016
+ request: {},
2017
+ details: {
2018
+ consequence: "It stops adding to-dos and moves to finished. No coins or badge come with it (undo: family undo reopens it).",
2019
+ },
2020
+ }, async () => unwrap(await api.client.POST("/parent-v2/kid/{kidId}/challenges/{goalId}/complete/", { params: { path: { kidId, goalId } } })));
2021
+ }
2022
+ if (verb === "set-todo-reward") {
2023
+ const todoId = flagUuid(parsed, "todo", { required: true });
2024
+ requireAnyFlag(parsed, ["xp", "coins"]);
2025
+ const xp = flagInteger(parsed, "xp", { min: 0, max: 300 });
2026
+ const coins = flagInteger(parsed, "coins", { min: 0, max: 300 });
2027
+ const reason = flagString(parsed, "reason", { required: true }).trim();
2028
+ const body = {
2029
+ reason: reason.slice(0, 500),
2030
+ ...(xp !== undefined ? { xp } : {}),
2031
+ ...(coins !== undefined ? { coins } : {}),
2032
+ };
2033
+ return writeCommand(parsed, {
2034
+ action: `set ${name}'s todo ${todoId} to${xp !== undefined ? ` ${xp} XP` : ""}${xp !== undefined && coins !== undefined ? " and" : ""}${coins !== undefined ? ` ${coins} coins` : ""}`,
2035
+ target: { ...kidTarget(kid), todoId },
2036
+ request: body,
2037
+ details: {
2038
+ consequence: "New totals for that to-do: a finished one gets the difference added to (or taken from) the kid's totals; an open one pays it when done (undo: family undo).",
2039
+ },
2040
+ }, async () => unwrap(await api.client.POST("/parent-v2/kid/{kidId}/todos/{todoId}/reward/", { params: { path: { kidId, todoId } }, body })));
2041
+ }
2042
+ if (verb === "progress") {
2043
+ const result = await api.client.GET("/parent-v2/kid/{kidId}/progress/", {
2044
+ params: { path: { kidId } },
2045
+ });
2046
+ if (result.response.status === 404)
2047
+ return {
2048
+ status: "not_available",
2049
+ note: "Progress isn't available yet for this kid.",
2050
+ };
2051
+ return compactProgress(unwrap(result));
2052
+ }
2053
+ if (verb === "schedule") {
2054
+ const days = flagInteger(parsed, "days", { min: 1, max: 31 });
2055
+ return unwrap(await api.client.GET("/parent-v2/kid/{kidId}/class-schedule/", {
2056
+ params: { path: { kidId }, query: days ? { days } : {} },
2057
+ }));
2058
+ }
2059
+ if (verb === "attendance") {
2060
+ const days = flagInteger(parsed, "days", { min: 1, max: 60 });
2061
+ return unwrap(await api.client.GET("/parent-v2/kid/{kidId}/attendance/", {
2062
+ params: { path: { kidId }, query: days ? { days } : {} },
2063
+ }));
2064
+ }
2065
+ if (verb === "browse-challenges") {
2066
+ const query = flagString(parsed, "query")?.trim();
2067
+ return browseChallenges(api, {
2068
+ kidId,
2069
+ ...(query ? { query } : {}),
2070
+ forKid: true,
2071
+ });
2072
+ }
2073
+ if (verb === "sign-in-code") {
2074
+ const body = { kidUserId: kidId };
2075
+ // A one-time code for the parent; nothing in the family changes.
2076
+ return writeNow(parsed, {
2077
+ action: `mint a one-time sign-in code for ${name}`,
2078
+ target: kidTarget(kid),
2079
+ request: body,
2080
+ details: {
2081
+ consequence: "The code signs this kid in once, for a few minutes. Give it only to the parent.",
2082
+ },
2083
+ }, async () => {
2084
+ const { shortCode, expiresAt } = unwrap(await api.client.POST("/auth/device-pairing/generate/", { body }));
2085
+ return {
2086
+ code: shortCode,
2087
+ expiresInMinutes: Math.max(1, Math.round((Date.parse(expiresAt) - Date.now()) / 60_000)),
2088
+ downloadUrl: `${api.config.webOrigin}/download`,
2089
+ note: `Works once. ${kid.firstName ?? name} types it at sign-in in the Recess app on their iPad or computer.`,
2090
+ };
2091
+ });
2092
+ }
2093
+ if (verb === "todos") {
2094
+ const date = flagDate(parsed, "date");
2095
+ const from = flagDate(parsed, "from");
2096
+ const to = flagDate(parsed, "to");
2097
+ const completedSince = flagDate(parsed, "completed-since");
2098
+ const status = flagString(parsed, "status");
2099
+ const subject = flagString(parsed, "subject");
2100
+ const search = flagString(parsed, "search")?.trim();
2101
+ const goalId = flagUuid(parsed, "goal");
2102
+ const limit = flagInteger(parsed, "limit", { min: 1, max: 100 });
2103
+ return unwrap(await api.client.GET("/parent-v2/kid/{kidId}/todos/", {
2104
+ params: {
2105
+ path: { kidId },
2106
+ query: {
2107
+ ...(date ? { date } : {}),
2108
+ ...(from ? { from } : {}),
2109
+ ...(to ? { to } : {}),
2110
+ ...(completedSince ? { completedSince } : {}),
2111
+ ...(status
2112
+ ? {
2113
+ status: assertChoice(status.toUpperCase(), [
2114
+ "NOT_STARTED",
2115
+ "STARTED",
2116
+ "PENDING_REVIEW",
2117
+ "COMPLETED",
2118
+ ], "--status"),
2119
+ }
2120
+ : {}),
2121
+ ...(subject
2122
+ ? {
2123
+ subject: assertChoice(subject.toUpperCase(), ["MATH", "READING", "WRITING", "SCIENCE"], "--subject"),
2124
+ }
2125
+ : {}),
2126
+ ...(search ? { search } : {}),
2127
+ ...(goalId ? { goalId } : {}),
2128
+ ...(limit ? { limit } : {}),
2129
+ },
2130
+ },
2131
+ }));
2132
+ }
2133
+ if (verb === "goal") {
2134
+ const goalId = flagUuid(parsed, "goal", { required: true });
2135
+ return unwrap(await api.client.GET("/parent-v2/kid/{kidId}/goals/{goalId}/", {
2136
+ params: { path: { kidId, goalId } },
2137
+ }));
2138
+ }
2139
+ if (verb === "conversations") {
2140
+ const query = flagString(parsed, "query")?.trim();
2141
+ const from = flagDate(parsed, "from");
2142
+ const to = flagDate(parsed, "to");
2143
+ const limit = flagInteger(parsed, "limit", { min: 1, max: 10 });
2144
+ return unwrap(await api.client.GET("/parent-v2/kid/{kidId}/conversations/", {
2145
+ params: {
2146
+ path: { kidId },
2147
+ query: {
2148
+ ...(query ? { query } : {}),
2149
+ ...(from ? { from } : {}),
2150
+ ...(to ? { to } : {}),
2151
+ ...(limit ? { limit } : {}),
2152
+ },
2153
+ },
2154
+ }));
2155
+ }
2156
+ if (verb === "social") {
2157
+ const view = assertChoice(flagString(parsed, "view") ?? "overview", ["overview", "friends", "activity"], "--view");
2158
+ if (view === "friends")
2159
+ return unwrap(await api.client.GET("/parent-v2/kid/{kidId}/social/friends/", {
2160
+ params: { path: { kidId } },
2161
+ }));
2162
+ if (view === "activity") {
2163
+ const days = flagInteger(parsed, "days", { min: 1, max: 90 });
2164
+ return unwrap(await api.client.GET("/parent-v2/kid/{kidId}/social/activity/", {
2165
+ params: { path: { kidId }, query: days ? { days } : {} },
2166
+ }));
2167
+ }
2168
+ const section = flagString(parsed, "section");
2169
+ const social = unwrap(await api.client.GET("/parent-v2/kid/{kidId}/social/", {
2170
+ params: { path: { kidId } },
2171
+ }));
2172
+ // A parent's DM link opens a chat with them (view only otherwise).
2173
+ const withDms = (friend) => ({
2174
+ ...friend,
2175
+ parents: friend.parents.map(({ dmPath, ...parent }) => ({
2176
+ ...parent,
2177
+ dmUrl: `${api.config.webOrigin}${dmPath}`,
2178
+ })),
2179
+ });
2180
+ const full = {
2181
+ ...social,
2182
+ closeFriends: social.closeFriends.map(withDms),
2183
+ newFriends: social.newFriends.map(withDms),
2184
+ };
2185
+ const sections = [
2186
+ "closeFriends",
2187
+ "newFriends",
2188
+ "events",
2189
+ "comments",
2190
+ "chats",
2191
+ "safety",
2192
+ ];
2193
+ const picked = section
2194
+ ? assertChoice(section, sections, "--section")
2195
+ : undefined;
2196
+ return {
2197
+ ...(picked ? { [picked]: full[picked] } : full),
2198
+ villageAvailable: social.villageAvailable,
2199
+ note: "View only. Chats are counts: never say what was said. A parent's dmUrl opens a DM with them.",
2200
+ };
2201
+ }
2202
+ if (verb === "enrollments") {
2203
+ return unwrap(await api.client.GET("/parent-v2/kid/{kidId}/enrollments/", {
2204
+ params: { path: { kidId } },
2205
+ }));
2206
+ }
2207
+ if (verb === "math-progress") {
2208
+ const view = assertChoice(flagString(parsed, "view") ?? "overview", ["overview", "activity"], "--view");
2209
+ const since = flagDate(parsed, "since");
2210
+ return unwrap(await api.client.GET("/parent-v2/kid/{kidId}/math-progress/", {
2211
+ params: {
2212
+ path: { kidId },
2213
+ query: { view, ...(since ? { since } : {}) },
2214
+ },
2215
+ }));
2216
+ }
2217
+ if (verb === "memory") {
2218
+ const op = assertChoice(parsed.positionals[2] ?? "ls", ["ls", "cat", "grep"], "kid memory");
2219
+ const path = flagString(parsed, "path")?.trim();
2220
+ const pattern = flagString(parsed, "pattern")?.trim();
2221
+ if (op === "cat" && !path)
2222
+ throw new CliError("invalid_arguments", "Pass --path (see kid memory ls).");
2223
+ if (op === "grep" && !pattern)
2224
+ throw new CliError("invalid_arguments", "Pass --pattern TEXT.");
2225
+ return unwrap(await api.client.GET("/parent-v2/kid/{kidId}/memory/", {
2226
+ params: {
2227
+ path: { kidId },
2228
+ query: {
2229
+ op,
2230
+ ...(path ? { path } : {}),
2231
+ ...(pattern ? { pattern } : {}),
2232
+ },
2233
+ },
2234
+ }));
2235
+ }
2236
+ if (verb === "observe") {
2237
+ const text = flagString(parsed, "note", { required: true }).trim();
2238
+ if (!text || text.length > 2000)
2239
+ throw new CliError("invalid_arguments", "--note must be 1-2000 characters.");
2240
+ const body = { text };
2241
+ // Rocky reads it in the kid's sessions; logged, nothing to undo.
2242
+ return writeNow(parsed, {
2243
+ action: `tell ${name}'s Rocky: "${text.slice(0, 80)}"`,
2244
+ target: kidTarget(kid),
2245
+ request: body,
2246
+ details: {
2247
+ consequence: "A note in the kid's Rocky memory for today, which Rocky and tomorrow's plan read. Logged, not undoable.",
2248
+ },
2249
+ }, async () => unwrap(await api.client.POST("/parent-v2/kid/{kidId}/observations/", {
2250
+ params: { path: { kidId } },
2251
+ body,
2252
+ })));
2253
+ }
2254
+ if (verb === "send-note") {
2255
+ const text = flagString(parsed, "note", { required: true }).trim();
2256
+ if (!text || text.length > 1000)
2257
+ throw new CliError("invalid_arguments", "--note must be 1-1000 characters.");
2258
+ const body = { text };
2259
+ return writeCommand(parsed, {
2260
+ action: `have Rocky pass ${name} your note: "${text.slice(0, 80)}"`,
2261
+ target: kidTarget(kid),
2262
+ request: body,
2263
+ details: {
2264
+ consequence: "Rocky passes it on in his own words the next time the kid opens a chat (within 7 days). It can't be unsent.",
2265
+ },
2266
+ }, async () => unwrap(await api.client.POST("/parent-v2/kid/{kidId}/notes/", {
2267
+ params: { path: { kidId } },
2268
+ body,
2269
+ })));
2270
+ }
2271
+ throw new CliError("invalid_arguments", "Use kid today|goals|xp|map-scores|classes|profile|set-profile|texts|set-texts|set-rooms|feed-lock|set-feed-lock|logins|reveal-login|add-login|edit-login|remove-login|excuse|unexcuse-weekly|cowork|switch-cowork|friends|friend-parent|pair-device|goal-schedule|pause-goal|resume-goal|goal-note|set-goal-note|add-todo|todo|move-todo|end-session|remove-todo|edit-todo|repeat-todo|join-challenge|leave-challenge|complete-challenge|set-goal-games|set-goal-required|set-goal-days|set-todo-reward|help|help-done|excuse-days|excused-days|unexcuse-days|moments|config|set|progress|schedule|attendance|browse-challenges|sign-in-code|todos|goal|conversations|social|enrollments|math-progress|memory|observe|send-note.");
2272
+ }
2273
+ /**
2274
+ * `me`: the caller's OWN to-dos and challenges (a parent learning too), over
2275
+ * the self-scoped `/parent-v2/me` routes. Only when they mean themselves.
2276
+ */
2277
+ export async function runMeCommand({ parsed, api, writeCommand, }) {
2278
+ const verb = parsed.positionals[1];
2279
+ const writeNow = (p, preview, execute) => writeCommand(p, preview, execute, { ungated: true });
2280
+ if (verb === "today") {
2281
+ const date = flagDate(parsed, "date");
2282
+ return unwrap(await api.client.GET("/parent-v2/me/today/", {
2283
+ params: { query: date ? { date } : {} },
2284
+ }));
2285
+ }
2286
+ if (verb === "goals") {
2287
+ return unwrap(await api.client.GET("/parent-v2/me/goals/"));
2288
+ }
2289
+ if (verb === "add-todo") {
2290
+ const title = flagString(parsed, "title", { required: true }).trim();
2291
+ if (!title || title.length > 200)
2292
+ throw new CliError("invalid_arguments", "--title must be 1-200 characters.");
2293
+ const dueDate = flagDate(parsed, "due-date");
2294
+ const minutes = flagInteger(parsed, "minutes", { min: 1, max: 600 });
2295
+ const url = flagString(parsed, "url")?.trim();
2296
+ if (url !== undefined && !/^https?:\/\/\S+$/.test(url)) {
2297
+ throw new CliError("invalid_arguments", "--url must be an http(s) URL.");
2298
+ }
2299
+ const body = {
2300
+ title,
2301
+ ...(dueDate !== undefined ? { dueDate } : {}),
2302
+ ...(minutes !== undefined ? { minutes } : {}),
2303
+ ...(url !== undefined ? { url } : {}),
2304
+ };
2305
+ return writeNow(parsed, {
2306
+ action: `add "${title}" to your own list${dueDate ? ` for ${dueDate}` : ""}`,
2307
+ target: { user: "@me" },
2308
+ request: body,
2309
+ details: { consequence: "On your own list (undo: family undo)." },
2310
+ }, async () => unwrap(await api.client.POST("/parent-v2/me/todos/", { body })));
2311
+ }
2312
+ if (verb === "remove-todo") {
2313
+ const todoId = flagUuid(parsed, "todo", { required: true });
2314
+ return writeNow(parsed, {
2315
+ action: `remove todo ${todoId} from your own list`,
2316
+ target: { user: "@me", todoId },
2317
+ request: {},
2318
+ details: { consequence: "Off your list (undo: family undo)." },
2319
+ }, async () => unwrap(await api.client.DELETE("/parent-v2/me/todos/{todoId}/", {
2320
+ params: { path: { todoId } },
2321
+ })));
2322
+ }
2323
+ if (verb === "repeat-todo") {
2324
+ const body = repeatBody(parsed);
2325
+ return writeNow(parsed, {
2326
+ action: `add "${body.title}" to your own list on ${body.days} for ${body.weeks ?? 2} week${body.weeks === 1 ? "" : "s"}`,
2327
+ target: { user: "@me" },
2328
+ request: body,
2329
+ details: {
2330
+ consequence: "One-off copies on each matching day (from tomorrow unless --start) (undo: family undo).",
2331
+ },
2332
+ }, async () => unwrap(await api.client.POST("/parent-v2/me/todos/repeat/", { body })));
2333
+ }
2334
+ if (verb === "browse-challenges") {
2335
+ const query = flagString(parsed, "query")?.trim();
2336
+ return browseChallenges(api, {
2337
+ ...(query ? { query } : {}),
2338
+ forKid: false,
2339
+ });
2340
+ }
2341
+ if (verb === "join-challenge") {
2342
+ const templateId = flagUuid(parsed, "challenge", { required: true });
2343
+ const answers = parseAnswers(parsed);
2344
+ const body = { templateId, ...(answers ? { answers } : {}) };
2345
+ return writeNow(parsed, {
2346
+ action: `join challenge ${templateId} yourself`,
2347
+ target: { user: "@me", templateId },
2348
+ request: body,
2349
+ details: {
2350
+ consequence: "It shows up on your own list from the next day (undo: family undo).",
2351
+ },
2352
+ }, async () => joinOutcome(unwrap(await api.client.POST("/parent-v2/me/challenges/join/", { body })), "You are"));
2353
+ }
2354
+ if (verb === "leave-challenge") {
2355
+ const goalId = flagUuid(parsed, "goal", { required: true });
2356
+ const { goals } = unwrap(await api.client.GET("/parent-v2/me/goals/"));
2357
+ const goal = goals.find((candidate) => candidate.id === goalId);
2358
+ if (!goal)
2359
+ throw new CliError("not_found", `You have no open challenge ${goalId}. Run \`me goals\` for yours.`);
2360
+ return writeCommand(parsed, {
2361
+ action: `take you off your challenge "${goal.title}"`,
2362
+ target: { user: "@me", goalId },
2363
+ request: {},
2364
+ details: {
2365
+ consequence: "It drops off your list; progress is kept and family undo (or joining it again) brings it back.",
2366
+ },
2367
+ }, async () => unwrap(await api.client.POST("/parent-v2/me/challenges/{goalId}/leave/", {
2368
+ params: { path: { goalId } },
2369
+ })));
2370
+ }
2371
+ throw new CliError("invalid_arguments", "Use me today|goals|add-todo|remove-todo|repeat-todo|browse-challenges|join-challenge|leave-challenge.");
1110
2372
  }
1111
2373
  //# sourceMappingURL=family.js.map