@dench.com/cli 3.4.0-staging.317 → 3.5.0-staging.327

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/cron.ts CHANGED
@@ -441,7 +441,7 @@ async function runCreate(ctx: CronCliContext): Promise<void> {
441
441
 
442
442
  let schedule: CronScheduleSpec | undefined;
443
443
  if (isWebhook) {
444
- // Webhook automations fire on demand / via their signed URL — no schedule.
444
+ // Webhook automations fire on demand / via their inbound URL — no schedule.
445
445
  if (consumeScheduleFlags(ctx.args)) {
446
446
  throw new CronCliError(
447
447
  "Webhook automations don't take a schedule. Omit --every/--cron/--at.",
@@ -470,26 +470,46 @@ async function runCreate(ctx: CronCliContext): Promise<void> {
470
470
  target,
471
471
  })) as { jobId?: string };
472
472
 
473
- // Webhook automations need a signing secret to be externally callable. Mint
474
- // one now (unless --no-secret) so `create` hands back a working URL+secret.
475
- if (isWebhook && !hasFlag(ctx.args, "--no-secret") && created.jobId) {
476
- const secret = await mintAutomationSecret(ctx, created.jobId);
477
- out(ctx, { ...created, ...secret });
473
+ // A webhook automation's URL is live (unsigned) as soon as it exists. Only
474
+ // mint a signing secret when asked (--signed). `--no-secret` was the old
475
+ // opt-out and is now the default; consume it so it stays accepted.
476
+ const legacyNoSecret = hasFlag(ctx.args, "--no-secret");
477
+ const signed = hasFlag(ctx.args, "--signed") && !legacyNoSecret;
478
+ if (isWebhook && created.jobId) {
479
+ if (signed) {
480
+ const secret = await mintAutomationSecret(ctx, created.jobId);
481
+ out(ctx, { ...created, ...secret });
482
+ return;
483
+ }
484
+ out(ctx, {
485
+ ...created,
486
+ webhookUrl: automationWebhookUrl(created.jobId),
487
+ webhookAccess: "open",
488
+ note: "Live now — plain POSTs to webhookUrl fire this automation. Keep the URL private. `dench cron secret <jobId>` turns on HMAC signing.",
489
+ });
478
490
  return;
479
491
  }
480
492
  out(ctx, created);
481
493
  }
482
494
 
495
+ function automationWebhookUrl(jobId: string): string {
496
+ return `${getApiBase()}/api/webhooks/automation/${encodeURIComponent(jobId)}`;
497
+ }
498
+
483
499
  /**
484
- * Mint (or rotate) a signing secret for an automation via the Next REST route
500
+ * Turn on (or rotate) HMAC signing for an automation via the Next REST route
485
501
  * (secret encryption runs in the Node route, not Convex's V8 runtime). Returns
486
- * the plaintext secret + callable URL — shown once.
502
+ * the plaintext secret + URL — shown once.
487
503
  */
488
504
  async function mintAutomationSecret(
489
505
  ctx: CronCliContext,
490
506
  jobId: string,
491
- ): Promise<{ webhookUrl: string | null; webhookSecret: string | null }> {
492
- const url = `${getApiBase()}/api/cron/jobs/${encodeURIComponent(jobId)}/regenerate-secret`;
507
+ ): Promise<{
508
+ webhookUrl: string | null;
509
+ webhookSecret: string | null;
510
+ webhookAccess: "signed";
511
+ }> {
512
+ const url = `${getApiBase()}/api/cron/jobs/${encodeURIComponent(jobId)}/webhook-signing`;
493
513
  const res = (await postJson(
494
514
  url,
495
515
  apiKeyHeaders(ctx.sessionToken ?? ""),
@@ -498,16 +518,34 @@ async function mintAutomationSecret(
498
518
  return {
499
519
  webhookUrl: res.webhookUrl ?? null,
500
520
  webhookSecret: res.webhookSecret ?? null,
521
+ webhookAccess: "signed",
501
522
  };
502
523
  }
503
524
 
504
525
  async function runSecret(ctx: CronCliContext): Promise<void> {
505
526
  const jobId = shift(ctx.args, "job id");
527
+ if (hasFlag(ctx.args, "--off")) {
528
+ const url = `${getApiBase()}/api/cron/jobs/${encodeURIComponent(jobId)}/webhook-signing`;
529
+ const res = (await deleteJson(
530
+ url,
531
+ apiKeyHeaders(ctx.sessionToken ?? ""),
532
+ )) as { webhookUrl?: string | null; webhookAccess?: "open" | "off" };
533
+ out(ctx, {
534
+ jobId,
535
+ webhookUrl: res.webhookUrl ?? null,
536
+ webhookAccess: res.webhookAccess ?? null,
537
+ note:
538
+ res.webhookAccess === "open"
539
+ ? "Signing is off — the URL now accepts plain (unsigned) POSTs."
540
+ : "Signing is off — this automation's URL no longer accepts requests.",
541
+ });
542
+ return;
543
+ }
506
544
  const secret = await mintAutomationSecret(ctx, jobId);
507
545
  out(ctx, {
508
546
  jobId,
509
547
  ...secret,
510
- note: "Secret shown once — store it now. Re-running rotates it (invalidates the old one).",
548
+ note: "Secret shown once — store it now. Re-running rotates it (invalidates the old one). `--off` turns signing off.",
511
549
  });
512
550
  }
513
551
 
@@ -838,9 +876,10 @@ Create / update:
838
876
  [--target chat_turn] # default: chat_turn (fires a fresh chat thread)
839
877
  [--json]
840
878
 
841
- # Webhook automation (fires on demand or via a signed URL). Mints + prints a
842
- # signing secret unless --no-secret. The secret is shown ONCE.
843
- dench cron create "Inbound lead triage" --prompt "Triage the lead…" --type webhook
879
+ # Webhook automation (fires on demand or when anything POSTs to its URL).
880
+ # Live + unsigned by default; prints webhookUrl. Add --signed to also mint
881
+ # an HMAC signing secret (shown ONCE).
882
+ dench cron create "Inbound lead triage" --prompt "Triage the lead…" --type webhook [--signed]
844
883
 
845
884
  # App-event automation (fires when something happens in a connected app).
846
885
  # 1. dench apps --json → connectedAccountId + toolkit
@@ -865,7 +904,7 @@ Lifecycle:
865
904
  dench cron disable <jobId>
866
905
  dench cron delete <jobId>
867
906
  dench cron run <jobId> [--wait] [--json] # manual fire; --wait blocks until run finishes
868
- dench cron secret <jobId> [--json] # mint/rotate a signing secret → callable signed URL (any automation type)
907
+ dench cron secret <jobId> [--off] [--json] # turn on / rotate HMAC signing (any type; makes non-webhook URLs live). --off turns it off.
869
908
 
870
909
  Schedule formats:
871
910
  --every <duration> Repeat every N. Accepts 30s, 5m, 2h, 1d, 12h, etc.
package/dench.ts CHANGED
@@ -562,6 +562,11 @@ Notifications (the bell's inbox):
562
562
  dench notifications prefs [--set emailEnabled=false] [--set <kind>.email=false]
563
563
  Help: dench notifications help
564
564
 
565
+ Workspace settings (Settings → Sync: what Dench creates and keeps current on its own):
566
+ dench settings sync [--json] the eight switches, all on by default
567
+ dench settings sync set <key> on|off [--json] admin-only; off stops new work, removes nothing
568
+ Help: dench settings help
569
+
565
570
  Workspace members (for CRM \`user\`-type fields, and who's doing what):
566
571
  dench members list [--json] (top-level alias)
567
572
  dench crm members list [--json] (canonical CRM-scoped name)
@@ -4706,6 +4711,38 @@ async function main() {
4706
4711
  return;
4707
4712
  }
4708
4713
 
4714
+ if (command === "settings") {
4715
+ // Settings → Sync from the terminal. Same auth shape as `dench crm`;
4716
+ // the write is admin-only server-side.
4717
+ const subArgs = stripRuntimeFlags(args.slice(args.indexOf("settings") + 1));
4718
+ const sub = subArgs[0];
4719
+ const { runSettingsCommand } = await import("./settings");
4720
+ if (!sub || sub === "help" || sub === "--help") {
4721
+ // biome-ignore lint/suspicious/noExplicitAny: harmless help-only stub
4722
+ await runSettingsCommand({ convex: {} as any, args: subArgs });
4723
+ return;
4724
+ }
4725
+ const runtime = await getRuntime();
4726
+ if (runtime.mode === "dev") {
4727
+ await runSettingsCommand({
4728
+ convex: runtime.client,
4729
+ args: subArgs,
4730
+ sessionToken: encodeDevCrmSessionToken(runtime.workspaceArgs),
4731
+ });
4732
+ return;
4733
+ }
4734
+ const authedRuntime = requireAuthenticatedRuntime(
4735
+ runtime,
4736
+ "dench settings",
4737
+ );
4738
+ await runSettingsCommand({
4739
+ convex: authedRuntime.client,
4740
+ args: subArgs,
4741
+ sessionToken: authedRuntime.sessionToken,
4742
+ });
4743
+ return;
4744
+ }
4745
+
4709
4746
  if (command === "fs") {
4710
4747
  await runFsCommand();
4711
4748
  return;
@@ -956,6 +956,72 @@ const notificationShape = z
956
956
  })
957
957
  .passthrough();
958
958
 
959
+ const syncSettingsShape = z
960
+ .object({
961
+ detectAccounts: z.boolean(),
962
+ linkedinContacts: z.boolean(),
963
+ slackConnectAccounts: z.boolean(),
964
+ calendarContacts: z.boolean(),
965
+ dossier: z.boolean(),
966
+ emailTasks: z.boolean(),
967
+ leadAutoQualify: z.boolean(),
968
+ intelligence: z.boolean(),
969
+ })
970
+ .describe(
971
+ "Settings → Sync, resolved: absent switches read as true. Off stops new work; nothing already created is removed.",
972
+ );
973
+
974
+ const syncSettingsPatchShape = z.object({
975
+ detectAccounts: z
976
+ .boolean()
977
+ .optional()
978
+ .describe(
979
+ "Accounts from email — new prospects and customers who email you become accounts and contacts.",
980
+ ),
981
+ linkedinContacts: z
982
+ .boolean()
983
+ .optional()
984
+ .describe(
985
+ "Contacts from LinkedIn — everyone you message on LinkedIn becomes a contact, with their company.",
986
+ ),
987
+ slackConnectAccounts: z
988
+ .boolean()
989
+ .optional()
990
+ .describe(
991
+ "Accounts from Slack Connect — a shared channel binds to the company on the other side.",
992
+ ),
993
+ calendarContacts: z
994
+ .boolean()
995
+ .optional()
996
+ .describe(
997
+ "Contacts from calendar — external invitees on upcoming meetings become contacts.",
998
+ ),
999
+ dossier: z
1000
+ .boolean()
1001
+ .optional()
1002
+ .describe(
1003
+ "Research dossier — Dench researches each new account into its Notes.",
1004
+ ),
1005
+ emailTasks: z
1006
+ .boolean()
1007
+ .optional()
1008
+ .describe(
1009
+ "Tasks from email — replies and follow-ups you owe become tasks; support issues become cases.",
1010
+ ),
1011
+ leadAutoQualify: z
1012
+ .boolean()
1013
+ .optional()
1014
+ .describe(
1015
+ "Qualify leads that book — a lead who books a meeting moves to Qualified and converts.",
1016
+ ),
1017
+ intelligence: z
1018
+ .boolean()
1019
+ .optional()
1020
+ .describe(
1021
+ "Summaries and Brief — conversations are summarised and each record keeps a Brief.",
1022
+ ),
1023
+ });
1024
+
959
1025
  const notificationPreferencesShape = z.object({
960
1026
  inAppEnabled: z.boolean(),
961
1027
  emailEnabled: z.boolean(),
@@ -3677,6 +3743,8 @@ export const requestSchemas: Record<string, ZodTypeAny> = {
3677
3743
  }),
3678
3744
  "notifications.readAll": noInput,
3679
3745
  "notifications.archive": z.object({ notificationId: z.string() }),
3746
+ "settings.sync.get": noInput,
3747
+ "settings.sync.update": syncSettingsPatchShape,
3680
3748
  "notifications.preferences.get": noInput,
3681
3749
  "notifications.preferences.update": z.object({
3682
3750
  inAppEnabled: z.boolean().optional(),
@@ -4293,6 +4361,10 @@ export const responseSchemas: Record<string, ZodTypeAny> = {
4293
4361
  "notifications.preferences.get": notificationPreferencesShape.nullable(),
4294
4362
  "notifications.preferences.update": okResponse,
4295
4363
 
4364
+ // Workspace settings
4365
+ "settings.sync.get": syncSettingsShape,
4366
+ "settings.sync.update": syncSettingsShape,
4367
+
4296
4368
  // CRM query + search
4297
4369
  "crm.query": z
4298
4370
  .array(crmEntryShape)
@@ -5126,6 +5198,7 @@ export const requestExamples: Record<string, unknown> = {
5126
5198
  emailEnabled: true,
5127
5199
  perKind: { entry_activity: { email: false } },
5128
5200
  },
5201
+ "settings.sync.update": { linkedinContacts: false },
5129
5202
  "me.profile.update": {
5130
5203
  tagline: "Head of Ops",
5131
5204
  timezone: "America/New_York",
@@ -70,6 +70,8 @@ export const APP_SDK_SCOPES = [
70
70
  "notifications:read",
71
71
  "notifications:write",
72
72
  "search:read",
73
+ "settings:read",
74
+ "settings:write",
73
75
  "store:read",
74
76
  "store:write",
75
77
  "ui",
@@ -156,7 +158,19 @@ export const APP_SDK_OPERATIONS: readonly AppSdkOperationInfo[] = [
156
158
  {"id":"crm.fields.enum.color","group":"crm","summary":"Set an enum color.","cli":"dench crm fields enum-set-color","method":"POST","path":"/crm/objects/{objectName}/fields/{fieldName}/enum/{value}/color","permission":"crm:write","pathParams":["objectName","fieldName","value"]},
157
159
  {"id":"crm.entries.list","group":"crm","summary":"List CRM entries.","cli":"dench crm entries list","method":"GET","path":"/crm/objects/{objectName}/entries","permission":"crm:read","pathParams":["objectName"]},
158
160
  {"id":"crm.entries.get","group":"crm","summary":"Get a CRM entry.","cli":"dench crm entries get","method":"GET","path":"/crm/objects/{objectName}/entries/{entryId}","permission":"crm:read","pathParams":["objectName","entryId"]},
161
+ {"id":"crm.entries.syncHistory","group":"crm","summary":"Queue a full, paged pull of the record's email history from every connected mailbox; the ledger fills as pages land.","cli":"dench crm entries sync-history","method":"POST","path":"/crm/objects/{objectName}/entries/{entryId}/sync-history","permission":"crm:write","pathParams":["objectName","entryId"]},
162
+ {"id":"crm.entries.syncHistoryStatus","group":"crm","summary":"Has Dench read this record's email history? One row per address per mailbox.","cli":"dench crm entries sync-history --status","method":"GET","path":"/crm/objects/{objectName}/entries/{entryId}/sync-history","permission":"crm:read","pathParams":["objectName","entryId"]},
163
+ {"id":"crm.entries.dossier.get","group":"crm","summary":"Status of the account's research dossier — the delimited `dench:dossier` section Dench keeps in the record's Notes: status, when it was written, how many dated updates followed, the last error.","cli":"dench crm entries dossier","method":"GET","path":"/crm/entries/{entryId}/dossier","permission":"crm:read","pathParams":["entryId"]},
164
+ {"id":"crm.entries.dossier.regenerate","group":"crm","summary":"Research the account again and append a fresh dossier section to its Notes (needs a Website / Domain on the record).","cli":"dench crm entries dossier --regenerate","method":"POST","path":"/crm/entries/{entryId}/dossier/regenerate","permission":"crm:write","pathParams":["entryId"]},
165
+ {"id":"crm.detections.list","group":"crm","summary":"List account-detection verdicts — why a domain (or personal address) did or did not become an account: verdict, counterparty type, probabilities, evidence threads, the rows created. `kind` picks the creator: `detections` (email + sweep), `linkedin` (the LinkedIn resolver's rows) or `all` (default). Newest first.","cli":"dench crm detections list","method":"GET","path":"/crm/detections","permission":"crm:read","pathParams":[]},
166
+ {"id":"crm.detections.undo","group":"crm","summary":"Undo what the ingestion jobs created since a timestamp (admin): `kind` = `detections` (accounts + contacts from the email detector and the sweep), `linkedin` (the LinkedIn resolver's contacts + accounts; their conversations are unlinked and parked), `email-tasks` (auto-created tasks and cases) or `all` (default). Deletes only rows no human has touched and marks the verdicts / decisions rolled_back so they are never re-created. `dryRun` lists what would go; per-kind counts in `kinds`.","cli":"dench crm detections undo","method":"POST","path":"/crm/detections/undo","permission":"crm:write","pathParams":[]},
159
167
  {"id":"crm.entries.history","group":"crm","summary":"List a CRM entry's audit history.","cli":"dench crm history","method":"GET","path":"/crm/objects/{objectName}/entries/{entryId}/history","permission":"crm:read","pathParams":["objectName","entryId"]},
168
+ {"id":"crm.activity.list","group":"crm","summary":"List a CRM entry's activity ledger (comments, notes, field changes, emails, meetings, Slack, LinkedIn) in one timeline, newest first by default.","cli":"dench crm activity","method":"GET","path":"/crm/objects/{objectName}/entries/{entryId}/activity","permission":"crm:read","pathParams":["objectName","entryId"]},
169
+ {"id":"crm.brief.get","group":"crm","summary":"The record's generated Brief: health, who owes the next move, open threads, commitments, risks, next step, with provenance. Read this before the ledger.","cli":"dench crm brief","method":"GET","path":"/crm/objects/{objectName}/entries/{entryId}/brief","permission":"crm:read","pathParams":["objectName","entryId"]},
170
+ {"id":"crm.brief.regenerate","group":"crm","summary":"Rebuild a record's Brief from the current timeline.","cli":"dench crm brief --regenerate","method":"POST","path":"/crm/objects/{objectName}/entries/{entryId}/brief/regenerate","permission":"crm:write","pathParams":["objectName","entryId"]},
171
+ {"id":"crm.activity.count","group":"crm","summary":"Bounded per-source counts of a CRM entry's activity ledger.","cli":"dench crm activity","method":"GET","path":"/crm/objects/{objectName}/entries/{entryId}/activity/count","permission":"crm:read","pathParams":["objectName","entryId"]},
172
+ {"id":"crm.notes.list","group":"crm","summary":"List a CRM entry's notes (titled, document-style comments), newest first.","cli":"dench crm notes list","method":"GET","path":"/crm/objects/{objectName}/entries/{entryId}/notes","permission":"crm:read","pathParams":["objectName","entryId"]},
173
+ {"id":"crm.notes.create","group":"crm","summary":"Add a titled note to a CRM entry's activity timeline (markdown body). Research goes here, never into the Notes document.","cli":"dench crm notes create","method":"POST","path":"/crm/objects/{objectName}/entries/{entryId}/notes","permission":"crm:write","pathParams":["objectName","entryId"]},
160
174
  {"id":"crm.comments.list","group":"crm","summary":"List comments on a CRM entry (roots newest first, with preview replies).","cli":"dench crm comments list","method":"GET","path":"/crm/objects/{objectName}/entries/{entryId}/comments","permission":"crm:read","pathParams":["objectName","entryId"]},
161
175
  {"id":"crm.comments.replies","group":"crm","summary":"List every reply under a root comment, oldest first.","cli":"dench crm comments replies","method":"GET","path":"/crm/comments/{commentId}/replies","permission":"crm:read","pathParams":["commentId"]},
162
176
  {"id":"crm.comments.get","group":"crm","summary":"Get one comment with its entry label.","cli":"dench crm comments get","method":"GET","path":"/crm/comments/{commentId}","permission":"crm:read","pathParams":["commentId"]},
@@ -414,6 +428,8 @@ export const APP_SDK_OPERATIONS: readonly AppSdkOperationInfo[] = [
414
428
  {"id":"notifications.archive","group":"notifications","summary":"Archive a notification.","cli":"dench notifications archive","method":"POST","path":"/notifications/{notificationId}/archive","permission":"notifications:write","pathParams":["notificationId"]},
415
429
  {"id":"notifications.preferences.get","group":"notifications","summary":"Read your notification preferences.","cli":"dench notifications prefs","method":"GET","path":"/notifications/preferences","permission":"notifications:read","pathParams":[]},
416
430
  {"id":"notifications.preferences.update","group":"notifications","summary":"Update your notification preferences.","cli":"dench notifications prefs --set","method":"PATCH","path":"/notifications/preferences","permission":"notifications:write","pathParams":[]},
431
+ {"id":"settings.sync.get","group":"settings","summary":"Read the workspace's Sync switches (accounts from email, contacts from LinkedIn, Slack Connect, calendar, dossier, tasks from email, lead auto-qualify, summaries and Brief). All on by default.","cli":"dench settings sync","method":"GET","path":"/settings/sync","permission":"settings:read","pathParams":[]},
432
+ {"id":"settings.sync.update","group":"settings","summary":"Flip Sync switches (admin). Partial patch: only the keys sent change. Off stops new work; nothing already created is removed.","cli":"dench settings sync set","method":"PATCH","path":"/settings/sync","permission":"settings:write","pathParams":[]},
417
433
  ];
418
434
 
419
435
  /** CLI-only operation ids (sessions, fs, imports): never callable from an app. */
@@ -1154,6 +1154,134 @@ const rawApiOperations = [
1154
1154
  responseSchema: anyResponse,
1155
1155
  backend: convex("query", "functions/crm/entries:get"),
1156
1156
  }),
1157
+ op({
1158
+ id: "crm.entries.syncHistory",
1159
+ group: "crm",
1160
+ summary:
1161
+ "Queue a full, paged pull of the record's email history from every connected mailbox; the ledger fills as pages land.",
1162
+ cli: "dench crm entries sync-history",
1163
+ method: "POST",
1164
+ path: "/crm/objects/{objectName}/entries/{entryId}/sync-history",
1165
+ requestSchema: noBody,
1166
+ responseSchema: anyResponse,
1167
+ backend: {
1168
+ ...convex("mutation", "functions/emailIdentityHistory:requestForEntry"),
1169
+ transformArgs: (input) => ({
1170
+ objectName: input.objectName,
1171
+ entryId: input.entryId,
1172
+ }),
1173
+ },
1174
+ }),
1175
+ op({
1176
+ id: "crm.entries.syncHistoryStatus",
1177
+ group: "crm",
1178
+ summary:
1179
+ "Has Dench read this record's email history? One row per address per mailbox.",
1180
+ cli: "dench crm entries sync-history --status",
1181
+ method: "GET",
1182
+ path: "/crm/objects/{objectName}/entries/{entryId}/sync-history",
1183
+ requestSchema: noBody,
1184
+ responseSchema: anyResponse,
1185
+ backend: {
1186
+ ...convex("query", "functions/emailIdentityHistory:statusForEntry"),
1187
+ transformArgs: (input) => ({
1188
+ objectName: input.objectName,
1189
+ entryId: input.entryId,
1190
+ }),
1191
+ },
1192
+ }),
1193
+ op({
1194
+ id: "crm.entries.dossier.get",
1195
+ group: "crm",
1196
+ summary:
1197
+ "Status of the account's research dossier — the delimited `dench:dossier` section Dench keeps in the record's Notes: status, when it was written, how many dated updates followed, the last error.",
1198
+ cli: "dench crm entries dossier",
1199
+ method: "GET",
1200
+ path: "/crm/entries/{entryId}/dossier",
1201
+ requestSchema: noBody,
1202
+ responseSchema: anyResponse,
1203
+ backend: {
1204
+ ...convex("query", "functions/crm/dossier:getForEntry"),
1205
+ transformArgs: (input) => ({ entryId: input.entryId }),
1206
+ },
1207
+ }),
1208
+ op({
1209
+ id: "crm.entries.dossier.regenerate",
1210
+ group: "crm",
1211
+ summary:
1212
+ "Research the account again and append a fresh dossier section to its Notes (needs a Website / Domain on the record).",
1213
+ cli: "dench crm entries dossier --regenerate",
1214
+ method: "POST",
1215
+ path: "/crm/entries/{entryId}/dossier/regenerate",
1216
+ requestSchema: noBody,
1217
+ responseSchema: anyResponse,
1218
+ backend: {
1219
+ ...convex("mutation", "functions/crm/dossier:regenerate"),
1220
+ transformArgs: (input) => ({ entryId: input.entryId }),
1221
+ },
1222
+ }),
1223
+ // Account detection (plan §4): the verdicts Dench took on counterparties
1224
+ // that emailed the workspace, the LinkedIn resolver's rows on the same
1225
+ // table, and the ONE rollback for everything the ingestion jobs created
1226
+ // (§13 #38): detections (email + sweep), linkedin, email-tasks.
1227
+ op({
1228
+ id: "crm.detections.list",
1229
+ group: "crm",
1230
+ summary:
1231
+ "List account-detection verdicts — why a domain (or personal address) did or did not become an account: verdict, counterparty type, probabilities, evidence threads, the rows created. `kind` picks the creator: `detections` (email + sweep), `linkedin` (the LinkedIn resolver's rows) or `all` (default). Newest first.",
1232
+ cli: "dench crm detections list",
1233
+ method: "GET",
1234
+ path: "/crm/detections",
1235
+ requestSchema: noBody,
1236
+ responseSchema: anyResponse,
1237
+ backend: {
1238
+ ...convex("query", "functions/crm/accountDetection:list"),
1239
+ transformArgs: (input) => ({
1240
+ ...(typeof input.verdict === "string"
1241
+ ? { verdict: input.verdict }
1242
+ : {}),
1243
+ ...(input.kind === "detections" ||
1244
+ input.kind === "linkedin" ||
1245
+ input.kind === "all"
1246
+ ? { kind: input.kind }
1247
+ : {}),
1248
+ ...(typeof input.since === "number" ? { since: input.since } : {}),
1249
+ ...(typeof input.limit === "number"
1250
+ ? { limit: Math.min(Math.max(Math.floor(input.limit), 1), 200) }
1251
+ : {}),
1252
+ }),
1253
+ },
1254
+ }),
1255
+ op({
1256
+ id: "crm.detections.undo",
1257
+ group: "crm",
1258
+ summary:
1259
+ "Undo what the ingestion jobs created since a timestamp (admin): `kind` = `detections` (accounts + contacts from the email detector and the sweep), `linkedin` (the LinkedIn resolver's contacts + accounts; their conversations are unlinked and parked), `email-tasks` (auto-created tasks and cases) or `all` (default). Deletes only rows no human has touched and marks the verdicts / decisions rolled_back so they are never re-created. `dryRun` lists what would go; per-kind counts in `kinds`.",
1260
+ cli: "dench crm detections undo",
1261
+ method: "POST",
1262
+ path: "/crm/detections/undo",
1263
+ requestSchema: z.object({
1264
+ since: z
1265
+ .number()
1266
+ .describe("Only verdicts / decisions at or after this ms timestamp."),
1267
+ kind: z
1268
+ .enum(["detections", "linkedin", "email-tasks", "all"])
1269
+ .optional()
1270
+ .describe("Which creator's rows to undo. Default `all`."),
1271
+ dryRun: z.boolean().optional(),
1272
+ limit: z.number().int().min(1).max(50).optional(),
1273
+ }),
1274
+ responseSchema: anyResponse,
1275
+ backend: {
1276
+ ...convex("mutation", "functions/crm/accountDetection:undo"),
1277
+ transformArgs: (input) => ({
1278
+ since: input.since,
1279
+ ...(typeof input.kind === "string" ? { kind: input.kind } : {}),
1280
+ ...(input.dryRun === true ? { dryRun: true } : {}),
1281
+ ...(typeof input.limit === "number" ? { limit: input.limit } : {}),
1282
+ }),
1283
+ },
1284
+ }),
1157
1285
  op({
1158
1286
  id: "crm.entries.history",
1159
1287
  group: "crm",
@@ -1186,6 +1314,141 @@ const rawApiOperations = [
1186
1314
  },
1187
1315
  }),
1188
1316
 
1317
+ // CRM activity ledger — one timeline per record: notes, comments, field
1318
+ // changes and every external touch (email, calendar, meeting, Slack,
1319
+ // LinkedIn). Newest first by default; only rows the caller may read.
1320
+ op({
1321
+ id: "crm.activity.list",
1322
+ group: "crm",
1323
+ summary:
1324
+ "List a CRM entry's activity ledger (comments, notes, field changes, emails, meetings, Slack, LinkedIn) in one timeline, newest first by default.",
1325
+ cli: "dench crm activity",
1326
+ method: "GET",
1327
+ path: "/crm/objects/{objectName}/entries/{entryId}/activity",
1328
+ requestSchema: noBody,
1329
+ responseSchema: anyResponse,
1330
+ backend: {
1331
+ ...convex("query", "functions/crm/activity:listForEntry"),
1332
+ transformArgs: (input) => {
1333
+ const limit =
1334
+ typeof input.limit === "number"
1335
+ ? Math.min(Math.max(Math.floor(input.limit), 1), 200)
1336
+ : 40;
1337
+ const kinds =
1338
+ typeof input.kinds === "string"
1339
+ ? input.kinds
1340
+ .split(",")
1341
+ .map((k: string) => k.trim())
1342
+ .filter(Boolean)
1343
+ : Array.isArray(input.kinds)
1344
+ ? input.kinds
1345
+ : undefined;
1346
+ return {
1347
+ objectName: input.objectName,
1348
+ entryId: input.entryId,
1349
+ order: input.order === "asc" ? "asc" : "desc",
1350
+ limit,
1351
+ includeSystem: input.includeSystem === true,
1352
+ ...(kinds && kinds.length > 0 ? { kinds } : {}),
1353
+ ...(typeof input.before === "number" ? { before: input.before } : {}),
1354
+ ...(typeof input.after === "number" ? { after: input.after } : {}),
1355
+ };
1356
+ },
1357
+ },
1358
+ }),
1359
+ op({
1360
+ id: "crm.brief.get",
1361
+ group: "crm",
1362
+ summary:
1363
+ "The record's generated Brief: health, who owes the next move, open threads, commitments, risks, next step, with provenance. Read this before the ledger.",
1364
+ cli: "dench crm brief",
1365
+ method: "GET",
1366
+ path: "/crm/objects/{objectName}/entries/{entryId}/brief",
1367
+ requestSchema: noBody,
1368
+ responseSchema: anyResponse,
1369
+ backend: {
1370
+ ...convex("query", "functions/crm/intelligence:getForEntry"),
1371
+ transformArgs: (input) => ({
1372
+ objectName: input.objectName,
1373
+ entryId: input.entryId,
1374
+ }),
1375
+ },
1376
+ }),
1377
+ op({
1378
+ id: "crm.brief.regenerate",
1379
+ group: "crm",
1380
+ summary: "Rebuild a record's Brief from the current timeline.",
1381
+ cli: "dench crm brief --regenerate",
1382
+ method: "POST",
1383
+ path: "/crm/objects/{objectName}/entries/{entryId}/brief/regenerate",
1384
+ requestSchema: noBody,
1385
+ responseSchema: anyResponse,
1386
+ backend: {
1387
+ ...convex("mutation", "functions/crm/intelligence:regenerate"),
1388
+ transformArgs: (input) => ({
1389
+ objectName: input.objectName,
1390
+ entryId: input.entryId,
1391
+ }),
1392
+ },
1393
+ }),
1394
+ op({
1395
+ id: "crm.activity.count",
1396
+ group: "crm",
1397
+ summary: "Bounded per-source counts of a CRM entry's activity ledger.",
1398
+ cli: "dench crm activity",
1399
+ method: "GET",
1400
+ path: "/crm/objects/{objectName}/entries/{entryId}/activity/count",
1401
+ requestSchema: noBody,
1402
+ responseSchema: anyResponse,
1403
+ backend: {
1404
+ ...convex("query", "functions/crm/activity:countForEntry"),
1405
+ transformArgs: (input) => ({
1406
+ objectName: input.objectName,
1407
+ entryId: input.entryId,
1408
+ includeSystem: input.includeSystem === true,
1409
+ }),
1410
+ },
1411
+ }),
1412
+ op({
1413
+ id: "crm.notes.list",
1414
+ group: "crm",
1415
+ summary:
1416
+ "List a CRM entry's notes (titled, document-style comments), newest first.",
1417
+ cli: "dench crm notes list",
1418
+ method: "GET",
1419
+ path: "/crm/objects/{objectName}/entries/{entryId}/notes",
1420
+ requestSchema: noBody,
1421
+ responseSchema: anyResponse,
1422
+ backend: {
1423
+ ...convex("query", "functions/crm/activity:listNotesForEntry"),
1424
+ transformArgs: (input) => ({
1425
+ objectName: input.objectName,
1426
+ entryId: input.entryId,
1427
+ limit:
1428
+ typeof input.limit === "number"
1429
+ ? Math.min(Math.max(Math.floor(input.limit), 1), 200)
1430
+ : 50,
1431
+ }),
1432
+ },
1433
+ }),
1434
+ op({
1435
+ id: "crm.notes.create",
1436
+ group: "crm",
1437
+ summary:
1438
+ "Add a titled note to a CRM entry's activity timeline (markdown body). Research goes here, never into the Notes document.",
1439
+ cli: "dench crm notes create",
1440
+ method: "POST",
1441
+ path: "/crm/objects/{objectName}/entries/{entryId}/notes",
1442
+ requestSchema: anyObject,
1443
+ responseSchema: anyResponse,
1444
+ backend: {
1445
+ ...convex("mutation", "functions/crm/comments:create", "bearer", {
1446
+ includeRunId: true,
1447
+ }),
1448
+ transformArgs: (input) => ({ ...input, kind: "note" }),
1449
+ },
1450
+ }),
1451
+
1189
1452
  // CRM comments — threaded conversation on a record, merged with history
1190
1453
  // into the record's Activity feed. `@Dench` in a body summons the agent.
1191
1454
  op({
@@ -4406,6 +4669,40 @@ const rawApiOperations = [
4406
4669
  "functions/notifications:updateMyNotificationPreferences",
4407
4670
  ),
4408
4671
  }),
4672
+
4673
+ // Workspace settings — Settings → Sync: the eight switches for what Dench
4674
+ // does on its own with email, calendar, Slack and LinkedIn. Reads for any
4675
+ // member; the write is admin-only server-side.
4676
+ op({
4677
+ id: "settings.sync.get",
4678
+ group: "settings",
4679
+ summary:
4680
+ "Read the workspace's Sync switches (accounts from email, contacts from LinkedIn, Slack Connect, calendar, dossier, tasks from email, lead auto-qualify, summaries and Brief). All on by default.",
4681
+ cli: "dench settings sync",
4682
+ method: "GET",
4683
+ path: "/settings/sync",
4684
+ requestSchema: noBody,
4685
+ responseSchema: anyResponse,
4686
+ backend: convex("query", "functions/organizations:getMySyncSettings"),
4687
+ }),
4688
+ op({
4689
+ id: "settings.sync.update",
4690
+ group: "settings",
4691
+ summary:
4692
+ "Flip Sync switches (admin). Partial patch: only the keys sent change. Off stops new work; nothing already created is removed.",
4693
+ cli: "dench settings sync set",
4694
+ method: "PATCH",
4695
+ path: "/settings/sync",
4696
+ requestSchema: anyObject,
4697
+ responseSchema: anyResponse,
4698
+ backend: {
4699
+ ...convex(
4700
+ "mutation",
4701
+ "functions/organizations:updateMyOrganizationSyncSettings",
4702
+ ),
4703
+ transformArgs: (input) => ({ patch: input }),
4704
+ },
4705
+ }),
4409
4706
  ] as const satisfies readonly ApiOperation[];
4410
4707
 
4411
4708
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dench.com/cli",
3
- "version": "3.4.0-staging.317",
3
+ "version": "3.5.0-staging.327",
4
4
  "description": "Dench agent workspace CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,11 +32,13 @@
32
32
  "crm.ts",
33
33
  "crm-comments.ts",
34
34
  "crm-analytics.ts",
35
+ "crm-detections.ts",
35
36
  "meetings.ts",
36
37
  "email.ts",
37
38
  "campaign.ts",
38
39
  "members.ts",
39
40
  "notifications.ts",
41
+ "settings.ts",
40
42
  "cron.ts",
41
43
  "browser.ts",
42
44
  "ads.ts",