toolcapsule 0.1.0-alpha.13 → 0.1.0-alpha.14

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/cli.js CHANGED
@@ -139,7 +139,12 @@ function linkedProfileForImportedServer(server, name = server.name) {
139
139
  }
140
140
  async function resolveProfileSource(source) {
141
141
  if (!existsSync(source.path)) return void 0;
142
- const config = asRecord(await readJson(source.path));
142
+ let config;
143
+ try {
144
+ config = asRecord(await readJson(source.path));
145
+ } catch {
146
+ return void 0;
147
+ }
143
148
  if (!config) return void 0;
144
149
  const entry = serverEntries(source, config).find(([name]) => name === source.server);
145
150
  if (!entry) return void 0;
@@ -166,7 +171,12 @@ async function discoverMcpServers(opts = {}) {
166
171
  const discovered = [];
167
172
  for (const source of sources) {
168
173
  if (!existsSync(source.path)) continue;
169
- const config = asRecord(await readJson(source.path));
174
+ let config;
175
+ try {
176
+ config = asRecord(await readJson(source.path));
177
+ } catch {
178
+ continue;
179
+ }
170
180
  if (!config) continue;
171
181
  for (const [name, raw] of serverEntries(source, config)) {
172
182
  const imported = mapServer(name, source, raw);
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts","../src/mcp/inventory.ts","../src/mcp/importer.ts","../src/utils/fs.ts","../src/paths.ts","../src/mcp/client.ts","../src/profile.ts","../src/schema/brief.ts","../src/schema/summarize.ts","../src/skill/generator.ts","../src/skill/installer.ts","../src/runs/recorder.ts","../src/utils/tokens.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { readFile } from \"node:fs/promises\";\nimport { cac } from \"cac\";\nimport pc from \"picocolors\";\nimport type { ProfileConfig, SnapshotProfileConfig } from \"./types.js\";\nimport { disableNativeMcp, disableToolCapsuleProfile, formatInventory, listMcpInventory } from \"./mcp/inventory.js\";\nimport { McpClient } from \"./mcp/client.js\";\nimport { discoverMcpServers, linkedProfileForImportedServer, selectImportedServers } from \"./mcp/importer.js\";\nimport { userProfilePath, workspaceProfilePath, workspaceRunBaseDir } from \"./paths.js\";\nimport { loadProfile } from \"./profile.js\";\nimport { briefTools } from \"./schema/brief.js\";\nimport { summarizeTool, summarizeTools } from \"./schema/summarize.js\";\nimport { defaultSkillTarget, fetchProfileTools, generateSkill, type SkillTarget, writeProfile } from \"./skill/generator.js\";\nimport { installAgentSkill } from \"./skill/installer.js\";\nimport { createRunId, loadRun, saveRun } from \"./runs/recorder.js\";\nimport { writeFile } from \"node:fs/promises\";\nimport { ensureToolCapsuleIgnored, readJson } from \"./utils/fs.js\";\nimport { percentReduction, roughTokens } from \"./utils/tokens.js\";\n\nconst cli = cac(\"toolcapsule\");\n\nasync function readPackageVersion(): Promise<string> {\n try {\n const pkg = JSON.parse(await readFile(new URL(\"../package.json\", import.meta.url), \"utf8\")) as { version?: string };\n return pkg.version || \"0.0.0\";\n } catch {\n return \"0.0.0\";\n }\n}\n\nconst packageVersion = await readPackageVersion();\n\nasync function withClient<T>(profile: SnapshotProfileConfig, fn: (client: McpClient) => Promise<T>): Promise<T> {\n const client = new McpClient(profile, { clientVersion: packageVersion });\n try {\n await client.init();\n return await fn(client);\n } finally {\n await client.close();\n }\n}\n\nfunction readArgsPath(raw: string): string {\n return raw.startsWith(\"@\") ? raw.slice(1) : raw;\n}\n\nfunction readSkillTarget(raw: string | undefined): SkillTarget {\n const target = raw || defaultSkillTarget;\n if ([\"copilot\", \"claude\", \"opencode\", \"agents\", \"all\"].includes(target)) return target as SkillTarget;\n throw new Error(\"Invalid --target. Use one of: copilot, claude, opencode, agents, all\");\n}\n\nfunction renameSnapshotProfile(profile: SnapshotProfileConfig, name: string): SnapshotProfileConfig {\n return { ...profile, name };\n}\n\nasync function writeImportedServer(\n server: Awaited<ReturnType<typeof discoverMcpServers>>[number],\n opts: { as?: string | undefined; local?: boolean | undefined; copy?: boolean | undefined; target?: string | undefined },\n): Promise<void> {\n const profileName = opts.as || server.name;\n const local = opts.local === true;\n const copy = opts.copy === true;\n const profilePath = local ? workspaceProfilePath(profileName) : userProfilePath(profileName);\n if (local) await ensureToolCapsuleIgnored();\n const profile = copy ? renameSnapshotProfile(server.profile, profileName) : linkedProfileForImportedServer(server, profileName);\n await writeProfile(profilePath, profile);\n const tools = await fetchProfileTools(renameSnapshotProfile(server.profile, profileName), { clientVersion: packageVersion });\n const skillOptions = { target: readSkillTarget(opts.target), embedProfile: local, ...(tools ? { tools } : {}) };\n const out = await generateSkill(profile, skillOptions);\n const mode = copy ? \"snapshot\" : \"linked\";\n console.log(pc.green(`Imported ${server.name} as ${profileName} from ${server.source.path} -> ${profilePath} (${mode}), ${out}`));\n for (const warning of server.warnings) console.log(pc.yellow(` warning: ${warning}`));\n}\n\ncli\n .command(\"init <name>\", \"Create a profile and generated Agent Skill for an MCP server\")\n .option(\"--url <url>\", \"Remote MCP URL\")\n .option(\"--command <command>\", \"stdio MCP command\")\n .option(\"--arg <arg>\", \"stdio MCP argument, repeatable\", { type: [String] })\n .option(\"--output <dir>\", \"Skill output directory\")\n .option(\"--target <target>\", \"Skill target: copilot, claude, opencode, agents, all\", { default: defaultSkillTarget })\n .option(\"--local\", \"Store the MCP profile in this workspace instead of ~/.toolcapsule\")\n .action(async (name: string, options: { url?: string; command?: string; arg?: string[]; output?: string; target?: string; local?: boolean }) => {\n if (!options.url && !options.command) throw new Error(\"Provide --url for remote MCP or --command for stdio MCP\");\n const local = options.local === true;\n const profile: ProfileConfig = options.url\n ? { name, transport: { type: \"remote\", url: options.url } }\n : { name, transport: { type: \"stdio\", command: options.command!, args: options.arg ?? [] } };\n const profilePath = local ? workspaceProfilePath(name) : userProfilePath(name);\n if (local) await ensureToolCapsuleIgnored();\n await writeProfile(profilePath, profile);\n const tools = await fetchProfileTools(profile, { clientVersion: packageVersion });\n const skillOptions = options.output\n ? { outputDir: options.output, embedProfile: local, ...(tools ? { tools } : {}) }\n : { target: readSkillTarget(options.target), embedProfile: local, ...(tools ? { tools } : {}) };\n const out = await generateSkill(\n profile,\n skillOptions,\n );\n console.log(pc.green(`Created profile at ${profilePath} and skill at ${out}`));\n });\n\ncli\n .command(\"install-skill\", \"Install the generic ToolCapsule Agent Skill into this workspace\")\n .option(\"--output <dir>\", \"Skill output directory\")\n .option(\"--target <target>\", \"Skill target: copilot, claude, opencode, agents, all\", { default: defaultSkillTarget })\n .action(async (options: { output?: string; target?: string }) => {\n const out = await installAgentSkill(options.output, readSkillTarget(options.target));\n console.log(pc.green(`Installed ToolCapsule Agent Skill at ${out}`));\n });\n\ncli\n .command(\"import\", \"Import existing MCP configuration into ToolCapsule profiles and skills\")\n .option(\"--include-user\", \"Also inspect user-level MCP config files\")\n .option(\"--name <name>\", \"Import only one MCP server by name\")\n .option(\"--as <name>\", \"Store the imported server under a different ToolCapsule profile name\")\n .option(\"--all\", \"Import all discovered MCP servers\")\n .option(\"--target <target>\", \"Skill target: copilot, claude, opencode, agents, all\", { default: defaultSkillTarget })\n .option(\"--local\", \"Store imported MCP profiles in this workspace instead of ~/.toolcapsule\")\n .option(\"--copy\", \"Copy MCP transport details into a ToolCapsule snapshot instead of linking the source config\")\n .option(\"--dry-run\", \"List importable MCP servers without writing files\")\n .action(\n async (options: { includeUser?: boolean; name?: string; as?: string; all?: boolean; target?: string; local?: boolean; copy?: boolean; dryRun?: boolean }) => {\n const local = options.local === true;\n const copy = options.copy === true;\n const discovered = await discoverMcpServers(options.includeUser ? { includeUser: true } : {});\n if (discovered.length === 0) {\n console.log(\"No importable MCP servers found.\");\n return;\n }\n\n if (options.dryRun) {\n for (const server of discovered) {\n console.log(`${server.name}\\t${server.source.tool}\\t${server.source.path}`);\n for (const warning of server.warnings) console.log(pc.yellow(` warning: ${warning}`));\n }\n return;\n }\n\n const selected = selectImportedServers(discovered, options.name, options.all);\n if (selected.length === 0) {\n throw new Error(\"Multiple MCP servers found. Re-run with --dry-run, then pass --name <server> or --all.\");\n }\n\n for (const server of selected) {\n await writeImportedServer(server, { as: options.as, local, copy, target: options.target });\n }\n },\n );\n\ncli\n .command(\"mcp <action> [name]\", \"List, enable, or disable MCP servers\")\n .option(\"--include-user\", \"Also inspect user-level MCP config files\")\n .option(\"--json\", \"Print JSON output for list\")\n .option(\"--as <name>\", \"Store an enabled server under a different ToolCapsule profile name\")\n .option(\"--target <target>\", \"Skill target: copilot, claude, opencode, agents, all\", { default: defaultSkillTarget })\n .option(\"--local\", \"Store ToolCapsule profile in this workspace\")\n .option(\"--copy\", \"Copy MCP transport details into a ToolCapsule snapshot instead of linking source config\")\n .option(\"--native\", \"For disable: disable the native MCP config instead of the ToolCapsule profile\")\n .option(\"--yes\", \"Apply native disable changes; otherwise native disable is dry-run\")\n .action(async (action: string, name: string | undefined, options: { includeUser?: boolean; json?: boolean; as?: string; target?: string; local?: boolean; copy?: boolean; native?: boolean; yes?: boolean }) => {\n if (action === \"list\") {\n const items = await listMcpInventory(options.includeUser ? { includeUser: true } : {});\n console.log(options.json ? JSON.stringify(items, null, 2) : formatInventory(items));\n return;\n }\n if (action === \"enable\") {\n if (!name) throw new Error(\"Usage: tcap mcp enable <server> [--as <profile>]\");\n const discovered = await discoverMcpServers(options.includeUser ? { includeUser: true } : {});\n const selected = selectImportedServers(discovered, name, false);\n if (selected.length !== 1) throw new Error(`Expected one MCP server named ${name}; run tcap mcp list --include-user first.`);\n await writeImportedServer(selected[0]!, { as: options.as, local: options.local, copy: options.copy, target: options.target });\n return;\n }\n if (action === \"disable\") {\n if (!name) throw new Error(\"Usage: tcap mcp disable <profile|server>\");\n const message = options.native\n ? await disableNativeMcp(name, { ...(options.includeUser ? { includeUser: true } : {}), dryRun: options.yes !== true })\n : await disableToolCapsuleProfile(name);\n console.log(message);\n return;\n }\n throw new Error(\"Unknown mcp action. Use: list, enable, disable\");\n });\n\ncli\n .command(\"tools <profile>\", \"List MCP tools\")\n .option(\"--brief\", \"Print compact tool summaries\")\n .option(\"--names\", \"Print tool names only\")\n .option(\"--json\", \"Print raw JSON\")\n .action(async (profileName: string, options: { brief?: boolean; names?: boolean; json?: boolean }) => {\n const profile = await loadProfile(profileName);\n const result = await withClient(profile, (client) => client.listTools());\n if (options.json) console.log(JSON.stringify(result, null, 2));\n else if (options.names) console.log(result.tools.map((tool) => tool.name).join(\"\\n\"));\n else console.log(briefTools(result.tools));\n });\n\ncli\n .command(\"describe <profile> <tool>\", \"Describe one MCP tool\")\n .option(\"--brief\", \"Print summarized schema instead of raw schema\")\n .action(async (profileName: string, toolName: string, options: { brief?: boolean }) => {\n const profile = await loadProfile(profileName);\n const result = await withClient(profile, (client) => client.listTools());\n const tool = result.tools.find((item) => item.name === toolName);\n if (!tool) throw new Error(`Tool not found: ${toolName}`);\n console.log(JSON.stringify(options.brief ? summarizeTool(tool) : tool, null, 2));\n });\n\ncli.command(\"schema <profile> <tool>\", \"Print a compact schema for one MCP tool\").action(async (profileName: string, toolName: string) => {\n const profile = await loadProfile(profileName);\n const result = await withClient(profile, (client) => client.listTools());\n const tool = result.tools.find((item) => item.name === toolName);\n if (!tool) throw new Error(`Tool not found: ${toolName}`);\n console.log(JSON.stringify(summarizeTool(tool), null, 2));\n});\n\ncli\n .command(\"call <profile> <tool> <args>\", \"Call an MCP tool with JSON args or @args.json\")\n .option(\"--save-run\", \"Save request, response, and command under .toolcapsule/runs/<profile>/\")\n .action(async (profileName: string, toolName: string, argsRaw: string, options: { saveRun?: boolean }) => {\n const argsPath = readArgsPath(argsRaw);\n const toolArgs = argsRaw.startsWith(\"@\") ? await readJson(argsPath) : JSON.parse(argsRaw);\n const profile = await loadProfile(profileName);\n const request = { name: toolName, arguments: toolArgs };\n const command = `toolcapsule call ${profileName} ${toolName} ${argsRaw}`;\n const runId = createRunId();\n try {\n const response = await withClient(profile, (client) => client.callTool(toolName, toolArgs));\n console.log(JSON.stringify(response, null, 2));\n if (options.saveRun) {\n await ensureToolCapsuleIgnored();\n const dir = await saveRun(workspaceRunBaseDir(profile.name), {\n id: runId,\n createdAt: new Date().toISOString(),\n profile: profile.name,\n tool: toolName,\n argsFile: argsPath,\n status: \"success\",\n command,\n request,\n response,\n });\n console.error(pc.green(`Saved run: ${dir}`));\n }\n } catch (error) {\n if (options.saveRun) {\n await ensureToolCapsuleIgnored();\n const dir = await saveRun(workspaceRunBaseDir(profile.name), {\n id: runId,\n createdAt: new Date().toISOString(),\n profile: profile.name,\n tool: toolName,\n argsFile: argsPath,\n status: \"error\",\n command,\n request,\n error: error instanceof Error ? error.message : String(error),\n });\n console.error(pc.yellow(`Saved failed run: ${dir}`));\n }\n throw error;\n }\n });\n\ncli.command(\"retry <runDir>\", \"Retry a saved run, re-reading the args file\").action(async (runDir: string) => {\n const run = await loadRun(runDir);\n const toolArgs = await readJson(run.argsFile);\n const profile = await loadProfile(run.profile);\n const response = await withClient(profile, (client) => client.callTool(run.tool, toolArgs));\n console.log(JSON.stringify(response, null, 2));\n});\n\ncli.command(\"summarize <profile>\", \"Summarize all tools into compact JSON\").action(async (profileName: string) => {\n const profile = await loadProfile(profileName);\n const result = await withClient(profile, (client) => client.listTools());\n console.log(JSON.stringify(summarizeTools(result.tools), null, 2));\n});\n\ncli\n .command(\"benchmark <profile>\", \"Estimate schema savings for a profile\")\n .option(\"--markdown\", \"Print a Markdown report\")\n .option(\"--out <file>\", \"Write report to a file\")\n .action(async (profileName: string, options: { markdown?: boolean; out?: string }) => {\n const profile = await loadProfile(profileName);\n const result = await withClient(profile, (client) => client.listTools());\n const nativeTokens = roughTokens(result);\n const brief = summarizeTools(result.tools);\n const briefTokens = roughTokens(brief);\n const summary = {\n profile: profileName,\n tools: result.tools.length,\n nativeToolsRoughTokens: nativeTokens,\n summarizedToolsRoughTokens: briefTokens,\n estimatedReductionPct: Number(percentReduction(nativeTokens, briefTokens).toFixed(2)),\n };\n const output = options.markdown\n ? `# ToolCapsule benchmark: ${profileName}\\n\\n| Metric | Value |\\n|---|---:|\\n| MCP tools | ${summary.tools} |\\n| Native MCP schema rough tokens | ${summary.nativeToolsRoughTokens} |\\n| ToolCapsule summary rough tokens | ${summary.summarizedToolsRoughTokens} |\\n| Estimated reduction | ${summary.estimatedReductionPct}% |\\n\\n> Rough tokens are estimated from serialized schema length. Use this report to compare schema footprint before and after capsule summaries.\\n`\n : JSON.stringify(summary, null, 2);\n if (options.out) await writeFile(options.out, output);\n console.log(output);\n});\n\ncli.command(\"render-readme\", \"Print website hero copy snippets\").action(async () => {\n console.log(await readFile(new URL(\"../docs/hero-copy.md\", import.meta.url), \"utf8\"));\n});\n\ncli.help();\ncli.version(packageVersion);\n\ntry {\n cli.parse();\n} catch (error) {\n console.error(pc.red(error instanceof Error ? error.message : String(error)));\n process.exit(1);\n}\n","import { existsSync } from \"node:fs\";\nimport { mkdir, readFile, readdir, rename, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { basename, dirname, join } from \"node:path\";\nimport pc from \"picocolors\";\nimport { discoverMcpServers, type ImportedMcpServer } from \"./importer.js\";\nimport { toolCapsuleHome, workspaceProfilePath } from \"../paths.js\";\nimport type { ProfileConfig } from \"../types.js\";\nimport { readJson, writeJson } from \"../utils/fs.js\";\n\nexport type InventoryItem = {\n name: string;\n status: \"enabled\" | \"disabled\" | \"managed\" | \"error\";\n scope: \"workspace\" | \"user\" | \"managed\";\n source: string;\n mode: \"native\" | \"linked\" | \"snapshot\";\n path: string;\n originalName?: string;\n warnings?: string[];\n};\n\nfunction sourceScope(server: ImportedMcpServer): \"workspace\" | \"user\" | \"managed\" {\n if (server.source.managed) return \"managed\";\n return server.source.userLevel ? \"user\" : \"workspace\";\n}\n\nfunction sourceStatus(server: ImportedMcpServer): \"enabled\" | \"managed\" {\n return server.source.managed ? \"managed\" : \"enabled\";\n}\n\nasync function profileItems(dir: string, scope: \"workspace\" | \"user\"): Promise<InventoryItem[]> {\n if (!existsSync(dir)) return [];\n const entries = await readdir(dir, { withFileTypes: true });\n const items: InventoryItem[] = [];\n for (const entry of entries) {\n if (!entry.isFile() || !entry.name.endsWith(\".json\")) continue;\n const path = join(dir, entry.name);\n try {\n const profile = (await readJson(path)) as ProfileConfig;\n items.push({\n name: profile.name || basename(entry.name, \".json\"),\n status: \"enabled\",\n scope,\n source: \"toolcapsule\",\n mode: profile.kind === \"linked\" ? \"linked\" : \"snapshot\",\n path,\n });\n } catch {\n items.push({ name: basename(entry.name, \".json\"), status: \"error\", scope, source: \"toolcapsule\", mode: \"snapshot\", path });\n }\n }\n return items;\n}\n\nexport async function listMcpInventory(opts: { includeUser?: boolean } = {}): Promise<InventoryItem[]> {\n const nativeServers = await discoverMcpServers(opts.includeUser ? { includeUser: true, includeManaged: true } : {});\n const nativeItems = nativeServers.map((server): InventoryItem => ({\n name: server.name,\n originalName: server.originalName,\n status: sourceStatus(server),\n scope: sourceScope(server),\n source: server.source.tool,\n mode: \"native\",\n path: server.source.path,\n warnings: server.warnings,\n }));\n const workspaceProfiles = await profileItems(join(\".toolcapsule\", \"profiles\"), \"workspace\");\n const userProfiles = await profileItems(join(toolCapsuleHome(), \"profiles\"), \"user\");\n return [...nativeItems, ...workspaceProfiles, ...userProfiles];\n}\n\nfunction colorStatus(status: InventoryItem[\"status\"]): string {\n if (status === \"enabled\") return pc.green(\"● on\");\n if (status === \"disabled\") return pc.gray(\"○ off\");\n if (status === \"managed\") return pc.yellow(\"◆ managed\");\n return pc.red(\"× error\");\n}\n\nfunction colorMode(mode: InventoryItem[\"mode\"]): string {\n if (mode === \"linked\") return pc.cyan(mode);\n if (mode === \"snapshot\") return pc.magenta(mode);\n return pc.gray(mode);\n}\n\nfunction pad(value: string, width: number): string {\n return value.length >= width ? value : `${value}${\" \".repeat(width - value.length)}`;\n}\n\nfunction padDisplay(display: string, raw: string, width: number): string {\n return raw.length >= width ? display : `${display}${\" \".repeat(width - raw.length)}`;\n}\n\nexport function formatInventory(items: InventoryItem[]): string {\n if (items.length === 0) return \"No MCP servers found.\";\n const rows = items.map((item) => ({\n status: colorStatus(item.status),\n statusRaw: item.status === \"enabled\" ? \"● on\" : item.status === \"disabled\" ? \"○ off\" : item.status === \"managed\" ? \"◆ managed\" : \"× error\",\n name: item.originalName && item.originalName !== item.name ? `${item.name} (${item.originalName})` : item.name,\n scope: item.scope,\n source: item.source,\n mode: colorMode(item.mode),\n modeRaw: item.mode,\n path: item.path.replace(`${homedir()}/`, \"~/\"),\n }));\n const widths = {\n status: Math.max(\"STATUS\".length, ...rows.map((row) => row.statusRaw.length)),\n name: Math.max(\"NAME\".length, ...rows.map((row) => row.name.length)),\n scope: Math.max(\"SCOPE\".length, ...rows.map((row) => row.scope.length)),\n source: Math.max(\"SOURCE\".length, ...rows.map((row) => row.source.length)),\n mode: Math.max(\"MODE\".length, ...rows.map((row) => row.modeRaw.length)),\n };\n const lines = [\n `${pad(\"STATUS\", widths.status)} ${pad(\"NAME\", widths.name)} ${pad(\"SCOPE\", widths.scope)} ${pad(\"SOURCE\", widths.source)} ${pad(\"MODE\", widths.mode)} PATH`,\n ...rows.map(\n (row) =>\n `${padDisplay(row.status, row.statusRaw, widths.status)} ${pad(row.name, widths.name)} ${pad(row.scope, widths.scope)} ${pad(row.source, widths.source)} ${padDisplay(row.mode, row.modeRaw, widths.mode)} ${row.path}`,\n ),\n ];\n return lines.join(\"\\n\");\n}\n\ntype DisablePlan = {\n path: string;\n tool: string;\n server: string;\n fromKey: string;\n toKey: string;\n};\n\nfunction disableKeys(tool: string): { fromKey: string; toKey: string } {\n if (tool === \"vscode\" || tool === \"cursor\") return { fromKey: \"servers\", toKey: \"disabledServers\" };\n if (tool === \"opencode\") return { fromKey: \"mcp\", toKey: \"disabledMcp\" };\n return { fromKey: \"mcpServers\", toKey: \"disabledMcpServers\" };\n}\n\nexport async function disableNativeMcp(serverName: string, opts: { includeUser?: boolean; dryRun?: boolean } = {}): Promise<string> {\n const servers = await discoverMcpServers(opts.includeUser ? { includeUser: true } : {});\n const server = servers.find((item) => item.name === serverName || item.originalName === serverName);\n if (!server) throw new Error(`Native MCP server not found: ${serverName}`);\n if (server.source.managed) throw new Error(`Cannot modify managed MCP config: ${server.source.path}`);\n const keys = disableKeys(server.source.tool);\n const plan: DisablePlan = { path: server.source.path, tool: server.source.tool, server: server.originalName, ...keys };\n const message = `Disable native MCP ${plan.server} in ${plan.path}: move ${plan.fromKey}.${plan.server} -> ${plan.toKey}.${plan.server}`;\n if (opts.dryRun !== false) return `${message}\\nDry run only. Re-run with --yes to write changes.`;\n\n const config = (await readJson(plan.path)) as Record<string, unknown>;\n const source = config[plan.fromKey] && typeof config[plan.fromKey] === \"object\" && !Array.isArray(config[plan.fromKey]) ? (config[plan.fromKey] as Record<string, unknown>) : {};\n if (!(plan.server in source)) throw new Error(`Server ${plan.server} not found under ${plan.fromKey} in ${plan.path}`);\n const disabled = config[plan.toKey] && typeof config[plan.toKey] === \"object\" && !Array.isArray(config[plan.toKey]) ? (config[plan.toKey] as Record<string, unknown>) : {};\n disabled[plan.server] = source[plan.server];\n delete source[plan.server];\n config[plan.fromKey] = source;\n config[plan.toKey] = disabled;\n const backup = `${plan.path}.toolcapsule.bak`;\n await mkdir(dirname(backup), { recursive: true }).catch(() => undefined);\n if (existsSync(plan.path)) await writeFile(backup, await readFile(plan.path, \"utf8\"));\n await writeJson(plan.path, config);\n return `${message}\\nBackup: ${backup}`;\n}\n\nexport async function disableToolCapsuleProfile(profileName: string): Promise<string> {\n const candidates = [workspaceProfilePath(profileName), join(toolCapsuleHome(), \"profiles\", `${profileName}.json`)];\n const found = candidates.find((path) => existsSync(path));\n if (!found) throw new Error(`ToolCapsule profile not found: ${profileName}`);\n const disabledPath = `${found}.disabled`;\n await rename(found, disabledPath);\n return `Disabled ToolCapsule profile ${profileName}: ${found} -> ${disabledPath}`;\n}\n","import { existsSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { isAbsolute, join, resolve } from \"node:path\";\nimport type { McpProfileSource, ProfileConfig, SnapshotProfileConfig, TransportConfig } from \"../types.js\";\nimport { readJson } from \"../utils/fs.js\";\n\nexport type McpConfigSource = Omit<McpProfileSource, \"server\">;\n\nexport type ImportedMcpServer = {\n name: string;\n originalName: string;\n source: McpConfigSource;\n profile: SnapshotProfileConfig;\n warnings: string[];\n};\n\ntype ServerRecord = Record<string, unknown>;\n\nconst workspaceSources: McpConfigSource[] = [\n { tool: \"vscode\", path: join(\".vscode\", \"mcp.json\") },\n { tool: \"generic\", path: \"mcp.json\" },\n { tool: \"claude\", path: \".mcp.json\" },\n { tool: \"opencode\", path: \"opencode.json\" },\n { tool: \"gemini\", path: join(\".gemini\", \"settings.json\") },\n { tool: \"cursor\", path: join(\".cursor\", \"mcp.json\") },\n];\n\nconst userSources: McpConfigSource[] = [\n { tool: \"vscode\", path: join(homedir(), \".config\", \"Code\", \"User\", \"mcp.json\"), userLevel: true },\n { tool: \"vscode\", path: join(homedir(), \".config\", \"Code - Insiders\", \"User\", \"mcp.json\"), userLevel: true },\n { tool: \"vscode\", path: join(homedir(), \".vscode-server\", \"data\", \"User\", \"mcp.json\"), userLevel: true },\n { tool: \"vscode\", path: join(homedir(), \".vscode-server-insiders\", \"data\", \"User\", \"mcp.json\"), userLevel: true },\n { tool: \"claude\", path: join(homedir(), \".claude.json\"), userLevel: true },\n { tool: \"opencode\", path: join(homedir(), \".config\", \"opencode\", \"opencode.json\"), userLevel: true },\n { tool: \"gemini\", path: join(homedir(), \".gemini\", \"settings.json\"), userLevel: true },\n { tool: \"cursor\", path: join(homedir(), \".cursor\", \"mcp.json\"), userLevel: true },\n { tool: \"cursor\", path: join(homedir(), \".config\", \"Cursor\", \"User\", \"mcp.json\"), userLevel: true },\n { tool: \"cursor\", path: join(homedir(), \".config\", \"Cursor\", \"User\", \"settings.json\"), userLevel: true },\n];\n\nconst managedSources: McpConfigSource[] = [\n { tool: \"claude\", path: \"/etc/claude-code/managed-mcp.json\", managed: true },\n];\n\nfunction asRecord(value: unknown): ServerRecord | undefined {\n return value && typeof value === \"object\" && !Array.isArray(value) ? (value as ServerRecord) : undefined;\n}\n\nfunction stringArray(value: unknown): string[] | undefined {\n return Array.isArray(value) && value.every((item) => typeof item === \"string\") ? value : undefined;\n}\n\nfunction stringRecord(value: unknown): Record<string, string> | undefined {\n const record = asRecord(value);\n if (!record) return undefined;\n const entries = Object.entries(record).filter((entry): entry is [string, string] => typeof entry[1] === \"string\");\n return entries.length > 0 ? Object.fromEntries(entries) : undefined;\n}\n\nfunction cleanName(name: string): string {\n const cleaned = name\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .replace(/-{2,}/g, \"-\");\n return cleaned || \"imported-mcp\";\n}\n\nfunction mapServer(name: string, source: McpConfigSource, raw: unknown): ImportedMcpServer | undefined {\n const server = asRecord(raw);\n if (!server) return undefined;\n\n const warnings: string[] = [];\n let transport: TransportConfig | undefined;\n const type = typeof server.type === \"string\" ? server.type : undefined;\n const url = typeof server.url === \"string\" ? server.url : typeof server.httpUrl === \"string\" ? server.httpUrl : undefined;\n const commandValue = server.command;\n const headers = stringRecord(server.headers);\n const env = stringRecord(server.env) ?? stringRecord(server.environment);\n const cwd = typeof server.cwd === \"string\" ? server.cwd : undefined;\n\n if (url && (!type || [\"http\", \"streamable-http\", \"remote\", \"sse\", \"ws\"].includes(type))) {\n transport = { type: \"remote\", url, ...(headers ? { headers } : {}), ...(env ? { env } : {}) };\n if (type === \"sse\" || type === \"ws\") warnings.push(`Imported ${type} server as remote URL; verify transport compatibility.`);\n } else if (typeof commandValue === \"string\") {\n transport = {\n type: \"stdio\",\n command: commandValue,\n args: stringArray(server.args) ?? [],\n ...(env ? { env } : {}),\n ...(cwd ? { cwd } : {}),\n };\n } else if (Array.isArray(commandValue) && commandValue.every((item) => typeof item === \"string\") && commandValue.length > 0) {\n transport = { type: \"stdio\", command: commandValue[0]!, args: commandValue.slice(1), ...(env ? { env } : {}), ...(cwd ? { cwd } : {}) };\n }\n\n if (!transport) return undefined;\n if (server.headers && !headers) warnings.push(\"Headers were present but not copied because they were not string values.\");\n if ((server.env || server.environment) && !env) warnings.push(\"Environment variables were present but not copied because they were not string values.\");\n if (server.includeTools || server.excludeTools) warnings.push(\"Tool include/exclude filters were not copied; use ToolCapsule brief/schema commands to choose tools manually.\");\n\n const profileName = cleanName(name);\n return {\n name: profileName,\n originalName: name,\n source,\n warnings,\n profile: {\n name: profileName,\n transport,\n },\n };\n}\n\nexport function linkedProfileForImportedServer(server: ImportedMcpServer, name = server.name): ProfileConfig {\n return {\n name,\n kind: \"linked\",\n source: {\n ...server.source,\n path: isAbsolute(server.source.path) ? server.source.path : resolve(server.source.path),\n server: server.originalName,\n },\n };\n}\n\nexport async function resolveProfileSource(source: McpProfileSource): Promise<SnapshotProfileConfig | undefined> {\n if (!existsSync(source.path)) return undefined;\n const config = asRecord(await readJson(source.path));\n if (!config) return undefined;\n const entry = serverEntries(source, config).find(([name]) => name === source.server);\n if (!entry) return undefined;\n return mapServer(entry[0], source, entry[1])?.profile;\n}\n\nfunction serverEntries(source: McpConfigSource, config: ServerRecord): Array<[string, unknown]> {\n if (source.tool === \"vscode\" || source.tool === \"cursor\") return Object.entries(asRecord(config.servers) ?? {});\n if (source.tool === \"opencode\") return Object.entries(asRecord(config.mcp) ?? {});\n if (source.tool === \"claude\") {\n const projectEntries = Object.entries(asRecord(config.mcpServers) ?? {});\n const projectConfigs = Object.entries(asRecord(config.projects) ?? {}).flatMap(([, project]) =>\n Object.entries(asRecord(asRecord(project)?.mcpServers) ?? {}),\n );\n return [...projectEntries, ...projectConfigs];\n }\n return Object.entries(asRecord(config.mcpServers) ?? {});\n}\n\nexport async function discoverMcpServers(opts: { includeUser?: boolean; includeManaged?: boolean } = {}): Promise<ImportedMcpServer[]> {\n const sources = [\n ...workspaceSources,\n ...(opts.includeUser ? userSources : []),\n ...(opts.includeManaged ? managedSources : []),\n ];\n const discovered: ImportedMcpServer[] = [];\n\n for (const source of sources) {\n if (!existsSync(source.path)) continue;\n const config = asRecord(await readJson(source.path));\n if (!config) continue;\n for (const [name, raw] of serverEntries(source, config)) {\n const imported = mapServer(name, source, raw);\n if (imported) discovered.push(imported);\n }\n }\n\n return discovered;\n}\n\nexport function selectImportedServers(servers: ImportedMcpServer[], name?: string, all?: boolean): ImportedMcpServer[] {\n if (all) return servers;\n if (!name) return servers.length === 1 ? servers : [];\n const normalized = cleanName(name);\n return servers.filter((server) => server.name === normalized || server.name === name);\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname, resolve } from \"node:path\";\n\nexport async function readJson<T>(path: string): Promise<T> {\n return JSON.parse(await readFile(path, \"utf8\")) as T;\n}\n\nexport async function writeJson(path: string, value: unknown): Promise<void> {\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, `${JSON.stringify(value, null, 2)}\\n`);\n}\n\nexport async function writeText(path: string, value: string): Promise<void> {\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, value);\n}\n\nexport async function ensureToolCapsuleIgnored(): Promise<void> {\n const gitignorePath = \".gitignore\";\n const entry = \".toolcapsule/\";\n let content = \"\";\n try {\n content = await readFile(gitignorePath, \"utf8\");\n } catch (error) {\n if (!(error instanceof Error && \"code\" in error && error.code === \"ENOENT\")) throw error;\n }\n\n const lines = content.split(/\\r?\\n/).map((line) => line.trim());\n const alreadyIgnored = lines.some((line) => line === entry || line === `/${entry}` || line === \".toolcapsule\");\n if (alreadyIgnored) return;\n\n const prefix = content.length > 0 && !content.endsWith(\"\\n\") ? \"\\n\" : \"\";\n await writeFile(gitignorePath, `${content}${prefix}${entry}\\n`);\n}\n\nexport function abs(path: string): string {\n return resolve(process.cwd(), path);\n}\n","import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\nexport function toolCapsuleHome(): string {\n return process.env.TOOLCAPSULE_HOME || join(homedir(), \".toolcapsule\");\n}\n\nexport function userProfilePath(profileName: string): string {\n return join(toolCapsuleHome(), \"profiles\", `${profileName}.json`);\n}\n\nexport function workspaceProfilePath(profileName: string): string {\n return join(\".toolcapsule\", \"profiles\", `${profileName}.json`);\n}\n\nexport function workspaceRunBaseDir(profileName: string): string {\n return join(\".toolcapsule\", \"runs\", profileName);\n}\n","import { spawn, type ChildProcessWithoutNullStreams } from \"node:child_process\";\nimport { once } from \"node:events\";\nimport { resolve } from \"node:path\";\nimport type { JsonRpcMessage, SnapshotProfileConfig, ToolsListResult } from \"../types.js\";\n\nexport type McpClientOptions = {\n timeoutMs?: number;\n debug?: boolean;\n clientVersion?: string;\n};\n\nexport class McpClient {\n private child: ChildProcessWithoutNullStreams;\n private nextId = 1;\n private buffer = \"\";\n private pending = new Map<\n number,\n { resolve: (value: JsonRpcMessage) => void; reject: (error: Error) => void }\n >();\n private timeoutMs: number;\n private debug: boolean;\n private clientVersion: string;\n\n constructor(profile: SnapshotProfileConfig, opts: McpClientOptions = {}) {\n this.timeoutMs = opts.timeoutMs ?? Number(process.env.TOOLCAPSULE_TIMEOUT_MS || \"45000\");\n this.debug = opts.debug ?? process.env.TOOLCAPSULE_DEBUG === \"1\";\n this.clientVersion = opts.clientVersion ?? \"0.0.0\";\n if (profile.transport.type === \"remote\") {\n this.child = spawn(\"npx\", [\"-y\", \"mcp-remote\", profile.transport.url, ...headersToArgs(profile.transport.headers)], {\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n env: { ...process.env, ...profile.transport.env },\n });\n } else {\n this.child = spawn(profile.transport.command, profile.transport.args ?? [], {\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n env: { ...process.env, ...profile.transport.env },\n cwd: profile.transport.cwd ? resolve(profile.transport.cwd) : undefined,\n });\n }\n this.child.stdout.setEncoding(\"utf8\");\n this.child.stdout.on(\"data\", (chunk: string) => this.onStdout(chunk));\n this.child.stderr.on(\"data\", (chunk: Buffer) => this.onStderr(chunk));\n this.child.on(\"exit\", (code, signal) => {\n const error = new Error(`MCP process exited early (code=${code}, signal=${signal})`);\n for (const waiter of this.pending.values()) waiter.reject(error);\n this.pending.clear();\n });\n }\n\n private onStderr(chunk: Buffer): void {\n if (!this.debug) return;\n process.stderr.write(redactSecrets(chunk.toString(\"utf8\")));\n }\n\n private onStdout(chunk: string): void {\n this.buffer += chunk;\n let newlineIndex: number;\n while ((newlineIndex = this.buffer.indexOf(\"\\n\")) >= 0) {\n const line = this.buffer.slice(0, newlineIndex).trim();\n this.buffer = this.buffer.slice(newlineIndex + 1);\n if (!line) continue;\n let message: JsonRpcMessage;\n try {\n message = JSON.parse(line) as JsonRpcMessage;\n } catch {\n process.stderr.write(`${line}\\n`);\n continue;\n }\n if (typeof message.id === \"number\") {\n const waiter = this.pending.get(message.id);\n if (waiter) {\n this.pending.delete(message.id);\n waiter.resolve(message);\n }\n }\n }\n }\n\n async init(): Promise<void> {\n await this.request(\"initialize\", {\n protocolVersion: \"2025-03-26\",\n capabilities: {},\n clientInfo: { name: \"toolcapsule\", version: this.clientVersion },\n });\n this.notify(\"notifications/initialized\", {});\n }\n\n async request(method: string, params?: unknown): Promise<unknown> {\n const id = this.nextId++;\n const responsePromise = new Promise<JsonRpcMessage>((resolve, reject) => {\n this.pending.set(id, { resolve, reject });\n });\n this.child.stdin.write(`${JSON.stringify({ jsonrpc: \"2.0\", id, method, params })}\\n`);\n const response = await this.withTimeout(responsePromise, method);\n if (response.error) throw new Error(`${method} failed: ${JSON.stringify(response.error, null, 2)}`);\n return response.result;\n }\n\n notify(method: string, params?: unknown): void {\n this.child.stdin.write(`${JSON.stringify({ jsonrpc: \"2.0\", method, params })}\\n`);\n }\n\n async listTools(): Promise<ToolsListResult> {\n return (await this.request(\"tools/list\", {})) as ToolsListResult;\n }\n\n async callTool(name: string, args: unknown): Promise<unknown> {\n return await this.request(\"tools/call\", { name, arguments: args });\n }\n\n async close(): Promise<void> {\n if (!this.child.killed) this.child.kill();\n if (this.child.exitCode === null) await Promise.race([once(this.child, \"exit\"), new Promise((resolve) => setTimeout(resolve, 500))]);\n }\n\n private async withTimeout<T>(promise: Promise<T>, label: string): Promise<T> {\n let timer: NodeJS.Timeout | undefined;\n const timeout = new Promise<never>((_, reject) => {\n timer = setTimeout(() => reject(new Error(`${label} timed out after ${this.timeoutMs}ms`)), this.timeoutMs);\n });\n try {\n return await Promise.race([promise, timeout]);\n } finally {\n if (timer) clearTimeout(timer);\n }\n }\n}\n\nfunction headersToArgs(headers: Record<string, string> | undefined): string[] {\n if (!headers) return [];\n return Object.entries(headers).flatMap(([key, value]) => [\"--header\", `${key}:${value}`]);\n}\n\nfunction redactSecrets(text: string): string {\n return text\n .replace(/https:\\/\\/mcp\\.feishu\\.cn\\/mcp\\/[^\\s\"']+/g, \"https://mcp.feishu.cn/mcp/[redacted]\")\n .replace(/(Bearer\\s+)[A-Za-z0-9._~+/=-]+/gi, \"$1[redacted]\")\n .replace(/(token=)[^\\s&\"']+/gi, \"$1[redacted]\")\n .replace(/(api[_-]?key=)[^\\s&\"']+/gi, \"$1[redacted]\");\n}\n","import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { z } from \"zod\";\nimport { resolveProfileSource } from \"./mcp/importer.js\";\nimport { userProfilePath, workspaceProfilePath } from \"./paths.js\";\nimport type { ProfileConfig, SnapshotProfileConfig } from \"./types.js\";\nimport { readJson } from \"./utils/fs.js\";\n\nconst transportSchema = z.union([\n z.object({\n type: z.literal(\"remote\"),\n url: z.string().url(),\n headers: z.record(z.string()).optional(),\n env: z.record(z.string()).optional(),\n }),\n z.object({\n type: z.literal(\"stdio\"),\n command: z.string().min(1),\n args: z.array(z.string()).optional(),\n env: z.record(z.string()).optional(),\n cwd: z.string().optional(),\n }),\n]);\n\nconst skillSchema = z\n .object({\n name: z.string().optional(),\n description: z.string().optional(),\n })\n .optional();\n\nconst shortcutsSchema = z\n .record(\n z.object({\n tool: z.string(),\n description: z.string().optional(),\n args: z.record(z.enum([\"string\", \"file\", \"json\", \"boolean\", \"number\"])).optional(),\n }),\n )\n .optional();\n\nconst snapshotProfileSchema = z.object({\n name: z.string().min(1),\n kind: z.literal(\"snapshot\").optional(),\n transport: transportSchema,\n skill: skillSchema,\n shortcuts: shortcutsSchema,\n});\n\nconst linkedProfileSchema = z.object({\n name: z.string().min(1),\n kind: z.literal(\"linked\"),\n source: z.object({\n tool: z.enum([\"vscode\", \"claude\", \"opencode\", \"gemini\", \"cursor\", \"generic\"]),\n path: z.string().min(1),\n server: z.string().min(1),\n userLevel: z.boolean().optional(),\n }),\n skill: skillSchema,\n shortcuts: shortcutsSchema,\n});\n\nconst profileSchema = z.union([snapshotProfileSchema, linkedProfileSchema]);\n\nexport async function loadProfile(profilePathOrName: string): Promise<SnapshotProfileConfig> {\n const candidates = [\n profilePathOrName,\n `${profilePathOrName}.json`,\n workspaceProfilePath(profilePathOrName),\n userProfilePath(profilePathOrName),\n join(\".github\", \"skills\", `${profilePathOrName}-mcp`, \"toolcapsule.config.json\"),\n join(\".claude\", \"skills\", `${profilePathOrName}-mcp`, \"toolcapsule.config.json\"),\n join(\".opencode\", \"skills\", `${profilePathOrName}-mcp`, \"toolcapsule.config.json\"),\n join(\".agents\", \"skills\", `${profilePathOrName}-mcp`, \"toolcapsule.config.json\"),\n ];\n const found = candidates.find((path) => existsSync(path));\n if (!found) throw new Error(`Profile not found: ${profilePathOrName}`);\n const profile = profileSchema.parse(await readJson(found)) as ProfileConfig;\n if (profile.kind !== \"linked\") return profile;\n\n const resolved = await resolveProfileSource(profile.source);\n if (!resolved) {\n throw new Error(`Linked profile source not found: ${profile.source.path}#${profile.source.server}`);\n }\n\n return snapshotProfileSchema.parse({\n ...resolved,\n name: profile.name,\n skill: profile.skill ?? resolved.skill,\n shortcuts: profile.shortcuts ?? resolved.shortcuts,\n }) as SnapshotProfileConfig;\n}\n","import type { McpTool } from \"../types.js\";\n\nexport function toolTitle(tool: McpTool): string {\n return tool.annotations?.title || tool.description?.split(/\\n/)[0]?.slice(0, 100) || tool.name;\n}\n\nexport function briefTool(tool: McpTool): string {\n const schema = tool.inputSchema as any;\n const required = Array.isArray(schema?.required) ? schema.required : [];\n const properties = schema?.properties && typeof schema.properties === \"object\" ? Object.keys(schema.properties) : [];\n const flags = [\n tool.annotations?.readOnlyHint ? \"read-only\" : undefined,\n tool.annotations?.destructiveHint ? \"destructive\" : undefined,\n ].filter(Boolean);\n return `- ${tool.name}: ${toolTitle(tool)}${flags.length ? ` [${flags.join(\", \")}]` : \"\"}${required.length ? ` required=${required.join(\"|\")}` : \"\"}${properties.length ? ` args=${properties.slice(0, 12).join(\"|\")}` : \"\"}`;\n}\n\nexport function briefTools(tools: McpTool[]): string {\n return tools.map(briefTool).join(\"\\n\");\n}\n","import type { McpTool } from \"../types.js\";\n\nexport function summarizeTool(tool: McpTool): unknown {\n const schema = tool.inputSchema as any;\n const properties = schema?.properties && typeof schema.properties === \"object\" ? schema.properties : {};\n return {\n name: tool.name,\n title: tool.annotations?.title,\n description: tool.description?.split(/\\n\\n/)[0]?.slice(0, 500),\n annotations: tool.annotations,\n required: Array.isArray(schema?.required) ? schema.required : [],\n arguments: Object.fromEntries(\n Object.entries(properties).map(([key, value]: [string, any]) => [\n key,\n { type: value?.type, enum: value?.enum, description: value?.description?.slice?.(0, 160) },\n ]),\n ),\n };\n}\n\nexport function summarizeTools(tools: McpTool[]): unknown[] {\n return tools.map(summarizeTool);\n}\n","import { mkdir, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport Handlebars from \"handlebars\";\nimport { McpClient } from \"../mcp/client.js\";\nimport type { McpTool } from \"../types.js\";\nimport { summarizeTools } from \"../schema/summarize.js\";\nimport type { ProfileConfig } from \"../types.js\";\nimport { writeJson } from \"../utils/fs.js\";\n\nexport type SkillTarget = \"copilot\" | \"claude\" | \"opencode\" | \"agents\" | \"all\";\n\nexport const defaultSkillTarget: SkillTarget = \"claude\";\n\nexport function skillOutputDir(skillName: string, target: Exclude<SkillTarget, \"all\">): string {\n if (target === \"copilot\") return join(\".github\", \"skills\", skillName);\n if (target === \"claude\") return join(\".claude\", \"skills\", skillName);\n if (target === \"opencode\") return join(\".opencode\", \"skills\", skillName);\n return join(\".agents\", \"skills\", skillName);\n}\n\nexport function expandSkillTargets(target: SkillTarget): Exclude<SkillTarget, \"all\">[] {\n return target === \"all\" ? [\"copilot\", \"claude\", \"opencode\", \"agents\"] : [target];\n}\n\nconst skillTemplate = `---\nname: {{skillName}}\ndescription: '{{description}}'\nargument-hint: 'MCP task, tool name, or args file to run'\n---\n\n# {{title}}\n\nThis skill wraps an MCP server as a lightweight, lazy-loaded, file-first workflow.\n\n## Why use this skill\n\n- Keep full MCP tool schemas out of the model context until needed.\n- Use brief tool summaries for everyday work.\n- Store large payloads in local files such as \\`args.json\\` or \\`content.md\\`.\n- Patch local artifacts and retry failed calls deterministically.\n\n## Commands\n\n\\`\\`\\`bash\ntoolcapsule tools {{profileName}} --brief\ntoolcapsule describe {{profileName}} <tool>\ntoolcapsule call {{profileName}} <tool> @args.json\ntoolcapsule retry .toolcapsule/runs/{{profileName}}/<run-id>\n\\`\\`\\`\n\n{{#if toolsMarkdown}}\n## Tool summary\n\nUse this summary for planning. Only run \\`toolcapsule schema {{profileName}} <tool>\\` when these brief details are insufficient.\n\n{{{toolsMarkdown}}}\n{{else}}\n## Tool discovery\n\nRun \\`toolcapsule tools {{profileName}} --brief\\` once before choosing a tool. Then run \\`toolcapsule schema {{profileName}} <tool>\\` only when the brief summary is insufficient.\n{{/if}}\n\n## Workflow\n\n1. Use \\`tools --brief\\` to find the likely tool.\n2. Use \\`describe <tool>\\` only when the brief schema is insufficient.\n3. Put complex arguments in a local JSON file.\n4. Call with \\`@args.json\\` and save the run.\n5. On failure, patch the local file and run \\`retry\\`.\n\n## Safety\n\n- Do not fabricate IDs, URLs, user IDs, or opaque tokens.\n- Prefer local files for large payloads.\n- Do not print secrets.\n- Review destructive tools before calling.\n`;\n\nexport type GenerateSkillOptions = {\n outputDir?: string;\n target?: SkillTarget;\n embedProfile?: boolean;\n tools?: McpTool[];\n};\n\ntype ToolSummary = {\n name?: string;\n description?: string;\n required?: unknown;\n annotations?: { readOnlyHint?: boolean; destructiveHint?: boolean };\n};\n\nfunction toolsMarkdown(tools: McpTool[] | undefined): string | undefined {\n if (!tools || tools.length === 0) return undefined;\n const summaries = summarizeTools(tools) as ToolSummary[];\n const rows = summaries.slice(0, 40).map((tool) => {\n const required = Array.isArray(tool.required) && tool.required.length > 0 ? tool.required.join(\", \") : \"-\";\n const risk = tool.annotations?.destructiveHint ? \"writes\" : tool.annotations?.readOnlyHint ? \"read\" : \"unknown\";\n const description = (tool.description || \"-\").replace(/\\|/g, \"\\\\|\").slice(0, 120);\n return `| \\`${tool.name || \"unknown\"}\\` | ${description} | ${required} | ${risk} |`;\n });\n return [\"| Tool | Purpose | Required args | Risk |\", \"|---|---|---|---|\", ...rows].join(\"\\n\");\n}\n\nexport async function fetchProfileTools(profile: ProfileConfig, opts: { clientVersion?: string } = {}): Promise<McpTool[] | undefined> {\n if (profile.kind === \"linked\") return undefined;\n const client = new McpClient(profile, { ...(opts.clientVersion ? { clientVersion: opts.clientVersion } : {}), timeoutMs: 15000 });\n try {\n await client.init();\n return (await client.listTools()).tools;\n } catch {\n return undefined;\n } finally {\n await client.close().catch(() => undefined);\n }\n}\n\nasync function generateSkillAt(profile: ProfileConfig, outputDir: string, opts: { embedProfile?: boolean; tools?: McpTool[] } = {}): Promise<string> {\n const skillName = profile.skill?.name || `${profile.name}-mcp`;\n await mkdir(join(outputDir, \"scripts\"), { recursive: true });\n\n const template = Handlebars.compile(skillTemplate);\n const description =\n profile.skill?.description ||\n `Use when operating tools from the ${profile.name} MCP server. Lazy-load schemas, call tools through local files, and retry failed calls by patching artifacts.`;\n const markdown = template({\n skillName,\n profileName: profile.name,\n title: `${profile.name} MCP Skill`,\n description: description.replace(/'/g, \"''\"),\n toolsMarkdown: toolsMarkdown(opts.tools),\n });\n await writeFile(join(outputDir, \"SKILL.md\"), markdown);\n if (opts.embedProfile) await writeJson(join(outputDir, \"toolcapsule.config.json\"), profile);\n await writeFile(\n join(outputDir, \"scripts\", \"README.md\"),\n `# Scripts\\n\\nThis skill uses the \\`toolcapsule\\` CLI and profiles resolved by name.\\n`,\n );\n return outputDir;\n}\n\nexport async function generateSkill(profile: ProfileConfig, opts: GenerateSkillOptions = {}): Promise<string> {\n const skillName = profile.skill?.name || `${profile.name}-mcp`;\n const target = opts.target || defaultSkillTarget;\n const embedProfile = opts.embedProfile === true;\n const atOptions = { embedProfile, ...(opts.tools ? { tools: opts.tools } : {}) };\n const outputs = opts.outputDir\n ? [await generateSkillAt(profile, opts.outputDir, atOptions)]\n : await Promise.all(\n expandSkillTargets(target).map((item) =>\n generateSkillAt(profile, skillOutputDir(skillName, item), atOptions),\n ),\n );\n return outputs.join(\", \");\n}\n\nexport async function writeProfile(path: string, profile: ProfileConfig): Promise<void> {\n await mkdir(dirname(path), { recursive: true });\n await writeJson(path, profile);\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { defaultSkillTarget, expandSkillTargets, skillOutputDir, type SkillTarget } from \"./generator.js\";\n\nexport async function installAgentSkill(outputDir?: string, target: SkillTarget = defaultSkillTarget): Promise<string> {\n let agentSkill: string;\n try {\n agentSkill = await readFile(new URL(\"../skills/toolcapsule/SKILL.md\", import.meta.url), \"utf8\");\n } catch {\n agentSkill = await readFile(new URL(\"../../skills/toolcapsule/SKILL.md\", import.meta.url), \"utf8\");\n }\n const outputDirs = outputDir ? [outputDir] : expandSkillTargets(target).map((item) => skillOutputDir(\"toolcapsule\", item));\n await Promise.all(\n outputDirs.map(async (dir) => {\n await mkdir(dir, { recursive: true });\n await writeFile(join(dir, \"SKILL.md\"), agentSkill);\n }),\n );\n return outputDirs.join(\", \");\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport type { RunRecord } from \"../types.js\";\nimport { writeJson } from \"../utils/fs.js\";\n\nexport function createRunId(): string {\n return new Date().toISOString().replace(/[:.]/g, \"-\");\n}\n\nexport async function saveRun(baseDir: string, record: RunRecord): Promise<string> {\n const dir = join(baseDir, record.id);\n await mkdir(dir, { recursive: true });\n await writeJson(join(dir, \"run.json\"), record);\n await writeJson(join(dir, \"request.json\"), record.request);\n if (record.response !== undefined) await writeJson(join(dir, \"response.json\"), record.response);\n if (record.error) await writeFile(join(dir, \"error.txt\"), record.error);\n await writeFile(join(dir, \"command.txt\"), `${record.command}\\n`);\n return dir;\n}\n\nexport async function loadRun(runDir: string): Promise<RunRecord> {\n return JSON.parse(await readFile(join(runDir, \"run.json\"), \"utf8\")) as RunRecord;\n}\n","export function roughTokens(value: unknown): number {\n const text = typeof value === \"string\" ? value : JSON.stringify(value);\n return Math.ceil(text.length / 4);\n}\n\nexport function percentReduction(before: number, after: number): number {\n return before === 0 ? 0 : ((before - after) / before) * 100;\n}\n"],"mappings":";;;AACA,SAAS,YAAAA,iBAAgB;AACzB,SAAS,WAAW;AACpB,OAAOC,SAAQ;;;ACHf,SAAS,cAAAC,mBAAkB;AAC3B,SAAS,SAAAC,QAAO,YAAAC,WAAU,SAAS,QAAQ,aAAAC,kBAAiB;AAC5D,SAAS,WAAAC,gBAAe;AACxB,SAAS,UAAU,WAAAC,UAAS,QAAAC,aAAY;AACxC,OAAO,QAAQ;;;ACJf,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AACxB,SAAS,YAAY,MAAM,WAAAC,gBAAe;;;ACF1C,SAAS,OAAO,UAAU,iBAAiB;AAC3C,SAAS,SAAS,eAAe;AAEjC,eAAsB,SAAY,MAA0B;AAC1D,SAAO,KAAK,MAAM,MAAM,SAAS,MAAM,MAAM,CAAC;AAChD;AAEA,eAAsB,UAAU,MAAc,OAA+B;AAC3E,QAAM,MAAM,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC9C,QAAM,UAAU,MAAM,GAAG,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AAAA,CAAI;AAC7D;AAOA,eAAsB,2BAA0C;AAC9D,QAAM,gBAAgB;AACtB,QAAM,QAAQ;AACd,MAAI,UAAU;AACd,MAAI;AACF,cAAU,MAAM,SAAS,eAAe,MAAM;AAAA,EAChD,SAAS,OAAO;AACd,QAAI,EAAE,iBAAiB,SAAS,UAAU,SAAS,MAAM,SAAS,UAAW,OAAM;AAAA,EACrF;AAEA,QAAM,QAA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,wBAAwB,EAC/C,OAAO,OAAO,aAAqB,YAAkD;AACtF,QAAM,UAAU,MAAM,YAAY,WAAW;AAC7C,QAAM,SAAS,MAAM,WAAW,SAAS,CAAC,WAAW,OAAO,UAAU,CAAC;AACvE,QAAM,eAAe,YAAY,MAAM;AACvC,QAAM,QAAQ,eAAe,OAAO,KAAK;AACzC,QAAM,cAAc,YAAY,KAAK;AACrC,QAAM,UAAU;AAAA,IACd,SAAS;AAAA,IACT,OAAO,OAAO,MAAM;AAAA,IACpB,wBAAwB;AAAA,IACxB,4BAA4B;AAAA,IAC5B,uBAAuB,OAAO,iBAAiB,cAAc,WAAW,EAAE,QAAQ,CAAC,CAAC;AAAA,EACtF;AACA,QAAM,SAAS,QAAQ,WACnB,4BAA4B,WAAW;AAAA;AAAA;AAAA;AAAA,gBAAqD,QAAQ,KAAK;AAAA,qCAA0C,QAAQ,sBAAsB;AAAA,uCAA4C,QAAQ,0BAA0B;AAAA,0BAA+B,QAAQ,qBAAqB;AAAA;AAAA;AAAA,IAC3T,KAAK,UAAU,SAAS,MAAM,CAAC;AACnC,MAAI,QAAQ,IAAK,OAAMC,WAAU,QAAQ,KAAK,MAAM;AACpD,UAAQ,IAAI,MAAM;AACpB,CAAC;AAED,IAAI,QAAQ,iBAAiB,kCAAkC,EAAE,OAAO,YAAY;AAClF,UAAQ,IAAI,MAAMF,UAAS,IAAI,IAAI,wBAAwB,YAAY,GAAG,GAAG,MAAM,CAAC;AACtF,CAAC;AAED,IAAI,KAAK;AACT,IAAI,QAAQ,cAAc;AAE1B,IAAI;AACF,MAAI,MAAM;AACZ,SAAS,OAAO;AACd,UAAQ,MAAMC,IAAG,IAAI,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,CAAC;AAC5E,UAAQ,KAAK,CAAC;AAChB;","names":["readFile","pc","existsSync","mkdir","readFile","writeFile","homedir","dirname","join","resolve","resolve","homedir","join","existsSync","join","homedir","mkdir","dirname","writeFile","readFile","resolve","existsSync","join","join","existsSync","mkdir","writeFile","dirname","join","join","mkdir","writeFile","dirname","mkdir","readFile","writeFile","join","readFile","mkdir","writeFile","join","mkdir","readFile","writeFile","join","join","mkdir","writeFile","readFile","writeFile","readFile","pc","writeFile"]}
1
+ {"version":3,"sources":["../src/cli.ts","../src/mcp/inventory.ts","../src/mcp/importer.ts","../src/utils/fs.ts","../src/paths.ts","../src/mcp/client.ts","../src/profile.ts","../src/schema/brief.ts","../src/schema/summarize.ts","../src/skill/generator.ts","../src/skill/installer.ts","../src/runs/recorder.ts","../src/utils/tokens.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { readFile } from \"node:fs/promises\";\nimport { cac } from \"cac\";\nimport pc from \"picocolors\";\nimport type { ProfileConfig, SnapshotProfileConfig } from \"./types.js\";\nimport { disableNativeMcp, disableToolCapsuleProfile, formatInventory, listMcpInventory } from \"./mcp/inventory.js\";\nimport { McpClient } from \"./mcp/client.js\";\nimport { discoverMcpServers, linkedProfileForImportedServer, selectImportedServers } from \"./mcp/importer.js\";\nimport { userProfilePath, workspaceProfilePath, workspaceRunBaseDir } from \"./paths.js\";\nimport { loadProfile } from \"./profile.js\";\nimport { briefTools } from \"./schema/brief.js\";\nimport { summarizeTool, summarizeTools } from \"./schema/summarize.js\";\nimport { defaultSkillTarget, fetchProfileTools, generateSkill, type SkillTarget, writeProfile } from \"./skill/generator.js\";\nimport { installAgentSkill } from \"./skill/installer.js\";\nimport { createRunId, loadRun, saveRun } from \"./runs/recorder.js\";\nimport { writeFile } from \"node:fs/promises\";\nimport { ensureToolCapsuleIgnored, readJson } from \"./utils/fs.js\";\nimport { percentReduction, roughTokens } from \"./utils/tokens.js\";\n\nconst cli = cac(\"toolcapsule\");\n\nasync function readPackageVersion(): Promise<string> {\n try {\n const pkg = JSON.parse(await readFile(new URL(\"../package.json\", import.meta.url), \"utf8\")) as { version?: string };\n return pkg.version || \"0.0.0\";\n } catch {\n return \"0.0.0\";\n }\n}\n\nconst packageVersion = await readPackageVersion();\n\nasync function withClient<T>(profile: SnapshotProfileConfig, fn: (client: McpClient) => Promise<T>): Promise<T> {\n const client = new McpClient(profile, { clientVersion: packageVersion });\n try {\n await client.init();\n return await fn(client);\n } finally {\n await client.close();\n }\n}\n\nfunction readArgsPath(raw: string): string {\n return raw.startsWith(\"@\") ? raw.slice(1) : raw;\n}\n\nfunction readSkillTarget(raw: string | undefined): SkillTarget {\n const target = raw || defaultSkillTarget;\n if ([\"copilot\", \"claude\", \"opencode\", \"agents\", \"all\"].includes(target)) return target as SkillTarget;\n throw new Error(\"Invalid --target. Use one of: copilot, claude, opencode, agents, all\");\n}\n\nfunction renameSnapshotProfile(profile: SnapshotProfileConfig, name: string): SnapshotProfileConfig {\n return { ...profile, name };\n}\n\nasync function writeImportedServer(\n server: Awaited<ReturnType<typeof discoverMcpServers>>[number],\n opts: { as?: string | undefined; local?: boolean | undefined; copy?: boolean | undefined; target?: string | undefined },\n): Promise<void> {\n const profileName = opts.as || server.name;\n const local = opts.local === true;\n const copy = opts.copy === true;\n const profilePath = local ? workspaceProfilePath(profileName) : userProfilePath(profileName);\n if (local) await ensureToolCapsuleIgnored();\n const profile = copy ? renameSnapshotProfile(server.profile, profileName) : linkedProfileForImportedServer(server, profileName);\n await writeProfile(profilePath, profile);\n const tools = await fetchProfileTools(renameSnapshotProfile(server.profile, profileName), { clientVersion: packageVersion });\n const skillOptions = { target: readSkillTarget(opts.target), embedProfile: local, ...(tools ? { tools } : {}) };\n const out = await generateSkill(profile, skillOptions);\n const mode = copy ? \"snapshot\" : \"linked\";\n console.log(pc.green(`Imported ${server.name} as ${profileName} from ${server.source.path} -> ${profilePath} (${mode}), ${out}`));\n for (const warning of server.warnings) console.log(pc.yellow(` warning: ${warning}`));\n}\n\ncli\n .command(\"init <name>\", \"Create a profile and generated Agent Skill for an MCP server\")\n .option(\"--url <url>\", \"Remote MCP URL\")\n .option(\"--command <command>\", \"stdio MCP command\")\n .option(\"--arg <arg>\", \"stdio MCP argument, repeatable\", { type: [String] })\n .option(\"--output <dir>\", \"Skill output directory\")\n .option(\"--target <target>\", \"Skill target: copilot, claude, opencode, agents, all\", { default: defaultSkillTarget })\n .option(\"--local\", \"Store the MCP profile in this workspace instead of ~/.toolcapsule\")\n .action(async (name: string, options: { url?: string; command?: string; arg?: string[]; output?: string; target?: string; local?: boolean }) => {\n if (!options.url && !options.command) throw new Error(\"Provide --url for remote MCP or --command for stdio MCP\");\n const local = options.local === true;\n const profile: ProfileConfig = options.url\n ? { name, transport: { type: \"remote\", url: options.url } }\n : { name, transport: { type: \"stdio\", command: options.command!, args: options.arg ?? [] } };\n const profilePath = local ? workspaceProfilePath(name) : userProfilePath(name);\n if (local) await ensureToolCapsuleIgnored();\n await writeProfile(profilePath, profile);\n const tools = await fetchProfileTools(profile, { clientVersion: packageVersion });\n const skillOptions = options.output\n ? { outputDir: options.output, embedProfile: local, ...(tools ? { tools } : {}) }\n : { target: readSkillTarget(options.target), embedProfile: local, ...(tools ? { tools } : {}) };\n const out = await generateSkill(\n profile,\n skillOptions,\n );\n console.log(pc.green(`Created profile at ${profilePath} and skill at ${out}`));\n });\n\ncli\n .command(\"install-skill\", \"Install the generic ToolCapsule Agent Skill into this workspace\")\n .option(\"--output <dir>\", \"Skill output directory\")\n .option(\"--target <target>\", \"Skill target: copilot, claude, opencode, agents, all\", { default: defaultSkillTarget })\n .action(async (options: { output?: string; target?: string }) => {\n const out = await installAgentSkill(options.output, readSkillTarget(options.target));\n console.log(pc.green(`Installed ToolCapsule Agent Skill at ${out}`));\n });\n\ncli\n .command(\"import\", \"Import existing MCP configuration into ToolCapsule profiles and skills\")\n .option(\"--include-user\", \"Also inspect user-level MCP config files\")\n .option(\"--name <name>\", \"Import only one MCP server by name\")\n .option(\"--as <name>\", \"Store the imported server under a different ToolCapsule profile name\")\n .option(\"--all\", \"Import all discovered MCP servers\")\n .option(\"--target <target>\", \"Skill target: copilot, claude, opencode, agents, all\", { default: defaultSkillTarget })\n .option(\"--local\", \"Store imported MCP profiles in this workspace instead of ~/.toolcapsule\")\n .option(\"--copy\", \"Copy MCP transport details into a ToolCapsule snapshot instead of linking the source config\")\n .option(\"--dry-run\", \"List importable MCP servers without writing files\")\n .action(\n async (options: { includeUser?: boolean; name?: string; as?: string; all?: boolean; target?: string; local?: boolean; copy?: boolean; dryRun?: boolean }) => {\n const local = options.local === true;\n const copy = options.copy === true;\n const discovered = await discoverMcpServers(options.includeUser ? { includeUser: true } : {});\n if (discovered.length === 0) {\n console.log(\"No importable MCP servers found.\");\n return;\n }\n\n if (options.dryRun) {\n for (const server of discovered) {\n console.log(`${server.name}\\t${server.source.tool}\\t${server.source.path}`);\n for (const warning of server.warnings) console.log(pc.yellow(` warning: ${warning}`));\n }\n return;\n }\n\n const selected = selectImportedServers(discovered, options.name, options.all);\n if (selected.length === 0) {\n throw new Error(\"Multiple MCP servers found. Re-run with --dry-run, then pass --name <server> or --all.\");\n }\n\n for (const server of selected) {\n await writeImportedServer(server, { as: options.as, local, copy, target: options.target });\n }\n },\n );\n\ncli\n .command(\"mcp <action> [name]\", \"List, enable, or disable MCP servers\")\n .option(\"--include-user\", \"Also inspect user-level MCP config files\")\n .option(\"--json\", \"Print JSON output for list\")\n .option(\"--as <name>\", \"Store an enabled server under a different ToolCapsule profile name\")\n .option(\"--target <target>\", \"Skill target: copilot, claude, opencode, agents, all\", { default: defaultSkillTarget })\n .option(\"--local\", \"Store ToolCapsule profile in this workspace\")\n .option(\"--copy\", \"Copy MCP transport details into a ToolCapsule snapshot instead of linking source config\")\n .option(\"--native\", \"For disable: disable the native MCP config instead of the ToolCapsule profile\")\n .option(\"--yes\", \"Apply native disable changes; otherwise native disable is dry-run\")\n .action(async (action: string, name: string | undefined, options: { includeUser?: boolean; json?: boolean; as?: string; target?: string; local?: boolean; copy?: boolean; native?: boolean; yes?: boolean }) => {\n if (action === \"list\") {\n const items = await listMcpInventory(options.includeUser ? { includeUser: true } : {});\n console.log(options.json ? JSON.stringify(items, null, 2) : formatInventory(items));\n return;\n }\n if (action === \"enable\") {\n if (!name) throw new Error(\"Usage: tcap mcp enable <server> [--as <profile>]\");\n const discovered = await discoverMcpServers(options.includeUser ? { includeUser: true } : {});\n const selected = selectImportedServers(discovered, name, false);\n if (selected.length !== 1) throw new Error(`Expected one MCP server named ${name}; run tcap mcp list --include-user first.`);\n await writeImportedServer(selected[0]!, { as: options.as, local: options.local, copy: options.copy, target: options.target });\n return;\n }\n if (action === \"disable\") {\n if (!name) throw new Error(\"Usage: tcap mcp disable <profile|server>\");\n const message = options.native\n ? await disableNativeMcp(name, { ...(options.includeUser ? { includeUser: true } : {}), dryRun: options.yes !== true })\n : await disableToolCapsuleProfile(name);\n console.log(message);\n return;\n }\n throw new Error(\"Unknown mcp action. Use: list, enable, disable\");\n });\n\ncli\n .command(\"tools <profile>\", \"List MCP tools\")\n .option(\"--brief\", \"Print compact tool summaries\")\n .option(\"--names\", \"Print tool names only\")\n .option(\"--json\", \"Print raw JSON\")\n .action(async (profileName: string, options: { brief?: boolean; names?: boolean; json?: boolean }) => {\n const profile = await loadProfile(profileName);\n const result = await withClient(profile, (client) => client.listTools());\n if (options.json) console.log(JSON.stringify(result, null, 2));\n else if (options.names) console.log(result.tools.map((tool) => tool.name).join(\"\\n\"));\n else console.log(briefTools(result.tools));\n });\n\ncli\n .command(\"describe <profile> <tool>\", \"Describe one MCP tool\")\n .option(\"--brief\", \"Print summarized schema instead of raw schema\")\n .action(async (profileName: string, toolName: string, options: { brief?: boolean }) => {\n const profile = await loadProfile(profileName);\n const result = await withClient(profile, (client) => client.listTools());\n const tool = result.tools.find((item) => item.name === toolName);\n if (!tool) throw new Error(`Tool not found: ${toolName}`);\n console.log(JSON.stringify(options.brief ? summarizeTool(tool) : tool, null, 2));\n });\n\ncli.command(\"schema <profile> <tool>\", \"Print a compact schema for one MCP tool\").action(async (profileName: string, toolName: string) => {\n const profile = await loadProfile(profileName);\n const result = await withClient(profile, (client) => client.listTools());\n const tool = result.tools.find((item) => item.name === toolName);\n if (!tool) throw new Error(`Tool not found: ${toolName}`);\n console.log(JSON.stringify(summarizeTool(tool), null, 2));\n});\n\ncli\n .command(\"call <profile> <tool> <args>\", \"Call an MCP tool with JSON args or @args.json\")\n .option(\"--save-run\", \"Save request, response, and command under .toolcapsule/runs/<profile>/\")\n .action(async (profileName: string, toolName: string, argsRaw: string, options: { saveRun?: boolean }) => {\n const argsPath = readArgsPath(argsRaw);\n const toolArgs = argsRaw.startsWith(\"@\") ? await readJson(argsPath) : JSON.parse(argsRaw);\n const profile = await loadProfile(profileName);\n const request = { name: toolName, arguments: toolArgs };\n const command = `toolcapsule call ${profileName} ${toolName} ${argsRaw}`;\n const runId = createRunId();\n try {\n const response = await withClient(profile, (client) => client.callTool(toolName, toolArgs));\n console.log(JSON.stringify(response, null, 2));\n if (options.saveRun) {\n await ensureToolCapsuleIgnored();\n const dir = await saveRun(workspaceRunBaseDir(profile.name), {\n id: runId,\n createdAt: new Date().toISOString(),\n profile: profile.name,\n tool: toolName,\n argsFile: argsPath,\n status: \"success\",\n command,\n request,\n response,\n });\n console.error(pc.green(`Saved run: ${dir}`));\n }\n } catch (error) {\n if (options.saveRun) {\n await ensureToolCapsuleIgnored();\n const dir = await saveRun(workspaceRunBaseDir(profile.name), {\n id: runId,\n createdAt: new Date().toISOString(),\n profile: profile.name,\n tool: toolName,\n argsFile: argsPath,\n status: \"error\",\n command,\n request,\n error: error instanceof Error ? error.message : String(error),\n });\n console.error(pc.yellow(`Saved failed run: ${dir}`));\n }\n throw error;\n }\n });\n\ncli.command(\"retry <runDir>\", \"Retry a saved run, re-reading the args file\").action(async (runDir: string) => {\n const run = await loadRun(runDir);\n const toolArgs = await readJson(run.argsFile);\n const profile = await loadProfile(run.profile);\n const response = await withClient(profile, (client) => client.callTool(run.tool, toolArgs));\n console.log(JSON.stringify(response, null, 2));\n});\n\ncli.command(\"summarize <profile>\", \"Summarize all tools into compact JSON\").action(async (profileName: string) => {\n const profile = await loadProfile(profileName);\n const result = await withClient(profile, (client) => client.listTools());\n console.log(JSON.stringify(summarizeTools(result.tools), null, 2));\n});\n\ncli\n .command(\"benchmark <profile>\", \"Estimate schema savings for a profile\")\n .option(\"--markdown\", \"Print a Markdown report\")\n .option(\"--out <file>\", \"Write report to a file\")\n .action(async (profileName: string, options: { markdown?: boolean; out?: string }) => {\n const profile = await loadProfile(profileName);\n const result = await withClient(profile, (client) => client.listTools());\n const nativeTokens = roughTokens(result);\n const brief = summarizeTools(result.tools);\n const briefTokens = roughTokens(brief);\n const summary = {\n profile: profileName,\n tools: result.tools.length,\n nativeToolsRoughTokens: nativeTokens,\n summarizedToolsRoughTokens: briefTokens,\n estimatedReductionPct: Number(percentReduction(nativeTokens, briefTokens).toFixed(2)),\n };\n const output = options.markdown\n ? `# ToolCapsule benchmark: ${profileName}\\n\\n| Metric | Value |\\n|---|---:|\\n| MCP tools | ${summary.tools} |\\n| Native MCP schema rough tokens | ${summary.nativeToolsRoughTokens} |\\n| ToolCapsule summary rough tokens | ${summary.summarizedToolsRoughTokens} |\\n| Estimated reduction | ${summary.estimatedReductionPct}% |\\n\\n> Rough tokens are estimated from serialized schema length. Use this report to compare schema footprint before and after capsule summaries.\\n`\n : JSON.stringify(summary, null, 2);\n if (options.out) await writeFile(options.out, output);\n console.log(output);\n});\n\ncli.command(\"render-readme\", \"Print website hero copy snippets\").action(async () => {\n console.log(await readFile(new URL(\"../docs/hero-copy.md\", import.meta.url), \"utf8\"));\n});\n\ncli.help();\ncli.version(packageVersion);\n\ntry {\n cli.parse();\n} catch (error) {\n console.error(pc.red(error instanceof Error ? error.message : String(error)));\n process.exit(1);\n}\n","import { existsSync } from \"node:fs\";\nimport { mkdir, readFile, readdir, rename, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { basename, dirname, join } from \"node:path\";\nimport pc from \"picocolors\";\nimport { discoverMcpServers, type ImportedMcpServer } from \"./importer.js\";\nimport { toolCapsuleHome, workspaceProfilePath } from \"../paths.js\";\nimport type { ProfileConfig } from \"../types.js\";\nimport { readJson, writeJson } from \"../utils/fs.js\";\n\nexport type InventoryItem = {\n name: string;\n status: \"enabled\" | \"disabled\" | \"managed\" | \"error\";\n scope: \"workspace\" | \"user\" | \"managed\";\n source: string;\n mode: \"native\" | \"linked\" | \"snapshot\";\n path: string;\n originalName?: string;\n warnings?: string[];\n};\n\nfunction sourceScope(server: ImportedMcpServer): \"workspace\" | \"user\" | \"managed\" {\n if (server.source.managed) return \"managed\";\n return server.source.userLevel ? \"user\" : \"workspace\";\n}\n\nfunction sourceStatus(server: ImportedMcpServer): \"enabled\" | \"managed\" {\n return server.source.managed ? \"managed\" : \"enabled\";\n}\n\nasync function profileItems(dir: string, scope: \"workspace\" | \"user\"): Promise<InventoryItem[]> {\n if (!existsSync(dir)) return [];\n const entries = await readdir(dir, { withFileTypes: true });\n const items: InventoryItem[] = [];\n for (const entry of entries) {\n if (!entry.isFile() || !entry.name.endsWith(\".json\")) continue;\n const path = join(dir, entry.name);\n try {\n const profile = (await readJson(path)) as ProfileConfig;\n items.push({\n name: profile.name || basename(entry.name, \".json\"),\n status: \"enabled\",\n scope,\n source: \"toolcapsule\",\n mode: profile.kind === \"linked\" ? \"linked\" : \"snapshot\",\n path,\n });\n } catch {\n items.push({ name: basename(entry.name, \".json\"), status: \"error\", scope, source: \"toolcapsule\", mode: \"snapshot\", path });\n }\n }\n return items;\n}\n\nexport async function listMcpInventory(opts: { includeUser?: boolean } = {}): Promise<InventoryItem[]> {\n const nativeServers = await discoverMcpServers(opts.includeUser ? { includeUser: true, includeManaged: true } : {});\n const nativeItems = nativeServers.map((server): InventoryItem => ({\n name: server.name,\n originalName: server.originalName,\n status: sourceStatus(server),\n scope: sourceScope(server),\n source: server.source.tool,\n mode: \"native\",\n path: server.source.path,\n warnings: server.warnings,\n }));\n const workspaceProfiles = await profileItems(join(\".toolcapsule\", \"profiles\"), \"workspace\");\n const userProfiles = await profileItems(join(toolCapsuleHome(), \"profiles\"), \"user\");\n return [...nativeItems, ...workspaceProfiles, ...userProfiles];\n}\n\nfunction colorStatus(status: InventoryItem[\"status\"]): string {\n if (status === \"enabled\") return pc.green(\"● on\");\n if (status === \"disabled\") return pc.gray(\"○ off\");\n if (status === \"managed\") return pc.yellow(\"◆ managed\");\n return pc.red(\"× error\");\n}\n\nfunction colorMode(mode: InventoryItem[\"mode\"]): string {\n if (mode === \"linked\") return pc.cyan(mode);\n if (mode === \"snapshot\") return pc.magenta(mode);\n return pc.gray(mode);\n}\n\nfunction pad(value: string, width: number): string {\n return value.length >= width ? value : `${value}${\" \".repeat(width - value.length)}`;\n}\n\nfunction padDisplay(display: string, raw: string, width: number): string {\n return raw.length >= width ? display : `${display}${\" \".repeat(width - raw.length)}`;\n}\n\nexport function formatInventory(items: InventoryItem[]): string {\n if (items.length === 0) return \"No MCP servers found.\";\n const rows = items.map((item) => ({\n status: colorStatus(item.status),\n statusRaw: item.status === \"enabled\" ? \"● on\" : item.status === \"disabled\" ? \"○ off\" : item.status === \"managed\" ? \"◆ managed\" : \"× error\",\n name: item.originalName && item.originalName !== item.name ? `${item.name} (${item.originalName})` : item.name,\n scope: item.scope,\n source: item.source,\n mode: colorMode(item.mode),\n modeRaw: item.mode,\n path: item.path.replace(`${homedir()}/`, \"~/\"),\n }));\n const widths = {\n status: Math.max(\"STATUS\".length, ...rows.map((row) => row.statusRaw.length)),\n name: Math.max(\"NAME\".length, ...rows.map((row) => row.name.length)),\n scope: Math.max(\"SCOPE\".length, ...rows.map((row) => row.scope.length)),\n source: Math.max(\"SOURCE\".length, ...rows.map((row) => row.source.length)),\n mode: Math.max(\"MODE\".length, ...rows.map((row) => row.modeRaw.length)),\n };\n const lines = [\n `${pad(\"STATUS\", widths.status)} ${pad(\"NAME\", widths.name)} ${pad(\"SCOPE\", widths.scope)} ${pad(\"SOURCE\", widths.source)} ${pad(\"MODE\", widths.mode)} PATH`,\n ...rows.map(\n (row) =>\n `${padDisplay(row.status, row.statusRaw, widths.status)} ${pad(row.name, widths.name)} ${pad(row.scope, widths.scope)} ${pad(row.source, widths.source)} ${padDisplay(row.mode, row.modeRaw, widths.mode)} ${row.path}`,\n ),\n ];\n return lines.join(\"\\n\");\n}\n\ntype DisablePlan = {\n path: string;\n tool: string;\n server: string;\n fromKey: string;\n toKey: string;\n};\n\nfunction disableKeys(tool: string): { fromKey: string; toKey: string } {\n if (tool === \"vscode\" || tool === \"cursor\") return { fromKey: \"servers\", toKey: \"disabledServers\" };\n if (tool === \"opencode\") return { fromKey: \"mcp\", toKey: \"disabledMcp\" };\n return { fromKey: \"mcpServers\", toKey: \"disabledMcpServers\" };\n}\n\nexport async function disableNativeMcp(serverName: string, opts: { includeUser?: boolean; dryRun?: boolean } = {}): Promise<string> {\n const servers = await discoverMcpServers(opts.includeUser ? { includeUser: true } : {});\n const server = servers.find((item) => item.name === serverName || item.originalName === serverName);\n if (!server) throw new Error(`Native MCP server not found: ${serverName}`);\n if (server.source.managed) throw new Error(`Cannot modify managed MCP config: ${server.source.path}`);\n const keys = disableKeys(server.source.tool);\n const plan: DisablePlan = { path: server.source.path, tool: server.source.tool, server: server.originalName, ...keys };\n const message = `Disable native MCP ${plan.server} in ${plan.path}: move ${plan.fromKey}.${plan.server} -> ${plan.toKey}.${plan.server}`;\n if (opts.dryRun !== false) return `${message}\\nDry run only. Re-run with --yes to write changes.`;\n\n const config = (await readJson(plan.path)) as Record<string, unknown>;\n const source = config[plan.fromKey] && typeof config[plan.fromKey] === \"object\" && !Array.isArray(config[plan.fromKey]) ? (config[plan.fromKey] as Record<string, unknown>) : {};\n if (!(plan.server in source)) throw new Error(`Server ${plan.server} not found under ${plan.fromKey} in ${plan.path}`);\n const disabled = config[plan.toKey] && typeof config[plan.toKey] === \"object\" && !Array.isArray(config[plan.toKey]) ? (config[plan.toKey] as Record<string, unknown>) : {};\n disabled[plan.server] = source[plan.server];\n delete source[plan.server];\n config[plan.fromKey] = source;\n config[plan.toKey] = disabled;\n const backup = `${plan.path}.toolcapsule.bak`;\n await mkdir(dirname(backup), { recursive: true }).catch(() => undefined);\n if (existsSync(plan.path)) await writeFile(backup, await readFile(plan.path, \"utf8\"));\n await writeJson(plan.path, config);\n return `${message}\\nBackup: ${backup}`;\n}\n\nexport async function disableToolCapsuleProfile(profileName: string): Promise<string> {\n const candidates = [workspaceProfilePath(profileName), join(toolCapsuleHome(), \"profiles\", `${profileName}.json`)];\n const found = candidates.find((path) => existsSync(path));\n if (!found) throw new Error(`ToolCapsule profile not found: ${profileName}`);\n const disabledPath = `${found}.disabled`;\n await rename(found, disabledPath);\n return `Disabled ToolCapsule profile ${profileName}: ${found} -> ${disabledPath}`;\n}\n","import { existsSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { isAbsolute, join, resolve } from \"node:path\";\nimport type { McpProfileSource, ProfileConfig, SnapshotProfileConfig, TransportConfig } from \"../types.js\";\nimport { readJson } from \"../utils/fs.js\";\n\nexport type McpConfigSource = Omit<McpProfileSource, \"server\">;\n\nexport type ImportedMcpServer = {\n name: string;\n originalName: string;\n source: McpConfigSource;\n profile: SnapshotProfileConfig;\n warnings: string[];\n};\n\ntype ServerRecord = Record<string, unknown>;\n\nconst workspaceSources: McpConfigSource[] = [\n { tool: \"vscode\", path: join(\".vscode\", \"mcp.json\") },\n { tool: \"generic\", path: \"mcp.json\" },\n { tool: \"claude\", path: \".mcp.json\" },\n { tool: \"opencode\", path: \"opencode.json\" },\n { tool: \"gemini\", path: join(\".gemini\", \"settings.json\") },\n { tool: \"cursor\", path: join(\".cursor\", \"mcp.json\") },\n];\n\nconst userSources: McpConfigSource[] = [\n { tool: \"vscode\", path: join(homedir(), \".config\", \"Code\", \"User\", \"mcp.json\"), userLevel: true },\n { tool: \"vscode\", path: join(homedir(), \".config\", \"Code - Insiders\", \"User\", \"mcp.json\"), userLevel: true },\n { tool: \"vscode\", path: join(homedir(), \".vscode-server\", \"data\", \"User\", \"mcp.json\"), userLevel: true },\n { tool: \"vscode\", path: join(homedir(), \".vscode-server-insiders\", \"data\", \"User\", \"mcp.json\"), userLevel: true },\n { tool: \"claude\", path: join(homedir(), \".claude.json\"), userLevel: true },\n { tool: \"opencode\", path: join(homedir(), \".config\", \"opencode\", \"opencode.json\"), userLevel: true },\n { tool: \"gemini\", path: join(homedir(), \".gemini\", \"settings.json\"), userLevel: true },\n { tool: \"cursor\", path: join(homedir(), \".cursor\", \"mcp.json\"), userLevel: true },\n { tool: \"cursor\", path: join(homedir(), \".config\", \"Cursor\", \"User\", \"mcp.json\"), userLevel: true },\n { tool: \"cursor\", path: join(homedir(), \".config\", \"Cursor\", \"User\", \"settings.json\"), userLevel: true },\n];\n\nconst managedSources: McpConfigSource[] = [\n { tool: \"claude\", path: \"/etc/claude-code/managed-mcp.json\", managed: true },\n];\n\nfunction asRecord(value: unknown): ServerRecord | undefined {\n return value && typeof value === \"object\" && !Array.isArray(value) ? (value as ServerRecord) : undefined;\n}\n\nfunction stringArray(value: unknown): string[] | undefined {\n return Array.isArray(value) && value.every((item) => typeof item === \"string\") ? value : undefined;\n}\n\nfunction stringRecord(value: unknown): Record<string, string> | undefined {\n const record = asRecord(value);\n if (!record) return undefined;\n const entries = Object.entries(record).filter((entry): entry is [string, string] => typeof entry[1] === \"string\");\n return entries.length > 0 ? Object.fromEntries(entries) : undefined;\n}\n\nfunction cleanName(name: string): string {\n const cleaned = name\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .replace(/-{2,}/g, \"-\");\n return cleaned || \"imported-mcp\";\n}\n\nfunction mapServer(name: string, source: McpConfigSource, raw: unknown): ImportedMcpServer | undefined {\n const server = asRecord(raw);\n if (!server) return undefined;\n\n const warnings: string[] = [];\n let transport: TransportConfig | undefined;\n const type = typeof server.type === \"string\" ? server.type : undefined;\n const url = typeof server.url === \"string\" ? server.url : typeof server.httpUrl === \"string\" ? server.httpUrl : undefined;\n const commandValue = server.command;\n const headers = stringRecord(server.headers);\n const env = stringRecord(server.env) ?? stringRecord(server.environment);\n const cwd = typeof server.cwd === \"string\" ? server.cwd : undefined;\n\n if (url && (!type || [\"http\", \"streamable-http\", \"remote\", \"sse\", \"ws\"].includes(type))) {\n transport = { type: \"remote\", url, ...(headers ? { headers } : {}), ...(env ? { env } : {}) };\n if (type === \"sse\" || type === \"ws\") warnings.push(`Imported ${type} server as remote URL; verify transport compatibility.`);\n } else if (typeof commandValue === \"string\") {\n transport = {\n type: \"stdio\",\n command: commandValue,\n args: stringArray(server.args) ?? [],\n ...(env ? { env } : {}),\n ...(cwd ? { cwd } : {}),\n };\n } else if (Array.isArray(commandValue) && commandValue.every((item) => typeof item === \"string\") && commandValue.length > 0) {\n transport = { type: \"stdio\", command: commandValue[0]!, args: commandValue.slice(1), ...(env ? { env } : {}), ...(cwd ? { cwd } : {}) };\n }\n\n if (!transport) return undefined;\n if (server.headers && !headers) warnings.push(\"Headers were present but not copied because they were not string values.\");\n if ((server.env || server.environment) && !env) warnings.push(\"Environment variables were present but not copied because they were not string values.\");\n if (server.includeTools || server.excludeTools) warnings.push(\"Tool include/exclude filters were not copied; use ToolCapsule brief/schema commands to choose tools manually.\");\n\n const profileName = cleanName(name);\n return {\n name: profileName,\n originalName: name,\n source,\n warnings,\n profile: {\n name: profileName,\n transport,\n },\n };\n}\n\nexport function linkedProfileForImportedServer(server: ImportedMcpServer, name = server.name): ProfileConfig {\n return {\n name,\n kind: \"linked\",\n source: {\n ...server.source,\n path: isAbsolute(server.source.path) ? server.source.path : resolve(server.source.path),\n server: server.originalName,\n },\n };\n}\n\nexport async function resolveProfileSource(source: McpProfileSource): Promise<SnapshotProfileConfig | undefined> {\n if (!existsSync(source.path)) return undefined;\n let config: ServerRecord | undefined;\n try {\n config = asRecord(await readJson(source.path));\n } catch {\n return undefined;\n }\n if (!config) return undefined;\n const entry = serverEntries(source, config).find(([name]) => name === source.server);\n if (!entry) return undefined;\n return mapServer(entry[0], source, entry[1])?.profile;\n}\n\nfunction serverEntries(source: McpConfigSource, config: ServerRecord): Array<[string, unknown]> {\n if (source.tool === \"vscode\" || source.tool === \"cursor\") return Object.entries(asRecord(config.servers) ?? {});\n if (source.tool === \"opencode\") return Object.entries(asRecord(config.mcp) ?? {});\n if (source.tool === \"claude\") {\n const projectEntries = Object.entries(asRecord(config.mcpServers) ?? {});\n const projectConfigs = Object.entries(asRecord(config.projects) ?? {}).flatMap(([, project]) =>\n Object.entries(asRecord(asRecord(project)?.mcpServers) ?? {}),\n );\n return [...projectEntries, ...projectConfigs];\n }\n return Object.entries(asRecord(config.mcpServers) ?? {});\n}\n\nexport async function discoverMcpServers(opts: { includeUser?: boolean; includeManaged?: boolean } = {}): Promise<ImportedMcpServer[]> {\n const sources = [\n ...workspaceSources,\n ...(opts.includeUser ? userSources : []),\n ...(opts.includeManaged ? managedSources : []),\n ];\n const discovered: ImportedMcpServer[] = [];\n\n for (const source of sources) {\n if (!existsSync(source.path)) continue;\n let config: ServerRecord | undefined;\n try {\n config = asRecord(await readJson(source.path));\n } catch {\n continue;\n }\n if (!config) continue;\n for (const [name, raw] of serverEntries(source, config)) {\n const imported = mapServer(name, source, raw);\n if (imported) discovered.push(imported);\n }\n }\n\n return discovered;\n}\n\nexport function selectImportedServers(servers: ImportedMcpServer[], name?: string, all?: boolean): ImportedMcpServer[] {\n if (all) return servers;\n if (!name) return servers.length === 1 ? servers : [];\n const normalized = cleanName(name);\n return servers.filter((server) => server.name === normalized || server.name === name);\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname, resolve } from \"node:path\";\n\nexport async function readJson<T>(path: string): Promise<T> {\n return JSON.parse(await readFile(path, \"utf8\")) as T;\n}\n\nexport async function writeJson(path: string, value: unknown): Promise<void> {\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, `${JSON.stringify(value, null, 2)}\\n`);\n}\n\nexport async function writeText(path: string, value: string): Promise<void> {\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, value);\n}\n\nexport async function ensureToolCapsuleIgnored(): Promise<void> {\n const gitignorePath = \".gitignore\";\n const entry = \".toolcapsule/\";\n let content = \"\";\n try {\n content = await readFile(gitignorePath, \"utf8\");\n } catch (error) {\n if (!(error instanceof Error && \"code\" in error && error.code === \"ENOENT\")) throw error;\n }\n\n const lines = content.split(/\\r?\\n/).map((line) => line.trim());\n const alreadyIgnored = lines.some((line) => line === entry || line === `/${entry}` || line === \".toolcapsule\");\n if (alreadyIgnored) return;\n\n const prefix = content.length > 0 && !content.endsWith(\"\\n\") ? \"\\n\" : \"\";\n await writeFile(gitignorePath, `${content}${prefix}${entry}\\n`);\n}\n\nexport function abs(path: string): string {\n return resolve(process.cwd(), path);\n}\n","import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\nexport function toolCapsuleHome(): string {\n return process.env.TOOLCAPSULE_HOME || join(homedir(), \".toolcapsule\");\n}\n\nexport function userProfilePath(profileName: string): string {\n return join(toolCapsuleHome(), \"profiles\", `${profileName}.json`);\n}\n\nexport function workspaceProfilePath(profileName: string): string {\n return join(\".toolcapsule\", \"profiles\", `${profileName}.json`);\n}\n\nexport function workspaceRunBaseDir(profileName: string): string {\n return join(\".toolcapsule\", \"runs\", profileName);\n}\n","import { spawn, type ChildProcessWithoutNullStreams } from \"node:child_process\";\nimport { once } from \"node:events\";\nimport { resolve } from \"node:path\";\nimport type { JsonRpcMessage, SnapshotProfileConfig, ToolsListResult } from \"../types.js\";\n\nexport type McpClientOptions = {\n timeoutMs?: number;\n debug?: boolean;\n clientVersion?: string;\n};\n\nexport class McpClient {\n private child: ChildProcessWithoutNullStreams;\n private nextId = 1;\n private buffer = \"\";\n private pending = new Map<\n number,\n { resolve: (value: JsonRpcMessage) => void; reject: (error: Error) => void }\n >();\n private timeoutMs: number;\n private debug: boolean;\n private clientVersion: string;\n\n constructor(profile: SnapshotProfileConfig, opts: McpClientOptions = {}) {\n this.timeoutMs = opts.timeoutMs ?? Number(process.env.TOOLCAPSULE_TIMEOUT_MS || \"45000\");\n this.debug = opts.debug ?? process.env.TOOLCAPSULE_DEBUG === \"1\";\n this.clientVersion = opts.clientVersion ?? \"0.0.0\";\n if (profile.transport.type === \"remote\") {\n this.child = spawn(\"npx\", [\"-y\", \"mcp-remote\", profile.transport.url, ...headersToArgs(profile.transport.headers)], {\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n env: { ...process.env, ...profile.transport.env },\n });\n } else {\n this.child = spawn(profile.transport.command, profile.transport.args ?? [], {\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n env: { ...process.env, ...profile.transport.env },\n cwd: profile.transport.cwd ? resolve(profile.transport.cwd) : undefined,\n });\n }\n this.child.stdout.setEncoding(\"utf8\");\n this.child.stdout.on(\"data\", (chunk: string) => this.onStdout(chunk));\n this.child.stderr.on(\"data\", (chunk: Buffer) => this.onStderr(chunk));\n this.child.on(\"exit\", (code, signal) => {\n const error = new Error(`MCP process exited early (code=${code}, signal=${signal})`);\n for (const waiter of this.pending.values()) waiter.reject(error);\n this.pending.clear();\n });\n }\n\n private onStderr(chunk: Buffer): void {\n if (!this.debug) return;\n process.stderr.write(redactSecrets(chunk.toString(\"utf8\")));\n }\n\n private onStdout(chunk: string): void {\n this.buffer += chunk;\n let newlineIndex: number;\n while ((newlineIndex = this.buffer.indexOf(\"\\n\")) >= 0) {\n const line = this.buffer.slice(0, newlineIndex).trim();\n this.buffer = this.buffer.slice(newlineIndex + 1);\n if (!line) continue;\n let message: JsonRpcMessage;\n try {\n message = JSON.parse(line) as JsonRpcMessage;\n } catch {\n process.stderr.write(`${line}\\n`);\n continue;\n }\n if (typeof message.id === \"number\") {\n const waiter = this.pending.get(message.id);\n if (waiter) {\n this.pending.delete(message.id);\n waiter.resolve(message);\n }\n }\n }\n }\n\n async init(): Promise<void> {\n await this.request(\"initialize\", {\n protocolVersion: \"2025-03-26\",\n capabilities: {},\n clientInfo: { name: \"toolcapsule\", version: this.clientVersion },\n });\n this.notify(\"notifications/initialized\", {});\n }\n\n async request(method: string, params?: unknown): Promise<unknown> {\n const id = this.nextId++;\n const responsePromise = new Promise<JsonRpcMessage>((resolve, reject) => {\n this.pending.set(id, { resolve, reject });\n });\n this.child.stdin.write(`${JSON.stringify({ jsonrpc: \"2.0\", id, method, params })}\\n`);\n const response = await this.withTimeout(responsePromise, method);\n if (response.error) throw new Error(`${method} failed: ${JSON.stringify(response.error, null, 2)}`);\n return response.result;\n }\n\n notify(method: string, params?: unknown): void {\n this.child.stdin.write(`${JSON.stringify({ jsonrpc: \"2.0\", method, params })}\\n`);\n }\n\n async listTools(): Promise<ToolsListResult> {\n return (await this.request(\"tools/list\", {})) as ToolsListResult;\n }\n\n async callTool(name: string, args: unknown): Promise<unknown> {\n return await this.request(\"tools/call\", { name, arguments: args });\n }\n\n async close(): Promise<void> {\n if (!this.child.killed) this.child.kill();\n if (this.child.exitCode === null) await Promise.race([once(this.child, \"exit\"), new Promise((resolve) => setTimeout(resolve, 500))]);\n }\n\n private async withTimeout<T>(promise: Promise<T>, label: string): Promise<T> {\n let timer: NodeJS.Timeout | undefined;\n const timeout = new Promise<never>((_, reject) => {\n timer = setTimeout(() => reject(new Error(`${label} timed out after ${this.timeoutMs}ms`)), this.timeoutMs);\n });\n try {\n return await Promise.race([promise, timeout]);\n } finally {\n if (timer) clearTimeout(timer);\n }\n }\n}\n\nfunction headersToArgs(headers: Record<string, string> | undefined): string[] {\n if (!headers) return [];\n return Object.entries(headers).flatMap(([key, value]) => [\"--header\", `${key}:${value}`]);\n}\n\nfunction redactSecrets(text: string): string {\n return text\n .replace(/https:\\/\\/mcp\\.feishu\\.cn\\/mcp\\/[^\\s\"']+/g, \"https://mcp.feishu.cn/mcp/[redacted]\")\n .replace(/(Bearer\\s+)[A-Za-z0-9._~+/=-]+/gi, \"$1[redacted]\")\n .replace(/(token=)[^\\s&\"']+/gi, \"$1[redacted]\")\n .replace(/(api[_-]?key=)[^\\s&\"']+/gi, \"$1[redacted]\");\n}\n","import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { z } from \"zod\";\nimport { resolveProfileSource } from \"./mcp/importer.js\";\nimport { userProfilePath, workspaceProfilePath } from \"./paths.js\";\nimport type { ProfileConfig, SnapshotProfileConfig } from \"./types.js\";\nimport { readJson } from \"./utils/fs.js\";\n\nconst transportSchema = z.union([\n z.object({\n type: z.literal(\"remote\"),\n url: z.string().url(),\n headers: z.record(z.string()).optional(),\n env: z.record(z.string()).optional(),\n }),\n z.object({\n type: z.literal(\"stdio\"),\n command: z.string().min(1),\n args: z.array(z.string()).optional(),\n env: z.record(z.string()).optional(),\n cwd: z.string().optional(),\n }),\n]);\n\nconst skillSchema = z\n .object({\n name: z.string().optional(),\n description: z.string().optional(),\n })\n .optional();\n\nconst shortcutsSchema = z\n .record(\n z.object({\n tool: z.string(),\n description: z.string().optional(),\n args: z.record(z.enum([\"string\", \"file\", \"json\", \"boolean\", \"number\"])).optional(),\n }),\n )\n .optional();\n\nconst snapshotProfileSchema = z.object({\n name: z.string().min(1),\n kind: z.literal(\"snapshot\").optional(),\n transport: transportSchema,\n skill: skillSchema,\n shortcuts: shortcutsSchema,\n});\n\nconst linkedProfileSchema = z.object({\n name: z.string().min(1),\n kind: z.literal(\"linked\"),\n source: z.object({\n tool: z.enum([\"vscode\", \"claude\", \"opencode\", \"gemini\", \"cursor\", \"generic\"]),\n path: z.string().min(1),\n server: z.string().min(1),\n userLevel: z.boolean().optional(),\n }),\n skill: skillSchema,\n shortcuts: shortcutsSchema,\n});\n\nconst profileSchema = z.union([snapshotProfileSchema, linkedProfileSchema]);\n\nexport async function loadProfile(profilePathOrName: string): Promise<SnapshotProfileConfig> {\n const candidates = [\n profilePathOrName,\n `${profilePathOrName}.json`,\n workspaceProfilePath(profilePathOrName),\n userProfilePath(profilePathOrName),\n join(\".github\", \"skills\", `${profilePathOrName}-mcp`, \"toolcapsule.config.json\"),\n join(\".claude\", \"skills\", `${profilePathOrName}-mcp`, \"toolcapsule.config.json\"),\n join(\".opencode\", \"skills\", `${profilePathOrName}-mcp`, \"toolcapsule.config.json\"),\n join(\".agents\", \"skills\", `${profilePathOrName}-mcp`, \"toolcapsule.config.json\"),\n ];\n const found = candidates.find((path) => existsSync(path));\n if (!found) throw new Error(`Profile not found: ${profilePathOrName}`);\n const profile = profileSchema.parse(await readJson(found)) as ProfileConfig;\n if (profile.kind !== \"linked\") return profile;\n\n const resolved = await resolveProfileSource(profile.source);\n if (!resolved) {\n throw new Error(`Linked profile source not found: ${profile.source.path}#${profile.source.server}`);\n }\n\n return snapshotProfileSchema.parse({\n ...resolved,\n name: profile.name,\n skill: profile.skill ?? resolved.skill,\n shortcuts: profile.shortcuts ?? resolved.shortcuts,\n }) as SnapshotProfileConfig;\n}\n","import type { McpTool } from \"../types.js\";\n\nexport function toolTitle(tool: McpTool): string {\n return tool.annotations?.title || tool.description?.split(/\\n/)[0]?.slice(0, 100) || tool.name;\n}\n\nexport function briefTool(tool: McpTool): string {\n const schema = tool.inputSchema as any;\n const required = Array.isArray(schema?.required) ? schema.required : [];\n const properties = schema?.properties && typeof schema.properties === \"object\" ? Object.keys(schema.properties) : [];\n const flags = [\n tool.annotations?.readOnlyHint ? \"read-only\" : undefined,\n tool.annotations?.destructiveHint ? \"destructive\" : undefined,\n ].filter(Boolean);\n return `- ${tool.name}: ${toolTitle(tool)}${flags.length ? ` [${flags.join(\", \")}]` : \"\"}${required.length ? ` required=${required.join(\"|\")}` : \"\"}${properties.length ? ` args=${properties.slice(0, 12).join(\"|\")}` : \"\"}`;\n}\n\nexport function briefTools(tools: McpTool[]): string {\n return tools.map(briefTool).join(\"\\n\");\n}\n","import type { McpTool } from \"../types.js\";\n\nexport function summarizeTool(tool: McpTool): unknown {\n const schema = tool.inputSchema as any;\n const properties = schema?.properties && typeof schema.properties === \"object\" ? schema.properties : {};\n return {\n name: tool.name,\n title: tool.annotations?.title,\n description: tool.description?.split(/\\n\\n/)[0]?.slice(0, 500),\n annotations: tool.annotations,\n required: Array.isArray(schema?.required) ? schema.required : [],\n arguments: Object.fromEntries(\n Object.entries(properties).map(([key, value]: [string, any]) => [\n key,\n { type: value?.type, enum: value?.enum, description: value?.description?.slice?.(0, 160) },\n ]),\n ),\n };\n}\n\nexport function summarizeTools(tools: McpTool[]): unknown[] {\n return tools.map(summarizeTool);\n}\n","import { mkdir, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport Handlebars from \"handlebars\";\nimport { McpClient } from \"../mcp/client.js\";\nimport type { McpTool } from \"../types.js\";\nimport { summarizeTools } from \"../schema/summarize.js\";\nimport type { ProfileConfig } from \"../types.js\";\nimport { writeJson } from \"../utils/fs.js\";\n\nexport type SkillTarget = \"copilot\" | \"claude\" | \"opencode\" | \"agents\" | \"all\";\n\nexport const defaultSkillTarget: SkillTarget = \"claude\";\n\nexport function skillOutputDir(skillName: string, target: Exclude<SkillTarget, \"all\">): string {\n if (target === \"copilot\") return join(\".github\", \"skills\", skillName);\n if (target === \"claude\") return join(\".claude\", \"skills\", skillName);\n if (target === \"opencode\") return join(\".opencode\", \"skills\", skillName);\n return join(\".agents\", \"skills\", skillName);\n}\n\nexport function expandSkillTargets(target: SkillTarget): Exclude<SkillTarget, \"all\">[] {\n return target === \"all\" ? [\"copilot\", \"claude\", \"opencode\", \"agents\"] : [target];\n}\n\nconst skillTemplate = `---\nname: {{skillName}}\ndescription: '{{description}}'\nargument-hint: 'MCP task, tool name, or args file to run'\n---\n\n# {{title}}\n\nThis skill wraps an MCP server as a lightweight, lazy-loaded, file-first workflow.\n\n## Why use this skill\n\n- Keep full MCP tool schemas out of the model context until needed.\n- Use brief tool summaries for everyday work.\n- Store large payloads in local files such as \\`args.json\\` or \\`content.md\\`.\n- Patch local artifacts and retry failed calls deterministically.\n\n## Commands\n\n\\`\\`\\`bash\ntoolcapsule tools {{profileName}} --brief\ntoolcapsule describe {{profileName}} <tool>\ntoolcapsule call {{profileName}} <tool> @args.json\ntoolcapsule retry .toolcapsule/runs/{{profileName}}/<run-id>\n\\`\\`\\`\n\n{{#if toolsMarkdown}}\n## Tool summary\n\nUse this summary for planning. Only run \\`toolcapsule schema {{profileName}} <tool>\\` when these brief details are insufficient.\n\n{{{toolsMarkdown}}}\n{{else}}\n## Tool discovery\n\nRun \\`toolcapsule tools {{profileName}} --brief\\` once before choosing a tool. Then run \\`toolcapsule schema {{profileName}} <tool>\\` only when the brief summary is insufficient.\n{{/if}}\n\n## Workflow\n\n1. Use \\`tools --brief\\` to find the likely tool.\n2. Use \\`describe <tool>\\` only when the brief schema is insufficient.\n3. Put complex arguments in a local JSON file.\n4. Call with \\`@args.json\\` and save the run.\n5. On failure, patch the local file and run \\`retry\\`.\n\n## Safety\n\n- Do not fabricate IDs, URLs, user IDs, or opaque tokens.\n- Prefer local files for large payloads.\n- Do not print secrets.\n- Review destructive tools before calling.\n`;\n\nexport type GenerateSkillOptions = {\n outputDir?: string;\n target?: SkillTarget;\n embedProfile?: boolean;\n tools?: McpTool[];\n};\n\ntype ToolSummary = {\n name?: string;\n description?: string;\n required?: unknown;\n annotations?: { readOnlyHint?: boolean; destructiveHint?: boolean };\n};\n\nfunction toolsMarkdown(tools: McpTool[] | undefined): string | undefined {\n if (!tools || tools.length === 0) return undefined;\n const summaries = summarizeTools(tools) as ToolSummary[];\n const rows = summaries.slice(0, 40).map((tool) => {\n const required = Array.isArray(tool.required) && tool.required.length > 0 ? tool.required.join(\", \") : \"-\";\n const risk = tool.annotations?.destructiveHint ? \"writes\" : tool.annotations?.readOnlyHint ? \"read\" : \"unknown\";\n const description = (tool.description || \"-\").replace(/\\|/g, \"\\\\|\").slice(0, 120);\n return `| \\`${tool.name || \"unknown\"}\\` | ${description} | ${required} | ${risk} |`;\n });\n return [\"| Tool | Purpose | Required args | Risk |\", \"|---|---|---|---|\", ...rows].join(\"\\n\");\n}\n\nexport async function fetchProfileTools(profile: ProfileConfig, opts: { clientVersion?: string } = {}): Promise<McpTool[] | undefined> {\n if (profile.kind === \"linked\") return undefined;\n const client = new McpClient(profile, { ...(opts.clientVersion ? { clientVersion: opts.clientVersion } : {}), timeoutMs: 15000 });\n try {\n await client.init();\n return (await client.listTools()).tools;\n } catch {\n return undefined;\n } finally {\n await client.close().catch(() => undefined);\n }\n}\n\nasync function generateSkillAt(profile: ProfileConfig, outputDir: string, opts: { embedProfile?: boolean; tools?: McpTool[] } = {}): Promise<string> {\n const skillName = profile.skill?.name || `${profile.name}-mcp`;\n await mkdir(join(outputDir, \"scripts\"), { recursive: true });\n\n const template = Handlebars.compile(skillTemplate);\n const description =\n profile.skill?.description ||\n `Use when operating tools from the ${profile.name} MCP server. Lazy-load schemas, call tools through local files, and retry failed calls by patching artifacts.`;\n const markdown = template({\n skillName,\n profileName: profile.name,\n title: `${profile.name} MCP Skill`,\n description: description.replace(/'/g, \"''\"),\n toolsMarkdown: toolsMarkdown(opts.tools),\n });\n await writeFile(join(outputDir, \"SKILL.md\"), markdown);\n if (opts.embedProfile) await writeJson(join(outputDir, \"toolcapsule.config.json\"), profile);\n await writeFile(\n join(outputDir, \"scripts\", \"README.md\"),\n `# Scripts\\n\\nThis skill uses the \\`toolcapsule\\` CLI and profiles resolved by name.\\n`,\n );\n return outputDir;\n}\n\nexport async function generateSkill(profile: ProfileConfig, opts: GenerateSkillOptions = {}): Promise<string> {\n const skillName = profile.skill?.name || `${profile.name}-mcp`;\n const target = opts.target || defaultSkillTarget;\n const embedProfile = opts.embedProfile === true;\n const atOptions = { embedProfile, ...(opts.tools ? { tools: opts.tools } : {}) };\n const outputs = opts.outputDir\n ? [await generateSkillAt(profile, opts.outputDir, atOptions)]\n : await Promise.all(\n expandSkillTargets(target).map((item) =>\n generateSkillAt(profile, skillOutputDir(skillName, item), atOptions),\n ),\n );\n return outputs.join(\", \");\n}\n\nexport async function writeProfile(path: string, profile: ProfileConfig): Promise<void> {\n await mkdir(dirname(path), { recursive: true });\n await writeJson(path, profile);\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { defaultSkillTarget, expandSkillTargets, skillOutputDir, type SkillTarget } from \"./generator.js\";\n\nexport async function installAgentSkill(outputDir?: string, target: SkillTarget = defaultSkillTarget): Promise<string> {\n let agentSkill: string;\n try {\n agentSkill = await readFile(new URL(\"../skills/toolcapsule/SKILL.md\", import.meta.url), \"utf8\");\n } catch {\n agentSkill = await readFile(new URL(\"../../skills/toolcapsule/SKILL.md\", import.meta.url), \"utf8\");\n }\n const outputDirs = outputDir ? [outputDir] : expandSkillTargets(target).map((item) => skillOutputDir(\"toolcapsule\", item));\n await Promise.all(\n outputDirs.map(async (dir) => {\n await mkdir(dir, { recursive: true });\n await writeFile(join(dir, \"SKILL.md\"), agentSkill);\n }),\n );\n return outputDirs.join(\", \");\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport type { RunRecord } from \"../types.js\";\nimport { writeJson } from \"../utils/fs.js\";\n\nexport function createRunId(): string {\n return new Date().toISOString().replace(/[:.]/g, \"-\");\n}\n\nexport async function saveRun(baseDir: string, record: RunRecord): Promise<string> {\n const dir = join(baseDir, record.id);\n await mkdir(dir, { recursive: true });\n await writeJson(join(dir, \"run.json\"), record);\n await writeJson(join(dir, \"request.json\"), record.request);\n if (record.response !== undefined) await writeJson(join(dir, \"response.json\"), record.response);\n if (record.error) await writeFile(join(dir, \"error.txt\"), record.error);\n await writeFile(join(dir, \"command.txt\"), `${record.command}\\n`);\n return dir;\n}\n\nexport async function loadRun(runDir: string): Promise<RunRecord> {\n return JSON.parse(await readFile(join(runDir, \"run.json\"), \"utf8\")) as RunRecord;\n}\n","export function roughTokens(value: unknown): number {\n const text = typeof value === \"string\" ? value : JSON.stringify(value);\n return Math.ceil(text.length / 4);\n}\n\nexport function percentReduction(before: number, after: number): number {\n return before === 0 ? 0 : ((before - after) / before) * 100;\n}\n"],"mappings":";;;AACA,SAAS,YAAAA,iBAAgB;AACzB,SAAS,WAAW;AACpB,OAAOC,SAAQ;;;ACHf,SAAS,cAAAC,mBAAkB;AAC3B,SAAS,SAAAC,QAAO,YAAAC,WAAU,SAAS,QAAQ,aAAAC,kBAAiB;AAC5D,SAAS,WAAAC,gBAA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E,QAAQ,CAAC,CAAC;AAAA,EACtF;AACA,QAAM,SAAS,QAAQ,WACnB,4BAA4B,WAAW;AAAA;AAAA;AAAA;AAAA,gBAAqD,QAAQ,KAAK;AAAA,qCAA0C,QAAQ,sBAAsB;AAAA,uCAA4C,QAAQ,0BAA0B;AAAA,0BAA+B,QAAQ,qBAAqB;AAAA;AAAA;AAAA,IAC3T,KAAK,UAAU,SAAS,MAAM,CAAC;AACnC,MAAI,QAAQ,IAAK,OAAMC,WAAU,QAAQ,KAAK,MAAM;AACpD,UAAQ,IAAI,MAAM;AACpB,CAAC;AAED,IAAI,QAAQ,iBAAiB,kCAAkC,EAAE,OAAO,YAAY;AAClF,UAAQ,IAAI,MAAMF,UAAS,IAAI,IAAI,wBAAwB,YAAY,GAAG,GAAG,MAAM,CAAC;AACtF,CAAC;AAED,IAAI,KAAK;AACT,IAAI,QAAQ,cAAc;AAE1B,IAAI;AACF,MAAI,MAAM;AACZ,SAAS,OAAO;AACd,UAAQ,MAAMC,IAAG,IAAI,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,CAAC;AAC5E,UAAQ,KAAK,CAAC;AAChB;","names":["readFile","pc","existsSync","mkdir","readFile","writeFile","homedir","dirname","join","resolve","resolve","homedir","join","existsSync","join","homedir","mkdir","dirname","writeFile","readFile","resolve","existsSync","join","join","existsSync","mkdir","writeFile","dirname","join","join","mkdir","writeFile","dirname","mkdir","readFile","writeFile","join","readFile","mkdir","writeFile","join","mkdir","readFile","writeFile","join","join","mkdir","writeFile","readFile","writeFile","readFile","pc","writeFile"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcapsule",
3
- "version": "0.1.0-alpha.13",
3
+ "version": "0.1.0-alpha.14",
4
4
  "description": "AI-first workflow manager for heavy MCP tools with lazy Agent Skills and patchable runs.",
5
5
  "type": "module",
6
6
  "bin": {