agentdock-cli 1.0.0 → 1.0.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/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentdock-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
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.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
|
@@ -97,6 +97,16 @@ async function exportFromScan(options) {
|
|
|
97
97
|
await (0, fs_1.ensureDirectory)(payloadSourcesRoot);
|
|
98
98
|
const sources = [];
|
|
99
99
|
const freeTextSecrets = [];
|
|
100
|
+
// 一次导出共享同一占位符键分配表:同名 leaf 键同值共享、异值 _2/_3 消歧。
|
|
101
|
+
const secretKeyRegistry = (0, sensitive_1.createSecretKeyRegistry)();
|
|
102
|
+
const structuredSecrets = new Map();
|
|
103
|
+
const recordAllocated = (items) => {
|
|
104
|
+
for (const item of items) {
|
|
105
|
+
if (!structuredSecrets.has(item.key)) {
|
|
106
|
+
structuredSecrets.set(item.key, item);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
100
110
|
const toFrom = (diskRel) => `payload/sources/${diskRel}`;
|
|
101
111
|
/**
|
|
102
112
|
* Walk a copied directory and mask (or re-inject, when `env` is set)
|
|
@@ -158,7 +168,7 @@ async function exportFromScan(options) {
|
|
|
158
168
|
continue;
|
|
159
169
|
}
|
|
160
170
|
const cloned = JSON.parse(JSON.stringify(def));
|
|
161
|
-
(0, sensitive_1.maskSecretsInPlace)(cloned, `${claudeJsonPath}#mcpServers.${name}`, agent, env);
|
|
171
|
+
recordAllocated((0, sensitive_1.maskSecretsInPlace)(cloned, `${claudeJsonPath}#mcpServers.${name}`, agent, env, undefined, secretKeyRegistry));
|
|
162
172
|
merged.mcpServers[name] = cloned;
|
|
163
173
|
}
|
|
164
174
|
const diskRel = '.agentdock-mcp.json';
|
|
@@ -195,7 +205,7 @@ async function exportFromScan(options) {
|
|
|
195
205
|
// lands back as a valid .codex/config.toml.
|
|
196
206
|
try {
|
|
197
207
|
const parsed = (0, smol_toml_1.parse)(await promises_1.default.readFile(entry.path, 'utf8'));
|
|
198
|
-
(0, sensitive_1.maskSecretsInPlace)(parsed, entry.path, agent, env);
|
|
208
|
+
recordAllocated((0, sensitive_1.maskSecretsInPlace)(parsed, entry.path, agent, env, undefined, secretKeyRegistry));
|
|
199
209
|
await (0, fs_1.writeTextFile)(targetDisk, (0, smol_toml_1.stringify)(parsed));
|
|
200
210
|
}
|
|
201
211
|
catch (parseErr) {
|
|
@@ -209,7 +219,7 @@ async function exportFromScan(options) {
|
|
|
209
219
|
else {
|
|
210
220
|
try {
|
|
211
221
|
const obj = JSON.parse(await promises_1.default.readFile(entry.path, 'utf8'));
|
|
212
|
-
(0, sensitive_1.maskSecretsInPlace)(obj, entry.path, agent, env);
|
|
222
|
+
recordAllocated((0, sensitive_1.maskSecretsInPlace)(obj, entry.path, agent, env, undefined, secretKeyRegistry));
|
|
213
223
|
await (0, fs_1.writeTextFile)(targetDisk, JSON.stringify(obj, null, 2));
|
|
214
224
|
}
|
|
215
225
|
catch (parseErr) {
|
|
@@ -266,8 +276,16 @@ async function exportFromScan(options) {
|
|
|
266
276
|
// Free-text secrets discovered during export are folded into the resolved
|
|
267
277
|
// manifest + the package's own `.env.example` so `--env` re-injection
|
|
268
278
|
// and `doctor --package` stay consistent end-to-end.
|
|
279
|
+
//
|
|
280
|
+
// Structured keys come from the export-side allocation table (source of
|
|
281
|
+
// truth for the actual `{{...}}` placeholders written into the payload),
|
|
282
|
+
// which disambiguates same-name leaf keys across MCP servers / settings.
|
|
269
283
|
const augmentedSecrets = [
|
|
270
|
-
...
|
|
284
|
+
...[...structuredSecrets.values()].map((item) => ({
|
|
285
|
+
key: item.key,
|
|
286
|
+
source: item.source,
|
|
287
|
+
sample: item.sample,
|
|
288
|
+
})),
|
|
271
289
|
...freeTextSecrets.map((secret) => ({
|
|
272
290
|
key: secret.key,
|
|
273
291
|
source: secret.source,
|
|
@@ -13,6 +13,8 @@ exports.isSecretKey = isSecretKey;
|
|
|
13
13
|
exports.looksLikeSecret = looksLikeSecret;
|
|
14
14
|
exports.findSecretLeaks = findSecretLeaks;
|
|
15
15
|
exports.maskSecret = maskSecret;
|
|
16
|
+
exports.createSecretKeyRegistry = createSecretKeyRegistry;
|
|
17
|
+
exports.allocateSecretKey = allocateSecretKey;
|
|
16
18
|
exports.collectSecrets = collectSecrets;
|
|
17
19
|
exports.secretKeyName = secretKeyName;
|
|
18
20
|
exports.maskSecretsInPlace = maskSecretsInPlace;
|
|
@@ -89,6 +91,31 @@ function maskSecret(value) {
|
|
|
89
91
|
}
|
|
90
92
|
return `${value.slice(0, 4)}****${value.slice(-4)}`;
|
|
91
93
|
}
|
|
94
|
+
function createSecretKeyRegistry() {
|
|
95
|
+
return { assigned: new Map() };
|
|
96
|
+
}
|
|
97
|
+
/** 为 `value` 分配一个以 `baseName` 为前缀的唯一占位符键(确定性:值相同必得同名)。 */
|
|
98
|
+
function allocateSecretKey(registry, baseName, value) {
|
|
99
|
+
const existing = registry.assigned.get(baseName);
|
|
100
|
+
if (existing === undefined) {
|
|
101
|
+
registry.assigned.set(baseName, value);
|
|
102
|
+
return baseName;
|
|
103
|
+
}
|
|
104
|
+
if (existing === value) {
|
|
105
|
+
return baseName;
|
|
106
|
+
}
|
|
107
|
+
for (let n = 2;; n++) {
|
|
108
|
+
const candidate = `${baseName}_${n}`;
|
|
109
|
+
const held = registry.assigned.get(candidate);
|
|
110
|
+
if (held === undefined) {
|
|
111
|
+
registry.assigned.set(candidate, value);
|
|
112
|
+
return candidate;
|
|
113
|
+
}
|
|
114
|
+
if (held === value) {
|
|
115
|
+
return candidate;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
92
119
|
/**
|
|
93
120
|
* Recursively walk a parsed JSON value and collect every leaf that looks like a
|
|
94
121
|
* secret. `seen` guards against cyclic objects (e.g. shared sub-objects).
|
|
@@ -129,38 +156,50 @@ function secretKeyName(agent, jsonPath) {
|
|
|
129
156
|
* mutating in place. Mirrors the detection used during `scan` so the placeholder names
|
|
130
157
|
* match what `renderEnvExample` emitted. Used by the scan→package bridge.
|
|
131
158
|
*
|
|
159
|
+
* Returns the placeholder keys actually allocated by this call, so the caller can
|
|
160
|
+
* rebuild the package's `.env.example` / resolved manifest from real assignments
|
|
161
|
+
* (scan-time key names may collide across MCP servers; the export-side registry is
|
|
162
|
+
* the source of truth).
|
|
163
|
+
*
|
|
132
164
|
* When `secretsEnv` is supplied (keyed by the secret placeholder name, e.g.
|
|
133
|
-
* `
|
|
165
|
+
* `AGENTDOCK_CLAUDE_GITHUB_TOKEN`), the real value is written back directly instead of
|
|
134
166
|
* the placeholder — this keeps masking and re-injection on the same object so they can
|
|
135
167
|
* never desync (no fragile string placeholder matching).
|
|
168
|
+
*
|
|
169
|
+
* `registry` lets consecutive calls (per MCP server / per settings file) share one
|
|
170
|
+
* allocation table; omitted, each call gets a private table (still disambiguating
|
|
171
|
+
* conflicts within the same file).
|
|
136
172
|
*/
|
|
137
|
-
function maskSecretsInPlace(node, basePath, agent, secretsEnv, seen = new WeakSet()) {
|
|
173
|
+
function maskSecretsInPlace(node, basePath, agent, secretsEnv, seen = new WeakSet(), registry = createSecretKeyRegistry()) {
|
|
138
174
|
if (node === null || typeof node !== 'object') {
|
|
139
|
-
return;
|
|
175
|
+
return [];
|
|
140
176
|
}
|
|
141
177
|
if (seen.has(node)) {
|
|
142
|
-
return;
|
|
178
|
+
return [];
|
|
143
179
|
}
|
|
144
180
|
seen.add(node);
|
|
181
|
+
const allocated = [];
|
|
145
182
|
if (Array.isArray(node)) {
|
|
146
183
|
node.forEach((item, index) => {
|
|
147
|
-
maskSecretsInPlace(item, `${basePath}[${index}]`, agent, secretsEnv, seen);
|
|
184
|
+
allocated.push(...maskSecretsInPlace(item, `${basePath}[${index}]`, agent, secretsEnv, seen, registry));
|
|
148
185
|
});
|
|
149
|
-
return;
|
|
186
|
+
return allocated;
|
|
150
187
|
}
|
|
151
188
|
for (const [key, value] of Object.entries(node)) {
|
|
152
189
|
const childPath = `${basePath}.${key}`;
|
|
153
190
|
if (typeof value === 'string') {
|
|
154
191
|
if (isSecretKey(key) || looksLikeSecret(value)) {
|
|
155
|
-
const
|
|
192
|
+
const keyName = allocateSecretKey(registry, secretKeyName(agent, childPath), value);
|
|
156
193
|
node[key] =
|
|
157
|
-
secretsEnv && secretsEnv[
|
|
194
|
+
secretsEnv && secretsEnv[keyName] !== undefined ? secretsEnv[keyName] : `{{${keyName}}}`;
|
|
195
|
+
allocated.push({ key: keyName, sample: maskSecret(value), source: childPath });
|
|
158
196
|
}
|
|
159
197
|
}
|
|
160
198
|
else if (typeof value === 'object' && value !== null) {
|
|
161
|
-
maskSecretsInPlace(value, childPath, agent, secretsEnv, seen);
|
|
199
|
+
allocated.push(...maskSecretsInPlace(value, childPath, agent, secretsEnv, seen, registry));
|
|
162
200
|
}
|
|
163
201
|
}
|
|
202
|
+
return allocated;
|
|
164
203
|
}
|
|
165
204
|
/**
|
|
166
205
|
* Stable short hash so the same token maps to the same placeholder key across
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentdock-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
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.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|