@lifeaitools/clauth 1.5.82 → 1.5.83
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/.clauth-skill/SKILL.md +6 -5
- package/README.md +9 -5
- package/cli/commands/npm.js +123 -0
- package/cli/commands/serve.js +202 -33
- package/cli/index.js +134 -0
- package/package.json +1 -1
package/.clauth-skill/SKILL.md
CHANGED
|
@@ -141,11 +141,12 @@ See `references/keys-guide.md` for where to find every credential.
|
|
|
141
141
|
```
|
|
142
142
|
clauth install [--ref R] [--pat P] First-time: provision Supabase + install skill
|
|
143
143
|
clauth setup [--admin-token T] [-p P] Register this machine
|
|
144
|
-
clauth status [-p P] All services + state
|
|
145
|
-
clauth test [-p P] Verify HMAC connection
|
|
146
|
-
clauth list [-p P] Service names
|
|
147
|
-
|
|
148
|
-
|
|
144
|
+
clauth status [-p P] All services + state
|
|
145
|
+
clauth test [-p P] Verify HMAC connection
|
|
146
|
+
clauth list [-p P] Service names
|
|
147
|
+
clauth search <query> [-p P] Search names, metadata, and redacted server addresses
|
|
148
|
+
|
|
149
|
+
clauth write key <service> [-p P] Store a credential
|
|
149
150
|
clauth write pw [-p P] Change password
|
|
150
151
|
clauth enable <svc|all> [-p P] Activate service
|
|
151
152
|
clauth disable <svc|all> [-p P] Suspend service
|
package/README.md
CHANGED
|
@@ -72,16 +72,20 @@ clauth get github
|
|
|
72
72
|
```
|
|
73
73
|
clauth install Provision Supabase + install Claude skill
|
|
74
74
|
clauth setup Register this machine with the vault
|
|
75
|
-
clauth status All services + state
|
|
76
|
-
clauth
|
|
75
|
+
clauth status All services + state
|
|
76
|
+
clauth search <query> Find services by name, project, description, or redacted address
|
|
77
|
+
clauth test Verify connection
|
|
77
78
|
|
|
78
79
|
clauth write key <service> Store a credential
|
|
79
80
|
clauth write pw Change password
|
|
80
81
|
clauth enable <svc|all> Activate service
|
|
81
82
|
clauth disable <svc|all> Suspend service
|
|
82
|
-
clauth get <service> Retrieve a key
|
|
83
|
-
|
|
84
|
-
clauth
|
|
83
|
+
clauth get <service> Retrieve a key
|
|
84
|
+
clauth npm whoami Verify npm token without PowerShell secret plumbing
|
|
85
|
+
clauth npm sync-github-secret LIFEAI/rdc-skills
|
|
86
|
+
Update GitHub NPM_TOKEN from clauth
|
|
87
|
+
|
|
88
|
+
clauth add service <n> Register new service
|
|
85
89
|
clauth remove service <n> Remove service
|
|
86
90
|
clauth revoke <svc|all> Delete key (destructive)
|
|
87
91
|
```
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { spawnSync } from "child_process";
|
|
5
|
+
|
|
6
|
+
const CLAUTH_NPM_URL = "http://127.0.0.1:52437/v/npm";
|
|
7
|
+
|
|
8
|
+
function run(cmd, args, opts = {}) {
|
|
9
|
+
const useCmd = process.platform === "win32" && ["npm", "gh"].includes(cmd);
|
|
10
|
+
const executable = useCmd ? "cmd.exe" : cmd;
|
|
11
|
+
const finalArgs = useCmd ? ["/d", "/s", "/c", cmd, ...args] : args;
|
|
12
|
+
const result = spawnSync(executable, finalArgs, {
|
|
13
|
+
encoding: "utf8",
|
|
14
|
+
...opts,
|
|
15
|
+
env: { ...process.env, ...(opts.env || {}) }
|
|
16
|
+
});
|
|
17
|
+
if (result.error) throw result.error;
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function redactNpmTokenList(text) {
|
|
22
|
+
return String(text || "").replace(/npm_[A-Za-z0-9]+/g, token => `${token.slice(0, 9)}...${token.slice(-4)}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function fetchNpmToken() {
|
|
26
|
+
const response = await fetch(CLAUTH_NPM_URL);
|
|
27
|
+
if (!response.ok) throw new Error(`failed to fetch npm token from clauth daemon: HTTP ${response.status}`);
|
|
28
|
+
const token = (await response.text()).trim();
|
|
29
|
+
if (!token) throw new Error("clauth npm token is empty");
|
|
30
|
+
if (!token.startsWith("npm_")) throw new Error("clauth npm token does not look like an npm token");
|
|
31
|
+
return token;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function withNpmAuth(token, fn) {
|
|
35
|
+
const npmrc = path.join(os.tmpdir(), `clauth-npm-${process.pid}-${Date.now()}.npmrc`);
|
|
36
|
+
try {
|
|
37
|
+
fs.writeFileSync(npmrc, `//registry.npmjs.org/:_authToken=${token}`, { encoding: "utf8", mode: 0o600 });
|
|
38
|
+
return fn(npmrc);
|
|
39
|
+
} finally {
|
|
40
|
+
try { fs.rmSync(npmrc, { force: true }); } catch {}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function runNpmWithToken(token, args) {
|
|
45
|
+
return withNpmAuth(token, npmrc => run("npm", ["--userconfig", npmrc, ...args]));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function printResult(result, { redact = true } = {}) {
|
|
49
|
+
const stdout = redact ? redactNpmTokenList(result.stdout) : result.stdout;
|
|
50
|
+
const stderr = redact ? redactNpmTokenList(result.stderr) : result.stderr;
|
|
51
|
+
if (stdout) process.stdout.write(stdout);
|
|
52
|
+
if (stderr) process.stderr.write(stderr);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function usage() {
|
|
56
|
+
console.log(`clauth npm <action>
|
|
57
|
+
|
|
58
|
+
Actions:
|
|
59
|
+
whoami Verify the clauth npm token identity
|
|
60
|
+
tokens List npm token metadata with token strings redacted
|
|
61
|
+
set-local Write the clauth npm token to the user npm config
|
|
62
|
+
sync-github-secret <repo> Set repo secret NPM_TOKEN from clauth, e.g. LIFEAI/rdc-skills
|
|
63
|
+
rerun <run-id> --repo <repo> Rerun a failed GitHub Actions workflow
|
|
64
|
+
`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function runNpm(action = "help", opts = {}) {
|
|
68
|
+
if (action === "help") {
|
|
69
|
+
usage();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const token = await fetchNpmToken();
|
|
74
|
+
|
|
75
|
+
if (action === "whoami") {
|
|
76
|
+
const result = runNpmWithToken(token, ["whoami", "--registry=https://registry.npmjs.org/"]);
|
|
77
|
+
printResult(result);
|
|
78
|
+
if (result.status !== 0) process.exitCode = result.status;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (action === "tokens") {
|
|
83
|
+
const result = runNpmWithToken(token, ["token", "list", "--json", "--registry=https://registry.npmjs.org/"]);
|
|
84
|
+
printResult(result);
|
|
85
|
+
if (result.status !== 0) process.exitCode = result.status;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (action === "set-local") {
|
|
90
|
+
const result = run("npm", ["config", "set", "//registry.npmjs.org/:_authToken", token, "--location=user"]);
|
|
91
|
+
if (result.status !== 0) {
|
|
92
|
+
printResult(result);
|
|
93
|
+
process.exitCode = result.status;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
console.log("local npm auth updated from clauth service 'npm'");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (action === "sync-github-secret") {
|
|
101
|
+
const repo = opts.repo || opts.args?.[0];
|
|
102
|
+
if (!repo) throw new Error("repo is required, e.g. clauth npm sync-github-secret LIFEAI/rdc-skills");
|
|
103
|
+
const result = run("gh", ["secret", "set", "NPM_TOKEN", "--repo", repo], { input: token });
|
|
104
|
+
printResult(result);
|
|
105
|
+
if (result.status !== 0) process.exitCode = result.status;
|
|
106
|
+
else console.log(`GitHub secret NPM_TOKEN updated for ${repo}`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (action === "rerun") {
|
|
111
|
+
const runId = opts.args?.[0];
|
|
112
|
+
const repo = opts.repo;
|
|
113
|
+
if (!runId || !repo) throw new Error("usage: clauth npm rerun <run-id> --repo LIFEAI/rdc-skills");
|
|
114
|
+
const result = run("gh", ["run", "rerun", runId, "--repo", repo, "--failed"]);
|
|
115
|
+
printResult(result);
|
|
116
|
+
if (result.status !== 0) process.exitCode = result.status;
|
|
117
|
+
else console.log(`rerun requested for ${repo} run ${runId}`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
usage();
|
|
122
|
+
throw new Error(`unknown clauth npm action: ${action}`);
|
|
123
|
+
}
|
package/cli/commands/serve.js
CHANGED
|
@@ -5076,8 +5076,8 @@ function createServer(initPassword, whitelist, port, tunnelHostnameInit = null,
|
|
|
5076
5076
|
}
|
|
5077
5077
|
|
|
5078
5078
|
// POST /update-service — update service metadata (project, label, description)
|
|
5079
|
-
if (method === "POST" && reqPath === "/update-service") {
|
|
5080
|
-
if (lockedGuard(res)) return;
|
|
5079
|
+
if (method === "POST" && reqPath === "/update-service") {
|
|
5080
|
+
if (lockedGuard(res)) return;
|
|
5081
5081
|
|
|
5082
5082
|
let body;
|
|
5083
5083
|
try { body = await readBody(req); } catch {
|
|
@@ -5108,10 +5108,39 @@ function createServer(initPassword, whitelist, port, tunnelHostnameInit = null,
|
|
|
5108
5108
|
return ok(res, { ok: true, service: service.toLowerCase(), ...updates });
|
|
5109
5109
|
} catch (err) {
|
|
5110
5110
|
return strike(res, 502, err.message);
|
|
5111
|
-
}
|
|
5112
|
-
}
|
|
5113
|
-
|
|
5114
|
-
|
|
5111
|
+
}
|
|
5112
|
+
}
|
|
5113
|
+
|
|
5114
|
+
if (method === "GET" && reqPath === "/search") {
|
|
5115
|
+
if (lockedGuard(res)) return;
|
|
5116
|
+
const query = (url.searchParams.get("q") || url.searchParams.get("query") || "").trim();
|
|
5117
|
+
const project = (url.searchParams.get("project") || "").trim() || undefined;
|
|
5118
|
+
const includeAddresses = url.searchParams.get("addresses") !== "false";
|
|
5119
|
+
if (!query) {
|
|
5120
|
+
res.writeHead(400, { "Content-Type": "application/json", ...CORS });
|
|
5121
|
+
return res.end(JSON.stringify({ error: "q query parameter is required" }));
|
|
5122
|
+
}
|
|
5123
|
+
|
|
5124
|
+
try {
|
|
5125
|
+
const { token, timestamp } = deriveToken(password, machineHash);
|
|
5126
|
+
const result = await searchServices({
|
|
5127
|
+
password,
|
|
5128
|
+
machineHash,
|
|
5129
|
+
token,
|
|
5130
|
+
timestamp,
|
|
5131
|
+
project,
|
|
5132
|
+
query,
|
|
5133
|
+
includeAddresses,
|
|
5134
|
+
whitelist
|
|
5135
|
+
});
|
|
5136
|
+
if (result.error) return strike(res, 502, result.error);
|
|
5137
|
+
return ok(res, result);
|
|
5138
|
+
} catch (err) {
|
|
5139
|
+
return strike(res, 502, err.message);
|
|
5140
|
+
}
|
|
5141
|
+
}
|
|
5142
|
+
|
|
5143
|
+
// Unknown route — a wrong URL is not an auth failure. Log it, return 404,
|
|
5115
5144
|
// but do NOT increment failCount (which locks the vault at MAX_FAILS).
|
|
5116
5145
|
// Auth failures (wrong password, wrong token) still strike via /auth and /get/:service.
|
|
5117
5146
|
try {
|
|
@@ -6086,9 +6115,9 @@ function stopCodevelopSession(session_id) {
|
|
|
6086
6115
|
return { stopped: true, session_id };
|
|
6087
6116
|
}
|
|
6088
6117
|
|
|
6089
|
-
const ENV_MAP = {
|
|
6090
|
-
"github": "GITHUB_TOKEN",
|
|
6091
|
-
"supabase-anon": "NEXT_PUBLIC_SUPABASE_ANON_KEY",
|
|
6118
|
+
const ENV_MAP = {
|
|
6119
|
+
"github": "GITHUB_TOKEN",
|
|
6120
|
+
"supabase-anon": "NEXT_PUBLIC_SUPABASE_ANON_KEY",
|
|
6092
6121
|
"supabase-service": "SUPABASE_SERVICE_ROLE_KEY",
|
|
6093
6122
|
"supabase-db": "SUPABASE_DB_URL",
|
|
6094
6123
|
"vercel": "VERCEL_TOKEN",
|
|
@@ -6100,11 +6129,116 @@ const ENV_MAP = {
|
|
|
6100
6129
|
"rocketreach": "ROCKETREACH_API_KEY",
|
|
6101
6130
|
"npm": "NPM_TOKEN",
|
|
6102
6131
|
"namecheap": "NAMECHEAP_API_KEY",
|
|
6103
|
-
"gmail": "GMAIL_CREDENTIALS",
|
|
6104
|
-
};
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6132
|
+
"gmail": "GMAIL_CREDENTIALS",
|
|
6133
|
+
};
|
|
6134
|
+
|
|
6135
|
+
const ADDRESS_KEY_TYPES = new Set(["connstring", "fileserver", "oauth"]);
|
|
6136
|
+
const ADDRESS_FIELDS = new Set(["url", "uri", "host", "hostname", "server", "address", "base_url", "endpoint", "path", "root"]);
|
|
6137
|
+
|
|
6138
|
+
function normalizeSearchText(value) {
|
|
6139
|
+
return String(value || "").toLowerCase();
|
|
6140
|
+
}
|
|
6141
|
+
|
|
6142
|
+
function redactUrlish(value) {
|
|
6143
|
+
const text = String(value || "").trim();
|
|
6144
|
+
if (!text) return "";
|
|
6145
|
+
try {
|
|
6146
|
+
const url = new URL(text);
|
|
6147
|
+
if (url.username) url.username = "***";
|
|
6148
|
+
if (url.password) url.password = "***";
|
|
6149
|
+
return url.toString();
|
|
6150
|
+
} catch {
|
|
6151
|
+
return text.replace(/:\/\/([^:@/\s]+):([^@/\s]+)@/g, "://***:***@");
|
|
6152
|
+
}
|
|
6153
|
+
}
|
|
6154
|
+
|
|
6155
|
+
function collectAddressHints(value, keyType) {
|
|
6156
|
+
if (!ADDRESS_KEY_TYPES.has(String(keyType || "").toLowerCase())) return [];
|
|
6157
|
+
const hints = new Set();
|
|
6158
|
+
|
|
6159
|
+
function add(candidate) {
|
|
6160
|
+
if (candidate === undefined || candidate === null) return;
|
|
6161
|
+
const text = redactUrlish(candidate);
|
|
6162
|
+
if (text) hints.add(text);
|
|
6163
|
+
}
|
|
6164
|
+
|
|
6165
|
+
function walk(node, fieldName = "") {
|
|
6166
|
+
if (node === undefined || node === null) return;
|
|
6167
|
+
if (typeof node === "string") {
|
|
6168
|
+
if (fieldName && ADDRESS_FIELDS.has(fieldName.toLowerCase())) add(node);
|
|
6169
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(node) || /^[A-Za-z]:[\\/]/.test(node) || node.startsWith("\\\\")) add(node);
|
|
6170
|
+
return;
|
|
6171
|
+
}
|
|
6172
|
+
if (Array.isArray(node)) {
|
|
6173
|
+
for (const item of node) walk(item, fieldName);
|
|
6174
|
+
return;
|
|
6175
|
+
}
|
|
6176
|
+
if (typeof node === "object") {
|
|
6177
|
+
for (const [key, child] of Object.entries(node)) walk(child, key);
|
|
6178
|
+
}
|
|
6179
|
+
}
|
|
6180
|
+
|
|
6181
|
+
try {
|
|
6182
|
+
walk(JSON.parse(value));
|
|
6183
|
+
} catch {
|
|
6184
|
+
walk(value);
|
|
6185
|
+
}
|
|
6186
|
+
|
|
6187
|
+
return [...hints];
|
|
6188
|
+
}
|
|
6189
|
+
|
|
6190
|
+
async function searchServices({ password, machineHash, token, timestamp, query, project, includeAddresses = true, whitelist }) {
|
|
6191
|
+
const q = normalizeSearchText(query);
|
|
6192
|
+
if (!q) return { error: "query is required" };
|
|
6193
|
+
|
|
6194
|
+
const result = await api.status(password, machineHash, token, timestamp, project);
|
|
6195
|
+
if (result.error) return { error: result.error };
|
|
6196
|
+
|
|
6197
|
+
let services = result.services || [];
|
|
6198
|
+
if (whitelist) services = services.filter(s => whitelist.includes(String(s.name || "").toLowerCase()));
|
|
6199
|
+
|
|
6200
|
+
const matches = [];
|
|
6201
|
+
for (const s of services) {
|
|
6202
|
+
const fields = {
|
|
6203
|
+
name: s.name,
|
|
6204
|
+
label: s.label,
|
|
6205
|
+
project: s.project,
|
|
6206
|
+
type: s.key_type,
|
|
6207
|
+
description: s.description
|
|
6208
|
+
};
|
|
6209
|
+
const matched = Object.entries(fields)
|
|
6210
|
+
.filter(([, value]) => normalizeSearchText(value).includes(q))
|
|
6211
|
+
.map(([field]) => field);
|
|
6212
|
+
|
|
6213
|
+
let addressHints = [];
|
|
6214
|
+
if (includeAddresses && ADDRESS_KEY_TYPES.has(String(s.key_type || "").toLowerCase()) && s.vault_key) {
|
|
6215
|
+
const secret = await api.retrieve(password, machineHash, token, timestamp, s.name);
|
|
6216
|
+
if (!secret.error) {
|
|
6217
|
+
addressHints = collectAddressHints(secret.value, s.key_type);
|
|
6218
|
+
if (addressHints.some(h => normalizeSearchText(h).includes(q))) matched.push("address");
|
|
6219
|
+
}
|
|
6220
|
+
}
|
|
6221
|
+
|
|
6222
|
+
if (matched.length) {
|
|
6223
|
+
matches.push({
|
|
6224
|
+
name: s.name,
|
|
6225
|
+
label: s.label || null,
|
|
6226
|
+
project: s.project || null,
|
|
6227
|
+
key_type: s.key_type,
|
|
6228
|
+
enabled: !!s.enabled,
|
|
6229
|
+
has_key: !!s.vault_key,
|
|
6230
|
+
description: s.description || null,
|
|
6231
|
+
matched: [...new Set(matched)],
|
|
6232
|
+
address_hints: addressHints
|
|
6233
|
+
});
|
|
6234
|
+
}
|
|
6235
|
+
}
|
|
6236
|
+
|
|
6237
|
+
return { query, count: matches.length, matches };
|
|
6238
|
+
}
|
|
6239
|
+
|
|
6240
|
+
// ── Filesystem service config — loaded from clauth vault ──
|
|
6241
|
+
let _fsMountsCache = null;
|
|
6108
6242
|
let _fsMountsCacheTime = 0;
|
|
6109
6243
|
const FS_CACHE_TTL = 60000; // 1 minute
|
|
6110
6244
|
|
|
@@ -6269,14 +6403,28 @@ const MCP_TOOLS = [
|
|
|
6269
6403
|
description: "List all services with type, enabled state, key presence, and last retrieval time",
|
|
6270
6404
|
inputSchema: { type: "object", properties: {}, additionalProperties: false }
|
|
6271
6405
|
},
|
|
6272
|
-
{
|
|
6273
|
-
name: "clauth_list",
|
|
6274
|
-
description: "List registered service names",
|
|
6275
|
-
inputSchema: { type: "object", properties: {}, additionalProperties: false }
|
|
6276
|
-
},
|
|
6277
|
-
{
|
|
6278
|
-
name: "
|
|
6279
|
-
description: "
|
|
6406
|
+
{
|
|
6407
|
+
name: "clauth_list",
|
|
6408
|
+
description: "List registered service names",
|
|
6409
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false }
|
|
6410
|
+
},
|
|
6411
|
+
{
|
|
6412
|
+
name: "clauth_search",
|
|
6413
|
+
description: "Search registered services by name, label, project, description, type, or redacted address hints from address-bearing secrets",
|
|
6414
|
+
inputSchema: {
|
|
6415
|
+
type: "object",
|
|
6416
|
+
properties: {
|
|
6417
|
+
query: { type: "string", description: "Search text, such as part of a service name, project, host, URL, or filesystem path" },
|
|
6418
|
+
project: { type: "string", description: "Optional project scope" },
|
|
6419
|
+
addresses: { type: "boolean", default: true, description: "Include redacted address hints from connstring/fileserver/oauth secrets" }
|
|
6420
|
+
},
|
|
6421
|
+
required: ["query"],
|
|
6422
|
+
additionalProperties: false
|
|
6423
|
+
}
|
|
6424
|
+
},
|
|
6425
|
+
{
|
|
6426
|
+
name: "clauth_get",
|
|
6427
|
+
description: "Retrieve a secret and deliver to a temp file (default), clipboard, or stdout. Temp files auto-delete after 30 seconds.",
|
|
6280
6428
|
inputSchema: {
|
|
6281
6429
|
type: "object",
|
|
6282
6430
|
properties: {
|
|
@@ -6993,10 +7141,10 @@ async function handleMcpTool(vault, name, args) {
|
|
|
6993
7141
|
}
|
|
6994
7142
|
}
|
|
6995
7143
|
|
|
6996
|
-
case "clauth_list": {
|
|
6997
|
-
if (!vault.password) return mcpError("Vault is locked — call clauth_unlock first");
|
|
6998
|
-
try {
|
|
6999
|
-
const { token, timestamp } = deriveToken(vault.password, vault.machineHash);
|
|
7144
|
+
case "clauth_list": {
|
|
7145
|
+
if (!vault.password) return mcpError("Vault is locked — call clauth_unlock first");
|
|
7146
|
+
try {
|
|
7147
|
+
const { token, timestamp } = deriveToken(vault.password, vault.machineHash);
|
|
7000
7148
|
const result = await api.status(vault.password, vault.machineHash, token, timestamp);
|
|
7001
7149
|
if (result.error) return mcpError(result.error);
|
|
7002
7150
|
let services = result.services || [];
|
|
@@ -7005,13 +7153,34 @@ async function handleMcpTool(vault, name, args) {
|
|
|
7005
7153
|
}
|
|
7006
7154
|
return mcpResult(services.map(s => s.name).join(", "));
|
|
7007
7155
|
} catch (err) {
|
|
7008
|
-
return mcpError(err.message);
|
|
7009
|
-
}
|
|
7010
|
-
}
|
|
7011
|
-
|
|
7012
|
-
case "
|
|
7013
|
-
if (!vault.password) return mcpError("Vault is locked — call clauth_unlock first");
|
|
7014
|
-
|
|
7156
|
+
return mcpError(err.message);
|
|
7157
|
+
}
|
|
7158
|
+
}
|
|
7159
|
+
|
|
7160
|
+
case "clauth_search": {
|
|
7161
|
+
if (!vault.password) return mcpError("Vault is locked — call clauth_unlock first");
|
|
7162
|
+
try {
|
|
7163
|
+
const { token, timestamp } = deriveToken(vault.password, vault.machineHash);
|
|
7164
|
+
const result = await searchServices({
|
|
7165
|
+
password: vault.password,
|
|
7166
|
+
machineHash: vault.machineHash,
|
|
7167
|
+
token,
|
|
7168
|
+
timestamp,
|
|
7169
|
+
query: args.query,
|
|
7170
|
+
project: args.project,
|
|
7171
|
+
includeAddresses: args.addresses !== false,
|
|
7172
|
+
whitelist: vault.whitelist
|
|
7173
|
+
});
|
|
7174
|
+
if (result.error) return mcpError(result.error);
|
|
7175
|
+
return mcpResult(JSON.stringify(result, null, 2));
|
|
7176
|
+
} catch (err) {
|
|
7177
|
+
return mcpError(err.message);
|
|
7178
|
+
}
|
|
7179
|
+
}
|
|
7180
|
+
|
|
7181
|
+
case "clauth_get": {
|
|
7182
|
+
if (!vault.password) return mcpError("Vault is locked — call clauth_unlock first");
|
|
7183
|
+
const service = (args.service || "").toLowerCase();
|
|
7015
7184
|
const target = args.target || "file";
|
|
7016
7185
|
if (!service) return mcpError("service is required");
|
|
7017
7186
|
if (vault.whitelist && !vault.whitelist.includes(service)) {
|
package/cli/index.js
CHANGED
|
@@ -40,6 +40,97 @@ async function getAuth(pw) {
|
|
|
40
40
|
return { password, machineHash, token, timestamp };
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
const ADDRESS_KEY_TYPES = new Set(["connstring", "fileserver", "oauth"]);
|
|
44
|
+
const ADDRESS_FIELDS = new Set(["url", "uri", "host", "hostname", "server", "address", "base_url", "endpoint", "path", "root"]);
|
|
45
|
+
|
|
46
|
+
function normalizeSearchText(value) {
|
|
47
|
+
return String(value || "").toLowerCase();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function redactUrlish(value) {
|
|
51
|
+
const text = String(value || "").trim();
|
|
52
|
+
if (!text) return "";
|
|
53
|
+
try {
|
|
54
|
+
const url = new URL(text);
|
|
55
|
+
if (url.username) url.username = "***";
|
|
56
|
+
if (url.password) url.password = "***";
|
|
57
|
+
return url.toString();
|
|
58
|
+
} catch {
|
|
59
|
+
return text.replace(/:\/\/([^:@/\s]+):([^@/\s]+)@/g, "://***:***@");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function collectAddressHints(value, keyType) {
|
|
64
|
+
if (!ADDRESS_KEY_TYPES.has(String(keyType || "").toLowerCase())) return [];
|
|
65
|
+
const hints = new Set();
|
|
66
|
+
|
|
67
|
+
function add(candidate) {
|
|
68
|
+
if (candidate === undefined || candidate === null) return;
|
|
69
|
+
const text = redactUrlish(candidate);
|
|
70
|
+
if (text) hints.add(text);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function walk(node, fieldName = "") {
|
|
74
|
+
if (node === undefined || node === null) return;
|
|
75
|
+
if (typeof node === "string") {
|
|
76
|
+
if (fieldName && ADDRESS_FIELDS.has(fieldName.toLowerCase())) add(node);
|
|
77
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(node) || /^[A-Za-z]:[\\/]/.test(node) || node.startsWith("\\\\")) add(node);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (Array.isArray(node)) {
|
|
81
|
+
for (const item of node) walk(item, fieldName);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (typeof node === "object") {
|
|
85
|
+
for (const [key, child] of Object.entries(node)) walk(child, key);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
walk(JSON.parse(value));
|
|
91
|
+
} catch {
|
|
92
|
+
walk(value);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return [...hints];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function searchServices(auth, query, opts = {}) {
|
|
99
|
+
const q = normalizeSearchText(query);
|
|
100
|
+
if (!q) throw new Error("Search query is required");
|
|
101
|
+
const result = await api.status(auth.password, auth.machineHash, auth.token, auth.timestamp, opts.project);
|
|
102
|
+
if (result.error) throw new Error(result.error);
|
|
103
|
+
|
|
104
|
+
const services = result.services || [];
|
|
105
|
+
const rows = [];
|
|
106
|
+
|
|
107
|
+
for (const s of services) {
|
|
108
|
+
const fields = {
|
|
109
|
+
name: s.name,
|
|
110
|
+
label: s.label,
|
|
111
|
+
project: s.project,
|
|
112
|
+
type: s.key_type,
|
|
113
|
+
description: s.description
|
|
114
|
+
};
|
|
115
|
+
const matched = Object.entries(fields)
|
|
116
|
+
.filter(([, value]) => normalizeSearchText(value).includes(q))
|
|
117
|
+
.map(([field]) => field);
|
|
118
|
+
|
|
119
|
+
let addressHints = [];
|
|
120
|
+
if (opts.addresses !== false && ADDRESS_KEY_TYPES.has(String(s.key_type || "").toLowerCase()) && s.vault_key) {
|
|
121
|
+
const secret = await api.retrieve(auth.password, auth.machineHash, auth.token, auth.timestamp, s.name);
|
|
122
|
+
if (!secret.error) {
|
|
123
|
+
addressHints = collectAddressHints(secret.value, s.key_type);
|
|
124
|
+
if (addressHints.some(h => normalizeSearchText(h).includes(q))) matched.push("address");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (matched.length) rows.push({ ...s, matched: [...new Set(matched)], addressHints });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return rows;
|
|
132
|
+
}
|
|
133
|
+
|
|
43
134
|
// ============================================================
|
|
44
135
|
// Program
|
|
45
136
|
// ============================================================
|
|
@@ -58,6 +149,7 @@ import { runUninstall } from './commands/uninstall.js';
|
|
|
58
149
|
import { runScrub } from './commands/scrub.js';
|
|
59
150
|
import { runServe } from './commands/serve.js';
|
|
60
151
|
import { runCodevelop } from './commands/codevelop.js';
|
|
152
|
+
import { runNpm } from './commands/npm.js';
|
|
61
153
|
|
|
62
154
|
program
|
|
63
155
|
.command('install')
|
|
@@ -126,6 +218,16 @@ program
|
|
|
126
218
|
await runCodevelop({ ...opts, action });
|
|
127
219
|
});
|
|
128
220
|
|
|
221
|
+
program
|
|
222
|
+
.command("npm")
|
|
223
|
+
.description("Operate npm auth safely through the clauth npm service")
|
|
224
|
+
.argument("[action]", "whoami | tokens | set-local | sync-github-secret | rerun | help", "help")
|
|
225
|
+
.argument("[args...]", "Action arguments")
|
|
226
|
+
.option("--repo <repo>", "GitHub repo, e.g. LIFEAI/rdc-skills")
|
|
227
|
+
.action(async (action, args, opts) => {
|
|
228
|
+
await runNpm(action, { ...opts, args });
|
|
229
|
+
});
|
|
230
|
+
|
|
129
231
|
// ──────────────────────────────────────────────
|
|
130
232
|
// clauth setup
|
|
131
233
|
// ──────────────────────────────────────────────
|
|
@@ -410,6 +512,38 @@ program
|
|
|
410
512
|
console.log();
|
|
411
513
|
});
|
|
412
514
|
|
|
515
|
+
program
|
|
516
|
+
.command("search <query>")
|
|
517
|
+
.description("Search services by name, label, project, description, type, or redacted address hints")
|
|
518
|
+
.option("-p, --pw <password>")
|
|
519
|
+
.option("--project <name>", "Filter by project scope")
|
|
520
|
+
.option("--no-addresses", "Skip address-bearing secret metadata scans")
|
|
521
|
+
.action(async (query, opts) => {
|
|
522
|
+
const auth = await getAuth(opts.pw);
|
|
523
|
+
const spinner = ora("Searching services...").start();
|
|
524
|
+
try {
|
|
525
|
+
const rows = await searchServices(auth, query, { project: opts.project, addresses: opts.addresses });
|
|
526
|
+
spinner.stop();
|
|
527
|
+
console.log(chalk.cyan(`\n Search results for "${query}":\n`));
|
|
528
|
+
if (!rows.length) {
|
|
529
|
+
console.log(chalk.gray(" No matching services found.\n"));
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
console.log(chalk.bold(" " + "SERVICE".padEnd(24) + "TYPE".padEnd(12) + "PROJECT".padEnd(20) + "MATCHED"));
|
|
533
|
+
console.log(" " + "─".repeat(78));
|
|
534
|
+
for (const s of rows) {
|
|
535
|
+
const project = s.project || "global";
|
|
536
|
+
console.log(` ${chalk.bold(s.name.padEnd(24))}${String(s.key_type || "").padEnd(12)}${project.padEnd(20)}${s.matched.join(", ")}`);
|
|
537
|
+
if (s.label) console.log(chalk.gray(` label: ${s.label}`));
|
|
538
|
+
if (s.description) console.log(chalk.gray(` description: ${s.description}`));
|
|
539
|
+
for (const hint of s.addressHints || []) console.log(chalk.gray(` address: ${hint}`));
|
|
540
|
+
}
|
|
541
|
+
console.log();
|
|
542
|
+
} catch (err) {
|
|
543
|
+
spinner.fail(chalk.red(err.message));
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
|
|
413
547
|
// ──────────────────────────────────────────────
|
|
414
548
|
// clauth test <service|all>
|
|
415
549
|
// ──────────────────────────────────────────────
|