insightcrm 0.1.13 → 0.1.15

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/README.md CHANGED
@@ -16,6 +16,7 @@ crm add --name "王小明" --org "同济大学:在职教师:在职"
16
16
  crm list --relationship 甲方 --json # 甲方名单
17
17
  crm list --org 同济 --json # 挂在某个机构的客户
18
18
  crm list --due-today --json
19
+ crm list --sort urgent --limit 20 --json # 最紧迫的 20 个;--offset 取下一页,返回里有 hasMore / nextOffset
19
20
  crm version # 当前版本 + npm 上有没有新版
20
21
  crm skill # 打印给 agent 的使用说明;在 agent 指令里加一句「先运行 crm skill」
21
22
  ```
package/SKILL.md CHANGED
@@ -41,8 +41,8 @@ crm login https://<服务器地址>
41
41
 
42
42
  **身份与联系**:`name`、`company`、`title`;`wechatId`、`city`。只填材料里明确出现的。看不到就省略,不要猜。
43
43
  - **`name` 只写姓名本身**(含常用英文名,如「李源枫 Philip F. Yuan」),不超过 40 字,**不要带括号注释**。「白微微(微信名…,昵称…,微信号…)」这种写法会被服务端拒绝。
44
- - 微信号(登录用的 ID)写 `wechatId`;微信昵称 / 显示名 / 群昵称写进 `socials`(`platform` 用 `wechat`,见下);职务、城市写各自字段;「真名未知」「shadow 备注」之类的说明写进 `notes`。
45
- - 无法确定真名时,`name` 写对方使用的称呼,并在 `notes` 里注明真名未知。
44
+ - 微信号(登录用的 ID)写 `wechatId`;微信昵称 / 显示名 / 群昵称写进 `socials`(`platform` 用 `wechat`,见下);职务、城市写各自字段;「真名未知」「shadow 备注」之类的说明写进 notes(`--note-fact`,见「写 notes」)。
45
+ - 无法确定真名时,`name` 写对方使用的称呼,并追加一条 `--note-fact "真名未知,暂用对方自称"`。
46
46
  `city` 取 `crm schema --json` 里 `city` 字段的 `values`(城市枚举);写成「上海市」「Shanghai」「臺北」也会被自动归一化成「上海」「上海」「台北」,所以直接按你看到的写就行。
47
47
 
48
48
  **画像**:
@@ -107,7 +107,27 @@ crm login https://<服务器地址>
107
107
  - 只在元数据里出现、原图上找不到的,写成「导出元数据记作 X(图片未佐证)」,别当成事实。
108
108
  - **判断是不是同一个人,头像一致是最硬的证据**,比文字描述可靠;不同平台头像不同很正常,不要据此起疑。
109
109
  - 性别、真实姓名这类「看起来像事实」的东西,原图上没有书面依据就不要写——微信名片、小红书主页、私信截图都不含性别信息,照片也认不出人,中文名尤其不能靠猜。
110
- - 核对出旧档案写错了,回头改掉,并在 `notes` 里留一段**更正说明**写清原来错在哪、正确是什么,别静默改掉——错值留痕才知道当时错在哪。
110
+ - 核对出旧档案写错了,回头改掉,并追加一条 `--note-fact` **更正说明**写清原来错在哪、正确是什么,别静默改掉——错值留痕才知道当时错在哪。
111
+
112
+ ## 写 notes
113
+
114
+ `notes` **不能直接写**:没有 `--notes`,JSON 里带 `notes` 也会被拒。它是服务端维护的 markdown,你只能**追加一条**或**删一条**,服务端负责拼成 `事实 / 判断 / 待核实 / 历史备注` 四段。
115
+
116
+ **notes 装什么**:结构化字段装不下、之后还要回头看的东西——带日期的事实、你的判断、还没确认的事。
117
+ **不要放**:微信号 / 昵称 / 视频号 / 标签(有 `wechatId` / `socials` / `relationships`)、下一步动作(写 `currentAction`)、对话原文、截图逐字转录。
118
+
119
+ ```bash
120
+ crm update <id> --note-fact "做 AI 画框,硬件是微雪屏 + 润芯微开发板" --note-source 直播答疑 --note-date 10-28
121
+ crm update <id> --note-judgment "艺术化 IP + 小硬件方向可行,暂无采购意向"
122
+ crm update <id> --note-todo "是否有量产计划"
123
+ crm update <id> --note-drop fact:2 # 序号取自 crm get 的输出
124
+ ```
125
+
126
+ - `--note-fact`:发生过什么、对方说了什么。`--note-judgment`:你的结论,一两句。`--note-todo`:还没确认的。
127
+ - **每条一句话,≤150 字,单行。** 超了就拆,或只留要紧的。`--note-source` ≤20 字(「名片」「朋友圈」),`--note-date` 写事情发生的日期(`YYYY-MM-DD` 或 `MM-DD`),不写默认今天;它们作用于本次调用追加的全部条目。
128
+ - **同一件事改写原条目,不要重复追加**:先 `--note-drop` 旧的,再 `--note-fact` 新的。每段最多 20 条。
129
+ - **预算 3000 字**(硬上限 10000)。超了服务端拒绝追加,报错里会说现有多少字。这时先压缩再写:`--note-drop` 删过时条目;老客户的存量自由文本显示为 `legacy`(历史备注),把里面还有用的内容提炼成几条短条目追加,再用 `--note-legacy "压缩后的文本"` 整段改写(传 `''` 清空)。同一条命令里可以先压缩再追加。
130
+ - `crm get` 里结构化的 notes 按 `fact:1`、`todo:2` 带序号显示;老客户没有结构标记的会标 `(legacy free text)`,原样保留,不用管它,除非要追加时被预算挡住。
111
131
 
112
132
  ## 成功钩子
113
133
 
@@ -158,6 +178,21 @@ crm list --related 李雅婷 --json # 和李雅婷有关系的人
158
178
  crm get <id> --json
159
179
  ```
160
180
 
181
+ ### 排序与分页(客户多时用)
182
+
183
+ `list` / `search` 默认一次返回**全部**客户,顺序是「最近更新在前」。库里人多时,别拉全库,用 `--sort` 取最该先处理的,再用 `--limit` 分页:
184
+
185
+ ```bash
186
+ crm list --sort urgent --limit 20 --json # 黄金窗口最紧迫的 20 个(已过期的排最前)
187
+ crm list --sort urgent --limit 20 --offset 20 --json # 下一页(offset 用上一页返回的 nextOffset)
188
+ crm list --potential high --sort urgent --limit 10 --json # 筛选和排序、分页可以叠加
189
+ crm search 跨境 --limit 10 --json
190
+ ```
191
+
192
+ - `--sort`:`urgent` 窗口到期最早在前 · `updated` 最近更新在前(默认)· `added` 最近添加在前 · `potential` High→Medium→Low,同级按紧迫 · `name` 姓名 A→Z。
193
+ - 不带 `--limit` 返回 `{customers, count}`。带了 `--limit` 只取一页,返回里多出 `total`(筛选后的总数)、`all`(全库总数)、`limit`、`offset`、`hasMore`、`nextOffset`。循环到 `hasMore` 为 `false` 就取完了;`nextOffset` 就是下一次的 `--offset`。
194
+ - `--offset` 必须和 `--limit` 一起用。`--sort` / `--limit` / `--offset` 写错值会以退出码 `2` 退出。
195
+
161
196
  ## 变更历史(这个客户什么时候被改过)
162
197
 
163
198
  服务端记录每次改动**改了哪些字段、旧值和新值**。用它回答「这个人什么时候从潜客变成学员」「潜力是什么时候升上去的」「哪一次改动把机构加上的」。
@@ -180,11 +215,11 @@ crm history --all --json # 全局身份迁移:谁的主身份从什么变
180
215
 
181
216
  ```bash
182
217
  crm lint --json # 全库体检:只报告,不改数据
183
- crm lint --severity error --json # 只看会造成实际问题的(notes 超上限、状态越界、过期日程、悬空引用)
218
+ crm lint --severity error --json # 只看会造成实际问题的(notes 超硬上限、状态越界、过期日程、悬空引用)
184
219
  crm lint --kind company-prose --json # 只看某一类
185
220
  ```
186
221
 
187
- 报告的类别:`notes-over-limit`(会被服务端拒)、`notes-long`、`unknown-status`(状态不在受控词表里,按状态聚合会漏)、
222
+ 报告的类别:`notes-over-limit`(超 10000 字硬上限)、`notes-long`(超 3000 字预算,已不再接受追加,先压缩)、`unknown-status`(状态不在受控词表里,按状态聚合会漏)、
188
223
  `expired-event`(过期日程)、`dangling-related-id`(相关人物指向库里没有的人)、
189
224
  `related-ambiguous`(相关人物没写 id 也没写微信号,而它的名字在库里有 ≥2 个同名客户——指哪一位说不准)、
190
225
  `related-wechat-unmatched`(相关人物写了微信号,但库里查不到这个号——可能拼错了,也可能对方还没入库)、
@@ -197,7 +232,7 @@ crm lint --kind company-prose --json # 只看某一类
197
232
  **批量清洗存量请走 `db:backfill-*` 脚本**(保留 `last_updated`、写审计日志),别用 update 循环。
198
233
 
199
234
  写入时 CLI 会把拿不准的地方打到 stderr 当提醒(未知的 `orgs.status`、清单外的城市、过期的日程、写成说明文的 company)。
200
- **这些是提醒不是错误**,写入照常成功——除非 `notes` 超过 10000 字符,那种会被服务端整条拒掉,所以 CLI 提前拦了一道。
235
+ **这些是提醒不是错误**,写入照常成功。notes 不在此列:它的规则由服务端强制,违反会被拒(见「写 notes」)。
201
236
 
202
237
  ## 推荐库(是用户的库存,不是聊天里挖出来的东西)
203
238
 
package/dist/cli.js CHANGED
@@ -654,9 +654,51 @@ function wechatKey(input2) {
654
654
  return (input2 ?? "").replace(/\s+/g, "").trim().toLowerCase();
655
655
  }
656
656
 
657
- // ../shared/src/profile.ts
657
+ // ../shared/src/notes.ts
658
+ var NOTE_KINDS = ["fact", "judgment", "todo"];
659
+ var NOTE_HEADINGS = { fact: "\u4E8B\u5B9E", judgment: "\u5224\u65AD", todo: "\u5F85\u6838\u5B9E" };
660
+ var NOTE_LEGACY_HEADING = "\u5386\u53F2\u5907\u6CE8";
658
661
  var NOTES_MAX = 1e4;
659
- var NOTES_LONG = 6e3;
662
+ var NOTES_BUDGET = 3e3;
663
+ var NOTE_ENTRY_MAX = 150;
664
+ var NOTE_SOURCE_MAX = 20;
665
+ var FM_RE = /^---\n([\s\S]*?)\n---\n?/;
666
+ var emptyEntries = () => ({ fact: [], judgment: [], todo: [] });
667
+ function parseNotes(notes) {
668
+ const text = (notes ?? "").replace(/\r\n/g, "\n");
669
+ const fm = FM_RE.exec(text);
670
+ const version2 = fm ? /^v:\s*(\d+)\s*$/m.exec(fm[1])?.[1] : void 0;
671
+ if (!fm || version2 !== "1") return { structured: false, entries: emptyEntries(), legacy: text.trim() };
672
+ const updated = /^updated:\s*(\S+)\s*$/m.exec(fm[1])?.[1];
673
+ const body = text.slice(fm[0].length);
674
+ const entries = emptyEntries();
675
+ let legacy = "";
676
+ let current = null;
677
+ const lines = body.split("\n");
678
+ for (let i = 0; i < lines.length; i++) {
679
+ const line2 = lines[i];
680
+ const h = /^##\s+(.+?)\s*$/.exec(line2);
681
+ if (h) {
682
+ const kind = NOTE_KINDS.find((k) => NOTE_HEADINGS[k] === h[1]);
683
+ if (kind) {
684
+ current = kind;
685
+ continue;
686
+ }
687
+ if (h[1] === NOTE_LEGACY_HEADING) {
688
+ legacy = lines.slice(i + 1).join("\n").trim();
689
+ break;
690
+ }
691
+ }
692
+ if (current) {
693
+ const m = /^-\s+(.+)$/.exec(line2);
694
+ if (m) entries[current].push(m[1].trim());
695
+ }
696
+ }
697
+ return { structured: true, ...updated ? { updated } : {}, entries, legacy };
698
+ }
699
+
700
+ // ../shared/src/profile.ts
701
+ var NOTES_LONG = NOTES_BUDGET;
660
702
  var COMPANY_LONG = 80;
661
703
  var NAME_MAX = 40;
662
704
  function nameProblem(name) {
@@ -20462,17 +20504,40 @@ var customerShape = {
20462
20504
  currentAction: short(2e3),
20463
20505
  conversionPotential: external_exports.enum(CONVERSION_POTENTIALS),
20464
20506
  conversionCycleDays: external_exports.number().int().min(0).max(3650),
20465
- notes: short(1e4).nullable(),
20507
+ notes: short(NOTES_MAX).nullable(),
20466
20508
  capturedAt: external_exports.iso.datetime({ offset: true }),
20467
20509
  /** 整体替换:传了就用这组覆盖旧日程,不传不动 */
20468
20510
  upcomingEvents: external_exports.array(eventInput).max(200)
20469
20511
  };
20512
+ var noteOp = external_exports.discriminatedUnion("op", [
20513
+ external_exports.object({
20514
+ op: external_exports.literal("add"),
20515
+ kind: external_exports.enum(NOTE_KINDS),
20516
+ text: external_exports.string().trim().min(1).max(NOTE_ENTRY_MAX),
20517
+ source: external_exports.string().trim().max(NOTE_SOURCE_MAX).optional(),
20518
+ date: external_exports.string().regex(/^(\d{4}-)?\d{2}-\d{2}$/, "date must be YYYY-MM-DD or MM-DD").optional()
20519
+ }),
20520
+ external_exports.object({ op: external_exports.literal("drop"), kind: external_exports.enum(NOTE_KINDS), index: external_exports.number().int().min(1) }),
20521
+ external_exports.object({ op: external_exports.literal("legacy"), text: external_exports.string().max(NOTES_MAX).nullable() })
20522
+ ]);
20523
+ var noteOps = external_exports.array(noteOp).min(1).max(50);
20470
20524
  var customerCreate = external_exports.object({
20471
20525
  ...customerShape,
20526
+ noteOps,
20472
20527
  /** 创建时可附带一条「成功钩子」,会同时写入钩子库并关联到这个客户 */
20473
20528
  socialHook: socialHookInput
20474
20529
  }).partial().required({ name: true });
20475
- var customerPatch = external_exports.object(customerShape).partial();
20530
+ var { notes: _rawNotes, ...writableShape } = customerShape;
20531
+ var rawNotesRejected = {
20532
+ notes: external_exports.never({ error: "notes is read-only here: write it with noteOps (CLI: --note-fact / --note-judgment / --note-todo)" }).optional()
20533
+ };
20534
+ var customerAdd = external_exports.object({
20535
+ ...writableShape,
20536
+ ...rawNotesRejected,
20537
+ noteOps,
20538
+ socialHook: socialHookInput
20539
+ }).partial().required({ name: true });
20540
+ var customerPatch = external_exports.object({ ...writableShape, ...rawNotesRejected, noteOps }).partial();
20476
20541
  var hookCreate = external_exports.object({
20477
20542
  title: short(200).min(1),
20478
20543
  description: short(5e3).min(1),
@@ -20520,6 +20585,14 @@ var orgFields = [
20520
20585
  guide: "\u8DDF\u8FD9\u4E2A\u673A\u6784\u7684\u5173\u7CFB\u72B6\u6001\u3002\u5199\u300C\u5728\u804C\u300D\u300C\u73B0\u4EFB\u300D\u300C\u5DF2\u79BB\u804C\u300D\u300C\u5728\u8BFB\u300D\u300C\u6821\u53CB\u300D\u7B49\u4E2D\u6587\u4F1A\u81EA\u52A8\u5F52\u4E00\u5316\uFF1B\u6E05\u5355\u5916\u7684\u5199\u6CD5\u4E0D\u62A5\u9519\uFF0C\u539F\u6837\u4FDD\u7559\u3002\u5206\u4E0D\u6E05\u5C31\u586B unknown\u3002"
20521
20586
  }
20522
20587
  ];
20588
+ var noteOpFields = [
20589
+ { name: "op", type: "enum", values: ["add", "drop", "legacy"], required: true, guide: "add \u8FFD\u52A0\u4E00\u6761 / drop \u5220\u6389\u7B2C index \u6761 / legacy \u6574\u6BB5\u6539\u5199\u5386\u53F2\u5907\u6CE8" },
20590
+ { name: "kind", type: "enum", values: [...NOTE_KINDS], guide: "fact \u4E8B\u5B9E\uFF08\u53D1\u751F\u8FC7\u4EC0\u4E48\u3001\u5BF9\u65B9\u8BF4\u4E86\u4EC0\u4E48\uFF09/ judgment \u5224\u65AD\uFF08\u4F60\u7684\u7ED3\u8BBA\uFF0C\u4E00\u4E24\u53E5\uFF09/ todo \u5F85\u6838\u5B9E\uFF08\u8FD8\u6CA1\u786E\u8BA4\u7684\u4E8B\uFF09\u3002add\u3001drop \u5FC5\u586B" },
20591
+ { name: "text", type: "string", guide: `add\uFF1A\u4E00\u53E5\u8BDD\u6B63\u6587\uFF0C\u2264${NOTE_ENTRY_MAX} \u5B57\uFF0C\u5355\u884C\uFF0C\u4E0D\u8981\u4EE5 # \u6216 - \u5F00\u5934\u3002legacy\uFF1A\u6539\u5199\u540E\u7684\u5386\u53F2\u5907\u6CE8\u5168\u6587\uFF0C\u7559\u7A7A / null \u5C31\u662F\u6E05\u6389` },
20592
+ { name: "source", type: "string", guide: `add \u53EF\u9009\uFF1A\u6765\u6E90\u77ED\u6807\u7B7E\uFF0C\u2264${NOTE_SOURCE_MAX} \u5B57\uFF0C\u5982\u300C\u76F4\u64AD\u7B54\u7591\u300D\u300C\u540D\u7247\u300D\u300C\u670B\u53CB\u5708\u300D` },
20593
+ { name: "date", type: "string", guide: "add \u53EF\u9009\uFF1A\u8FD9\u4EF6\u4E8B\u53D1\u751F\u7684\u65E5\u671F YYYY-MM-DD \u6216 MM-DD\uFF0C\u9ED8\u8BA4\u4ECA\u5929" },
20594
+ { name: "index", type: "integer", guide: "drop \u5FC5\u586B\uFF1A\u8BE5\u6BB5\u91CC\u7B2C\u51E0\u6761\uFF0C\u4ECE 1 \u5F00\u59CB\uFF08crm get \u91CC\u80FD\u770B\u5230\u5E8F\u53F7\uFF09" }
20595
+ ];
20523
20596
  var relatedFields = [
20524
20597
  { name: "name", type: "string", required: true, guide: "\u5BF9\u65B9\u59D3\u540D\u3002\u6750\u6599\u91CC\u51FA\u73B0\u7684\u4EBA\u540D\u7167\u6284\uFF0C\u4E0D\u8981\u6539\u5199\u6210\u5173\u7CFB\u79F0\u8C13" },
20525
20598
  { name: "wechatId", type: "string", nullable: true, guide: "\u5BF9\u65B9\u5FAE\u4FE1\u53F7\u3002\u8FD9\u6761\u94FE\u4E0A\u552F\u4E00\u53EF\u9760\u7684\u6807\u8BC6\uFF1A\u540C\u4E00\u4E2A\u8D26\u53F7\u4E0B\u5FAE\u4FE1\u53F7\u4E0D\u91CD\u590D\uFF0C\u540C\u540D\u4E0D\u540C\u4EBA\u65F6\u9760\u5B83\u5206\u51FA\u662F\u54EA\u4E00\u4F4D\u3002\u6750\u6599\u91CC\u51FA\u73B0\u4E86\u5BF9\u65B9\u7684\u5FAE\u4FE1\u53F7\u5C31\u586B\u4E0A\u2014\u2014\u6CA1\u6709\u5B83\uFF0C\u670D\u52A1\u7AEF\u53EA\u80FD\u6309\u59D3\u540D\u731C\uFF0C\u731C\u4E0D\u4E2D\u5C31\u7559\u7A7A" },
@@ -20568,7 +20641,18 @@ var SCHEMA = {
20568
20641
  { name: "conversionCycleDays", type: "integer", guide: "\u9884\u4F30\u7684\u8F6C\u5316\u9EC4\u91D1\u7A97\u53E3\u5929\u6570\uFF1B\u4FE1\u53F7\u8D8A\u5F31\u8D8A\u957F\uFF0C\u4FE1\u53F7\u660E\u786E\u53EF\u77ED\u81F3 7-14 \u5929" },
20569
20642
  { name: "upcomingEvents", type: "object[]", fields: eventFields, guide: "\u4E92\u52A8\u65E5\u5386\u3002\u66F4\u65B0\u65F6\u4F20\u5165\u5B8C\u6574\u5217\u8868\u4F1A\u6574\u4F53\u66FF\u6362\u65E7\u65E5\u7A0B\uFF1B\u4E0D\u4F20\u5219\u4E0D\u52A8" },
20570
20643
  { name: "socialHook", type: "object", fields: hookFields, guide: "\uFF08\u4EC5\u521B\u5EFA\u65F6\u53EF\u7528\uFF09\u5206\u6790\u5BF9\u8BDD\u4E2D\u54EA\u53E5\u8BDD\u3001\u54EA\u4E2A\u8BF4\u6CD5\u6210\u529F\u5F15\u8D77\u5BF9\u65B9\u6CE8\u610F\u6216\u89E6\u53D1\u6B63\u5411\u56DE\u590D\u3002\u7ED3\u6784\u5316 {title, description}\u3002\u627E\u4E0D\u5230\u5C31\u7701\u7565\uFF0C\u4E0D\u8981\u7F16\u9020\u3002" },
20571
- { name: "notes", type: "string", nullable: true, guide: "\u81EA\u7531\u5907\u6CE8" },
20644
+ {
20645
+ name: "notes",
20646
+ type: "string",
20647
+ nullable: true,
20648
+ guide: "\u53EA\u8BFB\uFF0C\u4E0D\u80FD\u76F4\u63A5\u5199\u3002\u88C5\u7ED3\u6784\u5316\u5B57\u6BB5\u653E\u4E0D\u4E0B\u3001\u4E4B\u540E\u8FD8\u8981\u56DE\u5934\u770B\u7684\u4E1C\u897F\uFF1A\u5E26\u65E5\u671F\u7684\u4E8B\u5B9E\u3001\u5224\u65AD\u3001\u5F85\u6838\u5B9E\u9879\u3002\u4E0D\u8981\u653E\u5FAE\u4FE1\u53F7 / \u6635\u79F0 / \u89C6\u9891\u53F7 / \u6807\u7B7E\uFF08\u6709 wechatId / socials / relationships\uFF09\uFF0C\u4E5F\u4E0D\u8981\u653E\u4E0B\u4E00\u6B65\u52A8\u4F5C\uFF08\u5199 currentAction\uFF09\uFF0C\u66F4\u4E0D\u8981\u8D34\u5BF9\u8BDD\u539F\u6587\u6216\u622A\u56FE\u8F6C\u5F55\u3002\u5199\u5165\u7528 noteOps\uFF08CLI\uFF1A--note-fact / --note-judgment / --note-todo / --note-drop\uFF09\uFF0C\u6BCF\u6761\u4E00\u53E5\u8BDD\u3001\u2264150 \u5B57\uFF0C\u683C\u5F0F `\u65E5\u671F \u6765\u6E90\uFF5C\u6B63\u6587`\uFF1B\u540C\u4E00\u4EF6\u4E8B\u6539\u5199\u539F\u6761\u76EE\uFF0C\u4E0D\u8981\u91CD\u590D\u8FFD\u52A0\u3002\u6574\u6761 notes \u9884\u7B97 3000 \u5B57\uFF0C\u8D85\u4E86\u5148\u538B\u7F29\uFF08drop / \u6539\u5199\u5386\u53F2\u5907\u6CE8\uFF09\u518D\u5199\uFF0C\u786C\u4E0A\u9650 10000 \u5B57\u3002\u6CA1\u6709\u7ED3\u6784\u5316\u6807\u8BB0\u7684\u8001 notes \u89C6\u4E3A\u300C\u5386\u53F2\u5907\u6CE8\u300D\uFF0C\u539F\u6837\u4FDD\u7559\uFF0C\u9700\u8981\u65F6\u7528 {op:'legacy'} \u6574\u6BB5\u538B\u7F29\u3002"
20649
+ },
20650
+ {
20651
+ name: "noteOps",
20652
+ type: "object[]",
20653
+ fields: noteOpFields,
20654
+ guide: "\uFF08\u53EA\u5199\uFF09notes \u7684\u8FFD\u52A0 / \u5220\u9664\u64CD\u4F5C\uFF0C\u6309\u987A\u5E8F\u5E94\u7528\u3002{op:'add', kind:'fact'|'judgment'|'todo', text, source?, date?}\u3001{op:'drop', kind, index}\u3001{op:'legacy', text}\u3002"
20655
+ },
20572
20656
  { name: "capturedAt", type: "datetime", guide: "\u7EBF\u7D22\u9996\u6B21\u88AB\u53D1\u73B0\u7684\u65F6\u95F4\uFF08ISO 8601\uFF09\uFF0C\u9ED8\u8BA4\u5F53\u524D\u65F6\u95F4" }
20573
20657
  ]
20574
20658
  },
@@ -20668,7 +20752,7 @@ function renderPrompt(text, customer) {
20668
20752
  // package.json
20669
20753
  var package_default = {
20670
20754
  name: "insightcrm",
20671
- version: "0.1.13",
20755
+ version: "0.1.15",
20672
20756
  description: "Command line and agent skill for InsightCRM: file customers from chats and screenshots with your own AI agent. Non-interactive, --json output, stable exit codes.",
20673
20757
  license: "MIT",
20674
20758
  type: "module",
@@ -20768,7 +20852,8 @@ function createClient(apiUrl, token) {
20768
20852
  `/customers${qs({
20769
20853
  ...f,
20770
20854
  limit: p?.limit === void 0 ? void 0 : String(p.limit),
20771
- offset: p?.offset === void 0 ? void 0 : String(p.offset)
20855
+ offset: p?.offset === void 0 ? void 0 : String(p.offset),
20856
+ sort: p?.sort
20772
20857
  })}`
20773
20858
  ),
20774
20859
  getCustomer: (id) => call("GET", `/customers/${enc(id)}`),
@@ -20814,8 +20899,8 @@ function lintCustomers(customers, today2) {
20814
20899
  }
20815
20900
  for (const c of customers) {
20816
20901
  const notesLen = (c.notes ?? "").length;
20817
- if (notesLen > NOTES_MAX) push(c, "notes-over-limit", "error", `notes ${notesLen} \u5B57\u7B26\uFF0C\u8D85\u670D\u52A1\u7AEF\u4E0A\u9650 ${NOTES_MAX}\uFF0C\u518D\u8FFD\u52A0\u4F1A\u88AB\u6574\u6761\u62D2\u7EDD`);
20818
- else if (notesLen > NOTES_LONG) push(c, "notes-long", "warn", `notes ${notesLen} \u5B57\u7B26\uFF0C\u504F\u81C3\u80BF\uFF08\u4E0A\u9650 ${NOTES_MAX}\uFF09`);
20902
+ if (notesLen > NOTES_MAX) push(c, "notes-over-limit", "error", `notes ${notesLen} \u5B57\u7B26\uFF0C\u8D85\u786C\u4E0A\u9650 ${NOTES_MAX}\u3002\u5148\u538B\u7F29\u518D\u5199\uFF1A--note-drop \u5220\u8FC7\u65F6\u6761\u76EE\uFF0C\u6216\u7528 --note-legacy \u628A\u5386\u53F2\u5907\u6CE8\u6539\u5199\u77ED`);
20903
+ else if (notesLen > NOTES_LONG) push(c, "notes-long", "warn", `notes ${notesLen} \u5B57\u7B26\uFF0C\u8D85\u8FC7 ${NOTES_BUDGET} \u5B57\u9884\u7B97\uFF0C\u5DF2\u4E0D\u518D\u63A5\u53D7\u8FFD\u52A0\u3002\u7528 --note-legacy \u538B\u7F29\u5386\u53F2\u5907\u6CE8 / --note-drop \u5220\u8FC7\u65F6\u6761\u76EE`);
20819
20904
  const nameIssue = nameProblem(c.name);
20820
20905
  if (nameIssue) push(c, "name-annotated", "warn", `${nameIssue}\uFF1A\u300C${c.name.slice(0, 40)}${c.name.length > 40 ? "\u2026" : ""}\u300D`);
20821
20906
  for (const o of c.orgs ?? []) {
@@ -21167,15 +21252,43 @@ async function client(requireToken = true) {
21167
21252
  return createClient(apiUrl, token);
21168
21253
  }
21169
21254
  var LIST_PAGE_SIZE = 500;
21170
- async function fetchAllCustomers(api, f) {
21255
+ async function fetchAllCustomers(api, f, sort) {
21171
21256
  const all = [];
21172
21257
  for (let offset = 0; ; offset += LIST_PAGE_SIZE) {
21173
- const r = await api.listCustomers(f, { limit: LIST_PAGE_SIZE, offset });
21258
+ const r = await api.listCustomers(f, { limit: LIST_PAGE_SIZE, offset, sort });
21174
21259
  all.push(...r.customers);
21175
21260
  if (r.customers.length < LIST_PAGE_SIZE || all.length >= r.total) break;
21176
21261
  }
21177
21262
  return all;
21178
21263
  }
21264
+ var CUSTOMER_SORTS = ["urgent", "updated", "added", "potential", "name"];
21265
+ function pageOf(o) {
21266
+ if (o.sort !== void 0 && !CUSTOMER_SORTS.includes(o.sort)) {
21267
+ throw new CliError("usage", `--sort must be one of ${CUSTOMER_SORTS.join(", ")} (got "${o.sort}")`, EXIT.usage);
21268
+ }
21269
+ const int2 = (name, v, min) => {
21270
+ if (v === void 0) return void 0;
21271
+ const n = Number(v);
21272
+ if (!Number.isInteger(n) || n < min) throw new CliError("usage", `--${name} must be an integer >= ${min} (got "${v}")`, EXIT.usage);
21273
+ return n;
21274
+ };
21275
+ const limit = int2("limit", o.limit, 1);
21276
+ const offset = int2("offset", o.offset, 0);
21277
+ if (limit === void 0 && offset !== void 0) throw new CliError("usage", "--offset needs --limit", EXIT.usage);
21278
+ return { sort: o.sort, limit, offset: offset ?? 0 };
21279
+ }
21280
+ async function listForCli(api, f, o) {
21281
+ const { sort, limit, offset } = pageOf(o);
21282
+ if (limit === void 0) {
21283
+ const customers = await fetchAllCustomers(api, f, sort);
21284
+ return { customers, count: customers.length };
21285
+ }
21286
+ const r = await api.listCustomers(f, { limit, offset, sort });
21287
+ const next = offset + r.customers.length;
21288
+ const hasMore = next < r.total && r.customers.length > 0;
21289
+ return { customers: r.customers, count: r.customers.length, total: r.total, all: r.all, limit, offset, hasMore, nextOffset: hasMore ? next : null };
21290
+ }
21291
+ var PAGE_OPTS = (c) => c.option("--sort <key>", `order: ${CUSTOMER_SORTS.join(" | ")} (default updated = newest update first; urgent = golden window expiring soonest, overdue first)`).option("--limit <n>", "return one page of n customers (adds total/hasMore/nextOffset to --json); omit to get everyone").option("--offset <n>", "skip this many (needs --limit); continue with nextOffset");
21179
21292
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
21180
21293
  function openBrowser(url2) {
21181
21294
  const [cmd, args] = platform() === "darwin" ? ["open", [url2]] : platform() === "win32" ? ["cmd", ["/c", "start", "", url2]] : ["xdg-open", [url2]];
@@ -21230,9 +21343,9 @@ var splitRelationships = (values) => values.flatMap((v) => {
21230
21343
  return parts.length > 1 && parts.every(isKnownRelationship) ? parts : [v];
21231
21344
  });
21232
21345
  function withCustomerOptions(cmd, forUpdate) {
21233
- cmd.option("--name <s>", "name").option("--company <s>").option("--title <s>", "job title").option("--city <s>").option("--wechat <s>", "WeChat id").option("--summary <s>").option("--current-action <s>").option("--notes <s>").option("--potential <High|Medium|Low>").option("--cycle-days <n>", "predicted conversion window in days").option("--pain <a,b,c>", `pain-point tags, comma separated${forUpdate ? " (replaces the whole list)" : ""}`).option("--goal <s...>", `goals${forUpdate ? " (replaces the whole list)" : ""}`).option("--event <date:type:title...>", `calendar events${forUpdate ? " (replaces the whole calendar; see --add-event)" : ""}`).option("--social <platform:handle...>", `social accounts, e.g. channels:@san xiaohongshu:san${forUpdate ? " (replaces the whole list; see --add-social)" : ""}`).option("--relationship <r...>", `relationship to the user, e.g. \u5B66\u5458 \u7532\u65B9${forUpdate ? " (replaces the whole list; see --add-relationship)" : ""}`).option("--org <name:role:status...>", `organizations, e.g. \u540C\u6D4E\u5927\u5B66:\u5728\u804C\u6559\u5E08:\u5728\u804C\uFF08\u673A\u6784\u540D:\u8EAB\u4EFD:\u72B6\u6001\uFF0C\u8EAB\u4EFD\u53EF\u7701\u7565\uFF09${forUpdate ? " (replaces the whole list; see --add-org)" : ""}`).option("--related <name:relation:note...>", `related people, e.g. \u674E\u96C5\u5A77:\u8F6C\u4ECB\u7ECD\u4EBA\uFF08\u59D3\u540D:\u5173\u7CFB\uFF0C\u8BF4\u660E\u53EF\u7701\u7565\uFF09\uFF1B\u5E26\u5FAE\u4FE1\u53F7\u5199 \u59D3\u540D:\u5173\u7CFB:wx=\u5FAE\u4FE1\u53F7${forUpdate ? " (replaces the whole list; see --add-related)" : ""}`);
21346
+ cmd.option("--name <s>", "name").option("--company <s>").option("--title <s>", "job title").option("--city <s>").option("--wechat <s>", "WeChat id").option("--summary <s>").option("--current-action <s>").option("--potential <High|Medium|Low>").option("--cycle-days <n>", "predicted conversion window in days").option("--pain <a,b,c>", `pain-point tags, comma separated${forUpdate ? " (replaces the whole list)" : ""}`).option("--goal <s...>", `goals${forUpdate ? " (replaces the whole list)" : ""}`).option("--event <date:type:title...>", `calendar events${forUpdate ? " (replaces the whole calendar; see --add-event)" : ""}`).option("--social <platform:handle...>", `social accounts, e.g. channels:@san xiaohongshu:san${forUpdate ? " (replaces the whole list; see --add-social)" : ""}`).option("--relationship <r...>", `relationship to the user, e.g. \u5B66\u5458 \u7532\u65B9${forUpdate ? " (replaces the whole list; see --add-relationship)" : ""}`).option("--org <name:role:status...>", `organizations, e.g. \u540C\u6D4E\u5927\u5B66:\u5728\u804C\u6559\u5E08:\u5728\u804C\uFF08\u673A\u6784\u540D:\u8EAB\u4EFD:\u72B6\u6001\uFF0C\u8EAB\u4EFD\u53EF\u7701\u7565\uFF09${forUpdate ? " (replaces the whole list; see --add-org)" : ""}`).option("--note-fact <s...>", "append a fact to notes: one sentence, \u2264150 chars, what happened / what they said (dated today unless --note-date)").option("--note-judgment <s...>", "append a judgment to notes: your conclusion, one or two sentences").option("--note-todo <s...>", "append an unverified item to notes: something still to confirm").option("--note-source <label>", "source label for the notes added in this call, \u226420 chars, e.g. \u76F4\u64AD\u7B54\u7591 / \u540D\u7247").option("--note-date <date>", "date the noted thing happened, YYYY-MM-DD or MM-DD (default today)").option("--related <name:relation:note...>", `related people, e.g. \u674E\u96C5\u5A77:\u8F6C\u4ECB\u7ECD\u4EBA\uFF08\u59D3\u540D:\u5173\u7CFB\uFF0C\u8BF4\u660E\u53EF\u7701\u7565\uFF09\uFF1B\u5E26\u5FAE\u4FE1\u53F7\u5199 \u59D3\u540D:\u5173\u7CFB:wx=\u5FAE\u4FE1\u53F7${forUpdate ? " (replaces the whole list; see --add-related)" : ""}`);
21234
21347
  if (forUpdate) {
21235
- cmd.option("--add-pain <s...>", "append pain-point tags, keeping existing ones").option("--add-goal <s...>", "append goals, keeping existing ones").option("--add-event <date:type:title...>", "append calendar events, keeping existing ones").option("--add-social <platform:handle...>", "append social accounts, keeping existing ones").option("--add-relationship <r...>", "append relationships, keeping existing ones").option("--add-org <name:role:status...>", "append organizations, keeping existing ones (\u673A\u6784\u540D:\u8EAB\u4EFD:\u72B6\u6001)").option("--add-related <name:relation:note...>", "append related people, keeping existing ones (\u59D3\u540D:\u5173\u7CFB\uFF0C\u8BF4\u660E\u53EF\u7701\u7565\uFF1B\u5FAE\u4FE1\u53F7\u5199 \u59D3\u540D:\u5173\u7CFB:wx=\u5FAE\u4FE1\u53F7)").option("--remove-event <date:keyword...>", "remove calendar events on that date (YYYY-MM-DD), or with date:keyword only those whose title contains the keyword; other events stay").option("--clear-events", "remove all calendar events");
21348
+ cmd.option("--add-pain <s...>", "append pain-point tags, keeping existing ones").option("--add-goal <s...>", "append goals, keeping existing ones").option("--add-event <date:type:title...>", "append calendar events, keeping existing ones").option("--add-social <platform:handle...>", "append social accounts, keeping existing ones").option("--add-relationship <r...>", "append relationships, keeping existing ones").option("--add-org <name:role:status...>", "append organizations, keeping existing ones (\u673A\u6784\u540D:\u8EAB\u4EFD:\u72B6\u6001)").option("--add-related <name:relation:note...>", "append related people, keeping existing ones (\u59D3\u540D:\u5173\u7CFB\uFF0C\u8BF4\u660E\u53EF\u7701\u7565\uFF1B\u5FAE\u4FE1\u53F7\u5199 \u59D3\u540D:\u5173\u7CFB:wx=\u5FAE\u4FE1\u53F7)").option("--remove-event <date:keyword...>", "remove calendar events on that date (YYYY-MM-DD), or with date:keyword only those whose title contains the keyword; other events stay").option("--clear-events", "remove all calendar events").option("--note-drop <kind:n...>", "delete note entries by kind and 1-based number as shown by `crm get`, e.g. fact:2 todo:1").option("--note-legacy <s>", "rewrite the whole \u5386\u53F2\u5907\u6CE8 block (old free-text notes) with this text; pass '' to clear it. Use it to compress old notes before appending");
21236
21349
  } else {
21237
21350
  cmd.option("--hook-title <s>", "also record a successful hook for this customer (needs --hook-desc)").option("--hook-desc <s>");
21238
21351
  }
@@ -21250,7 +21363,6 @@ function buildCustomerBody(base, o) {
21250
21363
  set2("wechatId", o.wechat);
21251
21364
  set2("summary", o.summary);
21252
21365
  set2("currentAction", o.currentAction);
21253
- set2("notes", o.notes);
21254
21366
  if (o.potential) body.conversionPotential = potentialOf(o.potential);
21255
21367
  if (o.cycleDays !== void 0) {
21256
21368
  const n = Number(o.cycleDays);
@@ -21265,18 +21377,36 @@ function buildCustomerBody(base, o) {
21265
21377
  if (o.relationship) body.relationships = splitRelationships(o.relationship);
21266
21378
  if (o.org) body.orgs = o.org.map(parseOrg);
21267
21379
  if (o.related) body.relatedPeople = o.related.map(parseRelated);
21380
+ const noteOps2 = buildNoteOps(o);
21381
+ if (noteOps2.length) body.noteOps = [...body.noteOps ?? [], ...noteOps2];
21268
21382
  if (o.hookTitle || o.hookDesc) {
21269
21383
  if (!o.hookTitle || !o.hookDesc) throw new CliError("usage", "--hook-title and --hook-desc go together", EXIT.usage);
21270
21384
  body.socialHook = { title: o.hookTitle, description: o.hookDesc };
21271
21385
  }
21272
21386
  return body;
21273
21387
  }
21274
- function checkNotesLength(body) {
21275
- const notes = body.notes;
21276
- if (typeof notes === "string" && notes.length > NOTES_MAX) {
21388
+ function buildNoteOps(o) {
21389
+ const ops = [];
21390
+ if (o.noteLegacy !== void 0) ops.push({ op: "legacy", text: o.noteLegacy.trim() ? o.noteLegacy : null });
21391
+ const drops = (o.noteDrop ?? []).map((d) => {
21392
+ const m = /^(fact|judgment|todo):(\d+)$/.exec(d.trim());
21393
+ if (!m) throw new CliError("usage", `--note-drop expects <fact|judgment|todo>:<number>, got "${d}"`, EXIT.usage);
21394
+ return { op: "drop", kind: m[1], index: Number(m[2]) };
21395
+ });
21396
+ ops.push(...drops.sort((a, b) => b.index - a.index));
21397
+ const extra = { ...o.noteSource ? { source: o.noteSource } : {}, ...o.noteDate ? { date: o.noteDate } : {} };
21398
+ const adds = [["fact", o.noteFact], ["judgment", o.noteJudgment], ["todo", o.noteTodo]];
21399
+ for (const [kind, texts] of adds) for (const text of texts ?? []) ops.push({ op: "add", kind, text, ...extra });
21400
+ if ((o.noteSource || o.noteDate) && !adds.some(([, t]) => t?.length)) {
21401
+ throw new CliError("usage", "--note-source / --note-date only apply together with --note-fact / --note-judgment / --note-todo", EXIT.usage);
21402
+ }
21403
+ return ops;
21404
+ }
21405
+ function rejectRawNotes(body) {
21406
+ if (body.notes !== void 0) {
21277
21407
  throw new CliError(
21278
21408
  "usage",
21279
- `notes is ${notes.length} characters, ${notes.length - NOTES_MAX} over the ${NOTES_MAX} limit. Compress it (move detail into the structured fields) and retry`,
21409
+ "notes cannot be written directly. Add entries with --note-fact / --note-judgment / --note-todo (or noteOps in the JSON); compress old free-text notes with --note-legacy",
21280
21410
  EXIT.usage
21281
21411
  );
21282
21412
  }
@@ -21300,6 +21430,16 @@ function warnPayload(body) {
21300
21430
  for (const w of warns) info(`\u26A0 ${w}`);
21301
21431
  }
21302
21432
  var line = (c) => `${c.id} ${c.name}${c.company || c.title ? ` (${[c.company, c.title].filter(Boolean).join(" \xB7 ")})` : ""}${c.city ? ` ${c.city}` : ""} ${c.conversionPotential} ${c.conversionCycleDays}d${c.painPoints.length ? ` [${c.painPoints.join(", ")}]` : ""}`;
21433
+ function notesView(notes) {
21434
+ if (!notes) return "";
21435
+ const p = parseNotes(notes);
21436
+ if (!p.structured) return `(legacy free text, ${notes.length} chars)
21437
+ ${notes}`;
21438
+ const pad = "\n ";
21439
+ const entries = NOTE_KINDS.flatMap((k) => p.entries[k].map((e, i) => `${k}:${i + 1} ${e}`));
21440
+ const legacy = p.legacy ? [`legacy (${p.legacy.length} chars) ${p.legacy}`] : [];
21441
+ return [...entries, ...legacy].join(pad);
21442
+ }
21303
21443
  function detail(c) {
21304
21444
  const rows = [
21305
21445
  ["id", c.id],
@@ -21318,7 +21458,7 @@ function detail(c) {
21318
21458
  ["goals", c.goals.join("; ")],
21319
21459
  ["current action", c.currentAction],
21320
21460
  ["summary", c.summary],
21321
- ["notes", c.notes ?? ""],
21461
+ ["notes", notesView(c.notes)],
21322
21462
  ["events", c.upcomingEvents.map((e) => `${e.date} ${e.type} ${e.title}`).join("\n ")],
21323
21463
  ["captured", c.capturedAt],
21324
21464
  ["updated", c.lastUpdated]
@@ -21452,7 +21592,7 @@ withCustomerOptions(
21452
21592
  ).action(async (src, o) => {
21453
21593
  const body = buildCustomerBody(await readJsonInput(src), o);
21454
21594
  if (!body.name) throw new CliError("usage", "name is required (pass --name or include it in the JSON)", EXIT.usage);
21455
- checkNotesLength(body);
21595
+ rejectRawNotes(body);
21456
21596
  warnPayload(body);
21457
21597
  const { customer } = await (await client()).addCustomer(body);
21458
21598
  out(`Created ${line(customer)}`, { customer, created: true });
@@ -21493,7 +21633,7 @@ withCustomerOptions(
21493
21633
  }
21494
21634
  }
21495
21635
  if (!Object.keys(body).length) throw new CliError("usage", "Nothing to change. Pass a JSON input or flags like --summary, --potential, --add-pain", EXIT.usage);
21496
- checkNotesLength(body);
21636
+ rejectRawNotes(body);
21497
21637
  warnPayload(body);
21498
21638
  const { customer } = await api.updateCustomer(id, body);
21499
21639
  out(`Updated ${line(customer)}`, { customer, updated: true });
@@ -21581,8 +21721,10 @@ program.command("lint").description("Audit every customer record and report what
21581
21721
  ].join("\n");
21582
21722
  out(human, { scanned: customers.length, count: issues.length, errors, warns, infos, issues, perCustomer });
21583
21723
  });
21584
- program.command("list").description("List customers (newest update first), optionally filtered").option("--potential <High|Medium|Low>").option("--city <s>", "exact city (case-insensitive)").option("--tag <s>", "has this pain-point tag").option("--social-platform <s>", "has a social account on this platform (e.g. xiaohongshu, channels, email)").option("--relationship <s>", "has this relationship to the user (e.g. \u7532\u65B9 / client, \u5B66\u5458 / student, \u6E20\u9053\u65B9 / channel)").option("--org <s>", "is affiliated with this organization (substring match, e.g. \u540C\u6D4E / \u535A\u4E16)").option("--related <s>", "is connected to this person (substring match on the related-people list; also matches records that point at this customer)").option("--due-today", "has a calendar event today (your local date)").option("--due <YYYY-MM-DD>", "has a calendar event on this date").option("--expired [date]", "has a calendar event before this date (default: today) \u2014 overdue events nobody cleaned up").option("-q, --query <s>", "keyword across name, company, title, city, wechat, social accounts, relationships, organizations, related people, summary, notes, tags, goals").action(async (o) => {
21585
- const customers = await fetchAllCustomers(await client(), {
21724
+ PAGE_OPTS(
21725
+ program.command("list").description("List customers, optionally filtered. Default order is newest update first; --sort changes it, --limit/--offset page through large books.").option("--potential <High|Medium|Low>").option("--city <s>", "exact city (case-insensitive)").option("--tag <s>", "has this pain-point tag").option("--social-platform <s>", "has a social account on this platform (e.g. xiaohongshu, channels, email)").option("--relationship <s>", "has this relationship to the user (e.g. \u7532\u65B9 / client, \u5B66\u5458 / student, \u6E20\u9053\u65B9 / channel)").option("--org <s>", "is affiliated with this organization (substring match, e.g. \u540C\u6D4E / \u535A\u4E16)").option("--related <s>", "is connected to this person (substring match on the related-people list; also matches records that point at this customer)").option("--due-today", "has a calendar event today (your local date)").option("--due <YYYY-MM-DD>", "has a calendar event on this date").option("--expired [date]", "has a calendar event before this date (default: today) \u2014 overdue events nobody cleaned up").option("-q, --query <s>", "keyword across name, company, title, city, wechat, social accounts, relationships, organizations, related people, summary, notes, tags, goals")
21726
+ ).action(async (o) => {
21727
+ const r = await listForCli(await client(), {
21586
21728
  potential: o.potential ? potentialOf(o.potential) : void 0,
21587
21729
  city: o.city,
21588
21730
  tag: o.tag,
@@ -21593,12 +21735,14 @@ program.command("list").description("List customers (newest update first), optio
21593
21735
  related: o.related,
21594
21736
  dueOn: o.dueToday ? today() : o.due,
21595
21737
  expiredBefore: o.expired ? o.expired === true ? today() : o.expired : void 0
21596
- });
21597
- out(customers.length ? customers.map(line).join("\n") : "No customers match.", { customers, count: customers.length });
21738
+ }, o);
21739
+ out(r.customers.length ? r.customers.map(line).join("\n") : "No customers match.", r);
21598
21740
  });
21599
- program.command("search").description("Search customers by keyword (same as `list -q`). Run this before `add` to avoid duplicates.").argument("<keyword>").action(async (keyword) => {
21600
- const customers = await fetchAllCustomers(await client(), { q: keyword });
21601
- out(customers.length ? customers.map(line).join("\n") : "No customers match.", { customers, count: customers.length });
21741
+ PAGE_OPTS(
21742
+ program.command("search").description("Search customers by keyword (same as `list -q`). Run this before `add` to avoid duplicates.").argument("<keyword>")
21743
+ ).action(async (keyword, o) => {
21744
+ const r = await listForCli(await client(), { q: keyword }, o);
21745
+ out(r.customers.length ? r.customers.map(line).join("\n") : "No customers match.", r);
21602
21746
  });
21603
21747
  program.command("rm").description("Delete a customer (their hooks stay in the hook library)").argument("<id>").option("-y, --yes", "skip the confirmation (required when not a TTY)").action(async (id, o) => {
21604
21748
  await confirm(`Delete customer ${id}?`, o.yes);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insightcrm",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "Command line and agent skill for InsightCRM: file customers from chats and screenshots with your own AI agent. Non-interactive, --json output, stable exit codes.",
5
5
  "license": "MIT",
6
6
  "type": "module",