insightcrm 0.1.2 → 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,6 +10,7 @@ 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 version # 当前版本 + npm 上有没有新版
13
14
  crm skill # 打印给 agent 的使用说明;在 agent 指令里加一句「先运行 crm skill」
14
15
  ```
15
16
 
package/SKILL.md CHANGED
@@ -140,6 +140,16 @@ crm import backup.json # 重复导入同一份是安全的(相同 id
140
140
 
141
141
  `crm rm <id> --yes` 删除客户,**先问用户**。客户的钩子会保留在钩子库里。
142
142
 
143
+ ## 检查版本
144
+
145
+ ```bash
146
+ crm version # 打印当前版本,并查 npm 上有没有新版
147
+ crm version --json # 结构化输出(agent 用这个)
148
+ crm version --offline # 只报本地版本,不联网
149
+ ```
150
+
151
+ 有新版时会给出 `update npm i -g insightcrm` 的提示,**升级前先问用户**。查不到(离线、npm 挂了)时命令仍然退出码 0,JSON 里的 `error` 字段说明原因,`latest` 为 `null`。
152
+
143
153
  ## 这份说明从哪来
144
154
 
145
155
  `crm skill` 把这份说明打印出来,内容永远和当前安装的 CLI 版本一致。**处理客户相关的事(录入、更新、查询、推荐)之前先运行一次 `crm skill`,并按它执行。**
package/dist/cli.js CHANGED
@@ -26,6 +26,7 @@ var EXIT = {
26
26
  failed: 5
27
27
  };
28
28
  var VERIFY_LINK_TTL_MS = 72 * 60 * 60 * 1e3;
29
+ var RESET_LINK_TTL_MS = 24 * 60 * 60 * 1e3;
29
30
  var CLI_AUTH = {
30
31
  ttlMs: 10 * 60 * 1e3,
31
32
  pollIntervalSec: 3
@@ -19907,6 +19908,57 @@ function renderPrompt(text, customer) {
19907
19908
  });
19908
19909
  }
19909
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
+
19910
19962
  // src/api.ts
19911
19963
  var CliError = class extends Error {
19912
19964
  constructor(code, message, exitCode, status) {
@@ -19922,7 +19974,7 @@ var CliError = class extends Error {
19922
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;
19923
19975
  function createClient(apiUrl, token) {
19924
19976
  async function call(method, p, body) {
19925
- const headers = { "user-agent": "insightcrm-cli/0.1" };
19977
+ const headers = { "user-agent": `insightcrm-cli/${package_default.version}` };
19926
19978
  if (token) headers.authorization = `Bearer ${token}`;
19927
19979
  let payload;
19928
19980
  if (body !== void 0) {
@@ -20055,56 +20107,61 @@ function defaultLang(env = process.env) {
20055
20107
  return v.startsWith("zh") ? "zh" : "en";
20056
20108
  }
20057
20109
 
20058
- // package.json
20059
- var package_default = {
20060
- name: "insightcrm",
20061
- version: "0.1.2",
20062
- 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.",
20063
- license: "MIT",
20064
- type: "module",
20065
- bin: {
20066
- insightcrm: "dist/cli.js",
20067
- crm: "dist/cli.js"
20068
- },
20069
- files: [
20070
- "dist",
20071
- "SKILL.md",
20072
- "README.md"
20073
- ],
20074
- engines: {
20075
- node: ">=20"
20076
- },
20077
- scripts: {
20078
- dev: "tsx src/cli.ts",
20079
- build: "tsup",
20080
- typecheck: "tsc -p .",
20081
- prepack: "tsup"
20082
- },
20083
- devDependencies: {
20084
- "@insightcrm/shared": "workspace:*"
20085
- },
20086
- dependencies: {
20087
- commander: "^15.0.0"
20088
- },
20089
- keywords: [
20090
- "crm",
20091
- "cli",
20092
- "agent",
20093
- "mcp",
20094
- "claude",
20095
- "customer",
20096
- "insightcrm"
20097
- ],
20098
- repository: {
20099
- type: "git",
20100
- url: "git+https://github.com/shadowcz007/InsightCRM.git",
20101
- directory: "packages/cli"
20102
- },
20103
- homepage: "https://github.com/shadowcz007/InsightCRM#readme",
20104
- bugs: {
20105
- 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;
20106
20145
  }
20107
- };
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
+ }
20108
20165
 
20109
20166
  // src/cli.ts
20110
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(
@@ -20353,6 +20410,23 @@ program.command("skill").description("Print the agent instructions (SKILL.md) fo
20353
20410
  if (g().json) out("", { path: src, content: text });
20354
20411
  else process.stdout.write(text);
20355
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 });
20418
+ return;
20419
+ }
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 });
20429
+ });
20356
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) => {
20357
20431
  const entities = (o.entity ? [o.entity] : [...ENTITIES]).map((e) => ({ entity: e, ...SCHEMA[e] }));
20358
20432
  const human = entities.map((e) => `# ${e.entity}: ${e.description}
@@ -20442,6 +20516,21 @@ rec.command("rm").argument("<id>").option("-y, --yes").action(async (id, o) => {
20442
20516
  out(`Deleted ${id}`, { ok: true, id });
20443
20517
  });
20444
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
+ );
20445
20534
  var langOption = () => new Option("--lang <lang>", "language of the built-in templates (default: CRM_LANG, then the system language)").choices([...PROMPT_LANGS]);
20446
20535
  var langOf = (o) => o.lang ?? defaultLang();
20447
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.2",
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",