insightcrm 0.1.1 → 0.1.3

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,7 +10,8 @@ crm login https://<你的服务器> # 浏览器里点「允许」(设备
10
10
  crm schema --json # 字段契约,含每个字段的填写指引
11
11
  echo '{"name":"王小明","company":"ACME"}' | crm add - --json
12
12
  crm list --due-today --json
13
- crm skill --install # 把使用说明装进 Claude Code
13
+ crm version # 当前版本 + npm 上有没有新版
14
+ crm skill # 打印给 agent 的使用说明;在 agent 指令里加一句「先运行 crm skill」
14
15
  ```
15
16
 
16
17
  - `--json` 时 stdout 只有一个 JSON 对象,过程信息走 stderr。
package/SKILL.md CHANGED
@@ -140,9 +140,20 @@ crm import backup.json # 重复导入同一份是安全的(相同 id
140
140
 
141
141
  `crm rm <id> --yes` 删除客户,**先问用户**。客户的钩子会保留在钩子库里。
142
142
 
143
- ## 装这份说明到 Claude Code
143
+ ## 检查版本
144
144
 
145
145
  ```bash
146
- crm skill --install # 装到 ~/.claude/skills/insightcrm/
147
- crm skill --install --dir ./.claude/skills # 只装到当前项目
146
+ crm version # 打印当前版本,并查 npm 上有没有新版
147
+ crm version --json # 结构化输出(agent 用这个)
148
+ crm version --offline # 只报本地版本,不联网
148
149
  ```
150
+
151
+ 有新版时会给出 `update npm i -g insightcrm` 的提示,**升级前先问用户**。查不到(离线、npm 挂了)时命令仍然退出码 0,JSON 里的 `error` 字段说明原因,`latest` 为 `null`。
152
+
153
+ ## 这份说明从哪来
154
+
155
+ `crm skill` 把这份说明打印出来,内容永远和当前安装的 CLI 版本一致。**处理客户相关的事(录入、更新、查询、推荐)之前先运行一次 `crm skill`,并按它执行。**
156
+
157
+ 想让你的 agent 每次都这样做,在它的指令里(`CLAUDE.md`、`AGENTS.md` 或系统提示)加一句:
158
+
159
+ > 处理客户档案之前,先运行 `crm skill` 读最新说明,并按它执行。
package/dist/cli.js CHANGED
@@ -7,9 +7,8 @@ var __export = (target, all) => {
7
7
 
8
8
  // src/cli.ts
9
9
  import { spawn } from "child_process";
10
- import { cp, mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
11
- import { homedir as homedir2, hostname as hostname3, platform } from "os";
12
- import path3 from "path";
10
+ import { readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
11
+ import { hostname as hostname3, platform } from "os";
13
12
  import { fileURLToPath } from "url";
14
13
  import { createInterface } from "readline/promises";
15
14
  import { Command, Option } from "commander";
@@ -27,6 +26,7 @@ var EXIT = {
27
26
  failed: 5
28
27
  };
29
28
  var VERIFY_LINK_TTL_MS = 72 * 60 * 60 * 1e3;
29
+ var RESET_LINK_TTL_MS = 24 * 60 * 60 * 1e3;
30
30
  var CLI_AUTH = {
31
31
  ttlMs: 10 * 60 * 1e3,
32
32
  pollIntervalSec: 3
@@ -849,10 +849,10 @@ function mergeDefs(...defs) {
849
849
  function cloneDef(schema) {
850
850
  return mergeDefs(schema._zod.def);
851
851
  }
852
- function getElementAtPath(obj, path4) {
853
- if (!path4)
852
+ function getElementAtPath(obj, path3) {
853
+ if (!path3)
854
854
  return obj;
855
- return path4.reduce((acc, key) => acc?.[key], obj);
855
+ return path3.reduce((acc, key) => acc?.[key], obj);
856
856
  }
857
857
  function promiseAllObject(promisesObj) {
858
858
  const keys = Object.keys(promisesObj);
@@ -1192,11 +1192,11 @@ function explicitlyAborted(x, startIndex = 0) {
1192
1192
  }
1193
1193
  return false;
1194
1194
  }
1195
- function prefixIssues(path4, issues) {
1195
+ function prefixIssues(path3, issues) {
1196
1196
  return issues.map((iss) => {
1197
1197
  var _a3;
1198
1198
  (_a3 = iss).path ?? (_a3.path = []);
1199
- iss.path.unshift(path4);
1199
+ iss.path.unshift(path3);
1200
1200
  return iss;
1201
1201
  });
1202
1202
  }
@@ -1658,16 +1658,16 @@ function flattenError(error62, mapper = (issue2) => issue2.message) {
1658
1658
  }
1659
1659
  function formatError(error62, mapper = (issue2) => issue2.message) {
1660
1660
  const fieldErrors = { _errors: [] };
1661
- const processError = (error63, path4 = []) => {
1661
+ const processError = (error63, path3 = []) => {
1662
1662
  for (const issue2 of error63.issues) {
1663
1663
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1664
- issue2.errors.map((issues) => processError({ issues }, [...path4, ...issue2.path]));
1664
+ issue2.errors.map((issues) => processError({ issues }, [...path3, ...issue2.path]));
1665
1665
  } else if (issue2.code === "invalid_key") {
1666
- processError({ issues: issue2.issues }, [...path4, ...issue2.path]);
1666
+ processError({ issues: issue2.issues }, [...path3, ...issue2.path]);
1667
1667
  } else if (issue2.code === "invalid_element") {
1668
- processError({ issues: issue2.issues }, [...path4, ...issue2.path]);
1668
+ processError({ issues: issue2.issues }, [...path3, ...issue2.path]);
1669
1669
  } else {
1670
- const fullpath = [...path4, ...issue2.path];
1670
+ const fullpath = [...path3, ...issue2.path];
1671
1671
  if (fullpath.length === 0) {
1672
1672
  fieldErrors._errors.push(mapper(issue2));
1673
1673
  } else {
@@ -1706,17 +1706,17 @@ function formatError(error62, mapper = (issue2) => issue2.message) {
1706
1706
  }
1707
1707
  function treeifyError(error62, mapper = (issue2) => issue2.message) {
1708
1708
  const result = { errors: [] };
1709
- const processError = (error63, path4 = []) => {
1709
+ const processError = (error63, path3 = []) => {
1710
1710
  var _a3;
1711
1711
  for (const issue2 of error63.issues) {
1712
1712
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1713
- issue2.errors.map((issues) => processError({ issues }, [...path4, ...issue2.path]));
1713
+ issue2.errors.map((issues) => processError({ issues }, [...path3, ...issue2.path]));
1714
1714
  } else if (issue2.code === "invalid_key") {
1715
- processError({ issues: issue2.issues }, [...path4, ...issue2.path]);
1715
+ processError({ issues: issue2.issues }, [...path3, ...issue2.path]);
1716
1716
  } else if (issue2.code === "invalid_element") {
1717
- processError({ issues: issue2.issues }, [...path4, ...issue2.path]);
1717
+ processError({ issues: issue2.issues }, [...path3, ...issue2.path]);
1718
1718
  } else {
1719
- const fullpath = [...path4, ...issue2.path];
1719
+ const fullpath = [...path3, ...issue2.path];
1720
1720
  if (fullpath.length === 0) {
1721
1721
  result.errors.push(mapper(issue2));
1722
1722
  continue;
@@ -1755,8 +1755,8 @@ function treeifyError(error62, mapper = (issue2) => issue2.message) {
1755
1755
  }
1756
1756
  function toDotPath(_path) {
1757
1757
  const segs = [];
1758
- const path4 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1759
- for (const seg of path4) {
1758
+ const path3 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1759
+ for (const seg of path3) {
1760
1760
  if (typeof seg === "number")
1761
1761
  segs.push(`[${seg}]`);
1762
1762
  else if (typeof seg === "symbol")
@@ -18894,13 +18894,13 @@ function resolveRef(ref, ctx) {
18894
18894
  if (!ref.startsWith("#")) {
18895
18895
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
18896
18896
  }
18897
- const path4 = ref.slice(1).split("/").filter(Boolean);
18898
- if (path4.length === 0) {
18897
+ const path3 = ref.slice(1).split("/").filter(Boolean);
18898
+ if (path3.length === 0) {
18899
18899
  return ctx.rootSchema;
18900
18900
  }
18901
18901
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
18902
- if (path4[0] === defsKey) {
18903
- const key = path4[1] === void 0 ? void 0 : decodeJSONPointerSegment(path4[1]);
18902
+ if (path3[0] === defsKey) {
18903
+ const key = path3[1] === void 0 ? void 0 : decodeJSONPointerSegment(path3[1]);
18904
18904
  if (!key || !ctx.defs[key]) {
18905
18905
  throw new Error(`Reference not found: ${ref}`);
18906
18906
  }
@@ -19908,6 +19908,57 @@ function renderPrompt(text, customer) {
19908
19908
  });
19909
19909
  }
19910
19910
 
19911
+ // package.json
19912
+ var package_default = {
19913
+ name: "insightcrm",
19914
+ version: "0.1.3",
19915
+ 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.",
19916
+ license: "MIT",
19917
+ type: "module",
19918
+ bin: {
19919
+ insightcrm: "dist/cli.js",
19920
+ crm: "dist/cli.js"
19921
+ },
19922
+ files: [
19923
+ "dist",
19924
+ "SKILL.md",
19925
+ "README.md"
19926
+ ],
19927
+ engines: {
19928
+ node: ">=20"
19929
+ },
19930
+ scripts: {
19931
+ dev: "tsx src/cli.ts",
19932
+ build: "tsup",
19933
+ typecheck: "tsc -p .",
19934
+ prepack: "tsup"
19935
+ },
19936
+ devDependencies: {
19937
+ "@insightcrm/shared": "workspace:*"
19938
+ },
19939
+ dependencies: {
19940
+ commander: "^15.0.0"
19941
+ },
19942
+ keywords: [
19943
+ "crm",
19944
+ "cli",
19945
+ "agent",
19946
+ "mcp",
19947
+ "claude",
19948
+ "customer",
19949
+ "insightcrm"
19950
+ ],
19951
+ repository: {
19952
+ type: "git",
19953
+ url: "git+https://github.com/shadowcz007/InsightCRM.git",
19954
+ directory: "packages/cli"
19955
+ },
19956
+ homepage: "https://github.com/shadowcz007/InsightCRM#readme",
19957
+ bugs: {
19958
+ url: "https://github.com/shadowcz007/InsightCRM/issues"
19959
+ }
19960
+ };
19961
+
19911
19962
  // src/api.ts
19912
19963
  var CliError = class extends Error {
19913
19964
  constructor(code, message, exitCode, status) {
@@ -19923,7 +19974,7 @@ var CliError = class extends Error {
19923
19974
  var exitFor = (status, code) => status === 401 || ["email_unverified", "banned", "access_denied", "expired_token", "forbidden", "bad_origin"].includes(code) ? EXIT.auth : status === 429 || code === "rate_limited" ? EXIT.quota : status === 400 ? EXIT.usage : status === 409 ? EXIT.failed : EXIT.error;
19924
19975
  function createClient(apiUrl, token) {
19925
19976
  async function call(method, p, body) {
19926
- const headers = { "user-agent": "insightcrm-cli/0.1" };
19977
+ const headers = { "user-agent": `insightcrm-cli/${package_default.version}` };
19927
19978
  if (token) headers.authorization = `Bearer ${token}`;
19928
19979
  let payload;
19929
19980
  if (body !== void 0) {
@@ -20056,62 +20107,68 @@ function defaultLang(env = process.env) {
20056
20107
  return v.startsWith("zh") ? "zh" : "en";
20057
20108
  }
20058
20109
 
20059
- // package.json
20060
- var package_default = {
20061
- name: "insightcrm",
20062
- version: "0.1.1",
20063
- 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.",
20064
- license: "MIT",
20065
- type: "module",
20066
- bin: {
20067
- insightcrm: "dist/cli.js",
20068
- crm: "dist/cli.js"
20069
- },
20070
- files: [
20071
- "dist",
20072
- "SKILL.md",
20073
- "README.md"
20074
- ],
20075
- engines: {
20076
- node: ">=20"
20077
- },
20078
- scripts: {
20079
- dev: "tsx src/cli.ts",
20080
- build: "tsup",
20081
- typecheck: "tsc -p .",
20082
- prepack: "tsup"
20083
- },
20084
- devDependencies: {
20085
- "@insightcrm/shared": "workspace:*"
20086
- },
20087
- dependencies: {
20088
- commander: "^15.0.0"
20089
- },
20090
- keywords: [
20091
- "crm",
20092
- "cli",
20093
- "agent",
20094
- "mcp",
20095
- "claude",
20096
- "customer",
20097
- "insightcrm"
20098
- ],
20099
- repository: {
20100
- type: "git",
20101
- url: "git+https://github.com/shadowcz007/InsightCRM.git",
20102
- directory: "packages/cli"
20103
- },
20104
- homepage: "https://github.com/shadowcz007/InsightCRM#readme",
20105
- bugs: {
20106
- url: "https://github.com/shadowcz007/InsightCRM/issues"
20110
+ // src/version.ts
20111
+ var REGISTRY_PACKAGE = package_default.name.replace("/", "%2f");
20112
+ var REGISTRY_URL = `https://registry.npmjs.org/${REGISTRY_PACKAGE}`;
20113
+ var UPDATE_COMMAND = `npm i -g ${package_default.name}`;
20114
+ function parseVersion(v) {
20115
+ const m = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(v.trim());
20116
+ if (!m) return null;
20117
+ return { parts: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ? m[4].split(".") : [] };
20118
+ }
20119
+ function compareVersions(a, b) {
20120
+ const pa = parseVersion(a);
20121
+ const pb = parseVersion(b);
20122
+ if (!pa || !pb) return 0;
20123
+ for (let i = 0; i < 3; i++) {
20124
+ const d = pa.parts[i] - pb.parts[i];
20125
+ if (d !== 0) return d < 0 ? -1 : 1;
20126
+ }
20127
+ if (pa.pre.length === 0 && pb.pre.length === 0) return 0;
20128
+ if (pa.pre.length === 0) return 1;
20129
+ if (pb.pre.length === 0) return -1;
20130
+ const len = Math.max(pa.pre.length, pb.pre.length);
20131
+ for (let i = 0; i < len; i++) {
20132
+ const x = pa.pre[i];
20133
+ const y = pb.pre[i];
20134
+ if (x === void 0) return -1;
20135
+ if (y === void 0) return 1;
20136
+ const nx = /^\d+$/.test(x) ? Number(x) : null;
20137
+ const ny = /^\d+$/.test(y) ? Number(y) : null;
20138
+ if (nx !== null && ny !== null) {
20139
+ if (nx !== ny) return nx < ny ? -1 : 1;
20140
+ continue;
20141
+ }
20142
+ if (nx !== null) return -1;
20143
+ if (ny !== null) return 1;
20144
+ if (x !== y) return x < y ? -1 : 1;
20107
20145
  }
20108
- };
20146
+ return 0;
20147
+ }
20148
+ async function fetchLatestVersion(opts = {}) {
20149
+ const { timeoutMs = 5e3, fetchImpl = fetch, registry: registry2 = REGISTRY_URL } = opts;
20150
+ const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
20151
+ try {
20152
+ const res = await fetchImpl(`${registry2}/latest`, {
20153
+ headers: { accept: "application/json", "user-agent": `insightcrm-cli/${package_default.version}` },
20154
+ signal: AbortSignal.timeout(timeoutMs)
20155
+ });
20156
+ if (!res.ok) return { version: "", checkedAt, error: `npm registry returned HTTP ${res.status}` };
20157
+ const body = await res.json().catch(() => null);
20158
+ const version2 = typeof body?.version === "string" ? body.version : "";
20159
+ if (!version2) return { version: "", checkedAt, error: "npm registry response had no version" };
20160
+ return { version: version2, checkedAt };
20161
+ } catch (e) {
20162
+ return { version: "", checkedAt, error: e.message };
20163
+ }
20164
+ }
20109
20165
 
20110
20166
  // src/cli.ts
20111
20167
  var program = new Command().name("crm").description("InsightCRM command line: read and write your customer records. The AI lives in your agent, not here.").version(package_default.version).addOption(new Option("--json", "print one JSON object to stdout (also CRM_JSON=1)").default(process.env.CRM_JSON === "1")).option("-n, --server <name>", "use a saved server for this command (env CRM_SERVER); see `crm servers`").option("--api-url <url>", "server URL, overrides the saved one (env CRM_API_URL)").option("--token <token>", "API token, overrides the saved one (env CRM_TOKEN)").showHelpAfterError().addHelpText(
20112
20168
  "after",
20113
20169
  `
20114
20170
  Recommended workflow (for agents):
20171
+ Read first skill (prints the full agent instructions; do this before your first task)
20115
20172
  First time login <server-url> (a human approves in the browser)
20116
20173
  Learn the fields schema --json (field types AND how to fill each one: read the "guide" texts)
20117
20174
  Before adding search <name> --json (avoid duplicates; if the customer exists, update instead of add)
@@ -20347,18 +20404,28 @@ program.command("whoami").description("Show the current server and account").act
20347
20404
  const { user } = await (await client()).me();
20348
20405
  out(`${user.email} (${user.role}${user.emailVerified ? "" : ", email NOT verified: read-only"}) on ${name ?? apiUrl} \xB7 ${apiUrl}`, { server: name ?? null, url: apiUrl, user });
20349
20406
  });
20350
- program.command("skill").description("Print the agent skill (SKILL.md) for this CLI, or install it for Claude Code with --install").option("--install", "copy SKILL.md to ~/.claude/skills/insightcrm/ (Claude Code loads it automatically)").option("--dir <dir>", "install into <dir>/insightcrm/ instead, e.g. ./.claude/skills for this project only").action(async (o) => {
20407
+ program.command("skill").description("Print the agent instructions (SKILL.md) for this CLI. Agents: run this before your first task and follow it. Nothing is installed anywhere.").action(async () => {
20351
20408
  const src = fileURLToPath(new URL("../SKILL.md", import.meta.url));
20352
- if (!o.install && !o.dir) {
20353
- const text = await readFile3(src, "utf8");
20354
- if (g().json) out("", { path: src, content: text });
20355
- else process.stdout.write(text);
20409
+ const text = await readFile3(src, "utf8");
20410
+ if (g().json) out("", { path: src, content: text });
20411
+ else process.stdout.write(text);
20412
+ });
20413
+ program.command("version").description("Show the installed version and check npm for a newer one.").option("--offline", "don't contact npm; just report the installed version").action(async (o) => {
20414
+ const current = package_default.version;
20415
+ if (o.offline) {
20416
+ out(`insightcrm ${current}
20417
+ latest (not checked)`, { current, latest: null, updateAvailable: null, checked: false, error: null, updateCommand: UPDATE_COMMAND });
20356
20418
  return;
20357
20419
  }
20358
- const dest = path3.join(o.dir ? path3.resolve(o.dir) : path3.join(homedir2(), ".claude", "skills"), "insightcrm");
20359
- await mkdir3(dest, { recursive: true });
20360
- await cp(src, path3.join(dest, "SKILL.md"));
20361
- out(`Installed skill to ${dest}/SKILL.md. Restart Claude Code to pick it up.`, { ok: true, path: path3.join(dest, "SKILL.md") });
20420
+ const res = await fetchLatestVersion();
20421
+ const latest = res.error ? null : res.version;
20422
+ const updateAvailable = latest ? compareVersions(latest, current) > 0 : null;
20423
+ let latestLine;
20424
+ if (!latest) latestLine = `unknown (couldn't reach npm: ${res.error ?? "unknown error"})`;
20425
+ else if (updateAvailable) latestLine = `${latest} (new version available)`;
20426
+ else latestLine = `${latest} (up to date)`;
20427
+ const human = [`insightcrm ${current}`, `latest ${latestLine}`, ...updateAvailable ? [`update ${UPDATE_COMMAND}`] : []].join("\n");
20428
+ out(human, { current, latest, updateAvailable, checked: !res.error, error: res.error ?? null, updateCommand: UPDATE_COMMAND });
20362
20429
  });
20363
20430
  program.command("schema").description('Field definitions AND filling guidance: the contract for writing records. Read the "guide" of every field before you add.').addOption(new Option("--entity <name>", "only this entity").choices([...ENTITIES])).action(async (o) => {
20364
20431
  const entities = (o.entity ? [o.entity] : [...ENTITIES]).map((e) => ({ entity: e, ...SCHEMA[e] }));
@@ -20449,6 +20516,21 @@ rec.command("rm").argument("<id>").option("-y, --yes").action(async (id, o) => {
20449
20516
  out(`Deleted ${id}`, { ok: true, id });
20450
20517
  });
20451
20518
  var prompts = program.command("prompts").description("Prompt templates for your agent: extraction rules and task presets (draft a message, gift ideas\u2026). Built-in defaults you can override.");
20519
+ prompts.addHelpText(
20520
+ "after",
20521
+ `
20522
+ When to use (agents):
20523
+ extraction-rules Before \`add\` / \`update\` when extracting from chats or screenshots: \`prompts show extraction-rules\`, and follow it.
20524
+ draft / gift / starters / advice
20525
+ When the user asks for that task: \`prompts show <id> --customer <id>\` first, then do it.
20526
+ {{name}} {{company}} {{title}} {{city}} {{wechatId}} are filled from the customer; --json also returns the profile.
20527
+ \`draft\` has a placeholder ([\u8BF7\u8865\u5145] / [Insert Topic]): ask the user for the topic before answering.
20528
+
20529
+ Notes:
20530
+ Templates are stored on this machine only (~/.config/insightcrm/prompts.json); the web app does not show them and they do not sync.
20531
+ \`set <id>\` overrides a built-in or adds your own; \`reset <id>\` / \`reset --all\` undoes it.
20532
+ `
20533
+ );
20452
20534
  var langOption = () => new Option("--lang <lang>", "language of the built-in templates (default: CRM_LANG, then the system language)").choices([...PROMPT_LANGS]);
20453
20535
  var langOf = (o) => o.lang ?? defaultLang();
20454
20536
  prompts.command("list").description("List templates. `customized` marks the ones you changed or added.").addOption(langOption()).action(async (o) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insightcrm",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
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",