@dench.com/cli 3.12.11 → 3.12.13-staging.1266

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dench.com/cli",
3
- "version": "3.12.11",
3
+ "version": "3.12.13-staging.1266",
4
4
  "description": "Dench agent workspace CLI.",
5
5
  "type": "module",
6
6
  "bin": {
package/settings.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * `dench settings <subcommand>` — workspace settings from the command line.
3
3
  *
4
- * Today that is Settings → Sync: the eight switches that decide what Dench
4
+ * Settings → Sync: the eight switches that decide what Dench
5
5
  * does on its own with the workspace's email, calendar, Slack and LinkedIn
6
6
  * (docs/agent-notes/account-context-ingestion.md §12). All on by default;
7
7
  * turning one off stops NEW work and never removes anything already created.
@@ -9,6 +9,16 @@
9
9
  * dench settings sync [--json] the eight switches
10
10
  * dench settings sync set <key> on|off [--json] admin-only
11
11
  *
12
+ * Settings → Dench in Slack → Announcements: the saved channel groups and
13
+ * the channels in each right now, and making, changing and deleting one
14
+ * (DENCH-81). Admin-only. Nothing here sends an announcement: that is a
15
+ * person's click in that screen.
16
+ *
17
+ * dench settings announcement-groups [name] [--json]
18
+ * dench settings announcement-groups save <name> [--rule <pattern>]
19
+ * [--channels a,b] [--add a,b] [--remove a,b] [--rename <new name>]
20
+ * dench settings announcement-groups delete <name>
21
+ *
12
22
  * Reads `functions/organizations:getMySyncSettings` and writes
13
23
  * `functions/organizations:updateMyOrganizationSyncSettings` with a one-key
14
24
  * patch, forwarding the same bearer every other CLI surface uses. The
@@ -20,7 +30,12 @@
20
30
  */
21
31
  import type { ConvexHttpClient } from "convex/browser";
22
32
  import { makeFunctionReference } from "convex/server";
23
- import { assertNoUnknownFlags, CliArgError, hasFlag } from "./lib/cli-args";
33
+ import {
34
+ assertNoUnknownFlags,
35
+ CliArgError,
36
+ getFlag,
37
+ hasFlag,
38
+ } from "./lib/cli-args";
24
39
 
25
40
  class SettingsCliError extends Error {}
26
41
 
@@ -55,6 +70,15 @@ const api = {
55
70
  updateSync: makeFunctionReference<"mutation">(
56
71
  "functions/organizations:updateMyOrganizationSyncSettings",
57
72
  ),
73
+ announcementGroups: makeFunctionReference<"action">(
74
+ "functions/slackAnnouncementsNode:listGroupsForCaller",
75
+ ),
76
+ saveAnnouncementGroup: makeFunctionReference<"action">(
77
+ "functions/slackAnnouncementsNode:saveGroupForCaller",
78
+ ),
79
+ deleteAnnouncementGroup: makeFunctionReference<"mutation">(
80
+ "functions/slackAnnouncements:deleteGroupForCaller",
81
+ ),
58
82
  };
59
83
 
60
84
  const HELP = `dench settings — workspace settings
@@ -65,6 +89,19 @@ const HELP = `dench settings — workspace settings
65
89
  dench settings sync set <key> on|off [--json]
66
90
  Flip one switch (workspace admins only). Off stops new work; nothing
67
91
  already created is removed.
92
+ dench settings announcement-groups [name] [--json]
93
+ The Slack announcement channel groups and the channels in each right
94
+ now (workspace admins only). Give a group's name to see only that
95
+ group, with every channel in it.
96
+ dench settings announcement-groups save <name> [--rule <pattern>]
97
+ [--channels a,b] [--add a,b] [--remove a,b] [--rename <new name>] [--json]
98
+ Make or change a group (workspace admins only). --rule makes it a rule
99
+ on channel names (dench-* starts with, *-acme ends with, a word is
100
+ found anywhere, a comma means or). --channels makes it exactly those
101
+ channels. --add and --remove put single channels in or take them out
102
+ without restating the group. It sends nothing.
103
+ dench settings announcement-groups delete <name> [--json]
104
+ Delete a group (workspace admins only).
68
105
 
69
106
  Keys:
70
107
  ${SYNC_SETTING_KEYS.map((key) => ` ${key.padEnd(22)} ${SYNC_SETTING_LABELS[key]}`).join("\n")}
@@ -160,6 +197,9 @@ export async function runSettingsCommand(opts: {
160
197
  console.log(HELP);
161
198
  return;
162
199
  }
200
+ if (subcommand === "announcement-groups") {
201
+ return await runAnnouncementGroups(ctx);
202
+ }
163
203
  if (subcommand !== "sync") {
164
204
  throw new SettingsCliError(
165
205
  `Unknown settings subcommand: ${subcommand}. Run \`dench settings help\`.`,
@@ -227,3 +267,184 @@ async function runSyncSet(ctx: Ctx): Promise<void> {
227
267
  console.log("");
228
268
  console.log(formatSyncSettingsTable(settings));
229
269
  }
270
+
271
+ type AnnouncementGroupChannel = {
272
+ name: string;
273
+ isPrivate?: true;
274
+ isShared?: true;
275
+ };
276
+
277
+ export type AnnouncementGroupsAnswer = {
278
+ slack: "connected" | "not_connected" | "account_not_linked";
279
+ groups: Array<{
280
+ name: string;
281
+ kind: "rule" | "picked" | "customer_channels";
282
+ rule?: string;
283
+ channelCount?: number;
284
+ channels?: AnnouncementGroupChannel[];
285
+ privateChannelsNotNamed?: number;
286
+ channelsNotListed?: number;
287
+ leftOutCount?: number;
288
+ leftOut?: AnnouncementGroupChannel[];
289
+ }>;
290
+ notes: string[];
291
+ };
292
+
293
+ function channelLabel(channel: AnnouncementGroupChannel): string {
294
+ const name = `${channel.isPrivate ? "🔒 " : "#"}${channel.name}`;
295
+ return channel.isShared ? `${name} (shared with another company)` : name;
296
+ }
297
+
298
+ /** The groups as a person reads them: one block per group, then the notes. */
299
+ export function formatAnnouncementGroups(
300
+ answer: AnnouncementGroupsAnswer,
301
+ ): string {
302
+ const blocks = answer.groups.map((group) => {
303
+ const what =
304
+ group.kind === "rule"
305
+ ? `channels named ${group.rule || "(any name)"}`
306
+ : group.kind === "customer_channels"
307
+ ? "customer channels Dench mapped in Admin"
308
+ : "channels picked by hand";
309
+ const count =
310
+ group.channelCount === undefined
311
+ ? ""
312
+ : ` · ${group.channelCount} ${group.channelCount === 1 ? "channel" : "channels"}`;
313
+ const lines = [`${group.name}: ${what}${count}`];
314
+ for (const channel of group.channels ?? [])
315
+ lines.push(` ${channelLabel(channel)}`);
316
+ if (group.privateChannelsNotNamed)
317
+ lines.push(` and ${group.privateChannelsNotNamed} private, not named`);
318
+ if (group.channelsNotListed)
319
+ lines.push(` and ${group.channelsNotListed} more`);
320
+ if (group.leftOutCount) {
321
+ const named = (group.leftOut ?? []).map(channelLabel).join(", ");
322
+ lines.push(
323
+ ` left out (${group.leftOutCount})${named ? `: ${named}` : ""}`,
324
+ );
325
+ }
326
+ return lines.join("\n");
327
+ });
328
+ return [
329
+ ...(blocks.length ? [blocks.join("\n\n")] : []),
330
+ ...(answer.notes.length ? [answer.notes.join("\n")] : []),
331
+ ].join("\n\n");
332
+ }
333
+
334
+ /** `a, #b,c` → `["a", "#b", "c"]`; an absent flag stays absent. */
335
+ function channelList(value: string | undefined): string[] | undefined {
336
+ return value
337
+ ?.split(",")
338
+ .map((name) => name.trim())
339
+ .filter(Boolean);
340
+ }
341
+
342
+ async function runAnnouncementGroupSave(ctx: Ctx): Promise<void> {
343
+ let rule: string | undefined;
344
+ let channels: string[] | undefined;
345
+ let add: string[] | undefined;
346
+ let remove: string[] | undefined;
347
+ let rename: string | undefined;
348
+ try {
349
+ rule = getFlag(ctx.args, "--rule");
350
+ channels = channelList(getFlag(ctx.args, "--channels"));
351
+ add = channelList(getFlag(ctx.args, "--add"));
352
+ remove = channelList(getFlag(ctx.args, "--remove"));
353
+ rename = getFlag(ctx.args, "--rename");
354
+ assertNoUnknownFlags(ctx.args, "settings announcement-groups save");
355
+ } catch (error) {
356
+ throw toCliError(error);
357
+ }
358
+ const name = ctx.args.join(" ").trim();
359
+ if (!name)
360
+ throw new SettingsCliError(
361
+ "Give the group's name: dench settings announcement-groups save <name> --rule dench-*",
362
+ );
363
+ let answer: AnnouncementGroupsAnswer & { outcome: "created" | "changed" };
364
+ try {
365
+ answer = (await ctx.convex.action(
366
+ api.saveAnnouncementGroup,
367
+ withToken(ctx, {
368
+ ...(rename ? { group: name, name: rename } : { name }),
369
+ ...(rule !== undefined ? { rule } : {}),
370
+ ...(channels ? { channels } : {}),
371
+ ...(add ? { addChannels: add } : {}),
372
+ ...(remove ? { removeChannels: remove } : {}),
373
+ }) as never,
374
+ )) as typeof answer;
375
+ } catch (error) {
376
+ throw toCliError(error);
377
+ }
378
+ if (ctx.jsonOutput) {
379
+ console.log(JSON.stringify(answer, null, 2));
380
+ return;
381
+ }
382
+ console.log(
383
+ `${answer.outcome === "created" ? "Created" : "Changed"} the group.`,
384
+ );
385
+ console.log("");
386
+ console.log(formatAnnouncementGroups(answer));
387
+ }
388
+
389
+ async function runAnnouncementGroupDelete(ctx: Ctx): Promise<void> {
390
+ try {
391
+ assertNoUnknownFlags(ctx.args, "settings announcement-groups delete");
392
+ } catch (error) {
393
+ throw toCliError(error);
394
+ }
395
+ const name = ctx.args.join(" ").trim();
396
+ if (!name)
397
+ throw new SettingsCliError(
398
+ "Give the group's name: dench settings announcement-groups delete <name>",
399
+ );
400
+ let result: { deleted: string };
401
+ try {
402
+ result = (await ctx.convex.mutation(
403
+ api.deleteAnnouncementGroup,
404
+ withToken(ctx, { name }) as never,
405
+ )) as typeof result;
406
+ } catch (error) {
407
+ throw toCliError(error);
408
+ }
409
+ if (ctx.jsonOutput) {
410
+ console.log(JSON.stringify(result, null, 2));
411
+ return;
412
+ }
413
+ console.log(`Deleted the group "${result.deleted}".`);
414
+ }
415
+
416
+ async function runAnnouncementGroups(ctx: Ctx): Promise<void> {
417
+ // A group that is itself called "save", "delete" or "list" is read with
418
+ // --group.
419
+ const verb = ctx.args[0];
420
+ if (verb === "save" || verb === "delete") {
421
+ ctx.args.shift();
422
+ return verb === "save"
423
+ ? await runAnnouncementGroupSave(ctx)
424
+ : await runAnnouncementGroupDelete(ctx);
425
+ }
426
+ if (verb === "list") ctx.args.shift();
427
+ let group: string | undefined;
428
+ try {
429
+ group = getFlag(ctx.args, "--group");
430
+ assertNoUnknownFlags(ctx.args, "settings announcement-groups");
431
+ } catch (error) {
432
+ throw toCliError(error);
433
+ }
434
+ // A name may be several words: `announcement-groups All Dench Channels`.
435
+ const name = (group ?? ctx.args.join(" ")).trim();
436
+ let answer: AnnouncementGroupsAnswer;
437
+ try {
438
+ answer = (await ctx.convex.action(
439
+ api.announcementGroups,
440
+ withToken(ctx, name ? { group: name } : {}) as never,
441
+ )) as AnnouncementGroupsAnswer;
442
+ } catch (error) {
443
+ throw toCliError(error);
444
+ }
445
+ if (ctx.jsonOutput) {
446
+ console.log(JSON.stringify(answer, null, 2));
447
+ return;
448
+ }
449
+ console.log(formatAnnouncementGroups(answer));
450
+ }