tyc-cli 0.3.2 → 0.3.4

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.
@@ -12,7 +12,7 @@ const LAYER_SPECS = [
12
12
  title: "Overview · 概要层",
13
13
  summary: "**6 个 facet 队长,每 facet 1 个总览**:company-base / 风险 / 知产 / 经营信用 / 历史 / 董监高 各 1 个 L1 工具,单次调用聚合该 facet 多子维度。",
14
14
  trigger: '"这家公司整体怎么样 / 风险如何 / 知产实力 / 经营状况 / 历史变更 / 这个人是谁"',
15
- contract: "Agent 按 facet 选 1 个 L1 调用即得 _summary + drill_down 线索;不需要你预先在 facet 内挑子维度。",
15
+ contract: "Agent 按 facet 选 1 个 L1 调用即得 _summary;下一跳可用 tyc L2 list 或 MCP get_company_capabilities 确认工具。",
16
16
  },
17
17
  {
18
18
  layer: "L2",
@@ -63,7 +63,7 @@ function registerLayers(program) {
63
63
  recommended_call_order: [
64
64
  `0. Anchor at L0 — feed the user's raw company name into the ${getLayerCount("L0")} L0 tool (search_companies); lock onto a USCC + official name`,
65
65
  `1. Ascend to L1 — pick ONE of the ${getLayerCount("L1")} overview tools with the anchored USCC`,
66
- "2. Read _summary + drill_down hints from the response",
66
+ "2. Read _summary and pick the next dimension via tyc layer lists or MCP get_company_capabilities",
67
67
  `3. Drill to L2 for a specific dimension (items + totals; ${getLayerCount("L2")} tools); when unsure which L2, default to the facet's L2 优先 (★, see l2_priority)`,
68
68
  `4. Reach L3 for id-based detail, search_*, or vertical SKILL tools (${getLayerCount("L3")} tools)`,
69
69
  ],
@@ -130,7 +130,7 @@ function renderLayersText() {
130
130
  lines.push("Rationale: LLM tool-selection accuracy collapses beyond 30 tools.");
131
131
  lines.push(` tyc carves L0 into a single entity-resolution tool, so the default LLM`);
132
132
  lines.push(` surface is L0 + L1 = ${defaultSurface} tools (≤ 15-tool exposure limit);`);
133
- lines.push(" L2/L3 are discovered on demand via _summary / drill_down_tools.");
133
+ lines.push(" L2/L3 are discovered on demand via _summary, layer lists, or get_company_capabilities.");
134
134
  lines.push("");
135
135
  for (const s of LAYER_SPECS) {
136
136
  const n = getLayerCount(s.layer);
@@ -153,7 +153,7 @@ function renderLayersText() {
153
153
  lines.push("Recommended call order for agents:");
154
154
  lines.push(` 0. Anchor at L0 — feed the user's raw company name into the ${getLayerCount("L0")} L0 tool (search_companies)`);
155
155
  lines.push(` 1. Ascend to L1 — one of the ${getLayerCount("L1")} overview tools, with the anchored USCC`);
156
- lines.push(" 2. Read _summary + drill_down hints in the response");
156
+ lines.push(" 2. Read _summary, then choose the next dimension via layer lists or get_company_capabilities");
157
157
  lines.push(` 3. Drill to L2 for a specific dimension (${getLayerCount("L2")} tools); unsure which L2 → default to that facet's L2★ 优先 (see L2 block above)`);
158
158
  lines.push(` 4. Reach L3 for id-based detail / search_* / vertical SKILL (${getLayerCount("L3")} tools)`);
159
159
  return lines.join("\n");
@@ -188,7 +188,7 @@ function renderLayersMarkdown() {
188
188
  lines.push("");
189
189
  lines.push(`0. Anchor at L0 — feed the user's raw company name into the ${getLayerCount("L0")} L0 tool (\`search_companies\`); lock onto a USCC + official name.`);
190
190
  lines.push(`1. Ascend to L1 — pick ONE of the ${getLayerCount("L1")} overview tools with the anchored USCC.`);
191
- lines.push("2. Read `_summary` + `drill_down` hints in the response.");
191
+ lines.push("2. Read `_summary`, then choose the next dimension via layer lists or MCP `get_company_capabilities`.");
192
192
  lines.push(`3. Drill to L2 for a specific dimension (items + totals; ${getLayerCount("L2")} tools). Unsure which L2 → default to that facet's L2★ 优先 (table above).`);
193
193
  lines.push(`4. Reach L3 for id-based detail, \`search_*\`, or vertical SKILL tools (${getLayerCount("L3")} tools).`);
194
194
  lines.push("");
package/dist/config.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // { "url": "https://mcp.tianyancha.com/v1",
5
5
  // "headers": { "Authorization": "xxxx" } }
6
6
  //
7
- // 默认端点指向 tyc 官方生产 MCP;本地调试通过
7
+ // 默认端点指向天眼查公网 MCP Server;连接本地或私有环境可通过
8
8
  // tyc init --url http://localhost:8080/v1 或 TYC_MCP_ENDPOINT 环境变量覆盖。
9
9
  import { readFileSync, writeFileSync, mkdirSync, existsSync, chmodSync } from "node:fs";
10
10
  import { join } from "node:path";
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import { registerInitCommand } from "./commands/init.js";
4
4
  import { registerCategoryCommands } from "./commands/category.js";
5
5
  import { registerLayerCommands } from "./commands/layers.js";
6
6
  import { getCategories, getLayerCount, getPriorityTools, getTotalCount, } from "./registry.js";
7
+ import { VERSION } from "./version.js";
7
8
  // 顶层 help:把"最懂 AI 的 CLI"落在 4 层架构 + 调用顺序 + 可发现性上。
8
9
  // Agent 看 tyc --help 时应立刻读懂"先 L0 锚定企业,再 L1 概览,再 L2 下钻,最后 L3 详情"这条主线。
9
10
  const helpText = `
@@ -15,7 +16,7 @@ ARCHITECTURE — Layered Tool Discovery for LLM Agents
15
16
  entity-resolution layer:
16
17
 
17
18
  ┌─ L0 Resolve ${pad(getLayerCount("L0"), 3)} tool entity resolution · 简称/曾用名/模糊名 → 精确企业
18
- ├─ L1 Overview ${pad(getLayerCount("L1"), 3)} tools one captain per facet · returns _summary + drill_down
19
+ ├─ L1 Overview ${pad(getLayerCount("L1"), 3)} tools one captain per facet · returns _summary for routing
19
20
  ├─ L2 Drill-down ${pad(getLayerCount("L2"), 3)} tools one-hop into a specific data dimension (★ = L2 优先, see below)
20
21
  └─ L3 Specialized ${pad(getLayerCount("L3"), 3)} tools id-based detail · search_* · vertical SKILLs
21
22
 
@@ -25,8 +26,9 @@ ARCHITECTURE — Layered Tool Discovery for LLM Agents
25
26
  指代) into \`search_companies\`; lock onto one entity
26
27
  with a USCC + official name before anything else.
27
28
  1. Ascend to L1. Pick ONE of the ${getLayerCount("L1")} overview tools with the
28
- anchored USCC. Read the response's _summary + drill_down.
29
- 2. Descend to L2. Follow hints to a specific dimension
29
+ anchored USCC. Read _summary, then use layer lists or
30
+ MCP get_company_capabilities for the next tool.
31
+ 2. Descend to L2. Pick a specific dimension
30
32
  (shareholders / litigation / patents / annual reports …).
31
33
  If unsure which L2, default to that facet's L2★ 优先 (below).
32
34
  3. Land on L3. When L2 returns a list item with an \`id\`, a \`search_*\`
@@ -114,7 +116,7 @@ function renderPriorityLines() {
114
116
  const program = new Command()
115
117
  .name("tyc")
116
118
  .description(`Tianyan AI CLI — ${getTotalCount()} commercial-data tools · L0=${getLayerCount("L0")} L1=${getLayerCount("L1")} L2=${getLayerCount("L2")} L3=${getLayerCount("L3")} · the AI-native gateway (pair with the TA MCP Server)`)
117
- .version("0.4.0")
119
+ .version(VERSION)
118
120
  .option("--pretty", "缩进 JSON 输出(默认行为,flag 保留以保持向后兼容)")
119
121
  .option("--md", "Markdown 表格化输出(适合人类阅读 / Agent 上屏)")
120
122
  .option("--compact", "紧凑单行 JSON(管道 / jq 场景;为旧默认行为)")
package/dist/mcpClient.js CHANGED
@@ -10,6 +10,7 @@
10
10
  // - 不做业务聚合/时间戳格式化(由 MCP Server 完成)
11
11
  // - 不做 Authorization 解析/验签
12
12
  import { clearSession, isSessionFresh, loadSession, saveSession } from "./session.js";
13
+ import { VERSION } from "./version.js";
13
14
  const PROTOCOL_VERSION = "2024-11-05";
14
15
  function maskToken(v) {
15
16
  if (!v)
@@ -28,31 +29,19 @@ function logVerbose(cfg, title, extra) {
28
29
  if (extra)
29
30
  console.error(extra);
30
31
  }
31
- /** 解析 MCP Streamable HTTP 响应:纯 JSON 或 SSE(`event:` + `data:` 行)。 */
32
+ /** 解析 MCP Streamable HTTP 响应——server 端实测固定回 application/json 单包,
33
+ * 无论 client Accept 头声明什么。SSE 路径不存在,所以只解析 JSON。 */
32
34
  function parseJsonRpc(raw) {
33
35
  const trimmed = raw.trim();
34
- if (trimmed.startsWith("{")) {
35
- return JSON.parse(trimmed);
36
+ if (!trimmed.startsWith("{")) {
37
+ throw new Error(`Unparseable MCP response: ${trimmed.slice(0, 200)}`);
36
38
  }
37
- // SSE 解析:抓第一个解析成功的 data 行
38
- for (const line of trimmed.split(/\r?\n/)) {
39
- const s = line.trim();
40
- if (!s.startsWith("data:"))
41
- continue;
42
- const body = s.slice(5).trim();
43
- if (!body.startsWith("{"))
44
- continue;
45
- try {
46
- return JSON.parse(body);
47
- }
48
- catch { /* try next */ }
49
- }
50
- throw new Error(`Unparseable MCP response: ${trimmed.slice(0, 200)}`);
39
+ return JSON.parse(trimmed);
51
40
  }
52
41
  async function httpPost(url, headers, body, verbose) {
53
42
  const h = {
54
43
  "Content-Type": "application/json",
55
- "Accept": "application/json, text/event-stream",
44
+ "Accept": "application/json",
56
45
  ...headers,
57
46
  };
58
47
  if (verbose) {
@@ -86,7 +75,7 @@ async function doInitialize(cfg, verbose) {
86
75
  params: {
87
76
  protocolVersion: PROTOCOL_VERSION,
88
77
  capabilities: {},
89
- clientInfo: { name: "tyc-cli", version: "0.2.0" },
78
+ clientInfo: { name: "tyc-cli", version: VERSION },
90
79
  },
91
80
  }, verbose);
92
81
  if (status < 200 || status >= 300) {
@@ -0,0 +1,22 @@
1
+ // CLI 版本号单一来源:从 package.json 读取
2
+ //
3
+ // 历史上 index.ts 与 mcpClient.ts 各自硬编码版本字符串,多处漂移。
4
+ // 收敛到 package.json 一处后,bump 版本只需 npm version <x>。
5
+ // 运行时 fs 读:dev (`tsx src/version.ts`) 与 dist (`dist/version.js`) 与
6
+ // package.json 都同级 (cli/t1_1/{src,dist} ↔ cli/t1_1/package.json),
7
+ // resolve(__dirname, "..", "package.json") 在两种场景下都指向同一文件。
8
+ import { readFileSync } from "node:fs";
9
+ import { resolve, dirname } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ const __dirname = dirname(fileURLToPath(import.meta.url));
12
+ const PKG_PATH = resolve(__dirname, "..", "package.json");
13
+ function readVersion() {
14
+ try {
15
+ const raw = readFileSync(PKG_PATH, "utf-8");
16
+ return JSON.parse(raw).version || "0.0.0";
17
+ }
18
+ catch {
19
+ return "0.0.0";
20
+ }
21
+ }
22
+ export const VERSION = readVersion();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tyc-cli",
3
- "version": "0.3.2",
4
- "description": "天眼查 MCP CLI — 163 个业务语义聚合工具 · 命令行直达企业数据 · 通过 MCP Server 调用",
3
+ "version": "0.3.4",
4
+ "description": "天眼查 MCP CLI — 162 个业务语义聚合工具 · 命令行直达企业数据 · 通过 MCP Server 调用",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
7
7
  "tyc": "./dist/index.js"