recess-cli 3.45.0 → 3.46.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.
@@ -1,28 +1,70 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
1
3
  import { unwrap } from "../api.js";
4
+ import { flagString } from "../args.js";
2
5
  import { CliError } from "../errors.js";
3
- import { positional } from "./shared.js";
6
+ import { assertChoice, positional } from "./shared.js";
7
+ async function readSend(parsed) {
8
+ const file = path.resolve(flagString(parsed, "file", { required: true }));
9
+ try {
10
+ return JSON.parse(await fs.readFile(file, "utf8"));
11
+ }
12
+ catch {
13
+ throw new CliError("invalid_arguments", `Can't read JSON from ${file}.`);
14
+ }
15
+ }
4
16
  /**
5
- * `changelog preview|send <slug>` — the same send as the post page's button. The
6
- * server holds the copy and audience, so this only names the post. It sends once,
7
- * and only when the post is live.
17
+ * `changelog preview|test|send|history|show` — the blast for a live post. Claude writes
18
+ * the send file (`changelog-post` skill); the server renders it, picks recipients,
19
+ * sends once, and keeps the copy with the record.
8
20
  */
9
21
  export async function runChangelogCommand({ parsed, api, writeCommand, }) {
10
22
  const action = positional(parsed, 1, "changelog action");
11
- if (action !== "preview" && action !== "send") {
12
- throw new CliError("invalid_arguments", "Use changelog preview|send.");
13
- }
14
- const slug = positional(parsed, 2, "post slug");
15
- const params = { path: { slug } };
16
- const preview = unwrap(await api.client.GET("/admin/changelog-sends/{slug}/", { params }));
17
- const reach = preview.audiences.map((a) => ({
18
- audience: a.audience,
19
- feed: a.feed?.count ?? 0,
20
- email: a.email?.count ?? 0,
21
- sms: a.sms?.count ?? 0,
22
- }));
23
- if (action === "preview")
24
- return { ...preview, reach };
25
- if (preview.record) {
23
+ if (action === "history") {
24
+ return unwrap(await api.client.GET("/admin/changelog-sends/"));
25
+ }
26
+ if (action === "show") {
27
+ const slug = positional(parsed, 2, "post slug");
28
+ return unwrap(await api.client.GET("/admin/changelog-sends/{slug}/", {
29
+ params: { path: { slug } },
30
+ }));
31
+ }
32
+ if (action !== "preview" && action !== "test" && action !== "send") {
33
+ throw new CliError("invalid_arguments", "Use changelog preview|test|send|history|show.");
34
+ }
35
+ const send = await readSend(parsed);
36
+ if (action === "test") {
37
+ const audience = assertChoice(flagString(parsed, "audience", { required: true }), ["kids", "parents", "tutors"], "--audience");
38
+ return unwrap(await api.client.POST("/admin/changelog-sends/test/", {
39
+ body: { send, audience },
40
+ }));
41
+ }
42
+ const preview = unwrap(await api.client.POST("/admin/changelog-sends/preview/", { body: send }));
43
+ if (action === "preview") {
44
+ const dir = flagString(parsed, "html-dir");
45
+ if (!dir)
46
+ return preview;
47
+ await fs.mkdir(dir, { recursive: true });
48
+ const files = {};
49
+ for (const { audience, email } of preview.audiences) {
50
+ if (!email)
51
+ continue;
52
+ files[audience] = path.resolve(dir, `${audience}.html`);
53
+ await fs.writeFile(files[audience], email.html);
54
+ }
55
+ return {
56
+ ...preview,
57
+ audiences: preview.audiences.map(({ email, ...rest }) => ({
58
+ ...rest,
59
+ email: email && {
60
+ subject: email.subject,
61
+ count: email.count,
62
+ file: files[rest.audience],
63
+ },
64
+ })),
65
+ };
66
+ }
67
+ if (preview.alreadySent) {
26
68
  throw new CliError("invalid_arguments", "This post was already sent.");
27
69
  }
28
70
  if (!preview.live) {
@@ -31,11 +73,20 @@ export async function runChangelogCommand({ parsed, api, writeCommand, }) {
31
73
  if (preview.problems.length > 0) {
32
74
  throw new CliError("invalid_arguments", preview.problems.join("; "));
33
75
  }
76
+ const reach = {
77
+ feed: preview.feed?.count ?? 0,
78
+ byAudience: preview.audiences.map((a) => ({
79
+ audience: a.audience,
80
+ email: a.email?.count ?? 0,
81
+ sms: a.sms?.count ?? 0,
82
+ slack: !!a.slack,
83
+ })),
84
+ };
34
85
  return writeCommand(parsed, {
35
- action: `send the "${slug}" changelog post to its audience${preview.dryRun ? " (test environment: nothing leaves)" : ""}. This can't be undone or sent twice.`,
36
- target: { slug },
37
- request: {},
38
- details: { reach, audiences: preview.audiences },
39
- }, async () => unwrap(await api.client.POST("/admin/changelog-sends/{slug}/send/", { params })));
86
+ action: `send the "${send.slug}" changelog post to its audience${preview.dryRun ? " (test environment: nothing leaves)" : ""}. This can't be undone or sent twice.`,
87
+ target: { slug: send.slug },
88
+ request: send,
89
+ details: { reach },
90
+ }, async () => unwrap(await api.client.POST("/admin/changelog-sends/send/", { body: send })));
40
91
  }
41
92
  //# sourceMappingURL=changelog.js.map
package/dist/help.js CHANGED
@@ -418,8 +418,11 @@ Usage:
418
418
  recess [--json] cohorts email <cohort-id> --target ALL_PARENTS|ALL_PARENTS_GUIDES
419
419
  --content TEXT [--confirm]
420
420
  recess [--json] feed post --users <id,id,...> --text TEXT [--send-email] [--confirm]
421
- recess [--json] changelog preview <slug>
422
- recess [--json] changelog send <slug> [--confirm]
421
+ recess [--json] changelog preview --file <send.json> [--html-dir <dir>]
422
+ recess [--json] changelog test --file <send.json> --audience kids|parents|tutors
423
+ recess [--json] changelog send --file <send.json> [--confirm]
424
+ recess [--json] changelog history
425
+ recess [--json] changelog show <slug>
423
426
  recess [--json] dms send --users <id,id,...> --text TEXT [--confirm]
424
427
  recess [--json] events get <event-id>
425
428
  recess [--json] events list --date YYYY-MM-DD [--timezone <iana>] [--search TEXT]
@@ -1514,8 +1517,11 @@ export const COMMAND_SUMMARIES = {
1514
1517
  "cohorts resume-billing": "Resume billing for a cohort.",
1515
1518
  "cohorts email": "Email a cohort's parents (and guides).",
1516
1519
  "feed post": "Post a message to users' feeds (optionally email).",
1517
- "changelog preview": "Show what a live changelog post would send, and to how many people.",
1520
+ "changelog preview": "Render a changelog blast and count who it reaches, sending nothing.",
1521
+ "changelog test": "Send yourself one audience's email and text.",
1518
1522
  "changelog send": "Send a live changelog post to its audience, once.",
1523
+ "changelog history": "List every changelog send.",
1524
+ "changelog show": "One changelog send and its exact copy.",
1519
1525
  "dms send": "Send a Recess chat DM as yourself to each user (1:1).",
1520
1526
  "events get": "Read one class event.",
1521
1527
  "events list": "List class events on a date.",
@@ -1773,7 +1779,7 @@ export const NOUN_SUMMARIES = {
1773
1779
  "tuition-plans": "Compute tuition plan sheets (stores nothing).",
1774
1780
  placement: "Give placement quests, one kid's results, results vs MAP, question bank, mastery sync.",
1775
1781
  feed: "Post messages to users' feeds.",
1776
- changelog: "Preview and send changelog posts.",
1782
+ changelog: "Preview, test and send changelog posts, and read past sends.",
1777
1783
  dms: "Send Recess chat DMs as yourself.",
1778
1784
  events: "Class events: list, attendance, cancel, reschedule, add.",
1779
1785
  registrations: "Approve or deny cohort registrations.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "recess-cli",
3
- "version": "3.45.0",
3
+ "version": "3.46.0",
4
4
  "description": "Safe Recess administration and family AI tools from the command line.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -46,8 +46,8 @@
46
46
  "oxlint-tsgolint": "^0.6.0",
47
47
  "typescript": "^5.9.2",
48
48
  "vitest": "^1.6.0",
49
- "@tryrecess/typescript-config": "0.0.0",
50
- "@tryrecess/api-types": "0.0.0"
49
+ "@tryrecess/api-types": "0.0.0",
50
+ "@tryrecess/typescript-config": "0.0.0"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "node node_modules/@tryrecess/typescript-config/bin/tsc-fast.mjs",