@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/app-sdk.d.ts +126 -0
- package/crm-comments.ts +444 -1
- package/crm-detections.ts +261 -0
- package/crm.ts +223 -13
- package/cron.ts +54 -15
- package/dench.ts +37 -0
- package/lib/api-schemas.ts +73 -0
- package/lib/app-sdk-catalog.generated.ts +16 -0
- package/lib/command-registry.ts +297 -0
- package/package.json +3 -1
- package/settings.ts +229 -0
package/settings.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dench settings <subcommand>` — workspace settings from the command line.
|
|
3
|
+
*
|
|
4
|
+
* Today that is Settings → Sync: the eight switches that decide what Dench
|
|
5
|
+
* does on its own with the workspace's email, calendar, Slack and LinkedIn
|
|
6
|
+
* (docs/agent-notes/account-context-ingestion.md §12). All on by default;
|
|
7
|
+
* turning one off stops NEW work and never removes anything already created.
|
|
8
|
+
*
|
|
9
|
+
* dench settings sync [--json] the eight switches
|
|
10
|
+
* dench settings sync set <key> on|off [--json] admin-only
|
|
11
|
+
*
|
|
12
|
+
* Reads `functions/organizations:getMySyncSettings` and writes
|
|
13
|
+
* `functions/organizations:updateMyOrganizationSyncSettings` with a one-key
|
|
14
|
+
* patch, forwarding the same bearer every other CLI surface uses. The
|
|
15
|
+
* backend enforces admin on the write (`requireCrmAdminAccess`), so an agent
|
|
16
|
+
* session acting for a member is refused server-side, not here.
|
|
17
|
+
*
|
|
18
|
+
* The key list mirrors `SYNC_SETTING_KEYS` in `convex/lib/orgSettings.ts`;
|
|
19
|
+
* the CLI package does not import from `convex/`, so a test pins the two.
|
|
20
|
+
*/
|
|
21
|
+
import type { ConvexHttpClient } from "convex/browser";
|
|
22
|
+
import { makeFunctionReference } from "convex/server";
|
|
23
|
+
import { assertNoUnknownFlags, CliArgError, hasFlag } from "./lib/cli-args";
|
|
24
|
+
|
|
25
|
+
class SettingsCliError extends Error {}
|
|
26
|
+
|
|
27
|
+
type Ctx = {
|
|
28
|
+
convex: ConvexHttpClient;
|
|
29
|
+
args: string[];
|
|
30
|
+
jsonOutput: boolean;
|
|
31
|
+
sessionToken?: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Key → the label Settings → Sync shows, in page order. */
|
|
35
|
+
export const SYNC_SETTING_LABELS = {
|
|
36
|
+
detectAccounts: "Accounts from email",
|
|
37
|
+
linkedinContacts: "Contacts from LinkedIn",
|
|
38
|
+
slackConnectAccounts: "Accounts from Slack Connect",
|
|
39
|
+
calendarContacts: "Contacts from calendar",
|
|
40
|
+
dossier: "Research dossier",
|
|
41
|
+
emailTasks: "Tasks from email",
|
|
42
|
+
leadAutoQualify: "Qualify leads that book",
|
|
43
|
+
intelligence: "Summaries and Brief",
|
|
44
|
+
} as const;
|
|
45
|
+
|
|
46
|
+
export type SyncSettingKey = keyof typeof SYNC_SETTING_LABELS;
|
|
47
|
+
export const SYNC_SETTING_KEYS = Object.keys(
|
|
48
|
+
SYNC_SETTING_LABELS,
|
|
49
|
+
) as SyncSettingKey[];
|
|
50
|
+
|
|
51
|
+
const api = {
|
|
52
|
+
getSync: makeFunctionReference<"query">(
|
|
53
|
+
"functions/organizations:getMySyncSettings",
|
|
54
|
+
),
|
|
55
|
+
updateSync: makeFunctionReference<"mutation">(
|
|
56
|
+
"functions/organizations:updateMyOrganizationSyncSettings",
|
|
57
|
+
),
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const HELP = `dench settings — workspace settings
|
|
61
|
+
|
|
62
|
+
dench settings sync [--json]
|
|
63
|
+
The eight Sync switches: what Dench does on its own with your email,
|
|
64
|
+
calendar, Slack and LinkedIn. All on by default.
|
|
65
|
+
dench settings sync set <key> on|off [--json]
|
|
66
|
+
Flip one switch (workspace admins only). Off stops new work; nothing
|
|
67
|
+
already created is removed.
|
|
68
|
+
|
|
69
|
+
Keys:
|
|
70
|
+
${SYNC_SETTING_KEYS.map((key) => ` ${key.padEnd(22)} ${SYNC_SETTING_LABELS[key]}`).join("\n")}
|
|
71
|
+
|
|
72
|
+
Keys are accepted in camelCase or kebab-case (detect-accounts).`;
|
|
73
|
+
|
|
74
|
+
/** `detect-accounts` / `DetectAccounts` → `detectAccounts`; unknown → error. */
|
|
75
|
+
export function parseSyncSettingKey(raw: string | undefined): SyncSettingKey {
|
|
76
|
+
const normalized = (raw ?? "")
|
|
77
|
+
.trim()
|
|
78
|
+
.toLowerCase()
|
|
79
|
+
.replace(/[-_\s]/g, "");
|
|
80
|
+
const key = SYNC_SETTING_KEYS.find(
|
|
81
|
+
(candidate) => candidate.toLowerCase() === normalized,
|
|
82
|
+
);
|
|
83
|
+
if (!key) {
|
|
84
|
+
throw new SettingsCliError(
|
|
85
|
+
`Unknown Sync setting "${raw ?? ""}". One of: ${SYNC_SETTING_KEYS.join(", ")}.`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return key;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** `on|off|true|false|1|0` → boolean; anything else → error. */
|
|
92
|
+
export function parseSyncSettingValue(raw: string | undefined): boolean {
|
|
93
|
+
const normalized = (raw ?? "").trim().toLowerCase();
|
|
94
|
+
if (["on", "true", "1", "yes", "enabled"].includes(normalized)) return true;
|
|
95
|
+
if (["off", "false", "0", "no", "disabled"].includes(normalized))
|
|
96
|
+
return false;
|
|
97
|
+
throw new SettingsCliError(
|
|
98
|
+
`Expected on|off after the key, got "${raw ?? ""}".`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function withToken(ctx: Ctx, args: Record<string, unknown>) {
|
|
103
|
+
return {
|
|
104
|
+
...args,
|
|
105
|
+
...(ctx.sessionToken ? { sessionToken: ctx.sessionToken } : {}),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function toCliError(error: unknown): Error {
|
|
110
|
+
if (error instanceof CliArgError) return new SettingsCliError(error.message);
|
|
111
|
+
const data = (error as { data?: unknown } | null)?.data;
|
|
112
|
+
if (typeof data === "string" && data.trim()) {
|
|
113
|
+
return new SettingsCliError(data.trim());
|
|
114
|
+
}
|
|
115
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function formatSyncSettingsTable(
|
|
119
|
+
settings: Record<string, boolean>,
|
|
120
|
+
): string {
|
|
121
|
+
const rows = SYNC_SETTING_KEYS.map((key) => [
|
|
122
|
+
key,
|
|
123
|
+
settings[key] === false ? "off" : "on",
|
|
124
|
+
SYNC_SETTING_LABELS[key],
|
|
125
|
+
]);
|
|
126
|
+
const headers = ["key", "state", "label"];
|
|
127
|
+
const widths = headers.map((header, idx) =>
|
|
128
|
+
Math.max(header.length, ...rows.map((row) => row[idx].length)),
|
|
129
|
+
);
|
|
130
|
+
const line = (row: string[]) =>
|
|
131
|
+
row
|
|
132
|
+
.map((cell, idx) => cell.padEnd(widths[idx]))
|
|
133
|
+
.join(" ")
|
|
134
|
+
.trimEnd();
|
|
135
|
+
return [
|
|
136
|
+
line(headers),
|
|
137
|
+
widths.map((w) => "-".repeat(w)).join(" "),
|
|
138
|
+
...rows.map(line),
|
|
139
|
+
].join("\n");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export async function runSettingsCommand(opts: {
|
|
143
|
+
convex: ConvexHttpClient;
|
|
144
|
+
args: string[];
|
|
145
|
+
sessionToken?: string;
|
|
146
|
+
jsonOutput?: boolean;
|
|
147
|
+
}): Promise<void> {
|
|
148
|
+
const args = [...opts.args];
|
|
149
|
+
// Drain the flag even when the dispatcher pre-resolved it, or
|
|
150
|
+
// `assertNoUnknownFlags` rejects `--json` (AGENTS.md, CLI `--json` contract).
|
|
151
|
+
const jsonOutput = hasFlag(args, "--json") || opts.jsonOutput === true;
|
|
152
|
+
const ctx: Ctx = {
|
|
153
|
+
convex: opts.convex,
|
|
154
|
+
args,
|
|
155
|
+
jsonOutput,
|
|
156
|
+
sessionToken: opts.sessionToken,
|
|
157
|
+
};
|
|
158
|
+
const subcommand = args.shift();
|
|
159
|
+
if (!subcommand || subcommand === "help" || subcommand === "--help") {
|
|
160
|
+
console.log(HELP);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (subcommand !== "sync") {
|
|
164
|
+
throw new SettingsCliError(
|
|
165
|
+
`Unknown settings subcommand: ${subcommand}. Run \`dench settings help\`.`,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
const verb = args[0];
|
|
169
|
+
if (verb === "set") {
|
|
170
|
+
args.shift();
|
|
171
|
+
return await runSyncSet(ctx);
|
|
172
|
+
}
|
|
173
|
+
if (verb === "get") args.shift();
|
|
174
|
+
return await runSyncGet(ctx);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async function runSyncGet(ctx: Ctx): Promise<void> {
|
|
178
|
+
assertNoUnknownFlags(ctx.args, "settings sync");
|
|
179
|
+
if (ctx.args.length > 0) {
|
|
180
|
+
throw new SettingsCliError(
|
|
181
|
+
`Unexpected argument "${ctx.args[0]}". Did you mean \`dench settings sync set <key> on|off\`?`,
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
let settings: Record<string, boolean>;
|
|
185
|
+
try {
|
|
186
|
+
settings = (await ctx.convex.query(
|
|
187
|
+
api.getSync,
|
|
188
|
+
withToken(ctx, {}) as never,
|
|
189
|
+
)) as Record<string, boolean>;
|
|
190
|
+
} catch (error) {
|
|
191
|
+
throw toCliError(error);
|
|
192
|
+
}
|
|
193
|
+
if (ctx.jsonOutput) {
|
|
194
|
+
console.log(JSON.stringify(settings, null, 2));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
console.log(formatSyncSettingsTable(settings));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function runSyncSet(ctx: Ctx): Promise<void> {
|
|
201
|
+
const key = parseSyncSettingKey(ctx.args.shift());
|
|
202
|
+
const value = parseSyncSettingValue(ctx.args.shift());
|
|
203
|
+
assertNoUnknownFlags(ctx.args, "settings sync set");
|
|
204
|
+
if (ctx.args.length > 0) {
|
|
205
|
+
throw new SettingsCliError(`Unexpected argument "${ctx.args[0]}".`);
|
|
206
|
+
}
|
|
207
|
+
let settings: Record<string, boolean>;
|
|
208
|
+
try {
|
|
209
|
+
settings = (await ctx.convex.mutation(
|
|
210
|
+
api.updateSync,
|
|
211
|
+
withToken(ctx, { patch: { [key]: value } }) as never,
|
|
212
|
+
)) as Record<string, boolean>;
|
|
213
|
+
} catch (error) {
|
|
214
|
+
throw toCliError(error);
|
|
215
|
+
}
|
|
216
|
+
if (ctx.jsonOutput) {
|
|
217
|
+
console.log(JSON.stringify(settings, null, 2));
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
console.log(
|
|
221
|
+
`${SYNC_SETTING_LABELS[key]} (${key}) is now ${value ? "on" : "off"}.${
|
|
222
|
+
value
|
|
223
|
+
? ""
|
|
224
|
+
: " New work stops from here; nothing already created is removed."
|
|
225
|
+
}`,
|
|
226
|
+
);
|
|
227
|
+
console.log("");
|
|
228
|
+
console.log(formatSyncSettingsTable(settings));
|
|
229
|
+
}
|