@usenaive-sdk/cli 0.11.0 → 0.12.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.
Files changed (46) hide show
  1. package/dist/client.js +1 -1
  2. package/dist/client.js.map +1 -1
  3. package/dist/commands/agent-profiles.d.ts +11 -0
  4. package/dist/commands/agent-profiles.js +120 -0
  5. package/dist/commands/agent-profiles.js.map +1 -0
  6. package/dist/commands/approvals.js +1 -1
  7. package/dist/commands/billing-client.d.ts +2 -0
  8. package/dist/commands/billing-client.js +271 -0
  9. package/dist/commands/billing-client.js.map +1 -0
  10. package/dist/commands/crm-app.d.ts +2 -0
  11. package/dist/commands/crm-app.js +306 -0
  12. package/dist/commands/crm-app.js.map +1 -0
  13. package/dist/commands/crm.d.ts +2 -0
  14. package/dist/commands/crm.js +319 -0
  15. package/dist/commands/crm.js.map +1 -0
  16. package/dist/commands/env.d.ts +7 -0
  17. package/dist/commands/env.js +48 -0
  18. package/dist/commands/env.js.map +1 -0
  19. package/dist/commands/init.d.ts +2 -0
  20. package/dist/commands/init.js +67 -0
  21. package/dist/commands/init.js.map +1 -0
  22. package/dist/commands/integrations.d.ts +2 -0
  23. package/dist/commands/integrations.js +199 -0
  24. package/dist/commands/integrations.js.map +1 -0
  25. package/dist/commands/logs.js +1 -1
  26. package/dist/commands/logs.js.map +1 -1
  27. package/dist/commands/module.d.ts +8 -0
  28. package/dist/commands/module.js +48 -0
  29. package/dist/commands/module.js.map +1 -0
  30. package/dist/commands/operators.d.ts +11 -0
  31. package/dist/commands/operators.js +120 -0
  32. package/dist/commands/operators.js.map +1 -0
  33. package/dist/commands/report.d.ts +17 -0
  34. package/dist/commands/report.js +109 -0
  35. package/dist/commands/report.js.map +1 -0
  36. package/dist/commands/up.d.ts +3 -0
  37. package/dist/commands/up.js +251 -0
  38. package/dist/commands/up.js.map +1 -0
  39. package/dist/index.js +40 -14
  40. package/dist/index.js.map +1 -1
  41. package/dist/output.js +11 -0
  42. package/dist/output.js.map +1 -1
  43. package/dist/version.d.ts +2 -0
  44. package/dist/version.js +14 -0
  45. package/dist/version.js.map +1 -0
  46. package/package.json +10 -10
@@ -0,0 +1,306 @@
1
+ import { Command } from "commander";
2
+ import { apiRequest, handleApiError } from "../client.js";
3
+ import { agentOutput } from "../output.js";
4
+ export const crmAppCmd = new Command("crm-app")
5
+ .description("CRM template app — agency pipeline (deals, deliverables, retainers). Distinct from 'naive crm' (vertical-agnostic primitive).")
6
+ .addHelpText("after", `
7
+ Subcommands:
8
+ naive crm-app deals ... Pipeline deals (lead → discovery → proposal → won → active → churned)
9
+ naive crm-app deliverables ... Client deliverables (with optional kanban task mirroring)
10
+ naive crm-app retainers ... Monthly retainers (linked to ext_subscriptions)
11
+ naive crm-app clients Won/active deals grouped by contact + billing-profile MRR/LTV
12
+ naive crm-app summary Aggregate pipeline + MRR + overdue counts
13
+
14
+ Examples:
15
+ $ naive crm-app deals create --title "Acme Q3 implementation" --crm-contact <id>
16
+ $ naive crm-app deals advance <deal-id> --stage proposal
17
+ $ naive crm-app deliverables create --deal <id> --title "Discovery doc" --create-task --assignee delivery-lead
18
+ `);
19
+ // ── Deals ─────────────────────────────────────────────────────────────────
20
+ const dealsCmd = crmAppCmd.command("deals").description("Pipeline deal management");
21
+ dealsCmd
22
+ .command("list")
23
+ .description("List deals")
24
+ .option("--stage <stage>", "Filter by stage (lead|discovery|proposal|won|active|churned)")
25
+ .option("--crm-contact <id>", "Filter by CRM contact")
26
+ .option("--owner <id>", "Filter by owner agent")
27
+ .option("--limit <n>", "Max results (default 50)", "50")
28
+ .option("--offset <n>", "Pagination offset", "0")
29
+ .action(async (opts) => {
30
+ const params = new URLSearchParams({ limit: opts.limit, offset: opts.offset });
31
+ if (opts.stage)
32
+ params.set("stage", opts.stage);
33
+ if (opts.crmContact)
34
+ params.set("crm_contact_id", opts.crmContact);
35
+ if (opts.owner)
36
+ params.set("owner_agent_id", opts.owner);
37
+ const resp = await apiRequest("GET", `/v1/crm-app/deals?${params}`);
38
+ handleApiError("crm-app.deals.list", resp);
39
+ const data = resp.data;
40
+ agentOutput({
41
+ action: "crm-app.deals.list",
42
+ result: resp.data,
43
+ hints: [`${data.count} deal${data.count === 1 ? "" : "s"} returned`],
44
+ next_steps: data.deals.length > 0
45
+ ? [{ command: `naive crm-app deals advance ${data.deals[0].id} --stage discovery`, description: "Advance the first deal" }]
46
+ : [{ command: "naive crm-app deals create --title <title> --crm-contact <id>", description: "Create your first deal" }],
47
+ related_commands: ["naive crm-app deals create", "naive crm-app deals advance", "naive crm-app summary"],
48
+ });
49
+ });
50
+ dealsCmd
51
+ .command("create")
52
+ .description("Create a deal")
53
+ .requiredOption("--title <title>", "Deal name")
54
+ .requiredOption("--crm-contact <id>", "CRM contact UUID")
55
+ .option("--crm-company <id>", "CRM company UUID")
56
+ .option("--template-app-instance <id>", "CRM template app instance UUID")
57
+ .option("--stage <stage>", "Initial stage (default lead)")
58
+ .option("--value-cents <n>", "Deal value in cents")
59
+ .option("--currency <iso>", "ISO currency code")
60
+ .option("--owner <id>", "Owning agent UUID")
61
+ .option("--source <text>", "Where the deal came from")
62
+ .option("--notes <text>", "Free-form notes")
63
+ .action(async (opts) => {
64
+ const resp = await apiRequest("POST", "/v1/crm-app/deals", {
65
+ title: opts.title,
66
+ crm_contact_id: opts.crmContact,
67
+ crm_company_id: opts.crmCompany,
68
+ template_app_instance_id: opts.templateAppInstance,
69
+ stage: opts.stage,
70
+ value_cents: opts.valueCents ? parseInt(opts.valueCents, 10) : undefined,
71
+ currency: opts.currency,
72
+ owner_agent_id: opts.owner,
73
+ source: opts.source,
74
+ notes: opts.notes,
75
+ });
76
+ handleApiError("crm-app.deals.create", resp);
77
+ const data = resp.data;
78
+ agentOutput({
79
+ action: "crm-app.deals.create",
80
+ result: resp.data,
81
+ next_steps: [
82
+ { command: `naive crm-app deliverables create --deal ${data.deal.id} --title <title>`, description: "Add the first deliverable" },
83
+ { command: `naive crm-app deals advance ${data.deal.id} --stage discovery`, description: "Advance to discovery once a meeting is booked" },
84
+ ],
85
+ related_commands: ["naive crm-app deals advance", "naive crm-app deliverables create"],
86
+ });
87
+ });
88
+ dealsCmd
89
+ .command("get <deal_id>")
90
+ .description("Get a deal")
91
+ .action(async (dealId) => {
92
+ const resp = await apiRequest("GET", `/v1/crm-app/deals/${dealId}`);
93
+ handleApiError("crm-app.deals.get", resp);
94
+ agentOutput({
95
+ action: "crm-app.deals.get",
96
+ result: resp.data,
97
+ related_commands: ["naive crm-app deals advance", "naive crm-app deliverables list"],
98
+ });
99
+ });
100
+ dealsCmd
101
+ .command("advance <deal_id>")
102
+ .description("Advance a deal to a new stage")
103
+ .requiredOption("--stage <stage>", "New stage (lead|discovery|proposal|won|active|churned)")
104
+ .option("--notes <text>", "Optional notes about the transition")
105
+ .action(async (dealId, opts) => {
106
+ const resp = await apiRequest("POST", `/v1/crm-app/deals/${dealId}/advance`, {
107
+ stage: opts.stage,
108
+ notes: opts.notes,
109
+ });
110
+ handleApiError("crm-app.deals.advance", resp);
111
+ agentOutput({
112
+ action: "crm-app.deals.advance",
113
+ result: resp.data,
114
+ next_steps: [{ command: `naive crm contacts history <contact_id>`, description: "Verify the transition was logged as an interaction" }],
115
+ related_commands: ["naive crm-app deals list", "naive crm-app summary"],
116
+ });
117
+ });
118
+ dealsCmd
119
+ .command("update <deal_id>")
120
+ .description("Update deal fields")
121
+ .option("--title <title>")
122
+ .option("--value-cents <n>")
123
+ .option("--notes <text>")
124
+ .action(async (dealId, opts) => {
125
+ const body = {};
126
+ if (opts.title !== undefined)
127
+ body.title = opts.title;
128
+ if (opts.valueCents !== undefined)
129
+ body.value_cents = parseInt(opts.valueCents, 10);
130
+ if (opts.notes !== undefined)
131
+ body.notes = opts.notes;
132
+ const resp = await apiRequest("PATCH", `/v1/crm-app/deals/${dealId}`, body);
133
+ handleApiError("crm-app.deals.update", resp);
134
+ agentOutput({ action: "crm-app.deals.update", result: resp.data, related_commands: ["naive crm-app deals get"] });
135
+ });
136
+ dealsCmd
137
+ .command("delete <deal_id>")
138
+ .description("Delete a deal (cascade)")
139
+ .action(async (dealId) => {
140
+ const resp = await apiRequest("DELETE", `/v1/crm-app/deals/${dealId}`);
141
+ handleApiError("crm-app.deals.delete", resp);
142
+ agentOutput({ action: "crm-app.deals.delete", result: resp.data, related_commands: ["naive crm-app deals list"] });
143
+ });
144
+ // ── Deliverables ─────────────────────────────────────────────────────────
145
+ const deliverablesCmd = crmAppCmd.command("deliverables").description("Client deliverable management");
146
+ deliverablesCmd
147
+ .command("list")
148
+ .description("List deliverables")
149
+ .option("--deal <id>")
150
+ .option("--status <status>", "pending|in_progress|review|done|blocked")
151
+ .option("--owner <id>")
152
+ .option("--limit <n>", "Max results", "50")
153
+ .option("--offset <n>", "Pagination offset", "0")
154
+ .action(async (opts) => {
155
+ const params = new URLSearchParams({ limit: opts.limit, offset: opts.offset });
156
+ if (opts.deal)
157
+ params.set("deal_id", opts.deal);
158
+ if (opts.status)
159
+ params.set("status", opts.status);
160
+ if (opts.owner)
161
+ params.set("owner_agent_id", opts.owner);
162
+ const resp = await apiRequest("GET", `/v1/crm-app/deliverables?${params}`);
163
+ handleApiError("crm-app.deliverables.list", resp);
164
+ const data = resp.data;
165
+ agentOutput({
166
+ action: "crm-app.deliverables.list",
167
+ result: resp.data,
168
+ hints: [`${data.count} deliverable${data.count === 1 ? "" : "s"} returned`],
169
+ related_commands: ["naive crm-app deliverables create", "naive crm-app deliverables update"],
170
+ });
171
+ });
172
+ deliverablesCmd
173
+ .command("create")
174
+ .description("Create a deliverable")
175
+ .requiredOption("--deal <id>", "Deal UUID")
176
+ .requiredOption("--title <title>", "Deliverable title")
177
+ .option("--description <text>")
178
+ .option("--status <status>", "pending|in_progress|review|done|blocked")
179
+ .option("--due-date <iso>")
180
+ .option("--owner <id>", "Owner agent UUID")
181
+ .option("--create-task", "Mirror as a kanban task (status will auto-sync)")
182
+ .option("--assignee <profile>", "Hermes profile name (when --create-task)")
183
+ .option("--priority <level>", "low|normal|high|critical (when --create-task)")
184
+ .action(async (opts) => {
185
+ const resp = await apiRequest("POST", "/v1/crm-app/deliverables", {
186
+ deal_id: opts.deal,
187
+ title: opts.title,
188
+ description: opts.description,
189
+ status: opts.status,
190
+ due_date: opts.dueDate,
191
+ owner_agent_id: opts.owner,
192
+ create_task: opts.createTask === true,
193
+ assignee: opts.assignee,
194
+ priority: opts.priority,
195
+ });
196
+ handleApiError("crm-app.deliverables.create", resp);
197
+ agentOutput({
198
+ action: "crm-app.deliverables.create",
199
+ result: resp.data,
200
+ next_steps: [{ command: "naive tasks", description: "View the mirrored task on the kanban board" }],
201
+ related_commands: ["naive crm-app deliverables update", "naive tasks"],
202
+ });
203
+ });
204
+ deliverablesCmd
205
+ .command("update <deliverable_id>")
206
+ .description("Update a deliverable")
207
+ .option("--title <title>")
208
+ .option("--status <status>")
209
+ .option("--due-date <iso>")
210
+ .option("--pct-complete <n>", "0-100")
211
+ .option("--blockers <text>")
212
+ .action(async (deliverableId, opts) => {
213
+ const body = {};
214
+ if (opts.title !== undefined)
215
+ body.title = opts.title;
216
+ if (opts.status !== undefined)
217
+ body.status = opts.status;
218
+ if (opts.dueDate !== undefined)
219
+ body.due_date = opts.dueDate;
220
+ if (opts.pctComplete !== undefined)
221
+ body.pct_complete = parseInt(opts.pctComplete, 10);
222
+ if (opts.blockers !== undefined)
223
+ body.blockers = opts.blockers;
224
+ const resp = await apiRequest("PATCH", `/v1/crm-app/deliverables/${deliverableId}`, body);
225
+ handleApiError("crm-app.deliverables.update", resp);
226
+ agentOutput({ action: "crm-app.deliverables.update", result: resp.data, related_commands: ["naive crm-app deliverables list"] });
227
+ });
228
+ deliverablesCmd
229
+ .command("delete <deliverable_id>")
230
+ .description("Delete a deliverable")
231
+ .action(async (deliverableId) => {
232
+ const resp = await apiRequest("DELETE", `/v1/crm-app/deliverables/${deliverableId}`);
233
+ handleApiError("crm-app.deliverables.delete", resp);
234
+ agentOutput({ action: "crm-app.deliverables.delete", result: resp.data, related_commands: ["naive crm-app deliverables list"] });
235
+ });
236
+ // ── Retainers ────────────────────────────────────────────────────────────
237
+ const retainersCmd = crmAppCmd.command("retainers").description("Retainer management");
238
+ retainersCmd
239
+ .command("list")
240
+ .description("List retainers")
241
+ .option("--deal <id>")
242
+ .option("--status <status>", "active|paused|ended")
243
+ .option("--limit <n>", "Max results", "50")
244
+ .option("--offset <n>", "Pagination offset", "0")
245
+ .action(async (opts) => {
246
+ const params = new URLSearchParams({ limit: opts.limit, offset: opts.offset });
247
+ if (opts.deal)
248
+ params.set("deal_id", opts.deal);
249
+ if (opts.status)
250
+ params.set("status", opts.status);
251
+ const resp = await apiRequest("GET", `/v1/crm-app/retainers?${params}`);
252
+ handleApiError("crm-app.retainers.list", resp);
253
+ agentOutput({ action: "crm-app.retainers.list", result: resp.data, related_commands: ["naive crm-app retainers create"] });
254
+ });
255
+ retainersCmd
256
+ .command("create")
257
+ .description("Create a retainer")
258
+ .requiredOption("--deal <id>", "Deal UUID")
259
+ .requiredOption("--crm-contact <id>", "CRM contact UUID")
260
+ .option("--ext-subscription <id>", "Linked ext_subscription UUID")
261
+ .option("--mrr-cents <n>", "MRR in cents", "0")
262
+ .option("--currency <iso>")
263
+ .action(async (opts) => {
264
+ const resp = await apiRequest("POST", "/v1/crm-app/retainers", {
265
+ deal_id: opts.deal,
266
+ crm_contact_id: opts.crmContact,
267
+ ext_subscription_id: opts.extSubscription,
268
+ mrr_cents: parseInt(opts.mrrCents, 10),
269
+ currency: opts.currency,
270
+ });
271
+ handleApiError("crm-app.retainers.create", resp);
272
+ agentOutput({ action: "crm-app.retainers.create", result: resp.data, related_commands: ["naive crm-app retainers list"] });
273
+ });
274
+ // ── Clients + summary ───────────────────────────────────────────────────
275
+ crmAppCmd
276
+ .command("clients")
277
+ .description("List clients (won/active deals grouped by contact, with billing-profile join)")
278
+ .option("--limit <n>", "Max results", "50")
279
+ .option("--offset <n>", "Pagination offset", "0")
280
+ .action(async (opts) => {
281
+ const params = new URLSearchParams({ limit: opts.limit, offset: opts.offset });
282
+ const resp = await apiRequest("GET", `/v1/crm-app/clients?${params}`);
283
+ handleApiError("crm-app.clients", resp);
284
+ agentOutput({
285
+ action: "crm-app.clients",
286
+ result: resp.data,
287
+ related_commands: ["naive crm-app deliverables list", "naive billing-client subscriptions list"],
288
+ });
289
+ });
290
+ crmAppCmd
291
+ .command("summary")
292
+ .description("Aggregate pipeline + MRR + overdue counts")
293
+ .option("--template-app-instance <id>")
294
+ .action(async (opts) => {
295
+ const params = new URLSearchParams();
296
+ if (opts.templateAppInstance)
297
+ params.set("template_app_instance_id", opts.templateAppInstance);
298
+ const resp = await apiRequest("GET", `/v1/crm-app/summary?${params}`);
299
+ handleApiError("crm-app.summary", resp);
300
+ agentOutput({
301
+ action: "crm-app.summary",
302
+ result: resp.data,
303
+ related_commands: ["naive crm-app deals list", "naive billing-client mrr"],
304
+ });
305
+ });
306
+ //# sourceMappingURL=crm-app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crm-app.js","sourceRoot":"","sources":["../../src/commands/crm-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,OAAO,CAAC,SAAS,CAAC;KAC5C,WAAW,CAAC,+HAA+H,CAAC;KAC5I,WAAW,CAAC,OAAO,EAAE;;;;;;;;;;;;CAYvB,CAAC,CAAC;AAEH,6EAA6E;AAE7E,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,0BAA0B,CAAC,CAAC;AAEpF,QAAQ;KACL,OAAO,CAAC,MAAM,CAAC;KACf,WAAW,CAAC,YAAY,CAAC;KACzB,MAAM,CAAC,iBAAiB,EAAE,8DAA8D,CAAC;KAC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,KAAK,EAAE,uBAAuB,MAAM,EAAE,CAAC,CAAC;IACtE,cAAc,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;IACxC,WAAW,CAAC;QACV,MAAM,EAAE,iBAAiB;QACzB,MAAM,EAAE,IAAI,CAAC,IAAI;QACjB,gBAAgB,EAAE,CAAC,iCAAiC,EAAE,yCAAyC,CAAC;KACjG,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEL,SAAS;KACN,OAAO,CAAC,SAAS,CAAC;KAClB,WAAW,CAAC,2CAA2C,CAAC;KACxD,MAAM,CAAC,8BAA8B,CAAC;KACtC,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;IACrB,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,IAAI,IAAI,CAAC,mBAAmB;QAAE,MAAM,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAC/F,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,KAAK,EAAE,uBAAuB,MAAM,EAAE,CAAC,CAAC;IACtE,cAAc,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;IACxC,WAAW,CAAC;QACV,MAAM,EAAE,iBAAiB;QACzB,MAAM,EAAE,IAAI,CAAC,IAAI;QACjB,gBAAgB,EAAE,CAAC,0BAA0B,EAAE,0BAA0B,CAAC;KAC3E,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const crmCmd: Command;
@@ -0,0 +1,319 @@
1
+ import { Command } from "commander";
2
+ import { apiRequest, handleApiError } from "../client.js";
3
+ import { agentOutput } from "../output.js";
4
+ export const crmCmd = new Command("crm")
5
+ .description("naive/crm primitive — contacts, companies, and interaction history")
6
+ .addHelpText("after", `
7
+ Subcommands:
8
+ naive crm contacts ... Manage CRM contacts (create, list, find, get, update, merge, log, history)
9
+ naive crm companies ... Manage CRM companies (external organizations)
10
+
11
+ The CRM primitive is the vertical-agnostic identity graph. Pipelines/deals
12
+ live in the CRM template app (naive crm-app). Use this primitive any time
13
+ an agent needs to:
14
+ - Look up a contact before sending email (dedupe by email/phone)
15
+ - Log activity history on a contact (calls, notes, payments)
16
+ - Find or create external companies (clients, prospects)
17
+
18
+ Examples:
19
+ $ naive crm contacts find --email lead@example.com
20
+ $ naive crm contacts create --name "Jane Smith" --email jane@acme.com --company Acme
21
+ $ naive crm contacts log-interaction <contact-id> --type note --content "Discovery call went well"
22
+ $ naive crm contacts history <contact-id> --limit 20
23
+ `);
24
+ // ── Contacts ──────────────────────────────────────────────────────────────
25
+ const contactsCmd = crmCmd.command("contacts").description("CRM contact management");
26
+ contactsCmd
27
+ .command("list")
28
+ .description("List CRM contacts")
29
+ .option("--search <term>", "Free-text search on name and emails")
30
+ .option("--crm-company <id>", "Filter to a specific CRM company")
31
+ .option("--sort <field>", "Sort field: created_at | name", "created_at")
32
+ .option("--limit <n>", "Max results (default 50, max 200)", "50")
33
+ .option("--offset <n>", "Pagination offset", "0")
34
+ .action(async (opts) => {
35
+ const params = new URLSearchParams({ limit: opts.limit, offset: opts.offset, sort: opts.sort });
36
+ if (opts.search)
37
+ params.set("search", opts.search);
38
+ if (opts.crmCompany)
39
+ params.set("crm_company_id", opts.crmCompany);
40
+ const resp = await apiRequest("GET", `/v1/crm/contacts?${params}`);
41
+ handleApiError("crm.contacts.list", resp);
42
+ const data = resp.data;
43
+ agentOutput({
44
+ action: "crm.contacts.list",
45
+ result: resp.data,
46
+ next_steps: [
47
+ ...(data.contacts.length > 0
48
+ ? [{ command: `naive crm contacts get ${data.contacts[0].id}`, description: "Inspect the first contact" }]
49
+ : [{ command: "naive crm contacts create --name <name> --email <email>", description: "Create your first contact" }]),
50
+ { command: "naive crm contacts find --email <email>", description: "Find a contact by email before creating to dedupe" },
51
+ ],
52
+ hints: [`${data.count} contact${data.count === 1 ? "" : "s"} returned`],
53
+ related_commands: ["naive crm contacts create", "naive crm contacts find", "naive crm contacts get"],
54
+ });
55
+ });
56
+ contactsCmd
57
+ .command("create")
58
+ .description("Create a CRM contact (idempotent on email/phone)")
59
+ .option("--name <name>", "Contact full name")
60
+ .option("--email <email>", "Primary email address")
61
+ .option("--phone <phone>", "Primary phone number")
62
+ .option("--company <name>", "Company name (auto-creates if no --crm-company-id is provided)")
63
+ .option("--crm-company-id <id>", "Existing CRM company UUID to link to")
64
+ .option("--source <source>", "Where this contact came from")
65
+ .action(async (opts) => {
66
+ const resp = await apiRequest("POST", "/v1/crm/contacts", {
67
+ name: opts.name,
68
+ email: opts.email,
69
+ phone: opts.phone,
70
+ company: opts.company,
71
+ crm_company_id: opts.crmCompanyId,
72
+ source: opts.source,
73
+ });
74
+ handleApiError("crm.contacts.create", resp);
75
+ const data = resp.data;
76
+ agentOutput({
77
+ action: "crm.contacts.create",
78
+ result: resp.data,
79
+ next_steps: [
80
+ { command: `naive crm contacts log-interaction ${data.contact.id} --type note --content "..."`, description: "Log activity on this contact" },
81
+ { command: `naive crm contacts history ${data.contact.id}`, description: "View full activity history" },
82
+ ],
83
+ hints: [
84
+ data.created ? "Created new contact" : "Returned existing contact (matched by email/phone)",
85
+ `Contact ID: ${data.contact.id}`,
86
+ ],
87
+ related_commands: ["naive crm contacts find", "naive crm contacts log-interaction"],
88
+ });
89
+ });
90
+ contactsCmd
91
+ .command("find")
92
+ .description("Find a contact by email, phone, or fuzzy name match — use this BEFORE creating to dedupe")
93
+ .option("--email <email>", "Exact match (case-insensitive)")
94
+ .option("--phone <phone>", "Exact match (digits-only)")
95
+ .option("--name <name>", "Fuzzy match (trigram)")
96
+ .option("--limit <n>", "Max results (default 10, max 50)", "10")
97
+ .action(async (opts) => {
98
+ const resp = await apiRequest("POST", "/v1/crm/contacts/find", {
99
+ email: opts.email,
100
+ phone: opts.phone,
101
+ name: opts.name,
102
+ limit: parseInt(opts.limit, 10),
103
+ });
104
+ handleApiError("crm.contacts.find", resp);
105
+ const data = resp.data;
106
+ agentOutput({
107
+ action: "crm.contacts.find",
108
+ result: resp.data,
109
+ next_steps: data.contacts.length > 0
110
+ ? [
111
+ { command: `naive crm contacts get ${data.contacts[0].id}`, description: "Get full contact details" },
112
+ { command: `naive crm contacts log-interaction ${data.contacts[0].id} --type note --content "..."`, description: "Log activity on this contact" },
113
+ ]
114
+ : [{ command: "naive crm contacts create --name <name> --email <email>", description: "Create a new contact" }],
115
+ hints: [
116
+ data.contacts.length === 0 ? "No match — safe to create a new contact" : `Match type: ${data.match_type}`,
117
+ ],
118
+ related_commands: ["naive crm contacts create", "naive crm contacts merge"],
119
+ });
120
+ });
121
+ contactsCmd
122
+ .command("get <contact_id>")
123
+ .description("Get full contact details")
124
+ .action(async (contactId) => {
125
+ const resp = await apiRequest("GET", `/v1/crm/contacts/${contactId}`);
126
+ handleApiError("crm.contacts.get", resp);
127
+ agentOutput({
128
+ action: "crm.contacts.get",
129
+ result: resp.data,
130
+ next_steps: [
131
+ { command: `naive crm contacts history ${contactId}`, description: "View interaction history" },
132
+ { command: `naive crm contacts update ${contactId} --name <name>`, description: "Update contact" },
133
+ ],
134
+ related_commands: ["naive crm contacts history", "naive crm contacts update"],
135
+ });
136
+ });
137
+ contactsCmd
138
+ .command("update <contact_id>")
139
+ .description("Update a contact")
140
+ .option("--name <name>", "New name")
141
+ .option("--emails <list>", "Comma-separated list of emails (replaces existing)")
142
+ .option("--phones <list>", "Comma-separated list of phones (replaces existing)")
143
+ .option("--crm-company-id <id>", "Link to a CRM company (use 'null' to clear)")
144
+ .action(async (contactId, opts) => {
145
+ const body = {};
146
+ if (opts.name !== undefined)
147
+ body.name = opts.name;
148
+ if (opts.emails !== undefined)
149
+ body.emails = opts.emails.split(",").map((s) => s.trim()).filter(Boolean);
150
+ if (opts.phones !== undefined)
151
+ body.phones = opts.phones.split(",").map((s) => s.trim()).filter(Boolean);
152
+ if (opts.crmCompanyId !== undefined)
153
+ body.crm_company_id = opts.crmCompanyId === "null" ? null : opts.crmCompanyId;
154
+ const resp = await apiRequest("PATCH", `/v1/crm/contacts/${contactId}`, body);
155
+ handleApiError("crm.contacts.update", resp);
156
+ agentOutput({
157
+ action: "crm.contacts.update",
158
+ result: resp.data,
159
+ next_steps: [{ command: `naive crm contacts get ${contactId}`, description: "Verify the update" }],
160
+ related_commands: ["naive crm contacts get", "naive crm contacts history"],
161
+ });
162
+ });
163
+ contactsCmd
164
+ .command("delete <contact_id>")
165
+ .description("Delete a CRM contact (cascade-deletes interactions)")
166
+ .action(async (contactId) => {
167
+ const resp = await apiRequest("DELETE", `/v1/crm/contacts/${contactId}`);
168
+ handleApiError("crm.contacts.delete", resp);
169
+ agentOutput({
170
+ action: "crm.contacts.delete",
171
+ result: resp.data,
172
+ next_steps: [{ command: "naive crm contacts list", description: "Verify removal" }],
173
+ related_commands: ["naive crm contacts list"],
174
+ });
175
+ });
176
+ contactsCmd
177
+ .command("merge <primary_id>")
178
+ .description("Merge a duplicate contact into the primary contact")
179
+ .requiredOption("--duplicate <id>", "The duplicate contact ID to merge into the primary")
180
+ .action(async (primaryId, opts) => {
181
+ const resp = await apiRequest("POST", `/v1/crm/contacts/${primaryId}/merge`, {
182
+ duplicate_id: opts.duplicate,
183
+ });
184
+ handleApiError("crm.contacts.merge", resp);
185
+ agentOutput({
186
+ action: "crm.contacts.merge",
187
+ result: resp.data,
188
+ next_steps: [{ command: `naive crm contacts get ${primaryId}`, description: "Inspect the merged contact" }],
189
+ hints: ["All interactions moved to primary, duplicate deleted"],
190
+ related_commands: ["naive crm contacts get", "naive crm contacts history"],
191
+ });
192
+ });
193
+ contactsCmd
194
+ .command("log-interaction <contact_id>")
195
+ .description("Log an interaction (email | call | note | task | payment) on a contact")
196
+ .requiredOption("--type <type>", "email | call | note | task | payment")
197
+ .option("--direction <dir>", "inbound | outbound | internal", "internal")
198
+ .option("--content <text>", "Free-text body")
199
+ .option("--refs <json>", "Cross-references as JSON, e.g. '{\"message_id\":\"abc\"}'")
200
+ .option("--occurred-at <iso>", "ISO timestamp; defaults to now")
201
+ .action(async (contactId, opts) => {
202
+ const body = {
203
+ type: opts.type,
204
+ direction: opts.direction,
205
+ };
206
+ if (opts.content !== undefined)
207
+ body.content = opts.content;
208
+ if (opts.refs !== undefined) {
209
+ try {
210
+ body.refs = JSON.parse(opts.refs);
211
+ }
212
+ catch {
213
+ agentOutput({
214
+ action: "crm.contacts.log-interaction",
215
+ result: { error: "invalid_input", message: "--refs must be valid JSON" },
216
+ hints: ["Wrap in single quotes: --refs '{\"key\":\"value\"}'"],
217
+ related_commands: ["naive crm contacts log-interaction"],
218
+ });
219
+ process.exit(1);
220
+ }
221
+ }
222
+ if (opts.occurredAt !== undefined)
223
+ body.occurred_at = opts.occurredAt;
224
+ const resp = await apiRequest("POST", `/v1/crm/contacts/${contactId}/interactions`, body);
225
+ handleApiError("crm.contacts.log-interaction", resp);
226
+ agentOutput({
227
+ action: "crm.contacts.log-interaction",
228
+ result: resp.data,
229
+ next_steps: [{ command: `naive crm contacts history ${contactId}`, description: "View updated history" }],
230
+ related_commands: ["naive crm contacts history", "naive crm contacts get"],
231
+ });
232
+ });
233
+ contactsCmd
234
+ .command("history <contact_id>")
235
+ .description("Get interaction history (most recent first)")
236
+ .option("--types <list>", "Comma-separated types to filter: email,call,note,task,payment")
237
+ .option("--since <iso>", "Lower bound ISO timestamp")
238
+ .option("--until <iso>", "Upper bound ISO timestamp")
239
+ .option("--limit <n>", "Max results (default 50, max 200)", "50")
240
+ .option("--offset <n>", "Pagination offset", "0")
241
+ .action(async (contactId, opts) => {
242
+ const params = new URLSearchParams({ limit: opts.limit, offset: opts.offset });
243
+ if (opts.types)
244
+ params.set("types", opts.types);
245
+ if (opts.since)
246
+ params.set("since", opts.since);
247
+ if (opts.until)
248
+ params.set("until", opts.until);
249
+ const resp = await apiRequest("GET", `/v1/crm/contacts/${contactId}/interactions?${params}`);
250
+ handleApiError("crm.contacts.history", resp);
251
+ const data = resp.data;
252
+ agentOutput({
253
+ action: "crm.contacts.history",
254
+ result: resp.data,
255
+ hints: [`${data.count} interaction${data.count === 1 ? "" : "s"} returned`],
256
+ next_steps: [{ command: `naive crm contacts log-interaction ${contactId} --type note --content "..."`, description: "Log a new interaction" }],
257
+ related_commands: ["naive crm contacts log-interaction", "naive crm contacts get"],
258
+ });
259
+ });
260
+ // ── Companies ────────────────────────────────────────────────────────────
261
+ const companiesSubCmd = crmCmd.command("companies").description("CRM company (external organization) management");
262
+ companiesSubCmd
263
+ .command("list")
264
+ .description("List CRM companies")
265
+ .option("--search <term>", "Free-text search on name/domain")
266
+ .option("--limit <n>", "Max results (default 50, max 200)", "50")
267
+ .option("--offset <n>", "Pagination offset", "0")
268
+ .action(async (opts) => {
269
+ const params = new URLSearchParams({ limit: opts.limit, offset: opts.offset });
270
+ if (opts.search)
271
+ params.set("search", opts.search);
272
+ const resp = await apiRequest("GET", `/v1/crm/companies?${params}`);
273
+ handleApiError("crm.companies.list", resp);
274
+ const data = resp.data;
275
+ agentOutput({
276
+ action: "crm.companies.list",
277
+ result: resp.data,
278
+ hints: [`${data.count} compan${data.count === 1 ? "y" : "ies"} returned`],
279
+ next_steps: [{ command: "naive crm companies create --name <name> --domain <domain>", description: "Create a new CRM company" }],
280
+ related_commands: ["naive crm companies create", "naive crm companies get"],
281
+ });
282
+ });
283
+ companiesSubCmd
284
+ .command("create")
285
+ .description("Create a CRM company (idempotent on lower(domain))")
286
+ .requiredOption("--name <name>", "Company name")
287
+ .option("--domain <domain>", "Primary web domain (e.g. acme.com)")
288
+ .option("--source <source>", "Where this record came from")
289
+ .action(async (opts) => {
290
+ const resp = await apiRequest("POST", "/v1/crm/companies", {
291
+ name: opts.name,
292
+ domain: opts.domain,
293
+ source: opts.source,
294
+ });
295
+ handleApiError("crm.companies.create", resp);
296
+ const data = resp.data;
297
+ agentOutput({
298
+ action: "crm.companies.create",
299
+ result: resp.data,
300
+ hints: [data.created ? "Created new company" : "Returned existing company (matched by domain)"],
301
+ next_steps: [
302
+ { command: `naive crm contacts create --crm-company-id ${data.company.id} --name <name> --email <email>`, description: "Link a contact to this company" },
303
+ ],
304
+ related_commands: ["naive crm contacts create", "naive crm companies get"],
305
+ });
306
+ });
307
+ companiesSubCmd
308
+ .command("get <company_id>")
309
+ .description("Get CRM company details")
310
+ .action(async (companyId) => {
311
+ const resp = await apiRequest("GET", `/v1/crm/companies/${companyId}`);
312
+ handleApiError("crm.companies.get", resp);
313
+ agentOutput({
314
+ action: "crm.companies.get",
315
+ result: resp.data,
316
+ related_commands: ["naive crm companies list", "naive crm contacts list"],
317
+ });
318
+ });
319
+ //# sourceMappingURL=crm.js.map