tyc-cli 0.3.9 → 0.3.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/CHANGELOG.md +2 -0
- package/README.md +2 -0
- package/dist/commands/output.js +4 -3
- package/dist/coreClient.js +3 -2
- package/dist/utils/history.js +3 -2
- package/dist/utils/identifierDetails.js +40 -0
- package/dist/utils/jsonToMarkdown.js +12 -7
- package/dist/utils/losslessJson.js +114 -0
- package/dist/utils/personnelChanges.js +3 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
### 修复
|
|
8
8
|
|
|
9
|
+
- 全部上游标识透传:CLI 无损解析 Core JSON,pretty/compact/Markdown 保留大整数数字、前导零字符串和显式空值;Markdown 增加与来源路径绑定的标识明细。服务端同步撤销 ID/UUID/记录/图边标识的隐藏规则;CLI 版本号已升至 0.3.10,尚未发布。
|
|
10
|
+
|
|
9
11
|
- E06 / E08:Markdown 完整呈现嵌套列表、对象和收到的变更原文,不再按字符数静默省略;用户显式指定的输出截断选项继续生效,上游原文已有的省略号不补造。
|
|
10
12
|
- 同步展示服务端的分页、日期与商标字段口径、风险状态和历史查询引导;人员变更使用服务端 `_parsed` 结果,股东来源及逐笔出资保留,历史列表 Markdown 按当前页日期排序且不改 JSON 顺序。
|
|
11
13
|
- E03:请求失败统一交由 CLI 入口输出并设置退出码,允许网络和标准流自然收尾;402 仍返回退出码 `1`,不触发额度重试。帮助、版本及参数错误也保留各自退出码,避免强制退出或重复输出。
|
package/README.md
CHANGED
|
@@ -149,6 +149,8 @@ tyc executive personnel-dishonest "..." --humanName "张三"
|
|
|
149
149
|
|
|
150
150
|
`--md` 从 Shared Core JSON 在本地渲染,布局可能与 MCP 的服务端 Markdown 不同。嵌套对象、数组完整保留,不再执行旧的 80 字符省略或 `key=…` 折叠;输出限制统一由下述显式选项控制。`_pagination`、日期/字段口径、历史查询指引和风险状态直接使用服务端元数据,不重新推导。变更记录只对 Markdown 的当前页按变更日期倒序展示,JSON 顺序不变;人员解析结果来自服务端 `_parsed`。
|
|
151
151
|
|
|
152
|
+
上游标识默认保留原键、值、类型。JSON 输出无损保留大整数数字字面量和前导零字符串;`--md` 附“上游标识明细”说明来源路径、所属记录及 JSON 原值,空串/null/零/空集合不混同。边 ID 和端点、业务记录主键、UUID 等也保留;同值标识不自动认定为同一主体。服务端具体契约与历史规则状态见 [API 通用约定](../../docs/t1_1/apis/README.md)。
|
|
153
|
+
|
|
152
154
|
#### 输出截断 / 落盘(与上述输出格式正交,可叠加任意子命令)
|
|
153
155
|
|
|
154
156
|
| 选项 | 默认值 | 说明 |
|
package/dist/commands/output.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseLosslessJSON, stringifyLosslessJSON } from "../utils/losslessJson.js";
|
|
1
2
|
import { jsonToMarkdown } from "../utils/jsonToMarkdown.js";
|
|
2
3
|
import { applyTruncation, resolveOptionalInt, TRUNCATE_DEFAULTS, } from "../utils/truncate.js";
|
|
3
4
|
export function emitToolResult(result, opts, toolName) {
|
|
@@ -11,7 +12,7 @@ export function emitToolResult(result, opts, toolName) {
|
|
|
11
12
|
}
|
|
12
13
|
let payload;
|
|
13
14
|
try {
|
|
14
|
-
payload =
|
|
15
|
+
payload = parseLosslessJSON(text);
|
|
15
16
|
}
|
|
16
17
|
catch {
|
|
17
18
|
emitWithTruncation(text.endsWith("\n") ? text.slice(0, -1) : text, opts);
|
|
@@ -22,10 +23,10 @@ export function emitToolResult(result, opts, toolName) {
|
|
|
22
23
|
rendered = jsonToMarkdown(payload, toolName);
|
|
23
24
|
}
|
|
24
25
|
else if (opts.compact) {
|
|
25
|
-
rendered =
|
|
26
|
+
rendered = stringifyLosslessJSON(payload);
|
|
26
27
|
}
|
|
27
28
|
else {
|
|
28
|
-
rendered =
|
|
29
|
+
rendered = stringifyLosslessJSON(payload, null, 2);
|
|
29
30
|
}
|
|
30
31
|
emitWithTruncation(rendered, opts);
|
|
31
32
|
}
|
package/dist/coreClient.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseLosslessJSON, stringifyLosslessJSON } from "./utils/losslessJson.js";
|
|
1
2
|
function maskToken(v) {
|
|
2
3
|
if (!v)
|
|
3
4
|
return "";
|
|
@@ -104,7 +105,7 @@ export async function callCoreTool(cfg, name, args, opts) {
|
|
|
104
105
|
}
|
|
105
106
|
let parsed;
|
|
106
107
|
try {
|
|
107
|
-
parsed =
|
|
108
|
+
parsed = parseLosslessJSON(text);
|
|
108
109
|
}
|
|
109
110
|
catch {
|
|
110
111
|
throw new Error(`core 响应不是 JSON:HTTP ${resp.status}\n${text.slice(0, 500)}`);
|
|
@@ -114,7 +115,7 @@ export async function callCoreTool(cfg, name, args, opts) {
|
|
|
114
115
|
throw new Error(`core/tools/call HTTP ${resp.status}\n${desc}`);
|
|
115
116
|
}
|
|
116
117
|
const content = parsed.content;
|
|
117
|
-
const contentText = typeof content === "string" ? content :
|
|
118
|
+
const contentText = typeof content === "string" ? content : stringifyLosslessJSON(content ?? {});
|
|
118
119
|
return {
|
|
119
120
|
content: [{ type: "text", text: contentText }],
|
|
120
121
|
};
|
package/dist/utils/history.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
import { stringifyLosslessJSON, LosslessNumber } from "./losslessJson.js";
|
|
2
|
+
const object = (v) => v !== null && typeof v === "object" && !Array.isArray(v) && !(v instanceof LosslessNumber);
|
|
3
|
+
const text = (v) => typeof v === "string" ? v : stringifyLosslessJSON(v) ?? "null";
|
|
3
4
|
const cell = (v) => text(v).replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
|
|
4
5
|
export function renderHistoryGuide(value) {
|
|
5
6
|
if (!object(value))
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { LosslessNumber, stringifyLosslessJSON } from "./losslessJson.js";
|
|
2
|
+
const identifier = (key) => {
|
|
3
|
+
if (["paid", "unpaid", "valid", "invalid", "solid", "fluid", "rapid", "grid"].includes(key.toLowerCase()))
|
|
4
|
+
return false;
|
|
5
|
+
return /(?:id|ids|uuid|uuids|guid|guids)$/i.test(key) || /^(?:startNode|endNode|idsFrom|idsTo|idsNew)$/i.test(key);
|
|
6
|
+
};
|
|
7
|
+
const cell = (text) => text.replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
|
|
8
|
+
/** Full identifiers, tied to their final source/record paths, including nulls.
|
|
9
|
+
* Rendering happens after Core's data-rights filtering and before truncation.
|
|
10
|
+
*/
|
|
11
|
+
export function identifierDetails(value) {
|
|
12
|
+
const rows = [];
|
|
13
|
+
const visit = (value, path, record) => {
|
|
14
|
+
if (value === null || typeof value !== "object" || value instanceof LosslessNumber)
|
|
15
|
+
return;
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
value.forEach((item, i) => visit(item, `${path}[${i}]`, record));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const object = value;
|
|
21
|
+
for (const key of ["name", "companyName", "investorName", "title"]) {
|
|
22
|
+
if (typeof object[key] === "string" && object[key]) {
|
|
23
|
+
record = object[key];
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const key of Object.keys(object).sort()) {
|
|
28
|
+
if (["_summary", "_empty", "_warnings", "_tip", "_truncated", "_pagination", "_riskOverview", "_dateSemantics", "_fieldSemantics", "_historyGuide", "_source", "_parsed", "_field_meanings"].includes(key))
|
|
29
|
+
continue;
|
|
30
|
+
const field = path ? path + "." + key : key;
|
|
31
|
+
if (identifier(key) || ((key === "source" || key === "target") && "source" in object && "target" in object)) {
|
|
32
|
+
rows.push(`| ${cell(field)} | ${cell(record)} | ${cell(stringifyLosslessJSON(object[key]))} |`);
|
|
33
|
+
}
|
|
34
|
+
else
|
|
35
|
+
visit(object[key], field, record);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
visit(value, "", "");
|
|
39
|
+
return rows.length ? "\n## 上游标识明细\n\n> 原字段和值按来源路径保留;记录主键、局部节点或同值 ID 不自动表示同一主体。空值不能作为关联键。\n\n| 来源路径(原键) | 所属记录 | 原值(JSON) |\n|---|---|---|\n" + rows.join("\n") + "\n" : "";
|
|
40
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { identifierDetails } from "./identifierDetails.js";
|
|
2
|
+
import { stringifyLosslessJSON, LosslessNumber } from "./losslessJson.js";
|
|
1
3
|
/**
|
|
2
4
|
* JSON → Markdown 输出格式化
|
|
3
5
|
*
|
|
@@ -11,7 +13,7 @@ import { renderChangeRecords, splitChangeRecords } from "./personnelChanges.js";
|
|
|
11
13
|
import { renderHistoryGuide, splitHistoricalPersonnel } from "./history.js";
|
|
12
14
|
const META_KEYS = new Set(["_summary", "_empty", "_warnings", "_tip", "_truncated", "_pagination", "_riskOverview", "_dateSemantics", "_fieldSemantics", "_historyGuide", "_source"]);
|
|
13
15
|
function isPlainObject(v) {
|
|
14
|
-
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
16
|
+
return v !== null && typeof v === "object" && !Array.isArray(v) && !(v instanceof LosslessNumber);
|
|
15
17
|
}
|
|
16
18
|
function formatPrimitive(v) {
|
|
17
19
|
if (v === null || v === undefined || v === "")
|
|
@@ -42,13 +44,13 @@ function formatArrayCell(arr) {
|
|
|
42
44
|
return arr.map(formatPrimitive).join(", ");
|
|
43
45
|
}
|
|
44
46
|
// 对象数组:紧凑 JSON
|
|
45
|
-
return
|
|
47
|
+
return stringifyLosslessJSON(arr);
|
|
46
48
|
}
|
|
47
49
|
function formatObjectInline(obj) {
|
|
48
|
-
return
|
|
50
|
+
return stringifyLosslessJSON(obj);
|
|
49
51
|
}
|
|
50
52
|
function renderJSONBlock(value) {
|
|
51
|
-
const text =
|
|
53
|
+
const text = stringifyLosslessJSON(value, null, 2);
|
|
52
54
|
const longestFence = Math.max(0, ...(text.match(/`+/g) || []).map((s) => s.length));
|
|
53
55
|
const fence = "`".repeat(Math.max(3, longestFence + 1));
|
|
54
56
|
return `${fence}json\n${text}\n${fence}\n`;
|
|
@@ -266,7 +268,7 @@ function renderNestedObjects(obj) {
|
|
|
266
268
|
* @param value 工具返回的 JSON(已 parse 为对象)
|
|
267
269
|
* @param toolName 工具名(可选,用作标题)
|
|
268
270
|
*/
|
|
269
|
-
|
|
271
|
+
function renderMarkdownValue(value, toolName) {
|
|
270
272
|
if (value === null || value === undefined) {
|
|
271
273
|
return "_(空)_\n";
|
|
272
274
|
}
|
|
@@ -278,12 +280,12 @@ export function jsonToMarkdown(value, toolName) {
|
|
|
278
280
|
const obj = value;
|
|
279
281
|
const historical = splitHistoricalPersonnel(obj, toolName);
|
|
280
282
|
if (historical)
|
|
281
|
-
return
|
|
283
|
+
return renderMarkdownValue(historical.rest, toolName) + "\n" + historical.markdown;
|
|
282
284
|
const changes = splitChangeRecords(obj, toolName);
|
|
283
285
|
if (changes) {
|
|
284
286
|
// The recursive call receives a copy without the extracted list. Keep raw
|
|
285
287
|
// code blocks verbatim: the generic newline compaction must not touch them.
|
|
286
|
-
return
|
|
288
|
+
return renderMarkdownValue(changes.rest, toolName) + "\n" + renderChangeRecords(changes.records, changes.title);
|
|
287
289
|
}
|
|
288
290
|
const parts = [];
|
|
289
291
|
// 标题
|
|
@@ -314,3 +316,6 @@ export function jsonToMarkdown(value, toolName) {
|
|
|
314
316
|
parts.push(nested);
|
|
315
317
|
return parts.join("\n").replace(/\n{3,}/g, "\n\n");
|
|
316
318
|
}
|
|
319
|
+
export function jsonToMarkdown(value, toolName) {
|
|
320
|
+
return renderMarkdownValue(value, toolName) + identifierDetails(value);
|
|
321
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** JSON numbers whose original token cannot survive native Number serialisation.
|
|
2
|
+
* Keep the token numeric in JSON; String(value) is exact in Markdown. Node 18+.
|
|
3
|
+
*/
|
|
4
|
+
export class LosslessNumber {
|
|
5
|
+
token;
|
|
6
|
+
constructor(token) {
|
|
7
|
+
this.token = token;
|
|
8
|
+
}
|
|
9
|
+
toString() { return this.token; }
|
|
10
|
+
}
|
|
11
|
+
export function parseLosslessJSON(text) {
|
|
12
|
+
let offset = 0;
|
|
13
|
+
const fail = () => { throw new SyntaxError(`Invalid JSON at ${offset}`); };
|
|
14
|
+
const whitespace = () => { while (/[\t\n\r ]/.test(text[offset] ?? "x"))
|
|
15
|
+
offset++; };
|
|
16
|
+
const string = () => {
|
|
17
|
+
const start = offset++;
|
|
18
|
+
while (offset < text.length) {
|
|
19
|
+
const ch = text[offset++];
|
|
20
|
+
if (ch === "\\")
|
|
21
|
+
offset++;
|
|
22
|
+
else if (ch === '"')
|
|
23
|
+
return JSON.parse(text.slice(start, offset));
|
|
24
|
+
}
|
|
25
|
+
return fail();
|
|
26
|
+
};
|
|
27
|
+
const value = () => {
|
|
28
|
+
whitespace();
|
|
29
|
+
const ch = text[offset];
|
|
30
|
+
if (ch === '"')
|
|
31
|
+
return string();
|
|
32
|
+
if (ch === "{" || ch === "[") {
|
|
33
|
+
const object = ch === "{";
|
|
34
|
+
offset++;
|
|
35
|
+
const result = object ? {} : [];
|
|
36
|
+
const end = object ? "}" : "]";
|
|
37
|
+
whitespace();
|
|
38
|
+
if (text[offset] === end) {
|
|
39
|
+
offset++;
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
while (offset < text.length) {
|
|
43
|
+
whitespace();
|
|
44
|
+
let key = "";
|
|
45
|
+
if (object) {
|
|
46
|
+
if (text[offset] !== '"')
|
|
47
|
+
fail();
|
|
48
|
+
key = string();
|
|
49
|
+
whitespace();
|
|
50
|
+
if (text[offset++] !== ":")
|
|
51
|
+
fail();
|
|
52
|
+
}
|
|
53
|
+
const item = value();
|
|
54
|
+
if (object)
|
|
55
|
+
Object.defineProperty(result, key, { value: item, enumerable: true, writable: true, configurable: true });
|
|
56
|
+
else
|
|
57
|
+
result.push(item);
|
|
58
|
+
whitespace();
|
|
59
|
+
if (text[offset] === end) {
|
|
60
|
+
offset++;
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
if (text[offset++] !== ",")
|
|
64
|
+
fail();
|
|
65
|
+
}
|
|
66
|
+
return fail();
|
|
67
|
+
}
|
|
68
|
+
for (const [token, item] of [["true", true], ["false", false], ["null", null]]) {
|
|
69
|
+
if (text.startsWith(token, offset)) {
|
|
70
|
+
offset += token.length;
|
|
71
|
+
return item;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const match = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(text.slice(offset));
|
|
75
|
+
if (!match)
|
|
76
|
+
return fail();
|
|
77
|
+
const token = match[0];
|
|
78
|
+
offset += token.length;
|
|
79
|
+
const number = Number(token);
|
|
80
|
+
return JSON.stringify(number) === token && (Number.isSafeInteger(number) || !Number.isInteger(number))
|
|
81
|
+
? number : new LosslessNumber(token);
|
|
82
|
+
};
|
|
83
|
+
const result = value();
|
|
84
|
+
whitespace();
|
|
85
|
+
if (offset !== text.length)
|
|
86
|
+
fail();
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
export function stringifyLosslessJSON(value, _replacer = null, space = 0) {
|
|
90
|
+
const indent = " ".repeat(Math.min(10, Math.max(0, space)));
|
|
91
|
+
const ancestors = new Set();
|
|
92
|
+
const encode = (item, depth) => {
|
|
93
|
+
if (item instanceof LosslessNumber)
|
|
94
|
+
return item.token;
|
|
95
|
+
if (item === null || typeof item !== "object")
|
|
96
|
+
return JSON.stringify(item);
|
|
97
|
+
if (ancestors.has(item))
|
|
98
|
+
throw new TypeError("Circular JSON value");
|
|
99
|
+
ancestors.add(item);
|
|
100
|
+
const array = Array.isArray(item);
|
|
101
|
+
const entries = array ? item.map((v) => encode(v, depth + 1) ?? "null")
|
|
102
|
+
: Object.entries(item).flatMap(([key, v]) => {
|
|
103
|
+
const text = encode(v, depth + 1);
|
|
104
|
+
return text === undefined ? [] : [JSON.stringify(key) + (indent ? ": " : ":") + text];
|
|
105
|
+
});
|
|
106
|
+
ancestors.delete(item);
|
|
107
|
+
const [open, close] = array ? ["[", "]"] : ["{", "}"];
|
|
108
|
+
if (!entries.length)
|
|
109
|
+
return open + close;
|
|
110
|
+
return indent ? open + "\n" + entries.map((entry) => indent.repeat(depth + 1) + entry).join(",\n")
|
|
111
|
+
+ "\n" + indent.repeat(depth) + close : open + entries.join(",") + close;
|
|
112
|
+
};
|
|
113
|
+
return encode(value, 0);
|
|
114
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { stringifyLosslessJSON, LosslessNumber } from "./losslessJson.js";
|
|
1
2
|
// Presentation only: all personnel extraction and statuses come from Shared Core.
|
|
2
3
|
import { changeRecordsForDisplay } from "./history.js";
|
|
3
|
-
const object = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
4
|
-
const text = (v) => typeof v === "string" ? v :
|
|
4
|
+
const object = (v) => v !== null && typeof v === "object" && !Array.isArray(v) && !(v instanceof LosslessNumber);
|
|
5
|
+
const text = (v) => typeof v === "string" ? v : stringifyLosslessJSON(v) ?? "null";
|
|
5
6
|
const cell = (v) => (v === undefined || v === "" ? "-" : text(v)).replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
|
|
6
7
|
function block(value) {
|
|
7
8
|
const raw = text(value);
|