@tankpkg/cli 0.0.0-nightly.20260428.ca481a8 → 0.0.0-nightly.20260429.a158e1d
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/bin/tank.js +413 -56
- package/dist/bin/tank.js.map +1 -1
- package/dist/{debug-logger-GawTDEGi.js → debug-logger-D21HW6qo.js} +2 -2
- package/dist/{debug-logger-GawTDEGi.js.map → debug-logger-D21HW6qo.js.map} +1 -1
- package/dist/index.js +1 -1
- package/dist/package.json +2 -1
- package/dist/proxy-download-ml-DUk7ehNs.js +39 -0
- package/dist/proxy-download-ml-DUk7ehNs.js.map +1 -0
- package/dist/proxy-remote-CCemokkz.js +44 -0
- package/dist/proxy-remote-CCemokkz.js.map +1 -0
- package/dist/proxy-reset-pins-CfEbaL-F.js +28 -0
- package/dist/proxy-reset-pins-CfEbaL-F.js.map +1 -0
- package/package.json +2 -1
package/dist/bin/tank.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as VERSION, i as USER_AGENT, l as setConfig, n as flushLogs, o as getConfig, s as getConfigDir, t as authFlowLog } from "../debug-logger-
|
|
2
|
+
import { a as VERSION, i as USER_AGENT, l as setConfig, n as flushLogs, o as getConfig, s as getConfigDir, t as authFlowLog } from "../debug-logger-D21HW6qo.js";
|
|
3
3
|
import { t as logger } from "../logger-BhULz3Uz.js";
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
import chalk from "chalk";
|
|
@@ -12,9 +12,9 @@ import ora from "ora";
|
|
|
12
12
|
import { confirm, input } from "@inquirer/prompts";
|
|
13
13
|
import { execSync, spawn } from "node:child_process";
|
|
14
14
|
import crypto$1 from "node:crypto";
|
|
15
|
+
import { mkdir, mkdtemp, rm, stat } from "node:fs/promises";
|
|
15
16
|
import { buildSkillKey, checkPermissionBudget, downloadAllParallel, extractSafely, getExtractDir as getExtractDir$1, getGlobalExtractDir, getResolvedNodesInOrder, parseLockKey as parseLockKey$2, parseVersionFromLockKey, readExtractedDependencies, resolveDependencyTree, verifyExtractedDependencies, writeLockfileWithResolvedGraph } from "@tankpkg/sdk";
|
|
16
17
|
import { createInterface } from "node:readline";
|
|
17
|
-
import { mkdir, mkdtemp, rm, stat } from "node:fs/promises";
|
|
18
18
|
import { Readable } from "node:stream";
|
|
19
19
|
import { pipeline } from "node:stream/promises";
|
|
20
20
|
import open from "open";
|
|
@@ -301,6 +301,35 @@ const packageIRSchema = z.object({
|
|
|
301
301
|
visibility: z.enum(["public", "private"]).optional(),
|
|
302
302
|
audit: z.object({ min_score: z.number().min(0).max(10) }).strict().optional()
|
|
303
303
|
}).strict();
|
|
304
|
+
const commandSchema = z.string().min(1, "command must not be empty");
|
|
305
|
+
const argSchema = z.array(z.string()).default([]);
|
|
306
|
+
const envSchema = z.record(z.string(), z.string()).optional();
|
|
307
|
+
const remoteUrlSchema = z.string().url("remote must be a valid URL");
|
|
308
|
+
const localMcpServerSchema = z.object({
|
|
309
|
+
command: commandSchema,
|
|
310
|
+
args: argSchema,
|
|
311
|
+
env: envSchema,
|
|
312
|
+
requires_auth: z.literal(false).optional()
|
|
313
|
+
}).strict();
|
|
314
|
+
const remoteMcpServerSchema = z.object({
|
|
315
|
+
remote: remoteUrlSchema,
|
|
316
|
+
requires_auth: z.boolean().default(false),
|
|
317
|
+
env: envSchema
|
|
318
|
+
}).strict();
|
|
319
|
+
const mcpServerSchema = z.union([localMcpServerSchema, remoteMcpServerSchema]);
|
|
320
|
+
function isRemoteMcpServer(server) {
|
|
321
|
+
return "remote" in server;
|
|
322
|
+
}
|
|
323
|
+
const perToolOverrideSchema = z.object({
|
|
324
|
+
scan: z.boolean().optional(),
|
|
325
|
+
blockOnMatch: z.boolean().optional()
|
|
326
|
+
}).strict();
|
|
327
|
+
z.object({
|
|
328
|
+
perfBudgetMs: z.number().positive().optional(),
|
|
329
|
+
blockOnMatch: z.boolean().optional(),
|
|
330
|
+
resetPinsOnMismatch: z.boolean().optional(),
|
|
331
|
+
perTool: z.record(z.string(), perToolOverrideSchema).optional()
|
|
332
|
+
}).strict();
|
|
304
333
|
const baseManifestFields = {
|
|
305
334
|
name: z.string().min(1, "Name must not be empty").max(214, `Name must be 214 characters or fewer`).regex(/^@[a-z0-9-]+\/[a-z0-9][a-z0-9-]*$/, "Name must be scoped (@org/name), lowercase alphanumeric and hyphens"),
|
|
306
335
|
version: z.string().regex(/^\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$/, "Version must be valid semver"),
|
|
@@ -309,7 +338,8 @@ const baseManifestFields = {
|
|
|
309
338
|
permissions: permissionsSchema.optional(),
|
|
310
339
|
repository: z.string().url("Repository must be a valid URL").optional(),
|
|
311
340
|
visibility: z.enum(["public", "private"]).optional(),
|
|
312
|
-
audit: z.object({ min_score: z.number().min(0).max(10) }).strict().optional()
|
|
341
|
+
audit: z.object({ min_score: z.number().min(0).max(10) }).strict().optional(),
|
|
342
|
+
mcp_server: mcpServerSchema.optional()
|
|
313
343
|
};
|
|
314
344
|
/** Legacy skills.json schema — strict, no atoms. Used for backward-compatible consumers. */
|
|
315
345
|
const skillsJsonSchema = z.object(baseManifestFields).strict();
|
|
@@ -2705,6 +2735,8 @@ async function initCommand(options = {}) {
|
|
|
2705
2735
|
}
|
|
2706
2736
|
//#endregion
|
|
2707
2737
|
//#region ../internals-helpers/dist/index.js
|
|
2738
|
+
const ALPHANUMERIC = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
2739
|
+
`${ALPHANUMERIC}`, `${ALPHANUMERIC}`, `${ALPHANUMERIC}`, `${ALPHANUMERIC}`;
|
|
2708
2740
|
function resolve(range, versions) {
|
|
2709
2741
|
try {
|
|
2710
2742
|
if (!range || !semver.validRange(range)) return null;
|
|
@@ -2716,6 +2748,196 @@ function resolve(range, versions) {
|
|
|
2716
2748
|
}
|
|
2717
2749
|
}
|
|
2718
2750
|
//#endregion
|
|
2751
|
+
//#region src/lib/adapter-rewriter.ts
|
|
2752
|
+
const DEFAULT_TANK_BINARY = "tank";
|
|
2753
|
+
const AUTH_ENV_VAR_PREFIX = "TANK_MCP_AUTH_";
|
|
2754
|
+
const AUTH_PLACEHOLDER_VALUE = "<agent-config-resolves-this>";
|
|
2755
|
+
function deriveAuthEnvVarName(skillName) {
|
|
2756
|
+
const lastSlash = skillName.lastIndexOf("/");
|
|
2757
|
+
return `${AUTH_ENV_VAR_PREFIX}${(lastSlash === -1 ? skillName : skillName.slice(lastSlash + 1)).replace(/[^A-Za-z0-9]+/g, "_").replace(/^_+|_+$/g, "").toUpperCase()}`;
|
|
2758
|
+
}
|
|
2759
|
+
function passthroughEntry(server) {
|
|
2760
|
+
if (isRemoteMcpServer(server)) throw new Error("adapter-rewriter: remote MCP servers cannot opt out (proxy transport is mandatory for remote)");
|
|
2761
|
+
const entry = {
|
|
2762
|
+
command: server.command,
|
|
2763
|
+
args: [...server.args]
|
|
2764
|
+
};
|
|
2765
|
+
if (server.env) entry.env = { ...server.env };
|
|
2766
|
+
return entry;
|
|
2767
|
+
}
|
|
2768
|
+
function wrapLocal(server, binary) {
|
|
2769
|
+
const entry = {
|
|
2770
|
+
command: binary,
|
|
2771
|
+
args: [
|
|
2772
|
+
"proxy",
|
|
2773
|
+
"--",
|
|
2774
|
+
server.command,
|
|
2775
|
+
...server.args
|
|
2776
|
+
]
|
|
2777
|
+
};
|
|
2778
|
+
if (server.env) entry.env = { ...server.env };
|
|
2779
|
+
return entry;
|
|
2780
|
+
}
|
|
2781
|
+
function wrapRemote(skillName, server, binary) {
|
|
2782
|
+
const entry = {
|
|
2783
|
+
command: binary,
|
|
2784
|
+
args: [
|
|
2785
|
+
"proxy",
|
|
2786
|
+
"--remote",
|
|
2787
|
+
server.remote
|
|
2788
|
+
]
|
|
2789
|
+
};
|
|
2790
|
+
const mergedEnv = { ...server.env ?? {} };
|
|
2791
|
+
if (server.requires_auth) mergedEnv[deriveAuthEnvVarName(skillName)] = AUTH_PLACEHOLDER_VALUE;
|
|
2792
|
+
if (Object.keys(mergedEnv).length > 0) entry.env = mergedEnv;
|
|
2793
|
+
return entry;
|
|
2794
|
+
}
|
|
2795
|
+
function rewriteMcpServerEntry(options) {
|
|
2796
|
+
const binary = options.tankBinaryPath ?? DEFAULT_TANK_BINARY;
|
|
2797
|
+
if (options.dangerouslyNoTankProxy) return passthroughEntry(options.mcpServer);
|
|
2798
|
+
if (isRemoteMcpServer(options.mcpServer)) return wrapRemote(options.skillName, options.mcpServer, binary);
|
|
2799
|
+
return wrapLocal(options.mcpServer, binary);
|
|
2800
|
+
}
|
|
2801
|
+
//#endregion
|
|
2802
|
+
//#region src/lib/mcp-config-writer.ts
|
|
2803
|
+
const AGENT_CONFIG_PATHS = {
|
|
2804
|
+
claude: [".claude", "settings.json"],
|
|
2805
|
+
cursor: [".cursor", "mcp.json"],
|
|
2806
|
+
opencode: [
|
|
2807
|
+
".config",
|
|
2808
|
+
"opencode",
|
|
2809
|
+
"mcp.json"
|
|
2810
|
+
],
|
|
2811
|
+
codex: [".codex", "config.json"],
|
|
2812
|
+
openclaw: [".openclaw", "mcp.json"],
|
|
2813
|
+
universal: [
|
|
2814
|
+
".config",
|
|
2815
|
+
"mcp",
|
|
2816
|
+
"servers.json"
|
|
2817
|
+
]
|
|
2818
|
+
};
|
|
2819
|
+
function getAgentConfigPath(agentId, homedir) {
|
|
2820
|
+
const segments = AGENT_CONFIG_PATHS[agentId];
|
|
2821
|
+
if (!segments) return null;
|
|
2822
|
+
const base = homedir ?? os.homedir();
|
|
2823
|
+
return path.join(base, ...segments);
|
|
2824
|
+
}
|
|
2825
|
+
function readConfigOrEmpty(configPath) {
|
|
2826
|
+
if (!fs.existsSync(configPath)) return {};
|
|
2827
|
+
try {
|
|
2828
|
+
const raw = fs.readFileSync(configPath, "utf-8");
|
|
2829
|
+
const parsed = JSON.parse(raw);
|
|
2830
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
2831
|
+
return parsed;
|
|
2832
|
+
} catch {
|
|
2833
|
+
return {};
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
function persistConfig(configPath, config) {
|
|
2837
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
2838
|
+
fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
2839
|
+
}
|
|
2840
|
+
function writeMcpServerEntry(options) {
|
|
2841
|
+
const configPath = getAgentConfigPath(options.agentId, options.homedir);
|
|
2842
|
+
if (!configPath) throw new Error(`unknown agent: ${options.agentId}`);
|
|
2843
|
+
const existing = readConfigOrEmpty(configPath);
|
|
2844
|
+
const mcpServers = { ...existing.mcpServers ?? {} };
|
|
2845
|
+
if (options.remove) {
|
|
2846
|
+
if (!(options.skillName in mcpServers)) {
|
|
2847
|
+
if (!fs.existsSync(configPath)) return;
|
|
2848
|
+
}
|
|
2849
|
+
delete mcpServers[options.skillName];
|
|
2850
|
+
} else {
|
|
2851
|
+
if (!options.entry) throw new Error("writeMcpServerEntry: entry is required when remove=false");
|
|
2852
|
+
mcpServers[options.skillName] = options.entry;
|
|
2853
|
+
}
|
|
2854
|
+
persistConfig(configPath, {
|
|
2855
|
+
...existing,
|
|
2856
|
+
mcpServers
|
|
2857
|
+
});
|
|
2858
|
+
}
|
|
2859
|
+
//#endregion
|
|
2860
|
+
//#region src/lib/apply-proxy-wrapping.ts
|
|
2861
|
+
function readManifest(skillDir) {
|
|
2862
|
+
const manifestPath = path.join(skillDir, "tank.json");
|
|
2863
|
+
if (!fs.existsSync(manifestPath)) return "missing";
|
|
2864
|
+
try {
|
|
2865
|
+
const raw = fs.readFileSync(manifestPath, "utf-8");
|
|
2866
|
+
const parsed = JSON.parse(raw);
|
|
2867
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return "invalid";
|
|
2868
|
+
return parsed;
|
|
2869
|
+
} catch {
|
|
2870
|
+
return "invalid";
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
function warnOptOut(skillName) {
|
|
2874
|
+
console.warn(`Proxy disabled for ${skillName} — MCP traffic will not be scanned`);
|
|
2875
|
+
}
|
|
2876
|
+
function isKnownAgent(agentId) {
|
|
2877
|
+
return agentId in AGENT_CONFIG_PATHS;
|
|
2878
|
+
}
|
|
2879
|
+
function applyRemoval(options) {
|
|
2880
|
+
const wrapped = [];
|
|
2881
|
+
for (const agentId of options.agentIds) {
|
|
2882
|
+
if (!isKnownAgent(agentId)) continue;
|
|
2883
|
+
writeMcpServerEntry({
|
|
2884
|
+
agentId,
|
|
2885
|
+
skillName: options.skillName,
|
|
2886
|
+
remove: true,
|
|
2887
|
+
homedir: options.homedir
|
|
2888
|
+
});
|
|
2889
|
+
wrapped.push(agentId);
|
|
2890
|
+
}
|
|
2891
|
+
return {
|
|
2892
|
+
wrapped,
|
|
2893
|
+
skipped: []
|
|
2894
|
+
};
|
|
2895
|
+
}
|
|
2896
|
+
function applyProxyWrapping(options) {
|
|
2897
|
+
if (options.remove) return applyRemoval(options);
|
|
2898
|
+
const manifest = readManifest(options.skillDir);
|
|
2899
|
+
if (manifest === "missing") return {
|
|
2900
|
+
wrapped: [],
|
|
2901
|
+
skipped: ["no-manifest"]
|
|
2902
|
+
};
|
|
2903
|
+
if (manifest === "invalid") return {
|
|
2904
|
+
wrapped: [],
|
|
2905
|
+
skipped: ["invalid-manifest"]
|
|
2906
|
+
};
|
|
2907
|
+
const rawMcpServer = manifest.mcp_server;
|
|
2908
|
+
if (rawMcpServer === void 0) return {
|
|
2909
|
+
wrapped: [],
|
|
2910
|
+
skipped: ["no-mcp-server"]
|
|
2911
|
+
};
|
|
2912
|
+
const parseResult = mcpServerSchema.safeParse(rawMcpServer);
|
|
2913
|
+
if (!parseResult.success) return {
|
|
2914
|
+
wrapped: [],
|
|
2915
|
+
skipped: ["invalid-mcp-server"]
|
|
2916
|
+
};
|
|
2917
|
+
const entry = rewriteMcpServerEntry({
|
|
2918
|
+
skillName: options.skillName,
|
|
2919
|
+
mcpServer: parseResult.data,
|
|
2920
|
+
...options.tankBinaryPath !== void 0 ? { tankBinaryPath: options.tankBinaryPath } : {},
|
|
2921
|
+
...options.dangerouslyNoTankProxy ? { dangerouslyNoTankProxy: true } : {}
|
|
2922
|
+
});
|
|
2923
|
+
if (options.dangerouslyNoTankProxy) warnOptOut(options.skillName);
|
|
2924
|
+
const wrapped = [];
|
|
2925
|
+
for (const agentId of options.agentIds) {
|
|
2926
|
+
if (!isKnownAgent(agentId)) continue;
|
|
2927
|
+
writeMcpServerEntry({
|
|
2928
|
+
agentId,
|
|
2929
|
+
skillName: options.skillName,
|
|
2930
|
+
entry,
|
|
2931
|
+
homedir: options.homedir
|
|
2932
|
+
});
|
|
2933
|
+
wrapped.push(agentId);
|
|
2934
|
+
}
|
|
2935
|
+
return {
|
|
2936
|
+
wrapped,
|
|
2937
|
+
skipped: []
|
|
2938
|
+
};
|
|
2939
|
+
}
|
|
2940
|
+
//#endregion
|
|
2719
2941
|
//#region src/lib/frontmatter.ts
|
|
2720
2942
|
function hasFrontmatter(content) {
|
|
2721
2943
|
return /^---\s*\n/.test(content);
|
|
@@ -2982,12 +3204,13 @@ const HOST_MAP = [
|
|
|
2982
3204
|
[/registry\.npmjs\.org/i, "npm"]
|
|
2983
3205
|
];
|
|
2984
3206
|
function detectSourceType(url) {
|
|
3207
|
+
if (url.startsWith("file://")) return "file";
|
|
2985
3208
|
for (const [pattern, sourceType] of HOST_MAP) if (pattern.test(url)) return sourceType;
|
|
2986
3209
|
return "unknown";
|
|
2987
3210
|
}
|
|
2988
3211
|
/** Returns true if the input looks like a URL rather than a package name. */
|
|
2989
3212
|
function isUrl(input) {
|
|
2990
|
-
if (input.startsWith("http://") || input.startsWith("https://")) return true;
|
|
3213
|
+
if (input.startsWith("http://") || input.startsWith("https://") || input.startsWith("file://")) return true;
|
|
2991
3214
|
for (const [pattern] of HOST_MAP) if (pattern.test(input)) return true;
|
|
2992
3215
|
return false;
|
|
2993
3216
|
}
|
|
@@ -3271,6 +3494,24 @@ async function fetchFromGenericUrl(url, tempDir) {
|
|
|
3271
3494
|
cleanup: () => cleanupDir(tempDir)
|
|
3272
3495
|
};
|
|
3273
3496
|
}
|
|
3497
|
+
async function fetchFromFileUrl(url, tempDir) {
|
|
3498
|
+
const sourcePath = new URL(url).pathname;
|
|
3499
|
+
const destDir = join(tempDir, "skill");
|
|
3500
|
+
const { cp } = await import("node:fs/promises");
|
|
3501
|
+
await mkdir(destDir, { recursive: true });
|
|
3502
|
+
await cp(sourcePath, destDir, {
|
|
3503
|
+
recursive: true,
|
|
3504
|
+
errorOnExist: false
|
|
3505
|
+
});
|
|
3506
|
+
return {
|
|
3507
|
+
localPath: destDir,
|
|
3508
|
+
sourceType: "file",
|
|
3509
|
+
sourceUrl: url,
|
|
3510
|
+
commitSha: null,
|
|
3511
|
+
inferredName: sourcePath.replace(/\/$/, "").split("/").pop() ?? null,
|
|
3512
|
+
cleanup: () => cleanupDir(tempDir)
|
|
3513
|
+
};
|
|
3514
|
+
}
|
|
3274
3515
|
/** Fetch a skill from a URL to a local temp directory. */
|
|
3275
3516
|
async function fetchFromUrl(url) {
|
|
3276
3517
|
const sourceType = detectSourceType(url);
|
|
@@ -3288,6 +3529,9 @@ async function fetchFromUrl(url) {
|
|
|
3288
3529
|
case "skills_sh":
|
|
3289
3530
|
result = await fetchFromSkillsSh(url, tempDir);
|
|
3290
3531
|
break;
|
|
3532
|
+
case "file":
|
|
3533
|
+
result = await fetchFromFileUrl(url, tempDir);
|
|
3534
|
+
break;
|
|
3291
3535
|
default:
|
|
3292
3536
|
result = await fetchFromGenericUrl(url, tempDir);
|
|
3293
3537
|
break;
|
|
@@ -3442,8 +3686,28 @@ function installToolDependencies(extractDir, skillName) {
|
|
|
3442
3686
|
logger.warn(`Dependency install skipped for ${skillName} (non-fatal)`);
|
|
3443
3687
|
}
|
|
3444
3688
|
}
|
|
3689
|
+
function wrapMcpServerForSkill(options) {
|
|
3690
|
+
try {
|
|
3691
|
+
const agents = detectInstalledAgents(options.homedir);
|
|
3692
|
+
if (agents.length === 0) return;
|
|
3693
|
+
const result = applyProxyWrapping({
|
|
3694
|
+
skillName: options.skillName,
|
|
3695
|
+
skillDir: options.extractDir,
|
|
3696
|
+
agentIds: agents.map((a) => a.id),
|
|
3697
|
+
...options.homedir !== void 0 ? { homedir: options.homedir } : {},
|
|
3698
|
+
...options.dangerouslyNoTankProxy ? { dangerouslyNoTankProxy: true } : {}
|
|
3699
|
+
});
|
|
3700
|
+
if (result.wrapped.length > 0) {
|
|
3701
|
+
const mode = options.dangerouslyNoTankProxy ? "registered (proxy disabled)" : "proxy-wrapped";
|
|
3702
|
+
logger.info(`${options.skillName}: ${mode} in ${result.wrapped.length} agent config(s)`);
|
|
3703
|
+
}
|
|
3704
|
+
} catch (err) {
|
|
3705
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
3706
|
+
logger.warn(`MCP proxy wrapping skipped for ${options.skillName}: ${msg}`);
|
|
3707
|
+
}
|
|
3708
|
+
}
|
|
3445
3709
|
async function linkInstalledRoots(options) {
|
|
3446
|
-
const { rootSkillNames, resolvedNodeByName, extractDirForSkill, directory, global, resolvedHome, homedir } = options;
|
|
3710
|
+
const { rootSkillNames, resolvedNodeByName, extractDirForSkill, directory, global, resolvedHome, homedir, dangerouslyNoTankProxy } = options;
|
|
3447
3711
|
const agentSkillsBaseDir = global ? getGlobalAgentSkillsDir(resolvedHome) : path.join(directory, ".tank", "agent-skills");
|
|
3448
3712
|
const linksDir = global ? path.join(resolvedHome, ".tank") : path.join(directory, ".tank");
|
|
3449
3713
|
for (const skillName of rootSkillNames) try {
|
|
@@ -3463,6 +3727,12 @@ async function linkInstalledRoots(options) {
|
|
|
3463
3727
|
});
|
|
3464
3728
|
if (linkResult.linked.length > 0) logger.info(`Linked to ${linkResult.linked.length} agent(s)`);
|
|
3465
3729
|
if (linkResult.failed.length > 0) for (const failedLink of linkResult.failed) logger.warn(`Failed to link to ${failedLink.agentId}: ${failedLink.error}`);
|
|
3730
|
+
wrapMcpServerForSkill({
|
|
3731
|
+
skillName,
|
|
3732
|
+
extractDir: extractDirForSkill(skillName),
|
|
3733
|
+
homedir,
|
|
3734
|
+
dangerouslyNoTankProxy
|
|
3735
|
+
});
|
|
3466
3736
|
} catch {
|
|
3467
3737
|
if (rootSkillNames.length === 1) logger.warn("Agent linking skipped (non-fatal)");
|
|
3468
3738
|
else logger.warn(`Agent linking skipped for ${skillName} (non-fatal)`);
|
|
@@ -3535,12 +3805,13 @@ async function executeInstallPipeline(options) {
|
|
|
3535
3805
|
directory,
|
|
3536
3806
|
global,
|
|
3537
3807
|
resolvedHome,
|
|
3538
|
-
homedir
|
|
3808
|
+
homedir,
|
|
3809
|
+
...options.dangerouslyNoTankProxy ? { dangerouslyNoTankProxy: true } : {}
|
|
3539
3810
|
});
|
|
3540
3811
|
return updatedLock;
|
|
3541
3812
|
}
|
|
3542
3813
|
async function installCommand(options) {
|
|
3543
|
-
const { name, versionRange = "*", directory = process.cwd(), configDir, global = false, homedir, isTransitive = false } = options;
|
|
3814
|
+
const { name, versionRange = "*", directory = process.cwd(), configDir, global = false, homedir, isTransitive = false, dangerouslyNoTankProxy } = options;
|
|
3544
3815
|
const config = getConfig(configDir);
|
|
3545
3816
|
const resolvedHome = homedir ?? os.homedir();
|
|
3546
3817
|
const requestHeaders = { "User-Agent": USER_AGENT };
|
|
@@ -3596,7 +3867,8 @@ async function installCommand(options) {
|
|
|
3596
3867
|
rootSkillNames: [name],
|
|
3597
3868
|
projectPermissions,
|
|
3598
3869
|
auditMinScore,
|
|
3599
|
-
spinner
|
|
3870
|
+
spinner,
|
|
3871
|
+
...dangerouslyNoTankProxy ? { dangerouslyNoTankProxy: true } : {}
|
|
3600
3872
|
});
|
|
3601
3873
|
if (!global && !isTransitive) {
|
|
3602
3874
|
const skills = skillsJson.skills ?? {};
|
|
@@ -3611,7 +3883,7 @@ async function installCommand(options) {
|
|
|
3611
3883
|
}
|
|
3612
3884
|
}
|
|
3613
3885
|
async function installFromLockfile(options) {
|
|
3614
|
-
const { directory = process.cwd(), configDir, global = false, homedir } = options;
|
|
3886
|
+
const { directory = process.cwd(), configDir, global = false, homedir, dangerouslyNoTankProxy } = options;
|
|
3615
3887
|
const resolvedHome = homedir ?? os.homedir();
|
|
3616
3888
|
const config = getConfig(configDir);
|
|
3617
3889
|
const requestHeaders = { "User-Agent": USER_AGENT };
|
|
@@ -3638,42 +3910,46 @@ async function installFromLockfile(options) {
|
|
|
3638
3910
|
const skillName = parseLockKey$2(key);
|
|
3639
3911
|
const version = parseVersionFromLockKey(key);
|
|
3640
3912
|
spinner.text = `Installing ${key}...`;
|
|
3641
|
-
const encodedName = encodeURIComponent(skillName);
|
|
3642
|
-
const metaUrl = `${config.registry}/api/v1/skills/${encodedName}/${version}`;
|
|
3643
|
-
let metaRes;
|
|
3644
|
-
try {
|
|
3645
|
-
metaRes = await fetch(metaUrl, { headers: requestHeaders });
|
|
3646
|
-
} catch (err) {
|
|
3647
|
-
throw new Error(`Network error fetching ${key}: ${err instanceof Error ? err.message : String(err)}`);
|
|
3648
|
-
}
|
|
3649
|
-
if (!metaRes.ok) {
|
|
3650
|
-
if (metaRes.status === 404) throw new Error(`Skill or version not found: ${key}`);
|
|
3651
|
-
const body = await metaRes.json().catch(() => null);
|
|
3652
|
-
throw new Error(`Failed to fetch ${key}: ${body?.error ?? metaRes.statusText}`);
|
|
3653
|
-
}
|
|
3654
|
-
const downloadUrl = (await metaRes.json()).downloadUrl;
|
|
3655
|
-
const downloadRes = await fetch(downloadUrl);
|
|
3656
|
-
if (!downloadRes.ok) throw new Error(`Failed to download ${key}: ${downloadRes.status} ${downloadRes.statusText}`);
|
|
3657
|
-
const tarballBuffer = Buffer.from(await downloadRes.arrayBuffer());
|
|
3658
|
-
const computedIntegrity = buildIntegrity(tarballBuffer);
|
|
3659
|
-
if (computedIntegrity !== entry.integrity) throw new Error(`Integrity mismatch for ${key}. Expected: ${entry.integrity}, Got: ${computedIntegrity}`);
|
|
3660
3913
|
const extractDir = global ? getGlobalExtractDir(resolvedHome, skillName) : getExtractDir$1(directory, skillName);
|
|
3661
|
-
if (fs.existsSync(
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3914
|
+
if (!fs.existsSync(path.join(extractDir, "tank.json"))) {
|
|
3915
|
+
const encodedName = encodeURIComponent(skillName);
|
|
3916
|
+
const metaUrl = `${config.registry}/api/v1/skills/${encodedName}/${version}`;
|
|
3917
|
+
let metaRes;
|
|
3918
|
+
try {
|
|
3919
|
+
metaRes = await fetch(metaUrl, { headers: requestHeaders });
|
|
3920
|
+
} catch (err) {
|
|
3921
|
+
throw new Error(`Network error fetching ${key}: ${err instanceof Error ? err.message : String(err)}`);
|
|
3922
|
+
}
|
|
3923
|
+
if (!metaRes.ok) {
|
|
3924
|
+
if (metaRes.status === 404) throw new Error(`Skill or version not found: ${key}`);
|
|
3925
|
+
const body = await metaRes.json().catch(() => null);
|
|
3926
|
+
throw new Error(`Failed to fetch ${key}: ${body?.error ?? metaRes.statusText}`);
|
|
3927
|
+
}
|
|
3928
|
+
const downloadUrl = (await metaRes.json()).downloadUrl;
|
|
3929
|
+
const downloadRes = await fetch(downloadUrl);
|
|
3930
|
+
if (!downloadRes.ok) throw new Error(`Failed to download ${key}: ${downloadRes.status} ${downloadRes.statusText}`);
|
|
3931
|
+
const tarballBuffer = Buffer.from(await downloadRes.arrayBuffer());
|
|
3932
|
+
const computedIntegrity = buildIntegrity(tarballBuffer);
|
|
3933
|
+
if (computedIntegrity !== entry.integrity) throw new Error(`Integrity mismatch for ${key}. Expected: ${entry.integrity}, Got: ${computedIntegrity}`);
|
|
3934
|
+
if (fs.existsSync(extractDir)) fs.rmSync(extractDir, {
|
|
3935
|
+
recursive: true,
|
|
3936
|
+
force: true
|
|
3937
|
+
});
|
|
3938
|
+
fs.mkdirSync(extractDir, { recursive: true });
|
|
3939
|
+
await extractSafely(tarballBuffer, extractDir);
|
|
3940
|
+
}
|
|
3941
|
+
try {
|
|
3942
|
+
const agentSkillsBaseDir = global ? getGlobalAgentSkillsDir(resolvedHome) : path.join(directory, ".tank", "agent-skills");
|
|
3943
|
+
const linksDir = global ? path.join(resolvedHome, ".tank") : path.join(directory, ".tank");
|
|
3668
3944
|
const linkResult = linkSkillToAgents({
|
|
3669
3945
|
skillName,
|
|
3670
3946
|
sourceDir: prepareAgentSkillDir({
|
|
3671
3947
|
skillName,
|
|
3672
3948
|
extractDir,
|
|
3673
|
-
agentSkillsBaseDir
|
|
3949
|
+
agentSkillsBaseDir
|
|
3674
3950
|
}),
|
|
3675
|
-
linksDir
|
|
3676
|
-
source: "global",
|
|
3951
|
+
linksDir,
|
|
3952
|
+
source: global ? "global" : "local",
|
|
3677
3953
|
homedir
|
|
3678
3954
|
});
|
|
3679
3955
|
if (detectInstalledAgents(homedir).length === 0) logger.warn("No agents detected for linking");
|
|
@@ -3682,6 +3958,12 @@ async function installFromLockfile(options) {
|
|
|
3682
3958
|
} catch {
|
|
3683
3959
|
logger.warn("Agent linking skipped (non-fatal)");
|
|
3684
3960
|
}
|
|
3961
|
+
wrapMcpServerForSkill({
|
|
3962
|
+
skillName,
|
|
3963
|
+
extractDir,
|
|
3964
|
+
...homedir !== void 0 ? { homedir } : {},
|
|
3965
|
+
...dangerouslyNoTankProxy ? { dangerouslyNoTankProxy: true } : {}
|
|
3966
|
+
});
|
|
3685
3967
|
}
|
|
3686
3968
|
spinner.succeed(`Installed ${entries.length} skill${entries.length === 1 ? "" : "s"} from lockfile`);
|
|
3687
3969
|
} catch (err) {
|
|
@@ -3694,7 +3976,7 @@ async function installFromLockfile(options) {
|
|
|
3694
3976
|
}
|
|
3695
3977
|
}
|
|
3696
3978
|
async function installAll(options) {
|
|
3697
|
-
const { directory = process.cwd(), configDir, global = false, homedir } = options;
|
|
3979
|
+
const { directory = process.cwd(), configDir, global = false, homedir, dangerouslyNoTankProxy } = options;
|
|
3698
3980
|
const resolvedHome = homedir ?? os.homedir();
|
|
3699
3981
|
const config = getConfig(configDir);
|
|
3700
3982
|
const requestHeaders = { "User-Agent": USER_AGENT };
|
|
@@ -3707,7 +3989,8 @@ async function installAll(options) {
|
|
|
3707
3989
|
directory,
|
|
3708
3990
|
configDir,
|
|
3709
3991
|
global,
|
|
3710
|
-
homedir
|
|
3992
|
+
homedir,
|
|
3993
|
+
...dangerouslyNoTankProxy ? { dangerouslyNoTankProxy: true } : {}
|
|
3711
3994
|
});
|
|
3712
3995
|
if (global) {
|
|
3713
3996
|
logger.info(`No ${LOCKFILE_FILENAME} found — nothing to install`);
|
|
@@ -3749,7 +4032,8 @@ async function installAll(options) {
|
|
|
3749
4032
|
rootSkillNames: skillEntries.map(([skillName]) => skillName),
|
|
3750
4033
|
projectPermissions,
|
|
3751
4034
|
auditMinScore,
|
|
3752
|
-
spinner
|
|
4035
|
+
spinner,
|
|
4036
|
+
...dangerouslyNoTankProxy ? { dangerouslyNoTankProxy: true } : {}
|
|
3753
4037
|
});
|
|
3754
4038
|
spinner.succeed(`Installed ${skillEntries.length} root skill${skillEntries.length === 1 ? "" : "s"}`);
|
|
3755
4039
|
} catch (err) {
|
|
@@ -3802,7 +4086,7 @@ function readManifestFromDir(dir) {
|
|
|
3802
4086
|
return null;
|
|
3803
4087
|
}
|
|
3804
4088
|
async function installFromUrl(url, options) {
|
|
3805
|
-
const { global = false, yes = false } = options;
|
|
4089
|
+
const { global = false, yes = false, dangerouslyNoTankProxy } = options;
|
|
3806
4090
|
const resolvedHome = os.homedir();
|
|
3807
4091
|
const directory = process.cwd();
|
|
3808
4092
|
const spinner = ora(`Fetching from URL...`).start();
|
|
@@ -3823,13 +4107,16 @@ async function installFromUrl(url, options) {
|
|
|
3823
4107
|
process.exit(1);
|
|
3824
4108
|
}
|
|
3825
4109
|
try {
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
4110
|
+
let scanResult = null;
|
|
4111
|
+
if (!url.startsWith("file://")) {
|
|
4112
|
+
scanResult = await scanUrl(url);
|
|
4113
|
+
displayScanResults(scanResult);
|
|
4114
|
+
const enforcement = await enforceVerdict(scanResult, { yes });
|
|
4115
|
+
if (!enforcement.allowed) {
|
|
4116
|
+
spinner.fail(enforcement.reason ?? "Install blocked by security scan");
|
|
4117
|
+
await fetchResult.cleanup();
|
|
4118
|
+
process.exit(1);
|
|
4119
|
+
}
|
|
3833
4120
|
}
|
|
3834
4121
|
const skillMdPath = path.join(fetchResult.localPath, "SKILL.md");
|
|
3835
4122
|
if (!fs.existsSync(skillMdPath)) throw new Error("No SKILL.md found. This doesn't appear to be a valid skill.");
|
|
@@ -3861,12 +4148,12 @@ async function installFromUrl(url, options) {
|
|
|
3861
4148
|
const lockKey = `${skillName}@${skillVersion}`;
|
|
3862
4149
|
const skillPermissions = existingManifest?.permissions ?? {};
|
|
3863
4150
|
lock.skills[lockKey] = {
|
|
3864
|
-
resolved: url.startsWith("http") ? url : `https://${url}`,
|
|
4151
|
+
resolved: url.startsWith("http") ? url : url.startsWith("file://") ? url : `https://${url}`,
|
|
3865
4152
|
integrity,
|
|
3866
4153
|
permissions: skillPermissions,
|
|
3867
|
-
audit_score: scanResult
|
|
4154
|
+
audit_score: scanResult?.auditScore ?? null,
|
|
3868
4155
|
source: mapSourceType(fetchResult.sourceType),
|
|
3869
|
-
scan_verdict: scanResult
|
|
4156
|
+
scan_verdict: scanResult?.verdict ?? "pass",
|
|
3870
4157
|
scanned_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
3871
4158
|
};
|
|
3872
4159
|
lock.lockfileVersion = 2;
|
|
@@ -3893,6 +4180,11 @@ async function installFromUrl(url, options) {
|
|
|
3893
4180
|
logger.warn("Agent linking skipped (non-fatal)");
|
|
3894
4181
|
}
|
|
3895
4182
|
if (detectInstalledAgents().length === 0) logger.warn("No agents detected for linking");
|
|
4183
|
+
wrapMcpServerForSkill({
|
|
4184
|
+
skillName,
|
|
4185
|
+
extractDir: installDir,
|
|
4186
|
+
...dangerouslyNoTankProxy ? { dangerouslyNoTankProxy: true } : {}
|
|
4187
|
+
});
|
|
3896
4188
|
await fetchResult.cleanup();
|
|
3897
4189
|
spinner.succeed(`Installed ${skillName} from ${fetchResult.sourceType}`);
|
|
3898
4190
|
if (linkedAgents.length > 0) logger.info(`Linked to ${linkedAgents.join(", ")}`);
|
|
@@ -4256,6 +4548,30 @@ async function permissionsCommand(options) {
|
|
|
4256
4548
|
}
|
|
4257
4549
|
}
|
|
4258
4550
|
//#endregion
|
|
4551
|
+
//#region src/commands/proxy.ts
|
|
4552
|
+
const PROXY_MODULE = "@tankpkg/proxy";
|
|
4553
|
+
async function proxyCommand(options) {
|
|
4554
|
+
if (!options.command || options.command.length === 0) throw new Error("tank proxy: missing child command (usage: tank proxy -- <command> [args...])");
|
|
4555
|
+
const { startProxy } = await import(PROXY_MODULE);
|
|
4556
|
+
if (options.verbose) console.error(chalk.dim(`[tank proxy] spawning: ${options.command} ${options.args.join(" ")}`));
|
|
4557
|
+
const startOptions = {
|
|
4558
|
+
command: options.command,
|
|
4559
|
+
args: options.args
|
|
4560
|
+
};
|
|
4561
|
+
if (options.auditPath !== void 0) startOptions.auditPath = options.auditPath;
|
|
4562
|
+
if (options.enableMl === true) startOptions.enableMl = true;
|
|
4563
|
+
const handle = await startProxy(startOptions);
|
|
4564
|
+
const forwardSignal = (signal) => {
|
|
4565
|
+
try {
|
|
4566
|
+
handle.kill(signal);
|
|
4567
|
+
} catch {}
|
|
4568
|
+
};
|
|
4569
|
+
process.on("SIGINT", () => forwardSignal("SIGINT"));
|
|
4570
|
+
process.on("SIGTERM", () => forwardSignal("SIGTERM"));
|
|
4571
|
+
const code = await handle.exitCode;
|
|
4572
|
+
process.exit(code);
|
|
4573
|
+
}
|
|
4574
|
+
//#endregion
|
|
4259
4575
|
//#region src/lib/packer.ts
|
|
4260
4576
|
const MAX_PACKAGE_SIZE = 50 * 1024 * 1024;
|
|
4261
4577
|
const MAX_FILE_COUNT = 1e3;
|
|
@@ -5554,18 +5870,23 @@ program.command("publish").alias("pub").description("Pack and publish a skill to
|
|
|
5554
5870
|
process.exit(1);
|
|
5555
5871
|
}
|
|
5556
5872
|
});
|
|
5557
|
-
program.command("install").alias("i").description("Install a skill from the Tank registry, a URL, or all skills from lockfile").argument("[name]", "Skill name or URL (e.g., @org/skill-name or https://github.com/owner/repo). Omit to install from lockfile.").argument("[version-range]", "Semver range (default: *)", "*").option("-g, --global", "Install skill globally (available to all projects)").option("-y, --yes", "Auto-accept flagged scan verdicts").action(async (name, versionRange, opts) => {
|
|
5873
|
+
program.command("install").alias("i").description("Install a skill from the Tank registry, a URL, or all skills from lockfile").argument("[name]", "Skill name or URL (e.g., @org/skill-name or https://github.com/owner/repo). Omit to install from lockfile.").argument("[version-range]", "Semver range (default: *)", "*").option("-g, --global", "Install skill globally (available to all projects)").option("-y, --yes", "Auto-accept flagged scan verdicts").option("--dangerously-no-tank-proxy", "Skip wrapping MCP servers with the tank proxy (no scanning, no enforcement)").action(async (name, versionRange, opts) => {
|
|
5558
5874
|
try {
|
|
5559
5875
|
if (name && isUrl(name)) await installFromUrl(name, {
|
|
5560
5876
|
global: opts.global,
|
|
5561
|
-
yes: opts.yes
|
|
5877
|
+
yes: opts.yes,
|
|
5878
|
+
...opts.dangerouslyNoTankProxy ? { dangerouslyNoTankProxy: true } : {}
|
|
5562
5879
|
});
|
|
5563
5880
|
else if (name) await installCommand({
|
|
5564
5881
|
name,
|
|
5565
5882
|
versionRange,
|
|
5566
|
-
global: opts.global
|
|
5883
|
+
global: opts.global,
|
|
5884
|
+
...opts.dangerouslyNoTankProxy ? { dangerouslyNoTankProxy: true } : {}
|
|
5885
|
+
});
|
|
5886
|
+
else await installAll({
|
|
5887
|
+
global: opts.global,
|
|
5888
|
+
...opts.dangerouslyNoTankProxy ? { dangerouslyNoTankProxy: true } : {}
|
|
5567
5889
|
});
|
|
5568
|
-
else await installAll({ global: opts.global });
|
|
5569
5890
|
} catch (err) {
|
|
5570
5891
|
const msg = err instanceof Error ? err.message : String(err);
|
|
5571
5892
|
console.error(`Install failed: ${msg}`);
|
|
@@ -5655,6 +5976,42 @@ program.command("run").description("Launch an agent with credential protection (
|
|
|
5655
5976
|
process.exit(1);
|
|
5656
5977
|
}
|
|
5657
5978
|
});
|
|
5979
|
+
program.command("proxy").description("Transparent MCP proxy — wraps an MCP server with runtime enforcement").argument("[command]", "Child MCP server command to wrap (omit when using --reset-pins, --remote, or download-ml-model)").allowUnknownOption(true).allowExcessArguments(true).option("--audit-path <path>", "JSONL audit log path (default: ~/.tank/proxy/audit.jsonl)").option("--reset-pins", "Delete all rug-pull schema pins under ~/.tank/proxy/pins/ and continue").option("--remote <url>", "Connect to a remote MCP server over SSE/HTTP instead of spawning a child").option("--requires-auth", "Require TANK_MCP_AUTH_<SLUG> env var before connecting to the remote").option("--enable-ml", "Enable the opt-in ML-based prompt-injection classifier (requires ~500MB model; run `tank proxy download-ml-model` first)").option("--verbose", "Print proxy diagnostic details to stderr").action(async (command, opts, cmd) => {
|
|
5980
|
+
try {
|
|
5981
|
+
if (command === "download-ml-model") {
|
|
5982
|
+
const { proxyDownloadMlCommand } = await import("../proxy-download-ml-DUk7ehNs.js");
|
|
5983
|
+
const downloadOpts = {};
|
|
5984
|
+
if (process.argv.includes("--yes") || process.argv.includes("-y")) downloadOpts.yes = true;
|
|
5985
|
+
await proxyDownloadMlCommand(downloadOpts);
|
|
5986
|
+
return;
|
|
5987
|
+
}
|
|
5988
|
+
if (opts.resetPins) {
|
|
5989
|
+
const { proxyResetPinsCommand } = await import("../proxy-reset-pins-CfEbaL-F.js");
|
|
5990
|
+
proxyResetPinsCommand();
|
|
5991
|
+
}
|
|
5992
|
+
if (opts.remote) {
|
|
5993
|
+
const { proxyRemoteCommand } = await import("../proxy-remote-CCemokkz.js");
|
|
5994
|
+
await proxyRemoteCommand({
|
|
5995
|
+
url: opts.remote,
|
|
5996
|
+
requiresAuth: opts.requiresAuth === true
|
|
5997
|
+
});
|
|
5998
|
+
return;
|
|
5999
|
+
}
|
|
6000
|
+
if (!command) return;
|
|
6001
|
+
const proxyOpts = {
|
|
6002
|
+
command,
|
|
6003
|
+
args: cmd.args.slice(1)
|
|
6004
|
+
};
|
|
6005
|
+
if (opts.auditPath !== void 0) proxyOpts.auditPath = opts.auditPath;
|
|
6006
|
+
if (opts.verbose !== void 0) proxyOpts.verbose = opts.verbose;
|
|
6007
|
+
if (opts.enableMl === true) proxyOpts.enableMl = true;
|
|
6008
|
+
await proxyCommand(proxyOpts);
|
|
6009
|
+
} catch (err) {
|
|
6010
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
6011
|
+
console.error(`Proxy failed: ${msg}`);
|
|
6012
|
+
process.exit(1);
|
|
6013
|
+
}
|
|
6014
|
+
});
|
|
5658
6015
|
program.command("scan").description("Scan a local skill for security issues without publishing").option("-d, --directory <path>", "Directory to scan (default: current directory)").action(async (opts) => {
|
|
5659
6016
|
try {
|
|
5660
6017
|
await scanCommand({ directory: opts.directory });
|