agentdock-cli 1.2.0 → 1.4.1
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 +59 -2
- package/dist/package.json +2 -2
- package/dist/src/agents/registry.js +551 -0
- package/dist/src/agents/semantic.js +208 -0
- package/dist/src/cli.js +3 -0
- package/dist/src/commands/agents.js +84 -0
- package/dist/src/commands/diff.js +3 -1
- package/dist/src/commands/history.js +3 -1
- package/dist/src/commands/list.js +2 -1
- package/dist/src/commands/recover.js +10 -5
- package/dist/src/commands/snapshot.js +2 -1
- package/dist/src/commands/sync.js +5 -1
- package/dist/src/core/doctor.js +151 -50
- package/dist/src/core/installer.js +18 -15
- package/dist/src/core/list.js +6 -0
- package/dist/src/core/report.js +29 -8
- package/dist/src/core/scan-export.js +31 -30
- package/dist/src/core/scan.js +59 -34
- package/dist/src/core/snapshot-diff.js +2 -13
- package/dist/src/core/snapshot.js +14 -14
- package/dist/src/core/uninstall.js +12 -7
- package/dist/src/i18n/index.js +24 -8
- package/dist/src/scanners/semantic-scanner.js +272 -0
- package/dist/src/scanners/sensitive.js +35 -2
- package/dist/src/utils/config-format.js +168 -0
- package/package.json +2 -2
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.isSecretKey = isSecretKey;
|
|
13
13
|
exports.looksLikeSecret = looksLikeSecret;
|
|
14
|
+
exports.isSensitiveEntry = isSensitiveEntry;
|
|
14
15
|
exports.findSecretLeaks = findSecretLeaks;
|
|
15
16
|
exports.maskSecret = maskSecret;
|
|
16
17
|
exports.createSecretKeyRegistry = createSecretKeyRegistry;
|
|
@@ -42,6 +43,38 @@ function looksLikeSecret(value) {
|
|
|
42
43
|
}
|
|
43
44
|
return SECRET_VALUE_PATTERNS.some((pattern) => pattern.test(value));
|
|
44
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* 纯数字 / 布尔 / 空值:这类值来自配置项(如 `CLAUDE_CODE_MAX_CONTEXT_TOKENS=32000`),
|
|
48
|
+
* 即使键名包含 token 也不应视为机密。真实令牌几乎不会只由数字组成。
|
|
49
|
+
*/
|
|
50
|
+
function isNonSecretScalar(value) {
|
|
51
|
+
const trimmed = value.trim();
|
|
52
|
+
if (trimmed === '') {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
if (/^[+-]?\d+(?:\.\d+)?$/.test(trimmed)) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return /^(true|false|null|none|undefined)$/i.test(trimmed);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 判定一个键值对是否应按机密处理:
|
|
62
|
+
* 1. 值本身匹配已知令牌形状 → 是;
|
|
63
|
+
* 2. 键名像凭据,且值不是纯数字 / 布尔等配置标量 → 是;
|
|
64
|
+
* 3. 其余 → 否。
|
|
65
|
+
*/
|
|
66
|
+
function isSensitiveEntry(name, value) {
|
|
67
|
+
if (looksLikeSecret(value)) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (!isSecretKey(name)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (typeof value === 'string') {
|
|
74
|
+
return !isNonSecretScalar(value);
|
|
75
|
+
}
|
|
76
|
+
return typeof value === 'object' && value !== null;
|
|
77
|
+
}
|
|
45
78
|
/**
|
|
46
79
|
* Scan arbitrary text (e.g. a free-text skill/agent/memory file) for leaked
|
|
47
80
|
* secret tokens. Tokenizes on whitespace and common delimiters, then tests each
|
|
@@ -137,7 +170,7 @@ function collectSecrets(node, basePath, accumulator, seen = new WeakSet()) {
|
|
|
137
170
|
for (const [key, value] of Object.entries(node)) {
|
|
138
171
|
const childPath = `${basePath}.${key}`;
|
|
139
172
|
if (typeof value === 'string') {
|
|
140
|
-
if (
|
|
173
|
+
if (isSensitiveEntry(key, value)) {
|
|
141
174
|
accumulator.push({ key, value, jsonPath: childPath });
|
|
142
175
|
}
|
|
143
176
|
}
|
|
@@ -188,7 +221,7 @@ function maskSecretsInPlace(node, basePath, agent, secretsEnv, seen = new WeakSe
|
|
|
188
221
|
for (const [key, value] of Object.entries(node)) {
|
|
189
222
|
const childPath = `${basePath}.${key}`;
|
|
190
223
|
if (typeof value === 'string') {
|
|
191
|
-
if (
|
|
224
|
+
if (isSensitiveEntry(key, value)) {
|
|
192
225
|
const keyName = allocateSecretKey(registry, secretKeyName(agent, childPath), value);
|
|
193
226
|
node[key] =
|
|
194
227
|
secretsEnv && secretsEnv[keyName] !== undefined ? secretsEnv[keyName] : `{{${keyName}}}`;
|
|
@@ -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.
|
|
4
|
-
"description": "Diagnose, migrate, and back up your AI coding
|
|
3
|
+
"version": "1.4.1",
|
|
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",
|