insightcrm 0.1.9 → 0.1.10

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
@@ -10,6 +10,7 @@ crm login https://<你的服务器> # 浏览器里点「允许」(设备
10
10
  crm schema --json # 字段契约,含每个字段的填写指引
11
11
  echo '{"name":"王小明","company":"ACME"}' | crm add - --json
12
12
  crm add --name "王小明" --social channels:@wm email:wm@example.com # 视频号 / 小红书 / 邮箱等社交账号
13
+ crm add --name "王小明" --wechat wm2024 --social wechat:小明 # 微信号用 --wechat,微信昵称用 wechat 平台;name 只写姓名本身
13
14
  crm add --name "王小明" --relationship 学员 社群成员 # 他在你这里是什么身份(可多个)
14
15
  crm add --name "王小明" --org "同济大学:在职教师:在职" # 他挂着的单位(可多个,机构名:身份:状态)
15
16
  crm list --relationship 甲方 --json # 甲方名单
package/SKILL.md CHANGED
@@ -37,6 +37,9 @@ crm login https://<服务器地址>
37
37
  ## 怎么从材料里抽取
38
38
 
39
39
  **身份与联系**:`name`、`company`、`title`;`wechatId`、`city`。只填材料里明确出现的。看不到就省略,不要猜。
40
+ - **`name` 只写姓名本身**(含常用英文名,如「李源枫 Philip F. Yuan」),不超过 40 字,**不要带括号注释**。「白微微(微信名…,昵称…,微信号…)」这种写法会被服务端拒绝。
41
+ - 微信号(登录用的 ID)写 `wechatId`;微信昵称 / 显示名 / 群昵称写进 `socials`(`platform` 用 `wechat`,见下);职务、城市写各自字段;「真名未知」「shadow 备注」之类的说明写进 `notes`。
42
+ - 无法确定真名时,`name` 写对方使用的称呼,并在 `notes` 里注明真名未知。
40
43
  `city` 取 `crm schema --json` 里 `city` 字段的 `values`(城市枚举);写成「上海市」「Shanghai」「臺北」也会被自动归一化成「上海」「上海」「台北」,所以直接按你看到的写就行。
41
44
 
42
45
  **画像**:
@@ -48,7 +51,7 @@ crm login https://<服务器地址>
48
51
 
49
52
  **社交账号 `socials`**:客户在其他平台上的号——视频号、小红书、邮箱、抖音、B站、公众号等。
50
53
  - 元素形如 `{"platform":"channels","handle":"@san三"}`。`platform` 直接写中文也行(`视频号`、`小红书`、`邮箱`),会自动归一化到标准值。
51
- - **微信不要放这里**,微信号统一写 `wechatId`。
54
+ - **微信昵称 / 显示名**用 `platform: "wechat"`,如 `{"platform":"wechat","handle":"白生"}`(`微信昵称` 也会归一化)。**微信号(ID)不放这里**,统一写 `wechatId`。
52
55
  - 有主页链接就补 `"url"`,没有就省略,不要猜。
53
56
  - 材料里没出现就整条省略,**不要编造**。邮箱也是:只在材料里明确写了邮箱才填。
54
57
  - 命令行写法:`--social channels:@san三 email:zhang@example.com`(平台:账号)。
@@ -111,6 +114,8 @@ crm login https://<服务器地址>
111
114
  - 写 `description` 时让别的客户场景也能照着用:写清楚话术本身和有效的原因,不要只写「聊得很好」。
112
115
  - **找不到就别编。** 没有明确的「这句话奏效了」的证据,就不要创建钩子。宁可没有,不要一条虚构的。
113
116
  - 想给新对话找灵感时:`crm hook list --json`。
117
+ - 钩子是独立库、按 `customerId` 关联的:`crm get <id>` 会把这个客户已有的钩子一起列出来(`--json` 时在 `hooks` 字段里)。
118
+ 看到某个客户已经有钩子,就别重复建;看到没有、而这次对话里确实有一句话奏效了,就补一条。
114
119
 
115
120
  ## 更新已有客户
116
121
 
@@ -138,14 +143,39 @@ crm login https://<服务器地址>
138
143
  crm list --potential high --city 北京 --json # 按等级、城市、标签筛选
139
144
  crm list --due-today --json # 今天有日程的客户(今天要联系谁)
140
145
  crm list --due 2026-10-20 --json
146
+ crm list --expired --json # 有过期日程的客户(日期早于今天,默认就是今天)
147
+ crm list --expired 2026-10-01 --json # 更早的截止日
141
148
  crm list -q 跨境 --json # 关键词:姓名、公司、职位、城市、微信、社交账号、关系、单位、相关人物、摘要、备注、标签、目标
142
149
  crm list --social-platform xiaohongshu --json # 有小红书账号的客户
143
150
  crm list --relationship 甲方 --json # 甲方名单(写 client 一样命中)
144
- crm list --org 同济 --json # 挂在某个机构的客户(包含匹配,简称也能命中)
151
+ crm list --org 同济 --json # 挂在某个机构的客户(包含匹配,简称也能命中;company 和 orgs 都查)
145
152
  crm list --related 李雅婷 --json # 和李雅婷有关系的人(含「被指向」的反向关联)
146
153
  crm get <id> --json
147
154
  ```
148
155
 
156
+ ## 体检(`crm lint`)
157
+
158
+ 写入路径对拿不准的值是**刻意宽松**的:认不出来的 `orgs.status`、清单外的城市、过期日期都原样保留、不报错,
159
+ 这是批量归档时想要的(一条写歪的记录不该打断整批)。代价是脏数据会悄悄攒起来。`crm lint` 就是那个能看见它们的入口。
160
+
161
+ ```bash
162
+ crm lint --json # 全库体检:只报告,不改数据
163
+ crm lint --severity error --json # 只看会造成实际问题的(notes 超上限、状态越界、过期日程、悬空引用)
164
+ crm lint --kind company-prose --json # 只看某一类
165
+ ```
166
+
167
+ 报告的类别:`notes-over-limit`(会被服务端拒)、`notes-long`、`unknown-status`(状态不在受控词表里,按状态聚合会漏)、
168
+ `expired-event`(过期日程)、`dangling-related-id`(相关人物指向库里没有的人)、`duplicate-wechat`、
169
+ `company-prose`(company 写成了说明文而不是简称)、`company-without-orgs`、`orgs-without-company`、
170
+ `no-relationship`(不知道这个人是谁)、`city-off-list`、`half-width-punctuation`。
171
+
172
+ **lint 只报告,不改。** 要改就照着报告里的 id 逐条 `crm update`。
173
+ 注意:`crm update` 会把 `last_updated` 顶到当前时间,把这条档案顶到列表最前面——
174
+ **批量清洗存量请走 `db:backfill-*` 脚本**(保留 `last_updated`、写审计日志),别用 update 循环。
175
+
176
+ 写入时 CLI 会把拿不准的地方打到 stderr 当提醒(未知的 `orgs.status`、清单外的城市、过期的日程、写成说明文的 company)。
177
+ **这些是提醒不是错误**,写入照常成功——除非 `notes` 超过 10000 字符,那种会被服务端整条拒掉,所以 CLI 提前拦了一道。
178
+
149
179
  ## 推荐库(是用户的库存,不是聊天里挖出来的东西)
150
180
 
151
181
  推荐库是**用户自己的待推荐库存**:他要推给客户的产品、服务、文章、活动。内容只来自用户本人。
package/dist/cli.js CHANGED
@@ -116,6 +116,8 @@ var CITIES = [
116
116
  var SOCIAL_PLATFORMS = [
117
117
  "email",
118
118
  // 邮箱
119
+ "wechat",
120
+ // 微信昵称 / 显示名(微信号写 wechatId,不放这里)
119
121
  "channels",
120
122
  // 视频号
121
123
  "xiaohongshu",
@@ -347,6 +349,7 @@ function normalizeCity(input2) {
347
349
  }
348
350
  return cleaned;
349
351
  }
352
+ var isKnownCity = (input2) => CITIES.includes(normalizeCity(input2));
350
353
 
351
354
  // ../shared/src/social.ts
352
355
  var SOCIAL_PLATFORM_ALIASES = {
@@ -357,6 +360,12 @@ var SOCIAL_PLATFORM_ALIASES = {
357
360
  \u90AE\u7BB1: "email",
358
361
  \u90AE\u4EF6: "email",
359
362
  \u7535\u5B50\u90AE\u4EF6: "email",
363
+ // 微信昵称(微信号是 wechatId,不是这里)
364
+ wechat: "wechat",
365
+ \u5FAE\u4FE1: "wechat",
366
+ \u5FAE\u4FE1\u6635\u79F0: "wechat",
367
+ \u5FAE\u4FE1\u540D: "wechat",
368
+ \u5FAE\u4FE1\u663E\u793A\u540D: "wechat",
360
369
  // 视频号
361
370
  channels: "channels",
362
371
  wechat_channels: "channels",
@@ -418,6 +427,7 @@ function normalizeSocialPlatform(input2) {
418
427
  }
419
428
  var SOCIAL_PLATFORM_LABELS = {
420
429
  email: { zh: "\u90AE\u7BB1", en: "Email" },
430
+ wechat: { zh: "\u5FAE\u4FE1\u6635\u79F0", en: "WeChat name" },
421
431
  channels: { zh: "\u89C6\u9891\u53F7", en: "Channels" },
422
432
  xiaohongshu: { zh: "\u5C0F\u7EA2\u4E66", en: "Xiaohongshu" },
423
433
  douyin: { zh: "\u6296\u97F3", en: "Douyin" },
@@ -633,6 +643,33 @@ function normalizeRelatedRelation(input2) {
633
643
  return input2.replace(/[ \s]+/g, " ").trim();
634
644
  }
635
645
 
646
+ // ../shared/src/profile.ts
647
+ var NOTES_MAX = 1e4;
648
+ var NOTES_LONG = 6e3;
649
+ var COMPANY_LONG = 80;
650
+ var NAME_MAX = 40;
651
+ function nameProblem(name) {
652
+ const n = (name ?? "").trim();
653
+ if (!n) return null;
654
+ const hint = "name \u53EA\u5199\u59D3\u540D\u672C\u8EAB\uFF1A\u5FAE\u4FE1\u53F7\u5199 wechatId\uFF0C\u5FAE\u4FE1\u6635\u79F0 / \u663E\u793A\u540D\u5199\u8FDB socials\uFF08platform=wechat\uFF09\uFF0C\u5176\u4F59\u8BF4\u660E\u5199\u8FDB notes";
655
+ if (n.length > NAME_MAX) return `name \u8FC7\u957F\uFF08${n.length} \u5B57\uFF0C\u4E0A\u9650 ${NAME_MAX}\uFF09\u3002${hint}`;
656
+ if (/[((][^))]*(微信|昵称|显示名|备注|手机|邮箱|真名|未知)/.test(n)) return `name \u91CC\u5E26\u4E86\u6CE8\u91CA\u6027\u62EC\u53F7\u3002${hint}`;
657
+ return null;
658
+ }
659
+ var CJK = /[一-鿿]/g;
660
+ function isProseCompany(company) {
661
+ const c = (company ?? "").trim();
662
+ if (!c) return false;
663
+ if (/^未明示|^未明确/.test(c)) return true;
664
+ const m = /((.+))\s*$/.exec(c);
665
+ if (m && m[1].length > 20 && (m[1].match(CJK) ?? []).length >= 12) return true;
666
+ return c.length > COMPANY_LONG;
667
+ }
668
+ function halfWidthPunctuation(text) {
669
+ const hits = text.match(/[一-鿿][,.:;!?]|[,;:!?][一-鿿]|[一-鿿]\([^)]{1,20}\)/g);
670
+ return hits ? [...new Set(hits)] : [];
671
+ }
672
+
636
673
  // ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/classic/external.js
637
674
  var external_exports = {};
638
675
  __export(external_exports, {
@@ -20381,7 +20418,10 @@ var socialHookInput = external_exports.object({
20381
20418
  description: short(5e3).min(1)
20382
20419
  });
20383
20420
  var customerShape = {
20384
- name: short(200).min(1),
20421
+ name: short(200).min(1).superRefine((v, ctx) => {
20422
+ const p = nameProblem(v);
20423
+ if (p) ctx.addIssue({ code: "custom", message: p });
20424
+ }),
20385
20425
  company: short(200),
20386
20426
  title: short(200),
20387
20427
  city,
@@ -20442,7 +20482,7 @@ var socialFields = [
20442
20482
  type: "enum",
20443
20483
  required: true,
20444
20484
  values: SOCIAL_PLATFORMS,
20445
- guide: "\u5E73\u53F0\u3002\u5199\u300C\u89C6\u9891\u53F7\u300D\u300C\u5C0F\u7EA2\u4E66\u300D\u300C\u90AE\u7BB1\u300D\u300C\u516C\u4F17\u53F7\u300D\u7B49\u4E2D\u6587\u4F1A\u81EA\u52A8\u5F52\u4E00\u5316\u5230\u6E05\u5355\u91CC\u7684\u503C\uFF1B\u6E05\u5355\u5916\u7684\u5E73\u53F0\uFF08\u5982\u300C\u5FEB\u624B\u300D\uFF09\u4E0D\u62A5\u9519\uFF0C\u539F\u6837\u4FDD\u7559\u3002\u5FAE\u4FE1\u4E0D\u8981\u653E\u8FD9\u91CC\uFF0C\u5FAE\u4FE1\u53F7\u5199 wechatId\u3002"
20485
+ guide: "\u5E73\u53F0\u3002\u5199\u300C\u89C6\u9891\u53F7\u300D\u300C\u5C0F\u7EA2\u4E66\u300D\u300C\u90AE\u7BB1\u300D\u300C\u516C\u4F17\u53F7\u300D\u7B49\u4E2D\u6587\u4F1A\u81EA\u52A8\u5F52\u4E00\u5316\u5230\u6E05\u5355\u91CC\u7684\u503C\uFF1B\u6E05\u5355\u5916\u7684\u5E73\u53F0\uFF08\u5982\u300C\u5FEB\u624B\u300D\uFF09\u4E0D\u62A5\u9519\uFF0C\u539F\u6837\u4FDD\u7559\u3002\u5FAE\u4FE1\u6635\u79F0 / \u663E\u793A\u540D\u7528 platform=wechat\uFF1B\u5FAE\u4FE1\u53F7\uFF08ID\uFF09\u4E0D\u653E\u8FD9\u91CC\uFF0C\u5199 wechatId\u3002"
20446
20486
  },
20447
20487
  { name: "handle", type: "string", required: true, guide: "\u8D26\u53F7\u540D\u6216\u90AE\u7BB1\u5730\u5740\uFF0C\u5982\u300C@san\u4E09\u300D\u300Czhang@example.com\u300D" },
20448
20488
  { name: "url", type: "string", nullable: true, guide: "\u8D26\u53F7\u4E3B\u9875\u94FE\u63A5\u3002\u6750\u6599\u91CC\u6CA1\u6709\u5C31\u7701\u7565\uFF0C\u4E0D\u8981\u731C" }
@@ -20468,11 +20508,11 @@ var SCHEMA = {
20468
20508
  customer: {
20469
20509
  description: "\u5BA2\u6237\u6863\u6848\u3002\u521B\u5EFA\u53EA\u9700\u8981 name\uFF0C\u5176\u4F59\u5B57\u6BB5\u80FD\u4ECE\u5BF9\u8BDD\u91CC\u786E\u5B9A\u7684\u90FD\u5E94\u586B\u5199\uFF0C\u6CA1\u6709\u4F9D\u636E\u7684\u4E0D\u8981\u7F16\u9020\u3002",
20470
20510
  fields: [
20471
- { name: "name", type: "string", required: true, guide: "\u5BA2\u6237\u59D3\u540D\u3002\u5BF9\u8BDD\u91CC\u51FA\u73B0\u7684\u79F0\u547C\u3001\u6635\u79F0\u82E5\u65E0\u6CD5\u786E\u5B9A\u771F\u540D\uFF0C\u5199\u5BF9\u65B9\u4F7F\u7528\u7684\u540D\u5B57" },
20511
+ { name: "name", type: "string", required: true, guide: "\u53EA\u5199\u59D3\u540D\u672C\u8EAB\uFF08\u542B\u5E38\u7528\u82F1\u6587\u540D\uFF0C\u5982\u300C\u674E\u6E90\u67AB Philip F. Yuan\u300D\uFF09\uFF0C\u4E0D\u8D85\u8FC7 40 \u5B57\uFF0C\u4E0D\u8981\u5E26\u62EC\u53F7\u6CE8\u91CA\u3002\u5FAE\u4FE1\u53F7\u5199 wechatId\uFF0C\u5FAE\u4FE1\u6635\u79F0 / \u663E\u793A\u540D / \u7FA4\u6635\u79F0\u5199\u8FDB socials\uFF08platform=wechat\uFF09\uFF0C\u804C\u52A1\u3001\u57CE\u5E02\u3001\u5907\u6CE8\u5199\u8FDB\u5404\u81EA\u5B57\u6BB5\u6216 notes\u3002\u65E0\u6CD5\u786E\u5B9A\u771F\u540D\u65F6\u5199\u5BF9\u65B9\u4F7F\u7528\u7684\u79F0\u547C\uFF0C\u300C\u771F\u540D\u672A\u77E5\u300D\u4E4B\u7C7B\u7684\u8BF4\u660E\u5199\u8FDB notes" },
20472
20512
  { name: "company", type: "string", guide: "\u4E3B\u5355\u4F4D\uFF1A\u4ED6\u73B0\u5728\u6700\u4E3B\u8981\u7684\u90A3\u4E2A\u673A\u6784\u7B80\u79F0\uFF0C\u5982\u300C\u5F00\u7D22 AI\u300D\u300C\u4E0A\u6D77\u7D22\u95FC\u79D1\u6280\u300D\u3002\u5B8C\u6574\u7684\u673A\u6784\u6E05\u5355\u5199\u8FDB orgs" },
20473
20513
  { name: "title", type: "string", guide: "\u804C\u4F4D\u6216\u8EAB\u4EFD\u3002\u4E3B\u5355\u4F4D\u91CC\u7684\u804C\u4F4D\uFF0C\u5982\u300C\u521B\u59CB\u4EBA\u517C CEO\u300D\u3002\u591A\u4E2A\u8EAB\u4EFD\u5199\u8FDB orgs \u7684 role" },
20474
20514
  { name: "city", type: "enum", values: CITIES, guide: "\u6240\u5728\u57CE\u5E02\u3002\u4F18\u5148\u53D6\u4E0B\u9762\u6E05\u5355\u91CC\u7684\u503C\uFF1B\u5199\u300C\u4E0A\u6D77\u5E02\u300D\u300CShanghai\u300D\u300C\u81FA\u5317\u300D\u4F1A\u81EA\u52A8\u5F52\u4E00\u5316\u6210\u300C\u4E0A\u6D77\u300D\u300C\u4E0A\u6D77\u300D\u300C\u53F0\u5317\u300D\u3002\u6E05\u5355\u5916\u7684\u5199\u6CD5\u4E0D\u4F1A\u62A5\u9519\uFF0C\u539F\u6837\u4FDD\u7559\uFF0C\u4E8B\u540E\u53EF\u5F52\u7C7B\u3002" },
20475
- { name: "wechatId", type: "string", nullable: true, guide: "\u5FAE\u4FE1\u53F7\u3002\u53EA\u5728\u5BF9\u8BDD\u91CC\u660E\u786E\u51FA\u73B0\u65F6\u586B\u5199" },
20515
+ { name: "wechatId", type: "string", nullable: true, guide: "\u5FAE\u4FE1\u53F7\uFF08\u767B\u5F55\u7528\u7684 ID\uFF0C\u5982 elphawhite\uFF09\u3002\u53EA\u5728\u5BF9\u8BDD\u91CC\u660E\u786E\u51FA\u73B0\u65F6\u586B\u5199\u3002\u5FAE\u4FE1\u6635\u79F0 / \u663E\u793A\u540D\u4E0D\u662F\u5FAE\u4FE1\u53F7\uFF0C\u5199\u8FDB socials" },
20476
20516
  {
20477
20517
  name: "socials",
20478
20518
  type: "object[]",
@@ -20590,7 +20630,7 @@ function renderPrompt(text, customer) {
20590
20630
  // package.json
20591
20631
  var package_default = {
20592
20632
  name: "insightcrm",
20593
- version: "0.1.9",
20633
+ version: "0.1.10",
20594
20634
  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.",
20595
20635
  license: "MIT",
20596
20636
  type: "module",
@@ -20702,6 +20742,83 @@ function createClient(apiUrl, token) {
20702
20742
  };
20703
20743
  }
20704
20744
 
20745
+ // src/lint.ts
20746
+ function lintCustomers(customers, today2) {
20747
+ const issues = [];
20748
+ const ids = new Set(customers.map((c) => c.id));
20749
+ const push = (c, kind, severity, detail2) => issues.push({ id: c.id, name: c.name, kind, severity, detail: detail2 });
20750
+ const byWechat = /* @__PURE__ */ new Map();
20751
+ for (const c of customers) {
20752
+ const w = (c.wechatId ?? "").trim();
20753
+ if (!w) continue;
20754
+ const arr = byWechat.get(w);
20755
+ if (arr) arr.push(c);
20756
+ else byWechat.set(w, [c]);
20757
+ }
20758
+ for (const c of customers) {
20759
+ const notesLen = (c.notes ?? "").length;
20760
+ 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`);
20761
+ else if (notesLen > NOTES_LONG) push(c, "notes-long", "warn", `notes ${notesLen} \u5B57\u7B26\uFF0C\u504F\u81C3\u80BF\uFF08\u4E0A\u9650 ${NOTES_MAX}\uFF09`);
20762
+ const nameIssue = nameProblem(c.name);
20763
+ if (nameIssue) push(c, "name-annotated", "warn", `${nameIssue}\uFF1A\u300C${c.name.slice(0, 40)}${c.name.length > 40 ? "\u2026" : ""}\u300D`);
20764
+ for (const o of c.orgs ?? []) {
20765
+ if (!isKnownOrgStatus(o.status)) {
20766
+ push(c, "unknown-status", "error", `orgs[].status="${o.status}"\uFF08org=${o.org}\uFF09\u4E0D\u5728\u53D7\u63A7\u8BCD\u8868\u91CC\uFF0C\u6309\u72B6\u6001\u805A\u5408\u65F6\u8FD9\u6761\u4F1A\u6F0F\u6389`);
20767
+ }
20768
+ }
20769
+ const company = (c.company ?? "").trim();
20770
+ const orgs = c.orgs ?? [];
20771
+ if (company && !orgs.length) push(c, "company-without-orgs", "warn", "company \u6709\u503C\u4F46 orgs \u4E3A\u7A7A\uFF0C\u673A\u6784\u4FE1\u606F\u53EA\u5B58\u5728\u4E8E\u6458\u8981\u91CC\uFF0C\u6309\u673A\u6784\u7B5B\u4E0D\u5230");
20772
+ if (!company && orgs.length) push(c, "orgs-without-company", "warn", "orgs \u6709\u503C\u4F46 company \u4E3A\u7A7A\uFF0C\u7F3A\u300C\u4E3B\u5355\u4F4D\u300D\u6458\u8981");
20773
+ if (company && isProseCompany(company)) push(c, "company-prose", "warn", `company \u662F\u8BF4\u660E\u6587\u800C\u4E0D\u662F\u7B80\u79F0\uFF1A\u300C${company.slice(0, 40)}${company.length > 40 ? "\u2026" : ""}\u300D`);
20774
+ if (!c.relationships?.length) push(c, "no-relationship", "warn", "relationships \u4E3A\u7A7A\uFF0C\u4E0D\u77E5\u9053\u8FD9\u4E2A\u4EBA\u662F\u8C01");
20775
+ const city2 = (c.city ?? "").trim();
20776
+ if (city2 && !isKnownCity(city2)) push(c, "city-off-list", "warn", `city="${city2}" \u4E0D\u5728\u6807\u51C6\u57CE\u5E02\u8868\u91CC\uFF0C\u6309\u57CE\u5E02\u805A\u5408\u65F6\u8FD9\u6761\u4F1A\u6F0F\u6389`);
20777
+ for (const e of c.upcomingEvents ?? []) {
20778
+ if (e.date && e.date < today2) push(c, "expired-event", "error", `\u65E5\u7A0B\u5DF2\u8FC7\u671F\uFF1A${e.date}\u300C${e.title}\u300D`);
20779
+ }
20780
+ for (const p of c.relatedPeople ?? []) {
20781
+ if (p.id && !ids.has(p.id)) push(c, "dangling-related-id", "error", `relatedPeople[${p.name}].id=${p.id} \u6307\u5411\u5E93\u91CC\u4E0D\u5B58\u5728\u7684\u5BA2\u6237`);
20782
+ }
20783
+ const w = (c.wechatId ?? "").trim();
20784
+ if (w && (byWechat.get(w)?.length ?? 0) > 1) {
20785
+ push(c, "duplicate-wechat", "warn", `wechatId=${w} \u5728 ${byWechat.get(w).length} \u6761\u8BB0\u5F55\u4E0A\u91CD\u590D`);
20786
+ }
20787
+ const texts = [
20788
+ ["summary", c.summary ?? ""],
20789
+ ["notes", c.notes ?? ""],
20790
+ ["currentAction", c.currentAction ?? ""],
20791
+ ...(c.painPoints ?? []).map((p) => ["painPoints", p]),
20792
+ ...(c.goals ?? []).map((g2) => ["goals", g2])
20793
+ ];
20794
+ for (const [field, text] of texts) {
20795
+ if (!text) continue;
20796
+ const hits = halfWidthPunctuation(text);
20797
+ if (hits.length) push(c, "half-width-punctuation", "info", `${field} \u6709 ${hits.length} \u5904\u534A\u89D2\u6807\u70B9\uFF1A${hits.slice(0, 4).join(" ")}`);
20798
+ }
20799
+ }
20800
+ return issues;
20801
+ }
20802
+ function groupLintIssues(issues) {
20803
+ const rank = { error: 0, warn: 1, info: 2 };
20804
+ const perCustomer = /* @__PURE__ */ new Map();
20805
+ for (const i of issues) {
20806
+ const arr = perCustomer.get(i.id);
20807
+ if (arr) arr.push(i);
20808
+ else perCustomer.set(i.id, [i]);
20809
+ }
20810
+ return {
20811
+ issues: [...issues].sort((a, b) => rank[a.severity] - rank[b.severity] || a.name.localeCompare(b.name)),
20812
+ perCustomer: [...perCustomer.entries()].map(([id, list]) => ({
20813
+ id,
20814
+ name: list[0].name,
20815
+ count: list.length,
20816
+ errors: list.filter((i) => i.severity === "error").length,
20817
+ kinds: [...new Set(list.map((i) => i.kind))]
20818
+ })).sort((a, b) => b.errors - a.errors || b.count - a.count)
20819
+ };
20820
+ }
20821
+
20705
20822
  // src/org.ts
20706
20823
  function parseOrg(s) {
20707
20824
  const parts = s.split(":").map((p) => p.trim());
@@ -20881,6 +20998,7 @@ Recommended workflow (for agents):
20881
20998
  Before adding search <name> --json (avoid duplicates; if the customer exists, update instead of add)
20882
20999
  Record a customer add - --json < profile.json (or: add --name ... --potential High)
20883
21000
  Update update <id> --add-pain "budget" --add-event 2026-10-20:follow_up:send quote --json
21001
+ Audit the records lint --json (report dirty records; reports only, never writes)
20884
21002
  Reuse what works hook list --json (successful phrasings from other customers)
20885
21003
  Recommend rec list --json (the user's OWN inventory: pick what fits; add items only when the user asks, never from chat)
20886
21004
  House rules prompts show extraction-rules (the user's own extraction rules: follow them when extracting)
@@ -20897,7 +21015,9 @@ Examples:
20897
21015
  $ crm add --name "\u738B\u5C0F\u660E" --relationship \u5B66\u5458 --relationship \u793E\u7FA4\u6210\u5458 --json
20898
21016
  $ crm add --name "\u738B\u5C0F\u660E" --org "\u540C\u6D4E\u5927\u5B66:\u5728\u804C\u6559\u5E08:\u5728\u804C" "\u6D59\u6C5F\u7406\u5DE5\u5927\u5B66:\u535A\u58EB\u5728\u8BFB:\u5728\u8BFB" --json
20899
21017
  $ crm list --potential high --city Beijing --due-today --json
21018
+ $ crm list --expired --json
20900
21019
  $ crm list --org \u540C\u6D4E --json
21020
+ $ crm lint --severity error --json
20901
21021
  $ crm add --name "\u738B\u5C0F\u660E" --related "\u674E\u96C5\u5A77:\u8F6C\u4ECB\u7ECD\u4EBA" "\u67F4\u8001\u5E08:\u5BFC\u5E08" --json
20902
21022
  $ crm list --related \u674E\u96C5\u5A77 --json
20903
21023
  $ crm update 3f2a\u2026 --summary "Needs a quote by Friday" --json
@@ -21018,6 +21138,34 @@ function buildCustomerBody(base, o) {
21018
21138
  }
21019
21139
  return body;
21020
21140
  }
21141
+ function checkNotesLength(body) {
21142
+ const notes = body.notes;
21143
+ if (typeof notes === "string" && notes.length > NOTES_MAX) {
21144
+ throw new CliError(
21145
+ "usage",
21146
+ `notes is ${notes.length} characters, ${notes.length - NOTES_MAX} over the ${NOTES_MAX} limit. Compress it (move detail into the structured fields) and retry`,
21147
+ EXIT.usage
21148
+ );
21149
+ }
21150
+ }
21151
+ function warnPayload(body) {
21152
+ const warns = [];
21153
+ for (const o of body.orgs ?? []) {
21154
+ if (o?.status && !isKnownOrgStatus(o.status)) {
21155
+ warns.push(`orgs[].status="${o.status}" is not a controlled value (${ORG_STATUSES.join(" | ")}) \u2014 it won't aggregate by status`);
21156
+ }
21157
+ }
21158
+ if (typeof body.city === "string" && body.city.trim() && !isKnownCity(body.city)) {
21159
+ warns.push(`city="${body.city}" is not in the standard city list \u2014 it won't aggregate by city`);
21160
+ }
21161
+ for (const e of body.upcomingEvents ?? []) {
21162
+ if (e?.date && e.date < today()) warns.push(`event "${e.title ?? ""}" ${e.date} is already in the past`);
21163
+ }
21164
+ if (typeof body.company === "string" && isProseCompany(body.company)) {
21165
+ warns.push(`company looks like a note rather than a short name \u2014 keep the name short and move the detail into orgs / notes`);
21166
+ }
21167
+ for (const w of warns) info(`\u26A0 ${w}`);
21168
+ }
21021
21169
  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(", ")}]` : ""}`;
21022
21170
  function detail(c) {
21023
21171
  const rows = [
@@ -21171,6 +21319,8 @@ withCustomerOptions(
21171
21319
  ).action(async (src, o) => {
21172
21320
  const body = buildCustomerBody(await readJsonInput(src), o);
21173
21321
  if (!body.name) throw new CliError("usage", "name is required (pass --name or include it in the JSON)", EXIT.usage);
21322
+ checkNotesLength(body);
21323
+ warnPayload(body);
21174
21324
  const { customer } = await (await client()).addCustomer(body);
21175
21325
  out(`Created ${line(customer)}`, { customer, created: true });
21176
21326
  });
@@ -21207,14 +21357,47 @@ withCustomerOptions(
21207
21357
  }
21208
21358
  }
21209
21359
  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);
21360
+ checkNotesLength(body);
21361
+ warnPayload(body);
21210
21362
  const { customer } = await api.updateCustomer(id, body);
21211
21363
  out(`Updated ${line(customer)}`, { customer, updated: true });
21212
21364
  });
21213
21365
  program.command("get").description("Show one customer").argument("<id>").action(async (id) => {
21214
- const { customer } = await (await client()).getCustomer(id);
21215
- out(detail(customer), { customer });
21366
+ const api = await client();
21367
+ const { customer } = await api.getCustomer(id);
21368
+ const { hooks } = await api.listHooks(id);
21369
+ const rows = [
21370
+ ...detail(customer).split("\n"),
21371
+ ...hooks.length ? ["", "hooks", ...hooks.map((h) => ` ${h.isEnabled ? " " : "\xD7"} ${h.title}
21372
+ ${h.description}`)] : []
21373
+ ].join("\n");
21374
+ out(rows, { customer, hooks });
21375
+ });
21376
+ program.command("lint").description("Audit every customer record and report what should be checked or fixed. Reports only \u2014 never writes.").option("--kind <kind>", "only report one kind of issue").option("--severity <level>", "only report this severity: error / warn / info").action(async (o) => {
21377
+ const api = await client();
21378
+ const { customers } = await api.listCustomers({});
21379
+ const all = lintCustomers(customers, today());
21380
+ const issues = all.filter(
21381
+ (i) => (!o.kind || i.kind === o.kind) && (!o.severity || i.severity === o.severity)
21382
+ );
21383
+ const { perCustomer } = groupLintIssues(issues);
21384
+ const errors = issues.filter((i) => i.severity === "error").length;
21385
+ const warns = issues.filter((i) => i.severity === "warn").length;
21386
+ const infos = issues.filter((i) => i.severity === "info").length;
21387
+ const human = [
21388
+ `Scanned ${customers.length} customers \xB7 ${issues.length} issues (${errors} error / ${warns} warn / ${infos} info)`,
21389
+ "",
21390
+ ...perCustomer.map(
21391
+ (p) => `${p.count === 1 ? " " : "!"} ${p.name} (${p.id}) ${p.count} issue${p.count > 1 ? "s" : ""}${p.errors ? `, ${p.errors} error` : ""}
21392
+ ${p.kinds.join(", ")}`
21393
+ ),
21394
+ "",
21395
+ "Per issue:",
21396
+ ...issues.map((i) => ` [${i.severity}] ${i.name} \u2014 ${i.kind}: ${i.detail}`)
21397
+ ].join("\n");
21398
+ out(human, { scanned: customers.length, count: issues.length, errors, warns, infos, issues, perCustomer });
21216
21399
  });
21217
- 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("-q, --query <s>", "keyword across name, company, title, city, wechat, social accounts, relationships, organizations, related people, summary, notes, tags, goals").action(async (o) => {
21400
+ 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) => {
21218
21401
  const { customers } = await (await client()).listCustomers({
21219
21402
  potential: o.potential ? potentialOf(o.potential) : void 0,
21220
21403
  city: o.city,
@@ -21224,7 +21407,8 @@ program.command("list").description("List customers (newest update first), optio
21224
21407
  relationship: o.relationship,
21225
21408
  org: o.org,
21226
21409
  related: o.related,
21227
- dueOn: o.dueToday ? today() : o.due
21410
+ dueOn: o.dueToday ? today() : o.due,
21411
+ expiredBefore: o.expired ? o.expired === true ? today() : o.expired : void 0
21228
21412
  });
21229
21413
  out(customers.length ? customers.map(line).join("\n") : "No customers match.", { customers, count: customers.length });
21230
21414
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insightcrm",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
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",