Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/__tests__/uninstall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,45 @@ describe('uninstall', () => {
expect(claudeMd).toContain(TEAMAI_RULES_START);
});

it('uninstall summary lists teamai-managed MCP servers', async () => {
const { homeDir, repoPath, teamaiHome } = await setupFixture(tmpDir);
vi.stubEnv('HOME', homeDir);
vi.stubEnv('SHELL', '/bin/zsh');

await fse.writeJson(path.join(teamaiHome, 'managed-mcp.json'), {
claude: [{ name: 'gpu-analysis', hash: 'abc' }],
cursor: [{ name: 'context7', hash: 'def' }],
});

mockAutoDetectInit.mockResolvedValue({
localConfig: makeLocalConfig(homeDir, repoPath),
teamConfig: makeTeamConfig({
toolPaths: {
claude: {
skills: '.claude/skills',
rules: '.claude/rules',
settings: '.claude/settings.json',
claudemd: '.claude/CLAUDE.md',
mcp: '.claude.json',
},
},
}),
});

const lines: string[] = [];
const spy = vi.spyOn(console, 'log').mockImplementation((...args: unknown[]) => {
lines.push(args.map(String).join(' '));
});

await uninstall({ dryRun: true, force: true });
spy.mockRestore();

const summary = lines.join('\n');
expect(summary).toContain('MCP servers (2):');
expect(summary).toContain('claude/gpu-analysis');
expect(summary).toContain('cursor/context7');
});

it('什么都不存在时正常退出', async () => {
const homeDir = path.join(tmpDir, 'empty-home');
const repoPath = path.join(tmpDir, 'empty-repo');
Expand Down
27 changes: 27 additions & 0 deletions src/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ import {
TEAMAI_ENV_END,
getTeamaiHome,
getManagedHooksPath,
managedMcpManifestPath,
resolveBaseDir,
type GlobalOptions,
type TeamaiConfig,
type LocalConfig,
type Scope,
type ManagedMcpManifest,
} from './types.js';
import { BUILTIN_RULE_NAMES } from './builtin-rules.js';
import { BUILTIN_AGENT_NAMES } from './builtin-agents.js';
import { BUILTIN_SKILL_NAMES } from './builtin-skills.js';
import {
pathExists,
readFileSafe,
readJson,
writeFile,
remove,
listDirs,
Expand Down Expand Up @@ -55,6 +58,8 @@ interface RemovalPlan {
ruleFiles: string[];
/** Built-in agent .md files deployed by the CLI (e.g. teamai-recall). */
agentFiles: string[];
/** teamai-managed MCP servers from managed-mcp.json (`tool/server` or `tool:project/server`). */
mcpServers: string[];
/** Shell profile path containing env block (null if none). */
shellProfile: string | null;
/** Docs directory (null if doesn't exist). */
Expand Down Expand Up @@ -148,6 +153,7 @@ async function buildRemovalPlan(
skillDirs: [],
ruleFiles: [],
agentFiles: [],
mcpServers: [],
shellProfile: null,
docsDir: null,
teamaiHome,
Expand All @@ -156,6 +162,18 @@ async function buildRemovalPlan(
scope: localConfig.scope,
};

// MCP servers are tracked in managed-mcp.json (same ownership model as hooks).
const mcpManifestPath = expandHome(
managedMcpManifestPath(localConfig.scope, localConfig.projectRoot),
);
const mcpManifest = (await readJson<ManagedMcpManifest>(mcpManifestPath)) ?? {};
for (const [toolKey, records] of Object.entries(mcpManifest)) {
for (const rec of records ?? []) {
if (rec?.name) plan.mcpServers.push(`${toolKey}/${rec.name}`);
}
}
plan.mcpServers.sort();

// Discover team repo resource names for targeted removal. CLI built-in
// resources (recall agent/rule, share-learnings skill, …) are deployed by
// the CLI itself rather than synced from the team repo, so fold their names
Expand Down Expand Up @@ -291,6 +309,7 @@ function isPlanEmpty(plan: RemovalPlan): boolean {
plan.skillDirs.length === 0 &&
plan.ruleFiles.length === 0 &&
plan.agentFiles.length === 0 &&
plan.mcpServers.length === 0 &&
plan.shellProfile === null &&
plan.docsDir === null &&
!plan.teamaiHomeExists
Expand Down Expand Up @@ -343,6 +362,14 @@ function printSummary(plan: RemovalPlan): void {
console.log('');
}

if (plan.mcpServers.length > 0) {
console.log(` MCP servers (${plan.mcpServers.length}):`);
for (const entry of plan.mcpServers) {
console.log(` ${entry}`);
}
console.log('');
}

if (plan.shellProfile) {
console.log(' Shell profile 环境变量块:');
console.log(` ${plan.shellProfile}`);
Expand Down
Loading