agentdock-cli 1.2.0 → 1.4.0

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.
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ /**
3
+ * 结构化配置格式的统一解析 / 序列化(v1.4)。
4
+ *
5
+ * 语义化迁移需要同时处理 JSON、JSONC、YAML、TOML 四种格式:
6
+ * - `scan` 按工具声明的格式读取 MCP / settings;
7
+ * - `export` 脱敏后按原格式重新序列化;
8
+ * - `install` 合并到目标文件时也按目标扩展名保留格式。
9
+ *
10
+ * JSONC 只支持读取(写回为标准 JSON),避免发明注释保留逻辑。
11
+ */
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.stripJsonc = stripJsonc;
17
+ exports.kindFromPath = kindFromPath;
18
+ exports.parseStructured = parseStructured;
19
+ exports.stringifyStructured = stringifyStructured;
20
+ exports.parseConfigObjectSafe = parseConfigObjectSafe;
21
+ const smol_toml_1 = require("smol-toml");
22
+ const yaml_1 = __importDefault(require("yaml"));
23
+ /** 去掉 JSONC 注释与尾随逗号,且不破坏字符串内容。 */
24
+ function stripJsonc(text) {
25
+ let out = '';
26
+ let inString = false;
27
+ let escaped = false;
28
+ let lineComment = false;
29
+ let blockComment = false;
30
+ for (let index = 0; index < text.length; index += 1) {
31
+ const char = text[index];
32
+ const next = text[index + 1];
33
+ if (lineComment) {
34
+ if (char === '\n') {
35
+ lineComment = false;
36
+ out += char;
37
+ }
38
+ continue;
39
+ }
40
+ if (blockComment) {
41
+ if (char === '*' && next === '/') {
42
+ blockComment = false;
43
+ index += 1;
44
+ }
45
+ continue;
46
+ }
47
+ if (inString) {
48
+ out += char;
49
+ if (escaped) {
50
+ escaped = false;
51
+ }
52
+ else if (char === '\\') {
53
+ escaped = true;
54
+ }
55
+ else if (char === '"') {
56
+ inString = false;
57
+ }
58
+ continue;
59
+ }
60
+ if (char === '"') {
61
+ inString = true;
62
+ out += char;
63
+ continue;
64
+ }
65
+ if (char === '/' && next === '/') {
66
+ lineComment = true;
67
+ index += 1;
68
+ continue;
69
+ }
70
+ if (char === '/' && next === '*') {
71
+ blockComment = true;
72
+ index += 1;
73
+ continue;
74
+ }
75
+ out += char;
76
+ }
77
+ // 去尾随逗号(同样跳过字符串)
78
+ let cleaned = '';
79
+ inString = false;
80
+ escaped = false;
81
+ for (let index = 0; index < out.length; index += 1) {
82
+ const char = out[index];
83
+ if (inString) {
84
+ cleaned += char;
85
+ if (escaped) {
86
+ escaped = false;
87
+ }
88
+ else if (char === '\\') {
89
+ escaped = true;
90
+ }
91
+ else if (char === '"') {
92
+ inString = false;
93
+ }
94
+ continue;
95
+ }
96
+ if (char === '"') {
97
+ inString = true;
98
+ cleaned += char;
99
+ continue;
100
+ }
101
+ if (char === ',') {
102
+ let lookahead = index + 1;
103
+ while (lookahead < out.length && /\s/.test(out[lookahead])) {
104
+ lookahead += 1;
105
+ }
106
+ if (out[lookahead] === '}' || out[lookahead] === ']') {
107
+ continue;
108
+ }
109
+ }
110
+ cleaned += char;
111
+ }
112
+ return cleaned;
113
+ }
114
+ /** 按文件扩展名推断配置格式;未知扩展名视为纯文本。 */
115
+ function kindFromPath(filePath) {
116
+ const lower = filePath.toLowerCase();
117
+ if (lower.endsWith('.jsonc'))
118
+ return 'jsonc';
119
+ if (lower.endsWith('.json'))
120
+ return 'json';
121
+ if (lower.endsWith('.toml'))
122
+ return 'toml';
123
+ if (lower.endsWith('.yml') || lower.endsWith('.yaml'))
124
+ return 'yaml';
125
+ return 'text';
126
+ }
127
+ /** 按格式解析文本;解析失败时抛出原始错误,由调用方决定如何处理。 */
128
+ function parseStructured(kind, text) {
129
+ switch (kind) {
130
+ case 'json':
131
+ return JSON.parse(text);
132
+ case 'jsonc':
133
+ return JSON.parse(stripJsonc(text));
134
+ case 'toml':
135
+ return (0, smol_toml_1.parse)(text);
136
+ case 'yaml':
137
+ return yaml_1.default.parse(text);
138
+ default:
139
+ throw new Error(`CONFIG_FORMAT_UNSUPPORTED: ${kind}`);
140
+ }
141
+ }
142
+ /** 按格式序列化;JSONC 统一写回标准 JSON(不保留注释)。 */
143
+ function stringifyStructured(kind, data) {
144
+ switch (kind) {
145
+ case 'toml':
146
+ return (0, smol_toml_1.stringify)(data);
147
+ case 'yaml':
148
+ return yaml_1.default.stringify(data);
149
+ case 'json':
150
+ case 'jsonc':
151
+ return `${JSON.stringify(data, null, 2)}\n`;
152
+ default:
153
+ throw new Error(`CONFIG_FORMAT_UNSUPPORTED: ${kind}`);
154
+ }
155
+ }
156
+ /** 解析失败返回 null(供快照 / 差异这类“尽力而为”场景使用)。 */
157
+ function parseConfigObjectSafe(relPath, text) {
158
+ const kind = kindFromPath(relPath);
159
+ if (kind === 'text') {
160
+ return null;
161
+ }
162
+ try {
163
+ return parseStructured(kind, text);
164
+ }
165
+ catch {
166
+ return null;
167
+ }
168
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agentdock-cli",
3
- "version": "1.2.0",
4
- "description": "Diagnose, migrate, and back up your AI coding assistant environment (Claude Code / Codex) — Chinese health reports, MCP servers, Skills, Agents, Plugins, Hooks, and memory, with secret isolation.",
3
+ "version": "1.4.0",
4
+ "description": "Diagnose, migrate, and back up your AI coding environment — Claude Code, Codex, Gemini CLI, TRAE, Cursor/Grok Build, Cline, Windsurf, Copilot, OpenCode and more — with config snapshots, restore, and secret isolation.",
5
5
  "keywords": [
6
6
  "claude-code",
7
7
  "codex",