clinkx 1.3.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.
- package/CHANGELOG.md +28 -0
- package/README.md +13 -6
- package/clinkx-workflows/dist/child-env.d.ts +3 -0
- package/clinkx-workflows/dist/child-env.js +11 -0
- package/clinkx-workflows/dist/child-env.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/api-routes.d.ts +21 -0
- package/clinkx-workflows/dist/dashboard/api-routes.js +27 -0
- package/clinkx-workflows/dist/dashboard/api-routes.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/auth/challenge-store.d.ts +13 -0
- package/clinkx-workflows/dist/dashboard/auth/challenge-store.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/auth/controller.d.ts +27 -0
- package/clinkx-workflows/dist/dashboard/auth/controller.js +262 -23
- package/clinkx-workflows/dist/dashboard/auth/controller.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/auth/settings-step-up.d.ts +62 -0
- package/clinkx-workflows/dist/dashboard/auth/settings-step-up.js +70 -0
- package/clinkx-workflows/dist/dashboard/auth/settings-step-up.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/request-admission.d.ts +6 -0
- package/clinkx-workflows/dist/dashboard/request-admission.js +9 -0
- package/clinkx-workflows/dist/dashboard/request-admission.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/server-factory.js +15 -1
- package/clinkx-workflows/dist/dashboard/server-factory.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/settings-contract.d.ts +1806 -0
- package/clinkx-workflows/dist/dashboard/settings-contract.js +630 -0
- package/clinkx-workflows/dist/dashboard/settings-contract.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/settings-process-reader.d.ts +48 -0
- package/clinkx-workflows/dist/dashboard/settings-process-reader.js +195 -0
- package/clinkx-workflows/dist/dashboard/settings-process-reader.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/settings-routes.d.ts +87 -0
- package/clinkx-workflows/dist/dashboard/settings-routes.js +690 -0
- package/clinkx-workflows/dist/dashboard/settings-routes.js.map +1 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/index-DSOtuS0p.js +122 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/style-C5guUjwN.css +1 -0
- package/clinkx-workflows/dist/dashboard-ui/index.html +2 -2
- package/clinkx-workflows/dist/durable-file-core.d.ts +76 -0
- package/clinkx-workflows/dist/durable-file-core.js +146 -0
- package/clinkx-workflows/dist/durable-file-core.js.map +1 -0
- package/clinkx-workflows/dist/durable-file.d.ts +8 -64
- package/clinkx-workflows/dist/durable-file.js +14 -137
- package/clinkx-workflows/dist/durable-file.js.map +1 -1
- package/clinkx-workflows/dist/index.js +68 -2
- package/clinkx-workflows/dist/index.js.map +1 -1
- package/clinkx-workflows/dist/settings/audit.d.ts +101 -0
- package/clinkx-workflows/dist/settings/audit.js +318 -0
- package/clinkx-workflows/dist/settings/audit.js.map +1 -0
- package/clinkx-workflows/dist/settings/bootstrap.d.ts +35 -0
- package/clinkx-workflows/dist/settings/bootstrap.js +52 -0
- package/clinkx-workflows/dist/settings/bootstrap.js.map +1 -0
- package/clinkx-workflows/dist/settings/codec.d.ts +51 -0
- package/clinkx-workflows/dist/settings/codec.js +410 -0
- package/clinkx-workflows/dist/settings/codec.js.map +1 -0
- package/clinkx-workflows/dist/settings/durable-write.d.ts +48 -0
- package/clinkx-workflows/dist/settings/durable-write.js +31 -0
- package/clinkx-workflows/dist/settings/durable-write.js.map +1 -0
- package/clinkx-workflows/dist/settings/index.d.ts +20 -0
- package/clinkx-workflows/dist/settings/index.js +23 -0
- package/clinkx-workflows/dist/settings/index.js.map +1 -0
- package/clinkx-workflows/dist/settings/loader.d.ts +80 -0
- package/clinkx-workflows/dist/settings/loader.js +577 -0
- package/clinkx-workflows/dist/settings/loader.js.map +1 -0
- package/clinkx-workflows/dist/settings/lock.d.ts +108 -0
- package/clinkx-workflows/dist/settings/lock.js +344 -0
- package/clinkx-workflows/dist/settings/lock.js.map +1 -0
- package/clinkx-workflows/dist/settings/paths.d.ts +65 -0
- package/clinkx-workflows/dist/settings/paths.js +173 -0
- package/clinkx-workflows/dist/settings/paths.js.map +1 -0
- package/clinkx-workflows/dist/settings/process-heartbeat.d.ts +47 -0
- package/clinkx-workflows/dist/settings/process-heartbeat.js +305 -0
- package/clinkx-workflows/dist/settings/process-heartbeat.js.map +1 -0
- package/clinkx-workflows/dist/settings/registry.d.ts +178 -0
- package/clinkx-workflows/dist/settings/registry.js +1285 -0
- package/clinkx-workflows/dist/settings/registry.js.map +1 -0
- package/clinkx-workflows/dist/settings/schema.d.ts +404 -0
- package/clinkx-workflows/dist/settings/schema.js +415 -0
- package/clinkx-workflows/dist/settings/schema.js.map +1 -0
- package/clinkx-workflows/dist/settings/store.d.ts +157 -0
- package/clinkx-workflows/dist/settings/store.js +842 -0
- package/clinkx-workflows/dist/settings/store.js.map +1 -0
- package/clinkx-workflows/dist/stdio-entry.d.ts +2 -0
- package/clinkx-workflows/dist/stdio-entry.js +52 -0
- package/clinkx-workflows/dist/stdio-entry.js.map +1 -0
- package/dist/dashboard-cli.js +50 -1
- package/dist/dashboard-cli.js.map +1 -1
- package/dist/dashboard-companion/protocol.js +17 -0
- package/dist/dashboard-companion/protocol.js.map +1 -1
- package/dist/dashboard-gateway/control-plane/contracts.d.ts +38 -38
- package/dist/dashboard-gateway/tunnel-http.js +20 -0
- package/dist/dashboard-gateway/tunnel-http.js.map +1 -1
- package/dist/elaris/config.d.ts +10 -0
- package/dist/elaris/config.js +27 -1
- package/dist/elaris/config.js.map +1 -1
- package/dist/elaris/tools.js +4 -1
- package/dist/elaris/tools.js.map +1 -1
- package/dist/index.d.ts +0 -31
- package/dist/index.js +41 -404
- package/dist/index.js.map +1 -1
- package/dist/lib.d.ts +17 -0
- package/dist/lib.js +17 -0
- package/dist/lib.js.map +1 -0
- package/dist/progress-report/lock.d.ts +17 -59
- package/dist/progress-report/lock.js +25 -329
- package/dist/progress-report/lock.js.map +1 -1
- package/dist/server.js +75 -4
- package/dist/server.js.map +1 -1
- package/dist/settings-cli/clients.d.ts +137 -0
- package/dist/settings-cli/clients.js +1124 -0
- package/dist/settings-cli/clients.js.map +1 -0
- package/dist/settings-cli/commands.d.ts +67 -0
- package/dist/settings-cli/commands.js +726 -0
- package/dist/settings-cli/commands.js.map +1 -0
- package/dist/settings-cli/format.d.ts +34 -0
- package/dist/settings-cli/format.js +40 -0
- package/dist/settings-cli/format.js.map +1 -0
- package/dist/settings-cli/main.d.ts +18 -0
- package/dist/settings-cli/main.js +256 -0
- package/dist/settings-cli/main.js.map +1 -0
- package/dist/stdio-main.d.ts +73 -0
- package/dist/stdio-main.js +455 -0
- package/dist/stdio-main.js.map +1 -0
- package/docs/configuration.md +340 -39
- package/docs/security.md +150 -6
- package/package.json +2 -2
- package/clinkx-workflows/dist/dashboard-ui/assets/index-DRId2DVA.js +0 -119
- package/clinkx-workflows/dist/dashboard-ui/assets/style-CHAw57y5.css +0 -1
|
@@ -0,0 +1,1124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guided trim for MCP client configs (A3-2): `import-clients` and
|
|
3
|
+
* `trim-report`.
|
|
4
|
+
*
|
|
5
|
+
* Core invariants:
|
|
6
|
+
* - ClinkX NEVER writes client config files (~/.claude.json, ~/.cursor/mcp.json,
|
|
7
|
+
* ~/.zcode/cli/config.json, ~/.codex/config.toml). Every file here is opened
|
|
8
|
+
* read-only; the trimmed block is printed for the user to paste manually.
|
|
9
|
+
* - Codex is read only through `codex mcp list --json` (spawned with
|
|
10
|
+
* shell:false, availability probed once via `codex mcp list --help`). The
|
|
11
|
+
* TOML file is never hand-parsed; if the subcommand is unavailable, Codex is
|
|
12
|
+
* skipped with a note.
|
|
13
|
+
* - Secret values are compared transiently for equality only. They are never
|
|
14
|
+
* printed or hashed into output; on --apply they go straight from the client
|
|
15
|
+
* entries into the 0600 secrets document through the store, in-process.
|
|
16
|
+
* - `trim-report` lists a key as removable ONLY when the settings file holds an
|
|
17
|
+
* equal value (the core invariant); dead keys are separately removable.
|
|
18
|
+
* - In a rendered trimmed block, only non-secret registry keys keep their raw
|
|
19
|
+
* value. Every other kept name (unknown, ENV_ONLY, DEPLOYMENT_ONLY, the
|
|
20
|
+
* dashboard token) renders the secret sentinel: any of them may carry secret
|
|
21
|
+
* material (C1). The env name an entry's CLINKX_ELARIS_API_KEY_ENV points at
|
|
22
|
+
* (resolved per entry, trimmed) holds that entry's Elaris credential when it
|
|
23
|
+
* is not itself a secret-class registry key: when SET in that entry it casts
|
|
24
|
+
* no import vote, is never printed or written by `--apply`, is never
|
|
25
|
+
* removable, renders the sentinel, and is reported once by name (L6); every
|
|
26
|
+
* other spelling of that canonical key in that entry is kept as an override,
|
|
27
|
+
* never removable, because the retained target spelling would then decide
|
|
28
|
+
* the effective value (L6a); when the target is NOT set in the entry nothing
|
|
29
|
+
* is withheld and the key votes and trims normally (L6b). A secret-class
|
|
30
|
+
* target (the documented default `CLINKX_ELARIS_API_KEY` written out
|
|
31
|
+
* explicitly) keeps flowing through the secret paths, which already withhold
|
|
32
|
+
* its value.
|
|
33
|
+
*/
|
|
34
|
+
import { lstatSync, readFileSync } from "node:fs";
|
|
35
|
+
import { join } from "node:path";
|
|
36
|
+
import { SETTINGS_DEAD, SETTINGS_KEYS, classifySettingsEnvName, getSettingDescriptor, isSecretSettingKey, } from "../../clinkx-workflows/dist/settings/registry.js";
|
|
37
|
+
import { legacyParseSetting, validateSettingValue } from "../../clinkx-workflows/dist/settings/codec.js";
|
|
38
|
+
import { resolveSettingsDir, secretsFilePath } from "../../clinkx-workflows/dist/settings/paths.js";
|
|
39
|
+
import { parseSecretsDocument } from "../../clinkx-workflows/dist/settings/schema.js";
|
|
40
|
+
import { SettingsStoreError, } from "../../clinkx-workflows/dist/settings/store.js";
|
|
41
|
+
import { EXIT_FAILURE, EXIT_OK, EXIT_UNCERTAIN, SECRET_TRIM_SENTINEL, line } from "./format.js";
|
|
42
|
+
import { encodeForDisplay, parseStrictArgvValue, reportMutation } from "./commands.js";
|
|
43
|
+
export const CLIENT_KINDS = ["claude", "codex", "cursor", "zcode"];
|
|
44
|
+
const MAX_CODEX_JSON_BYTES = 4 * 1024 * 1024;
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// Discovery
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
/** True when the launch command/args look like this ClinkX package. */
|
|
49
|
+
export function isClinkxLaunch(command, args) {
|
|
50
|
+
const base = command.split("/").pop() ?? command;
|
|
51
|
+
if (base === "clinkx")
|
|
52
|
+
return true;
|
|
53
|
+
if (base.startsWith("npx")) {
|
|
54
|
+
return args.some((arg) => arg === "clinkx" || /^clinkx@/.test(arg));
|
|
55
|
+
}
|
|
56
|
+
if (base === "node" || base === "node.exe") {
|
|
57
|
+
return args.some((arg) => /(?:^|\/)(?:clink-mcp|clinkx)(?:\/[^/]+)*\/dist\/index\.js$/.test(arg) ||
|
|
58
|
+
/node_modules\/clinkx\/dist\/index\.js$/.test(arg));
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
/** Extract command/args/env defensively from one client server object. */
|
|
63
|
+
function parseServerObject(raw) {
|
|
64
|
+
if (typeof raw !== "object" || raw === null)
|
|
65
|
+
return undefined;
|
|
66
|
+
const record = raw;
|
|
67
|
+
const command = typeof record["command"] === "string" ? record["command"] : "";
|
|
68
|
+
if (command === "")
|
|
69
|
+
return undefined;
|
|
70
|
+
const args = Array.isArray(record["args"])
|
|
71
|
+
? record["args"].filter((arg) => typeof arg === "string")
|
|
72
|
+
: [];
|
|
73
|
+
const env = {};
|
|
74
|
+
const rawEnv = record["env"];
|
|
75
|
+
if (typeof rawEnv === "object" && rawEnv !== null) {
|
|
76
|
+
for (const [name, value] of Object.entries(rawEnv)) {
|
|
77
|
+
if (typeof value === "string")
|
|
78
|
+
env[name] = value;
|
|
79
|
+
else if (typeof value === "number" || typeof value === "boolean")
|
|
80
|
+
env[name] = String(value);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const extra = {};
|
|
84
|
+
for (const [key, value] of Object.entries(record)) {
|
|
85
|
+
if (key === "command" || key === "args" || key === "env")
|
|
86
|
+
continue;
|
|
87
|
+
extra[key] = value;
|
|
88
|
+
}
|
|
89
|
+
return { command, args, env, extra };
|
|
90
|
+
}
|
|
91
|
+
function readJsonFile(path) {
|
|
92
|
+
let text;
|
|
93
|
+
try {
|
|
94
|
+
const stats = lstatSync(path);
|
|
95
|
+
if (stats.isSymbolicLink())
|
|
96
|
+
return { ok: false, reason: "symbolic link" };
|
|
97
|
+
if (!stats.isFile())
|
|
98
|
+
return { ok: false, reason: "not a regular file" };
|
|
99
|
+
text = readFileSync(path, "utf8");
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
const code = error.code;
|
|
103
|
+
if (code === "ENOENT")
|
|
104
|
+
return { ok: false, reason: "absent" };
|
|
105
|
+
return { ok: false, reason: code ?? "unreadable" };
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
return { ok: true, value: JSON.parse(text) };
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return { ok: false, reason: "not valid JSON" };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function collectFromServerRecord(servers, client, location, out) {
|
|
115
|
+
if (typeof servers !== "object" || servers === null)
|
|
116
|
+
return 0;
|
|
117
|
+
let added = 0;
|
|
118
|
+
for (const [name, raw] of Object.entries(servers)) {
|
|
119
|
+
const parsed = parseServerObject(raw);
|
|
120
|
+
if (parsed === undefined)
|
|
121
|
+
continue;
|
|
122
|
+
if (!isClinkxLaunch(parsed.command, parsed.args))
|
|
123
|
+
continue;
|
|
124
|
+
out.push({ client, name, location, ...parsed });
|
|
125
|
+
added += 1;
|
|
126
|
+
}
|
|
127
|
+
return added;
|
|
128
|
+
}
|
|
129
|
+
async function scanCodex(deps, out, notes) {
|
|
130
|
+
const probe = await deps.runCommand("codex", ["mcp", "list", "--help"]);
|
|
131
|
+
if (!probe.ok) {
|
|
132
|
+
notes.push(`codex: skipped (${probe.failure ?? "codex mcp list is unavailable"}); ~/.codex/config.toml was not read`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const listing = await deps.runCommand("codex", ["mcp", "list", "--json"]);
|
|
136
|
+
if (!listing.ok) {
|
|
137
|
+
notes.push(`codex: skipped (codex mcp list --json failed: ${listing.failure ?? "nonzero exit"}); ~/.codex/config.toml was not read`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (listing.stdout.length > MAX_CODEX_JSON_BYTES) {
|
|
141
|
+
notes.push("codex: skipped (codex mcp list --json output exceeded the size cap)");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
let parsed;
|
|
145
|
+
try {
|
|
146
|
+
parsed = JSON.parse(listing.stdout);
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
notes.push("codex: skipped (codex mcp list --json did not print valid JSON)");
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const record = typeof parsed === "object" && parsed !== null ? parsed : {};
|
|
153
|
+
const items = Array.isArray(parsed)
|
|
154
|
+
? parsed
|
|
155
|
+
: Array.isArray(record["servers"])
|
|
156
|
+
? record["servers"]
|
|
157
|
+
: Array.isArray(record["mcp_servers"])
|
|
158
|
+
? record["mcp_servers"]
|
|
159
|
+
: undefined;
|
|
160
|
+
if (items === undefined) {
|
|
161
|
+
notes.push("codex: skipped (unrecognized codex mcp list --json output shape)");
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
let count = 0;
|
|
165
|
+
for (const item of items) {
|
|
166
|
+
if (typeof item !== "object" || item === null)
|
|
167
|
+
continue;
|
|
168
|
+
const itemRecord = item;
|
|
169
|
+
const name = typeof itemRecord["name"] === "string"
|
|
170
|
+
? itemRecord["name"]
|
|
171
|
+
: typeof itemRecord["id"] === "string"
|
|
172
|
+
? itemRecord["id"]
|
|
173
|
+
: "";
|
|
174
|
+
// codex 0.166.0 nests the launch under `transport` (C4); the older flat
|
|
175
|
+
// shape stays a fallback. Listing metadata is dropped in both paths — it
|
|
176
|
+
// describes the listing, not config.toml state.
|
|
177
|
+
const transportRaw = itemRecord["transport"];
|
|
178
|
+
const source = typeof transportRaw === "object" && transportRaw !== null
|
|
179
|
+
? { ...transportRaw }
|
|
180
|
+
: Object.fromEntries(Object.entries(itemRecord).filter(([key]) => !isCodexListingMetadataKey(key)));
|
|
181
|
+
// `env_vars` is a name array in the 0.166.0 shape; the legacy flat shape
|
|
182
|
+
// used it as the env map itself.
|
|
183
|
+
const rawEnvVars = source["env_vars"];
|
|
184
|
+
delete source["env_vars"];
|
|
185
|
+
let codexEnvVars;
|
|
186
|
+
if (Array.isArray(rawEnvVars)) {
|
|
187
|
+
const names = rawEnvVars.filter((entry) => typeof entry === "string");
|
|
188
|
+
if (names.length === rawEnvVars.length)
|
|
189
|
+
codexEnvVars = names;
|
|
190
|
+
}
|
|
191
|
+
else if (source["env"] === undefined && typeof rawEnvVars === "object" && rawEnvVars !== null) {
|
|
192
|
+
source["env"] = rawEnvVars;
|
|
193
|
+
}
|
|
194
|
+
const parsedServer = parseServerObject(source);
|
|
195
|
+
if (parsedServer === undefined)
|
|
196
|
+
continue;
|
|
197
|
+
if (!isClinkxLaunch(parsedServer.command, parsedServer.args))
|
|
198
|
+
continue;
|
|
199
|
+
out.push({
|
|
200
|
+
client: "codex",
|
|
201
|
+
name: name === "" ? "(unnamed)" : name,
|
|
202
|
+
location: "~/.codex/config.toml (via codex mcp list)",
|
|
203
|
+
...parsedServer,
|
|
204
|
+
...(codexEnvVars === undefined ? {} : { codexEnvVars }),
|
|
205
|
+
});
|
|
206
|
+
count += 1;
|
|
207
|
+
}
|
|
208
|
+
if (count === 0) {
|
|
209
|
+
notes.push("codex: no ClinkX entries in `codex mcp list --json` output");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/** Per-server keys `codex mcp list` prints that are not config.toml state (C4). */
|
|
213
|
+
function isCodexListingMetadataKey(key) {
|
|
214
|
+
return (key === "name" ||
|
|
215
|
+
key === "id" ||
|
|
216
|
+
key === "enabled" ||
|
|
217
|
+
key === "disabled_reason" ||
|
|
218
|
+
key === "auth_status" ||
|
|
219
|
+
key.endsWith("_timeout_sec"));
|
|
220
|
+
}
|
|
221
|
+
export async function scanClientEntries(deps, only) {
|
|
222
|
+
const entries = [];
|
|
223
|
+
const notes = [];
|
|
224
|
+
const home = deps.home;
|
|
225
|
+
const readClientJson = (client, relative, locationLabel, collect) => {
|
|
226
|
+
if (only !== undefined && only !== client)
|
|
227
|
+
return;
|
|
228
|
+
const path = join(home, relative);
|
|
229
|
+
const result = readJsonFile(path);
|
|
230
|
+
if (!result.ok) {
|
|
231
|
+
if (result.reason !== "absent") {
|
|
232
|
+
notes.push(`${client}: skipped ${locationLabel} (${result.reason})`);
|
|
233
|
+
}
|
|
234
|
+
else if (only === client) {
|
|
235
|
+
notes.push(`${client}: ${locationLabel} not found`);
|
|
236
|
+
}
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const added = collect(result.value, entries);
|
|
240
|
+
if (added === 0 && only === client) {
|
|
241
|
+
notes.push(`${client}: no ClinkX entries in ${locationLabel}`);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
readClientJson("claude", ".claude.json", "~/.claude.json", (parsed, out) => {
|
|
245
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
246
|
+
return 0;
|
|
247
|
+
const record = parsed;
|
|
248
|
+
let added = collectFromServerRecord(record["mcpServers"], "claude", "~/.claude.json (user)", out);
|
|
249
|
+
const projects = record["projects"];
|
|
250
|
+
if (typeof projects === "object" && projects !== null) {
|
|
251
|
+
for (const [projectPath, projectRaw] of Object.entries(projects)) {
|
|
252
|
+
if (typeof projectRaw !== "object" || projectRaw === null)
|
|
253
|
+
continue;
|
|
254
|
+
added += collectFromServerRecord(projectRaw["mcpServers"], "claude", `~/.claude.json (projects/${projectPath})`, out);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return added;
|
|
258
|
+
});
|
|
259
|
+
readClientJson("cursor", ".cursor/mcp.json", "~/.cursor/mcp.json", (parsed, out) => {
|
|
260
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
261
|
+
return 0;
|
|
262
|
+
return collectFromServerRecord(parsed["mcpServers"], "cursor", "~/.cursor/mcp.json (user)", out);
|
|
263
|
+
});
|
|
264
|
+
readClientJson("zcode", ".zcode/cli/config.json", "~/.zcode/cli/config.json", (parsed, out) => {
|
|
265
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
266
|
+
return 0;
|
|
267
|
+
const mcp = parsed["mcp"];
|
|
268
|
+
if (typeof mcp !== "object" || mcp === null)
|
|
269
|
+
return 0;
|
|
270
|
+
return collectFromServerRecord(mcp["servers"], "zcode", "~/.zcode/cli/config.json (mcp.servers)", out);
|
|
271
|
+
});
|
|
272
|
+
if (only === undefined || only === "codex") {
|
|
273
|
+
await scanCodex(deps, entries, notes);
|
|
274
|
+
}
|
|
275
|
+
return { entries, notes };
|
|
276
|
+
}
|
|
277
|
+
function entryLabel(entry) {
|
|
278
|
+
return `${entry.client}/${entry.name}`;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* The env name this entry's Elaris credential indirection points at (L6):
|
|
282
|
+
* `CLINKX_ELARIS_API_KEY_ENV` names the variable holding the Elaris key — the
|
|
283
|
+
* same resolution as `src/elaris/config.ts` (trimmed; empty/unset ignored).
|
|
284
|
+
* The named variable may be an ordinary non-secret registry key, yet for THIS
|
|
285
|
+
* entry its value IS the credential, so it is never printed, voted, written
|
|
286
|
+
* by `--apply`, or classified removable. A SECRET-class target (canonical or
|
|
287
|
+
* legacy alias of one) returns undefined instead: the secret paths already
|
|
288
|
+
* withhold its value, so an entry that writes the documented default
|
|
289
|
+
* `CLINKX_ELARIS_API_KEY_ENV=CLINKX_ELARIS_API_KEY` out explicitly still
|
|
290
|
+
* imports the key into secrets.json and keeps its secret_* trim decision.
|
|
291
|
+
*/
|
|
292
|
+
export function elarisKeyEnvTarget(entry) {
|
|
293
|
+
const raw = entry.env["CLINKX_ELARIS_API_KEY_ENV"];
|
|
294
|
+
if (raw === undefined)
|
|
295
|
+
return undefined;
|
|
296
|
+
const trimmed = raw.trim();
|
|
297
|
+
if (trimmed === "")
|
|
298
|
+
return undefined;
|
|
299
|
+
const classification = classifySettingsEnvName(trimmed);
|
|
300
|
+
if (classification !== undefined && classification.kind !== "excluded") {
|
|
301
|
+
const key = classification.kind === "alias" ? classification.of : classification.key;
|
|
302
|
+
if (isSecretSettingKey(key))
|
|
303
|
+
return undefined;
|
|
304
|
+
}
|
|
305
|
+
return trimmed;
|
|
306
|
+
}
|
|
307
|
+
/** One-line reason carried by every withheld credential-indirection target. */
|
|
308
|
+
const WITHHELD_CREDENTIAL_NOTE = "withheld: credential-indirection target of CLINKX_ELARIS_API_KEY_ENV";
|
|
309
|
+
/**
|
|
310
|
+
* The withheld target spelling and the canonical registry key it spells, when
|
|
311
|
+
* the target is actually SET in this entry (L6b, matching `buildImportPlan`'s
|
|
312
|
+
* report gate): an indirection naming a variable the entry does not carry
|
|
313
|
+
* holds no credential, so it withholds nothing and the key votes and trims
|
|
314
|
+
* normally. Secret-class targets never appear here (`elarisKeyEnvTarget`
|
|
315
|
+
* already returns undefined for them).
|
|
316
|
+
*/
|
|
317
|
+
function withheldCredentialFor(entry) {
|
|
318
|
+
const target = elarisKeyEnvTarget(entry);
|
|
319
|
+
if (target === undefined || entry.env[target] === undefined)
|
|
320
|
+
return undefined;
|
|
321
|
+
const classification = classifySettingsEnvName(target);
|
|
322
|
+
if (classification === undefined || classification.kind === "excluded")
|
|
323
|
+
return undefined;
|
|
324
|
+
return { target, key: classification.kind === "alias" ? classification.of : classification.key };
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Tally votes per canonical registry key. Within one entry a canonical
|
|
328
|
+
* spelling beats a legacy alias; one entry contributes at most one vote.
|
|
329
|
+
* Missing is not a vote. The credential-indirection target of an entry's
|
|
330
|
+
* `CLINKX_ELARIS_API_KEY_ENV` (per `elarisKeyEnvTarget`; never a secret-class
|
|
331
|
+
* key, whose votes flow through the normal secret path) casts no vote in any
|
|
332
|
+
* spelling — but only when the target is actually SET in that entry (L6b,
|
|
333
|
+
* matching `buildImportPlan`): the direct spelling holds the credential, so a
|
|
334
|
+
* fallback alias vote would both leak a misattribution and misrepresent the
|
|
335
|
+
* entry (the direct spelling shadows it). An unset target withholds nothing.
|
|
336
|
+
*/
|
|
337
|
+
export function tallyRegistryKeys(entries) {
|
|
338
|
+
const votesByKey = new Map();
|
|
339
|
+
for (const key of SETTINGS_KEYS)
|
|
340
|
+
votesByKey.set(key, []);
|
|
341
|
+
for (const entry of entries) {
|
|
342
|
+
const direct = new Map();
|
|
343
|
+
const aliases = new Map();
|
|
344
|
+
const withheld = withheldCredentialFor(entry);
|
|
345
|
+
const withheldTarget = withheld?.target;
|
|
346
|
+
const withheldKey = withheld?.key;
|
|
347
|
+
for (const [envName, raw] of Object.entries(entry.env)) {
|
|
348
|
+
if (envName === withheldTarget)
|
|
349
|
+
continue;
|
|
350
|
+
const classification = classifySettingsEnvName(envName);
|
|
351
|
+
if (classification === undefined)
|
|
352
|
+
continue;
|
|
353
|
+
if (classification.kind === "alias") {
|
|
354
|
+
if (classification.of === withheldKey)
|
|
355
|
+
continue;
|
|
356
|
+
if (!aliases.has(classification.of))
|
|
357
|
+
aliases.set(classification.of, { entry, raw, envName });
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (classification.kind !== "key")
|
|
361
|
+
continue;
|
|
362
|
+
if (classification.key === withheldKey)
|
|
363
|
+
continue;
|
|
364
|
+
if (!direct.has(classification.key))
|
|
365
|
+
direct.set(classification.key, { entry, raw, envName });
|
|
366
|
+
}
|
|
367
|
+
// C3: one vote per entry per canonical key. The direct spelling wins over
|
|
368
|
+
// a legacy alias; both spellings of one key never vote twice.
|
|
369
|
+
const canonicalKeys = new Set([...direct.keys(), ...aliases.keys()]);
|
|
370
|
+
for (const key of canonicalKeys) {
|
|
371
|
+
const vote = direct.get(key) ?? aliases.get(key);
|
|
372
|
+
if (vote !== undefined)
|
|
373
|
+
votesByKey.get(key)?.push(vote);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return votesByKey;
|
|
377
|
+
}
|
|
378
|
+
/** Unique maximum only; a tie is not a majority (never imported). */
|
|
379
|
+
export function uniqueMajority(votes) {
|
|
380
|
+
if (votes.length === 0)
|
|
381
|
+
return undefined;
|
|
382
|
+
const counts = new Map();
|
|
383
|
+
for (const vote of votes)
|
|
384
|
+
counts.set(vote.raw, (counts.get(vote.raw) ?? 0) + 1);
|
|
385
|
+
let topValue = "";
|
|
386
|
+
let topCount = 0;
|
|
387
|
+
let tie = false;
|
|
388
|
+
for (const [value, count] of counts) {
|
|
389
|
+
if (count > topCount) {
|
|
390
|
+
topValue = value;
|
|
391
|
+
topCount = count;
|
|
392
|
+
tie = false;
|
|
393
|
+
}
|
|
394
|
+
else if (count === topCount) {
|
|
395
|
+
tie = true;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (tie)
|
|
399
|
+
return undefined;
|
|
400
|
+
return {
|
|
401
|
+
value: topValue,
|
|
402
|
+
count: topCount,
|
|
403
|
+
all: votes,
|
|
404
|
+
disagreeing: votes.filter((vote) => vote.raw !== topValue),
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
// ---------------------------------------------------------------------------
|
|
408
|
+
// Secrets document (values compared transiently, never rendered)
|
|
409
|
+
// ---------------------------------------------------------------------------
|
|
410
|
+
const MAX_SECRETS_READ_BYTES = 1024 * 1024;
|
|
411
|
+
export function readSecretValuesForComparison(dir) {
|
|
412
|
+
const path = secretsFilePath(dir);
|
|
413
|
+
let stats;
|
|
414
|
+
try {
|
|
415
|
+
stats = lstatSync(path);
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
const code = error.code;
|
|
419
|
+
if (code === "ENOENT")
|
|
420
|
+
return { values: {} };
|
|
421
|
+
return { values: {}, problem: `secrets.json could not be read (${code ?? "unreadable"})` };
|
|
422
|
+
}
|
|
423
|
+
if (stats.isSymbolicLink())
|
|
424
|
+
return { values: {}, problem: "secrets.json is a symbolic link; treated as unset" };
|
|
425
|
+
if (!stats.isFile())
|
|
426
|
+
return { values: {}, problem: "secrets.json is not a regular file; treated as unset" };
|
|
427
|
+
if ((stats.mode & 0o077) !== 0) {
|
|
428
|
+
return { values: {}, problem: "secrets.json mode allows group/other access; refusing to read it (treated as unset)" };
|
|
429
|
+
}
|
|
430
|
+
if (stats.size > MAX_SECRETS_READ_BYTES) {
|
|
431
|
+
return { values: {}, problem: "secrets.json is larger than the read cap; treated as unset" };
|
|
432
|
+
}
|
|
433
|
+
let parsed;
|
|
434
|
+
try {
|
|
435
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
return { values: {}, problem: "secrets.json is not valid JSON; treated as unset" };
|
|
439
|
+
}
|
|
440
|
+
const result = parseSecretsDocument(parsed);
|
|
441
|
+
if (result.status !== "ok") {
|
|
442
|
+
return { values: {}, problem: "secrets.json failed validation; treated as unset" };
|
|
443
|
+
}
|
|
444
|
+
const values = {};
|
|
445
|
+
for (const [key, entry] of Object.entries(result.document.entries)) {
|
|
446
|
+
values[key] = entry.value;
|
|
447
|
+
}
|
|
448
|
+
return { values };
|
|
449
|
+
}
|
|
450
|
+
// ---------------------------------------------------------------------------
|
|
451
|
+
// Value equality (typed, mirroring the consumer env grammar)
|
|
452
|
+
// ---------------------------------------------------------------------------
|
|
453
|
+
function valuesEqual(a, b) {
|
|
454
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
455
|
+
return a.length === b.length && a.every((entry, index) => entry === b[index]);
|
|
456
|
+
}
|
|
457
|
+
return a === b;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Typed equality between a client entry's env spelling and the settings file's
|
|
461
|
+
* value. The env side parses through the consumer grammar mirror, so an entry
|
|
462
|
+
* spelling the consumer would read identically counts as equal.
|
|
463
|
+
*/
|
|
464
|
+
export function entryMatchesFileValue(descriptor, raw, fileValue) {
|
|
465
|
+
const parsed = legacyParseSetting(descriptor, raw);
|
|
466
|
+
return parsed.ok && valuesEqual(parsed.value, fileValue);
|
|
467
|
+
}
|
|
468
|
+
function deadKeyReason(name) {
|
|
469
|
+
for (const entry of SETTINGS_DEAD) {
|
|
470
|
+
if (entry.name === name)
|
|
471
|
+
return entry.reason;
|
|
472
|
+
}
|
|
473
|
+
return "declared dead";
|
|
474
|
+
}
|
|
475
|
+
export function buildImportPlan(entries) {
|
|
476
|
+
const items = [];
|
|
477
|
+
const ties = [];
|
|
478
|
+
const deadSeen = new Map();
|
|
479
|
+
const unknownSeen = new Map();
|
|
480
|
+
const envOnlySeen = new Map();
|
|
481
|
+
const withheldSeen = new Map();
|
|
482
|
+
for (const entry of entries) {
|
|
483
|
+
const label = entryLabel(entry);
|
|
484
|
+
// L6: the credential-indirection target is reported exactly once, by name,
|
|
485
|
+
// and never through another section.
|
|
486
|
+
const withheldTarget = elarisKeyEnvTarget(entry);
|
|
487
|
+
if (withheldTarget !== undefined && entry.env[withheldTarget] !== undefined) {
|
|
488
|
+
let set = withheldSeen.get(withheldTarget);
|
|
489
|
+
if (set === undefined) {
|
|
490
|
+
set = new Set();
|
|
491
|
+
withheldSeen.set(withheldTarget, set);
|
|
492
|
+
}
|
|
493
|
+
set.add(label);
|
|
494
|
+
}
|
|
495
|
+
for (const name of Object.keys(entry.env)) {
|
|
496
|
+
if (name === withheldTarget)
|
|
497
|
+
continue;
|
|
498
|
+
const classification = classifySettingsEnvName(name);
|
|
499
|
+
if (classification === undefined) {
|
|
500
|
+
let set = unknownSeen.get(name);
|
|
501
|
+
if (set === undefined) {
|
|
502
|
+
set = new Set();
|
|
503
|
+
unknownSeen.set(name, set);
|
|
504
|
+
}
|
|
505
|
+
set.add(label);
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
if (classification.kind !== "excluded")
|
|
509
|
+
continue;
|
|
510
|
+
if (classification.list === "DEAD") {
|
|
511
|
+
let set = deadSeen.get(name);
|
|
512
|
+
if (set === undefined) {
|
|
513
|
+
set = new Set();
|
|
514
|
+
deadSeen.set(name, set);
|
|
515
|
+
}
|
|
516
|
+
set.add(label);
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
let seen = envOnlySeen.get(name);
|
|
520
|
+
if (seen === undefined) {
|
|
521
|
+
seen = { list: classification.list, labels: new Set() };
|
|
522
|
+
envOnlySeen.set(name, seen);
|
|
523
|
+
}
|
|
524
|
+
seen.labels.add(label);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
for (const [key, votes] of tallyRegistryKeys(entries)) {
|
|
528
|
+
if (votes.length === 0)
|
|
529
|
+
continue;
|
|
530
|
+
const majority = uniqueMajority(votes);
|
|
531
|
+
if (majority === undefined) {
|
|
532
|
+
ties.push({ key, votes });
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
const descriptor = getSettingDescriptor(key);
|
|
536
|
+
if (descriptor === undefined)
|
|
537
|
+
continue;
|
|
538
|
+
let invalidReason;
|
|
539
|
+
if (!isSecretSettingKey(key)) {
|
|
540
|
+
const parsed = parseStrictArgvValue(descriptor, majority.value);
|
|
541
|
+
if (!parsed.ok) {
|
|
542
|
+
invalidReason = parsed.error;
|
|
543
|
+
}
|
|
544
|
+
else {
|
|
545
|
+
const registryError = validateSettingValue(descriptor, parsed.value);
|
|
546
|
+
if (registryError !== undefined)
|
|
547
|
+
invalidReason = registryError;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
items.push({
|
|
551
|
+
key,
|
|
552
|
+
secret: isSecretSettingKey(key),
|
|
553
|
+
majority,
|
|
554
|
+
descriptor,
|
|
555
|
+
...(invalidReason === undefined ? {} : { invalidReason }),
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
return {
|
|
559
|
+
items,
|
|
560
|
+
ties,
|
|
561
|
+
dead: [...deadSeen.entries()].map(([name, labels]) => ({
|
|
562
|
+
name,
|
|
563
|
+
reason: deadKeyReason(name),
|
|
564
|
+
entries: [...labels],
|
|
565
|
+
})),
|
|
566
|
+
unknown: [...unknownSeen.entries()].map(([name, labels]) => ({ name, entries: [...labels] })),
|
|
567
|
+
envOnly: [...envOnlySeen.entries()].map(([name, seen]) => ({
|
|
568
|
+
name,
|
|
569
|
+
list: seen.list,
|
|
570
|
+
entries: [...seen.labels],
|
|
571
|
+
})),
|
|
572
|
+
withheld: [...withheldSeen.entries()].map(([name, labels]) => ({ name, entries: [...labels] })),
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
export async function commandImportClients(ctx, opts) {
|
|
576
|
+
const scan = await scanClientEntries({ home: opts.home, runCommand: opts.runCommand });
|
|
577
|
+
printScanSummary(ctx, scan, opts.home);
|
|
578
|
+
if (scan.entries.length === 0) {
|
|
579
|
+
ctx.io.out(line("no ClinkX entries found — nothing to import"));
|
|
580
|
+
return EXIT_OK;
|
|
581
|
+
}
|
|
582
|
+
const plan = buildImportPlan(scan.entries);
|
|
583
|
+
ctx.io.out(line(""));
|
|
584
|
+
ctx.io.out(line(opts.apply ? "applying majority values:" : "import plan (dry run):"));
|
|
585
|
+
for (const item of plan.items) {
|
|
586
|
+
if (item.secret) {
|
|
587
|
+
const disagreeing = item.majority.disagreeing.map((vote) => entryLabel(vote.entry)).join(", ");
|
|
588
|
+
ctx.io.out(line(` ${item.key} (secret): majority held by ${String(item.majority.count)} of ${String(item.majority.count + item.majority.disagreeing.length)} entries` + (disagreeing === "" ? "" : `; disagreeing: ${disagreeing} (value withheld)`)));
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
const suffix = item.invalidReason === undefined ? "" : ` (NOT imported: ${item.invalidReason})`;
|
|
592
|
+
ctx.io.out(line(` ${item.key} = ${item.majority.value}${suffix}`));
|
|
593
|
+
const disagreeing = item.majority.disagreeing
|
|
594
|
+
.map((vote) => `${entryLabel(vote.entry)} (${vote.raw})`)
|
|
595
|
+
.join(", ");
|
|
596
|
+
if (disagreeing !== "") {
|
|
597
|
+
ctx.io.out(line(` disagreeing: ${disagreeing}`));
|
|
598
|
+
}
|
|
599
|
+
const voters = new Set(item.majority.all.map((vote) => vote.entry));
|
|
600
|
+
const nonVoters = scan.entries.filter((entry) => !voters.has(entry)).map(entryLabel).join(", ");
|
|
601
|
+
if (nonVoters !== "") {
|
|
602
|
+
ctx.io.out(line(` not set by: ${nonVoters}`));
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
for (const tie of plan.ties) {
|
|
606
|
+
ctx.io.out(line(` ${tie.key}: no majority (${String(tie.votes.length)} entries split evenly) — not imported; keep exactly one spelling as an explicit override`));
|
|
607
|
+
}
|
|
608
|
+
for (const dead of plan.dead) {
|
|
609
|
+
ctx.io.out(line(` ${dead.name}: dead key (${dead.reason}) — not imported; safe to delete from client entries (${dead.entries.join(", ")})`));
|
|
610
|
+
}
|
|
611
|
+
for (const unknown of plan.unknown) {
|
|
612
|
+
ctx.io.out(line(` ${unknown.name}: unknown key (no registry entry; check the spelling) — not imported (${unknown.entries.join(", ")})`));
|
|
613
|
+
}
|
|
614
|
+
for (const envOnly of plan.envOnly) {
|
|
615
|
+
ctx.io.out(line(` ${envOnly.name}: ${envOnly.list === "ENV_ONLY" ? "env-only" : "deployment-only"} key — cannot come from the settings file; must stay in client entries (${envOnly.entries.join(", ")})`));
|
|
616
|
+
}
|
|
617
|
+
// L6: name only — the withheld value is the credential and never prints.
|
|
618
|
+
for (const withheld of plan.withheld) {
|
|
619
|
+
ctx.io.out(line(` ${withheld.name}: ${WITHHELD_CREDENTIAL_NOTE} (${withheld.entries.join(", ")})`));
|
|
620
|
+
}
|
|
621
|
+
if (!opts.apply) {
|
|
622
|
+
ctx.io.out(line(""));
|
|
623
|
+
ctx.io.out(line("apply with: clinkx settings import-clients --apply"));
|
|
624
|
+
return EXIT_OK;
|
|
625
|
+
}
|
|
626
|
+
return applyImportPlan(ctx, plan);
|
|
627
|
+
}
|
|
628
|
+
async function applyImportPlan(ctx, plan) {
|
|
629
|
+
const importable = plan.items.filter((item) => item.invalidReason === undefined);
|
|
630
|
+
const regular = importable.filter((item) => !item.secret);
|
|
631
|
+
const secrets = importable.filter((item) => item.secret);
|
|
632
|
+
if (regular.length === 0 && secrets.length === 0) {
|
|
633
|
+
ctx.io.out(line("nothing importable (ties or invalid majority values only)"));
|
|
634
|
+
return EXIT_OK;
|
|
635
|
+
}
|
|
636
|
+
const resolution = resolveSettingsDir({ env: ctx.env });
|
|
637
|
+
if (resolution.dir === "") {
|
|
638
|
+
ctx.io.err(line(`clinkx settings: the settings directory is not usable: ${resolution.warning ?? "unresolvable"}`));
|
|
639
|
+
return EXIT_FAILURE;
|
|
640
|
+
}
|
|
641
|
+
const store = ctx.createStore(resolution.dir);
|
|
642
|
+
// Set once the settings half's bytes are on disk under a confirmable store
|
|
643
|
+
// outcome: a later secrets failure is then a PARTIAL import the user must be
|
|
644
|
+
// told to re-run, not a bare store error.
|
|
645
|
+
let settingsWritten = false;
|
|
646
|
+
// `published_uncertain` from EITHER half decides the final exit code (3),
|
|
647
|
+
// even when the other half saves cleanly.
|
|
648
|
+
let settingsUncertain = false;
|
|
649
|
+
if (regular.length > 0) {
|
|
650
|
+
try {
|
|
651
|
+
const read = await store.read();
|
|
652
|
+
if (read.state === "unreadable") {
|
|
653
|
+
ctx.io.err(line(`clinkx settings: the settings document is unreadable (${read.reason ?? "unknown reason"}); fix or recover it before importing`));
|
|
654
|
+
return EXIT_FAILURE;
|
|
655
|
+
}
|
|
656
|
+
const ops = regular.map((item) => {
|
|
657
|
+
const parsed = parseStrictArgvValue(item.descriptor, item.majority.value);
|
|
658
|
+
if (!parsed.ok)
|
|
659
|
+
throw new Error(`internal: plan item failed to re-parse: ${parsed.error}`);
|
|
660
|
+
return { key: item.key, action: "set", value: parsed.value };
|
|
661
|
+
});
|
|
662
|
+
const result = await store.save({
|
|
663
|
+
expectedRevision: read.revision,
|
|
664
|
+
ops,
|
|
665
|
+
actor: "cli",
|
|
666
|
+
auth: "local-fs",
|
|
667
|
+
});
|
|
668
|
+
const reported = reportMutation(ctx.io, result, `settings: wrote ${String(regular.length)} key(s) at revision ${String(result.revision)}`);
|
|
669
|
+
if (result.outcome !== "ok" && result.outcome !== "published_uncertain") {
|
|
670
|
+
// Unexpected store outcome: refuse to continue into the secrets half.
|
|
671
|
+
return reported;
|
|
672
|
+
}
|
|
673
|
+
// `published_uncertain` bytes are live on disk, so the import still
|
|
674
|
+
// proceeds; the exit code is decided after the secrets half.
|
|
675
|
+
settingsWritten = true;
|
|
676
|
+
settingsUncertain = result.outcome === "published_uncertain";
|
|
677
|
+
}
|
|
678
|
+
catch (error) {
|
|
679
|
+
return describeStoreFailure(ctx, error);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
if (secrets.length > 0) {
|
|
683
|
+
// L6: every secrets-half failure routes through one partial-outcome
|
|
684
|
+
// reporter. Once the settings half landed, the partial line must always
|
|
685
|
+
// print (those bytes are on disk and a re-run is safe), and an earlier
|
|
686
|
+
// `published_uncertain` still decides the exit code — 3 beats 1 whenever
|
|
687
|
+
// any half was uncertain. `message` is null when the error line was
|
|
688
|
+
// already printed (reportMutation's unexpected-outcome branch).
|
|
689
|
+
const reportSecretsFailure = (message) => {
|
|
690
|
+
if (message !== null)
|
|
691
|
+
ctx.io.err(line(message));
|
|
692
|
+
if (settingsWritten) {
|
|
693
|
+
ctx.io.err(line(`partial import: ${String(regular.length)} settings key(s) were written but the secrets were not — fix and re-run import-clients --apply`));
|
|
694
|
+
}
|
|
695
|
+
return settingsUncertain ? EXIT_UNCERTAIN : EXIT_FAILURE;
|
|
696
|
+
};
|
|
697
|
+
try {
|
|
698
|
+
const status = await store.secretStatus();
|
|
699
|
+
if (status.state === "unreadable") {
|
|
700
|
+
return reportSecretsFailure(`clinkx settings: the secrets document is unreadable (${status.reason ?? "unknown reason"}); fix or recover it before importing secrets`);
|
|
701
|
+
}
|
|
702
|
+
const ops = secrets.map((item) => ({ key: item.key, action: "set", value: item.majority.value }));
|
|
703
|
+
const result = await store.saveSecrets({
|
|
704
|
+
expectedRevision: status.revision,
|
|
705
|
+
ops,
|
|
706
|
+
actor: "cli",
|
|
707
|
+
auth: "local-fs",
|
|
708
|
+
});
|
|
709
|
+
const secretsExit = reportMutation(ctx.io, result, `secrets: wrote ${String(secrets.length)} key(s) at secrets revision ${String(result.revision)}`);
|
|
710
|
+
if (secretsExit === EXIT_UNCERTAIN)
|
|
711
|
+
return EXIT_UNCERTAIN;
|
|
712
|
+
if (secretsExit !== EXIT_OK) {
|
|
713
|
+
return reportSecretsFailure(null);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
catch (error) {
|
|
717
|
+
return reportSecretsFailure(error instanceof SettingsStoreError
|
|
718
|
+
? `clinkx settings: ${error.message}`
|
|
719
|
+
: `clinkx settings: failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
if (settingsUncertain)
|
|
723
|
+
return EXIT_UNCERTAIN;
|
|
724
|
+
ctx.io.out(line(""));
|
|
725
|
+
ctx.io.out(line("next: run `clinkx settings trim-report --client <claude|codex|cursor|zcode>` and paste the trimmed entries"));
|
|
726
|
+
return EXIT_OK;
|
|
727
|
+
}
|
|
728
|
+
function describeStoreFailure(ctx, error) {
|
|
729
|
+
if (error instanceof SettingsStoreError) {
|
|
730
|
+
ctx.io.err(line(`clinkx settings: ${error.message}`));
|
|
731
|
+
return EXIT_FAILURE;
|
|
732
|
+
}
|
|
733
|
+
ctx.io.err(line(`clinkx settings: failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
734
|
+
return EXIT_FAILURE;
|
|
735
|
+
}
|
|
736
|
+
function printScanSummary(ctx, scan, home) {
|
|
737
|
+
ctx.io.out(line(`scanned MCP client configs under ${home}`));
|
|
738
|
+
const byClient = new Map();
|
|
739
|
+
for (const entry of scan.entries) {
|
|
740
|
+
const list = byClient.get(entry.client) ?? [];
|
|
741
|
+
list.push(entry);
|
|
742
|
+
byClient.set(entry.client, list);
|
|
743
|
+
}
|
|
744
|
+
for (const kind of CLIENT_KINDS) {
|
|
745
|
+
const list = byClient.get(kind);
|
|
746
|
+
if (list === undefined)
|
|
747
|
+
continue;
|
|
748
|
+
const names = list.map((entry) => `${entry.name} [${entry.location}]`).join(", ");
|
|
749
|
+
ctx.io.out(line(` ${kind}: ${String(list.length)} ClinkX ${list.length === 1 ? "entry" : "entries"} (${names})`));
|
|
750
|
+
}
|
|
751
|
+
for (const note of scan.notes) {
|
|
752
|
+
ctx.io.out(line(` note: ${note}`));
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
function summarizeEnvNames(decisions, category) {
|
|
756
|
+
return decisions.filter((decision) => decision.category === category).map((decision) => decision.envName);
|
|
757
|
+
}
|
|
758
|
+
const NEAREST_NAME_MAX_DISTANCE = 3;
|
|
759
|
+
function levenshteinDistance(a, b) {
|
|
760
|
+
if (a === b)
|
|
761
|
+
return 0;
|
|
762
|
+
if (a.length === 0)
|
|
763
|
+
return b.length;
|
|
764
|
+
if (b.length === 0)
|
|
765
|
+
return a.length;
|
|
766
|
+
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
767
|
+
for (let i = 1; i <= a.length; i += 1) {
|
|
768
|
+
const current = [i];
|
|
769
|
+
for (let j = 1; j <= b.length; j += 1) {
|
|
770
|
+
current[j] = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
771
|
+
}
|
|
772
|
+
previous = current;
|
|
773
|
+
}
|
|
774
|
+
return previous[b.length];
|
|
775
|
+
}
|
|
776
|
+
/** Nearest registry key within the distance cap; first registry entry wins ties (R7). */
|
|
777
|
+
function nearestRegistryName(name) {
|
|
778
|
+
let best;
|
|
779
|
+
let bestDistance = NEAREST_NAME_MAX_DISTANCE + 1;
|
|
780
|
+
for (const key of SETTINGS_KEYS) {
|
|
781
|
+
const distance = levenshteinDistance(name, key);
|
|
782
|
+
if (distance < bestDistance) {
|
|
783
|
+
best = key;
|
|
784
|
+
bestDistance = distance;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
return best;
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* An entry that points its server at a different settings source can never be
|
|
791
|
+
* trimmed against this CLI's settings file: removing an env key would change
|
|
792
|
+
* that server's effective value, because it does not read this file at all.
|
|
793
|
+
*/
|
|
794
|
+
function entrySettingsScopeNote(entry, resolvedSettingsDir) {
|
|
795
|
+
if (entry.env["CLINKX_SETTINGS"] === "off") {
|
|
796
|
+
return "entry sets CLINKX_SETTINGS=off — this server does not read the settings file";
|
|
797
|
+
}
|
|
798
|
+
const dir = entry.env["CLINKX_SETTINGS_DIR"];
|
|
799
|
+
if (dir !== undefined && dir.trim() !== "" && dir.trim() !== resolvedSettingsDir) {
|
|
800
|
+
return `entry sets CLINKX_SETTINGS_DIR to a different directory than this CLI resolved (${resolvedSettingsDir}) — this server does not read this settings file`;
|
|
801
|
+
}
|
|
802
|
+
return undefined;
|
|
803
|
+
}
|
|
804
|
+
function decideTrimForEntry(entry, settingsValues, secretValues, resolvedSettingsDir) {
|
|
805
|
+
const withheldTarget = elarisKeyEnvTarget(entry);
|
|
806
|
+
const withheld = withheldCredentialFor(entry);
|
|
807
|
+
const scopeNote = entrySettingsScopeNote(entry, resolvedSettingsDir);
|
|
808
|
+
if (scopeNote !== undefined) {
|
|
809
|
+
return Object.keys(entry.env).map((envName) => envName === withheldTarget
|
|
810
|
+
? { envName, category: "withheld_credential", note: WITHHELD_CREDENTIAL_NOTE }
|
|
811
|
+
: { envName, category: "override", note: scopeNote });
|
|
812
|
+
}
|
|
813
|
+
const decisions = [];
|
|
814
|
+
const groups = new Map();
|
|
815
|
+
for (const [envName, raw] of Object.entries(entry.env)) {
|
|
816
|
+
if (envName === withheldTarget) {
|
|
817
|
+
// L6: decided before any classification — even a non-secret registry
|
|
818
|
+
// spelling is this entry's credential, so it never reaches the value
|
|
819
|
+
// comparisons (whose override notes print the entry's raw value).
|
|
820
|
+
decisions.push({ envName, category: "withheld_credential", note: WITHHELD_CREDENTIAL_NOTE });
|
|
821
|
+
continue;
|
|
822
|
+
}
|
|
823
|
+
const classification = classifySettingsEnvName(envName);
|
|
824
|
+
if (classification === undefined) {
|
|
825
|
+
decisions.push({ envName, category: "unknown" });
|
|
826
|
+
continue;
|
|
827
|
+
}
|
|
828
|
+
if (classification.kind === "excluded") {
|
|
829
|
+
decisions.push(classification.list === "DEAD"
|
|
830
|
+
? { envName, category: "removable_dead", note: deadKeyReason(envName) }
|
|
831
|
+
: { envName, category: "env_only", note: classification.list });
|
|
832
|
+
continue;
|
|
833
|
+
}
|
|
834
|
+
const key = classification.kind === "alias" ? classification.of : classification.key;
|
|
835
|
+
const descriptor = getSettingDescriptor(key);
|
|
836
|
+
if (descriptor === undefined) {
|
|
837
|
+
decisions.push({ envName, category: "unknown" });
|
|
838
|
+
continue;
|
|
839
|
+
}
|
|
840
|
+
if (isSecretSettingKey(key)) {
|
|
841
|
+
const stored = secretValues[key];
|
|
842
|
+
if (stored === raw) {
|
|
843
|
+
decisions.push({ envName, category: "secret_match" });
|
|
844
|
+
}
|
|
845
|
+
else if (stored === undefined) {
|
|
846
|
+
decisions.push({ envName, category: "secret_not_stored" });
|
|
847
|
+
}
|
|
848
|
+
else {
|
|
849
|
+
decisions.push({ envName, category: "secret_differs" });
|
|
850
|
+
}
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
const spellings = groups.get(key);
|
|
854
|
+
if (spellings === undefined)
|
|
855
|
+
groups.set(key, [{ envName, raw }]);
|
|
856
|
+
else
|
|
857
|
+
spellings.push({ envName, raw });
|
|
858
|
+
}
|
|
859
|
+
// C2: env precedence is per canonical key (direct spelling shadows its
|
|
860
|
+
// legacy aliases), so removability is decided per group: if any spelling
|
|
861
|
+
// stays, every spelling stays, or trimming the canonical name would let the
|
|
862
|
+
// alias resurface. An empty-string value is present (OQ-3) and never equal.
|
|
863
|
+
for (const [key, spellings] of groups) {
|
|
864
|
+
const descriptor = getSettingDescriptor(key);
|
|
865
|
+
if (descriptor === undefined)
|
|
866
|
+
continue;
|
|
867
|
+
if (withheld !== undefined && key === withheld.key) {
|
|
868
|
+
// L6a: the withheld target spelling of this key stays in the entry, and
|
|
869
|
+
// env presence beats the settings file (the loader reads the canonical
|
|
870
|
+
// name, else the first present alias; consumers read canonical-or-alias),
|
|
871
|
+
// so marking any other spelling removable would hand the effective value
|
|
872
|
+
// to the credential. The note names the target env NAME only.
|
|
873
|
+
for (const spelling of spellings) {
|
|
874
|
+
decisions.push({
|
|
875
|
+
envName: spelling.envName,
|
|
876
|
+
category: "override",
|
|
877
|
+
note: `kept: ${withheld.target} is this entry's credential-indirection target and is never removed; removing this spelling would let that retained spelling decide the effective value`,
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
const fileValue = settingsValues[key];
|
|
883
|
+
if (fileValue === undefined) {
|
|
884
|
+
for (const spelling of spellings)
|
|
885
|
+
decisions.push({ envName: spelling.envName, category: "not_in_file" });
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
const matches = spellings.map((spelling) => spelling.raw !== "" && entryMatchesFileValue(descriptor, spelling.raw, fileValue));
|
|
889
|
+
const firstKept = spellings.find((_, index) => !matches[index])?.envName ?? "another spelling";
|
|
890
|
+
const allMatch = matches.every((match) => match);
|
|
891
|
+
for (const [index, spelling] of spellings.entries()) {
|
|
892
|
+
if (allMatch) {
|
|
893
|
+
decisions.push({ envName: spelling.envName, category: "removable" });
|
|
894
|
+
}
|
|
895
|
+
else if (matches[index]) {
|
|
896
|
+
decisions.push({
|
|
897
|
+
envName: spelling.envName,
|
|
898
|
+
category: "override",
|
|
899
|
+
note: `kept with ${firstKept}: that spelling does not equal the settings file, so no spelling of this key is removable`,
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
else {
|
|
903
|
+
decisions.push({
|
|
904
|
+
envName: spelling.envName,
|
|
905
|
+
category: "override",
|
|
906
|
+
note: `entry ${spelling.raw === "" ? '""' : spelling.raw}; settings file ${encodeForDisplay(descriptor, fileValue)}`,
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return decisions;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* True only for a registry key (canonical or legacy alias) that is not
|
|
915
|
+
* secret-class. Anything else kept in a block may hold secret material —
|
|
916
|
+
* unknown names, ENV_ONLY/DEPLOYMENT_ONLY entries, the dashboard token — so
|
|
917
|
+
* it renders redacted. The name targeted by an entry's
|
|
918
|
+
* CLINKX_ELARIS_API_KEY_ENV is redacted through its `withheld_credential`
|
|
919
|
+
* decision (L6), which this name-class test cannot see.
|
|
920
|
+
*/
|
|
921
|
+
function isNonSecretRegistryEnvName(envName) {
|
|
922
|
+
const classification = classifySettingsEnvName(envName);
|
|
923
|
+
if (classification === undefined || classification.kind === "excluded")
|
|
924
|
+
return false;
|
|
925
|
+
const key = classification.kind === "alias" ? classification.of : classification.key;
|
|
926
|
+
return getSettingDescriptor(key) !== undefined && !isSecretSettingKey(key);
|
|
927
|
+
}
|
|
928
|
+
/** Env names that stay in the trimmed block, mapped to their rendered value. */
|
|
929
|
+
function keptEnvForRender(entry, decisions) {
|
|
930
|
+
const keep = {};
|
|
931
|
+
for (const decision of decisions) {
|
|
932
|
+
if (decision.category === "removable" || decision.category === "removable_dead")
|
|
933
|
+
continue;
|
|
934
|
+
const raw = entry.env[decision.envName];
|
|
935
|
+
if (raw === undefined)
|
|
936
|
+
continue;
|
|
937
|
+
keep[decision.envName] =
|
|
938
|
+
decision.category !== "withheld_credential" && isNonSecretRegistryEnvName(decision.envName)
|
|
939
|
+
? raw
|
|
940
|
+
: SECRET_TRIM_SENTINEL;
|
|
941
|
+
}
|
|
942
|
+
return keep;
|
|
943
|
+
}
|
|
944
|
+
function tomlBasicString(value) {
|
|
945
|
+
let out = "\"";
|
|
946
|
+
for (const char of value) {
|
|
947
|
+
switch (char) {
|
|
948
|
+
case "\\":
|
|
949
|
+
out += "\\\\";
|
|
950
|
+
break;
|
|
951
|
+
case "\"":
|
|
952
|
+
out += "\\\"";
|
|
953
|
+
break;
|
|
954
|
+
case "\n":
|
|
955
|
+
out += "\\n";
|
|
956
|
+
break;
|
|
957
|
+
case "\r":
|
|
958
|
+
out += "\\r";
|
|
959
|
+
break;
|
|
960
|
+
case "\t":
|
|
961
|
+
out += "\\t";
|
|
962
|
+
break;
|
|
963
|
+
default: {
|
|
964
|
+
const code = char.codePointAt(0) ?? 0;
|
|
965
|
+
if (code < 0x20 || code === 0x7f) {
|
|
966
|
+
out += `\\u${code.toString(16).padStart(4, "0")}`;
|
|
967
|
+
}
|
|
968
|
+
else {
|
|
969
|
+
out += char;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
return `${out}"`;
|
|
975
|
+
}
|
|
976
|
+
function renderTrimmedBlock(entry, keepEnv) {
|
|
977
|
+
if (entry.client === "codex") {
|
|
978
|
+
const lines = [];
|
|
979
|
+
lines.push(`[mcp_servers.${entry.name}]`);
|
|
980
|
+
lines.push(`command = ${tomlBasicString(entry.command)}`);
|
|
981
|
+
lines.push(`args = [${entry.args.map((arg) => tomlBasicString(arg)).join(", ")}]`);
|
|
982
|
+
const envEntries = Object.entries(keepEnv).map(([name, value]) => `${name} = ${tomlBasicString(value)}`);
|
|
983
|
+
// codex rejects an env_vars map ("invalid type: map, expected a sequence"),
|
|
984
|
+
// so the env map goes to `env` and env_vars only ever renders as the
|
|
985
|
+
// original name sequence from the listing (C4).
|
|
986
|
+
lines.push(envEntries.length === 0 ? "env = {}" : `env = { ${envEntries.join(", ")} }`);
|
|
987
|
+
if (entry.codexEnvVars !== undefined) {
|
|
988
|
+
lines.push(`env_vars = [${entry.codexEnvVars.map((name) => tomlBasicString(name)).join(", ")}]`);
|
|
989
|
+
}
|
|
990
|
+
for (const [key, value] of Object.entries(entry.extra)) {
|
|
991
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
992
|
+
lines.push(`${key} = ${String(value)}`);
|
|
993
|
+
}
|
|
994
|
+
else if (typeof value === "boolean") {
|
|
995
|
+
lines.push(`${key} = ${value ? "true" : "false"}`);
|
|
996
|
+
}
|
|
997
|
+
else if (typeof value === "string") {
|
|
998
|
+
lines.push(`${key} = ${tomlBasicString(value)}`);
|
|
999
|
+
}
|
|
1000
|
+
else {
|
|
1001
|
+
lines.push(`# ${key}: not representable here — copy this field manually from your config`);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
return lines.join("\n");
|
|
1005
|
+
}
|
|
1006
|
+
const rendered = { ...entry.extra, command: entry.command, args: entry.args, env: keepEnv };
|
|
1007
|
+
return JSON.stringify(rendered, null, 2);
|
|
1008
|
+
}
|
|
1009
|
+
function pasteTargetHint(entry) {
|
|
1010
|
+
switch (entry.client) {
|
|
1011
|
+
case "claude":
|
|
1012
|
+
return `paste over "mcpServers.${entry.name}" in ~/.claude.json (${entry.location})`;
|
|
1013
|
+
case "cursor":
|
|
1014
|
+
return `paste over "mcpServers.${entry.name}" in ~/.cursor/mcp.json`;
|
|
1015
|
+
case "zcode":
|
|
1016
|
+
return `paste over "mcp.servers.${entry.name}" in ~/.zcode/cli/config.json`;
|
|
1017
|
+
case "codex":
|
|
1018
|
+
return `paste over [mcp_servers.${entry.name}] in ~/.codex/config.toml`;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
export async function commandTrimReport(ctx, opts) {
|
|
1022
|
+
const scan = await scanClientEntries({ home: opts.home, runCommand: opts.runCommand }, opts.client);
|
|
1023
|
+
ctx.io.out(line(`client: ${opts.client}`));
|
|
1024
|
+
for (const note of scan.notes) {
|
|
1025
|
+
ctx.io.out(line(` note: ${note}`));
|
|
1026
|
+
}
|
|
1027
|
+
if (scan.entries.length === 0) {
|
|
1028
|
+
ctx.io.out(line("no ClinkX entries found for this client — nothing to trim"));
|
|
1029
|
+
return EXIT_OK;
|
|
1030
|
+
}
|
|
1031
|
+
const resolution = resolveSettingsDir({ env: ctx.env });
|
|
1032
|
+
if (resolution.dir === "") {
|
|
1033
|
+
ctx.io.err(line(`clinkx settings: the settings directory is not usable: ${resolution.warning ?? "unresolvable"}`));
|
|
1034
|
+
return EXIT_FAILURE;
|
|
1035
|
+
}
|
|
1036
|
+
const store = ctx.createStore(resolution.dir);
|
|
1037
|
+
let read;
|
|
1038
|
+
try {
|
|
1039
|
+
read = await store.read();
|
|
1040
|
+
}
|
|
1041
|
+
catch (error) {
|
|
1042
|
+
return describeStoreFailure(ctx, error);
|
|
1043
|
+
}
|
|
1044
|
+
if (read.state === "unreadable") {
|
|
1045
|
+
ctx.io.err(line(`clinkx settings: the settings document is unreadable (${read.reason ?? "unknown reason"}); nothing is removable until it is fixed or recovered`));
|
|
1046
|
+
return EXIT_FAILURE;
|
|
1047
|
+
}
|
|
1048
|
+
const secretValues = readSecretValuesForComparison(resolution.dir);
|
|
1049
|
+
if (secretValues.problem !== undefined) {
|
|
1050
|
+
ctx.io.err(line(`warning: ${secretValues.problem}`));
|
|
1051
|
+
}
|
|
1052
|
+
ctx.io.out(read.state === "absent"
|
|
1053
|
+
? line("settings file: none yet — run `clinkx settings import-clients --apply` first; no key is removable before import")
|
|
1054
|
+
: line(`settings file: revision ${String(read.revision)} (${resolution.dir}/settings.json)`));
|
|
1055
|
+
ctx.io.out(line("ClinkX never edits client config files — review and paste the trimmed entries yourself."));
|
|
1056
|
+
let anyRemovable = false;
|
|
1057
|
+
for (const entry of scan.entries) {
|
|
1058
|
+
const decisions = decideTrimForEntry(entry, read.values, secretValues.values, resolution.dir);
|
|
1059
|
+
ctx.io.out(line(""));
|
|
1060
|
+
ctx.io.out(line(`entry "${entry.name}" (${entry.location}):`));
|
|
1061
|
+
const removable = summarizeEnvNames(decisions, "removable");
|
|
1062
|
+
anyRemovable = anyRemovable || removable.length > 0;
|
|
1063
|
+
ctx.io.out(removable.length === 0
|
|
1064
|
+
? line(" removable: none yet")
|
|
1065
|
+
: line(` removable (the settings file now supplies the same value): ${removable.join(", ")}`));
|
|
1066
|
+
const dead = summarizeEnvNames(decisions, "removable_dead");
|
|
1067
|
+
if (dead.length > 0) {
|
|
1068
|
+
anyRemovable = anyRemovable || true;
|
|
1069
|
+
ctx.io.out(line(` removable (dead keys ClinkX ignores): ${dead.join(", ")}`));
|
|
1070
|
+
}
|
|
1071
|
+
const overrides = decisions.filter((decision) => decision.category === "override");
|
|
1072
|
+
if (overrides.length > 0) {
|
|
1073
|
+
for (const decision of overrides) {
|
|
1074
|
+
ctx.io.out(line(` keep as override: ${decision.envName} (${decision.note ?? "differs"})`));
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
const notInFile = summarizeEnvNames(decisions, "not_in_file");
|
|
1078
|
+
if (notInFile.length > 0) {
|
|
1079
|
+
ctx.io.out(line(` keep (not in the settings file; import first or keep as an explicit override): ${notInFile.join(", ")}`));
|
|
1080
|
+
}
|
|
1081
|
+
const envOnly = decisions.filter((decision) => decision.category === "env_only");
|
|
1082
|
+
for (const decision of envOnly) {
|
|
1083
|
+
ctx.io.out(line(` must stay (${decision.note === "ENV_ONLY" ? "env-only" : "deployment-only"}; the settings file cannot supply it): ${decision.envName}`));
|
|
1084
|
+
}
|
|
1085
|
+
// L6: name only — the value is the credential and never prints.
|
|
1086
|
+
for (const decision of decisions) {
|
|
1087
|
+
if (decision.category === "withheld_credential") {
|
|
1088
|
+
ctx.io.out(line(` keep (${WITHHELD_CREDENTIAL_NOTE}): ${decision.envName}`));
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
const unknown = summarizeEnvNames(decisions, "unknown");
|
|
1092
|
+
if (unknown.length > 0) {
|
|
1093
|
+
// R7: unknown CLINKX_* names get a nearest-registry-name suggestion so a
|
|
1094
|
+
// typo is visible at trim time; startup stays quiet.
|
|
1095
|
+
const renderedUnknown = unknown.map((envName) => {
|
|
1096
|
+
const suggestion = envName.startsWith("CLINKX_") ? nearestRegistryName(envName) : undefined;
|
|
1097
|
+
return suggestion === undefined ? envName : `${envName} (did you mean \`${suggestion}\`?)`;
|
|
1098
|
+
});
|
|
1099
|
+
ctx.io.out(line(` unknown keys (kept in the block below; review manually): ${renderedUnknown.join(", ")}`));
|
|
1100
|
+
}
|
|
1101
|
+
for (const decision of decisions) {
|
|
1102
|
+
if (decision.category === "secret_match") {
|
|
1103
|
+
ctx.io.out(line(` secret ${decision.envName}: matches the stored secret — the block below renders a sentinel; paste your existing value over it, or delete the entry to read it from secrets.json`));
|
|
1104
|
+
}
|
|
1105
|
+
else if (decision.category === "secret_differs") {
|
|
1106
|
+
ctx.io.out(line(` secret ${decision.envName}: differs from the stored secret (values withheld) — keep this entry's value; the block below renders a sentinel you must replace`));
|
|
1107
|
+
}
|
|
1108
|
+
else if (decision.category === "secret_not_stored") {
|
|
1109
|
+
ctx.io.out(line(` secret ${decision.envName}: not stored in secrets.json yet ("clinkx settings secret set ${decision.envName}" or import-clients --apply) — the block below renders a sentinel you must replace`));
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
ctx.io.out(line(""));
|
|
1113
|
+
ctx.io.out(line(`trimmed entry (${pasteTargetHint(entry)}):`));
|
|
1114
|
+
for (const blockLine of renderTrimmedBlock(entry, keptEnvForRender(entry, decisions)).split("\n")) {
|
|
1115
|
+
ctx.io.out(line(blockLine));
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
if (!anyRemovable) {
|
|
1119
|
+
ctx.io.out(line(""));
|
|
1120
|
+
ctx.io.out(line("note: nothing was removable yet — run `clinkx settings import-clients --apply` and re-run this report"));
|
|
1121
|
+
}
|
|
1122
|
+
return EXIT_OK;
|
|
1123
|
+
}
|
|
1124
|
+
//# sourceMappingURL=clients.js.map
|