claude-slim 2.2.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,97 @@
1
+ import { readlink } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { countTokensCached } from '../tokenizer.js';
4
+ import { getSkillsDir } from '../paths.js';
5
+ import { safeReadFile, safeReaddir, isDirectory, isBrokenSymlink, resolveRealPath, } from './fs-walk.js';
6
+ export function dedupeBySymlink(candidates) {
7
+ const seen = new Map();
8
+ for (const { skill, realMdPath } of candidates) {
9
+ const existing = seen.get(realMdPath);
10
+ if (!existing) {
11
+ seen.set(realMdPath, skill);
12
+ continue;
13
+ }
14
+ // Prefer top-level name (no slash) over nested duplicate
15
+ const existingIsNested = existing.name.includes('/');
16
+ const currentIsNested = skill.name.includes('/');
17
+ if (existingIsNested && !currentIsNested) {
18
+ seen.set(realMdPath, skill);
19
+ }
20
+ }
21
+ return Array.from(seen.values());
22
+ }
23
+ export async function scanLocalSkills() {
24
+ const skillsDir = getSkillsDir();
25
+ const candidates = [];
26
+ const brokenSymlinks = [];
27
+ const contents = new Map();
28
+ const entries = await safeReaddir(skillsDir);
29
+ const scanPromises = entries.map(async (entry) => {
30
+ const dirPath = join(skillsDir, entry);
31
+ if (!(await isDirectory(dirPath)))
32
+ return;
33
+ const skillMd = join(dirPath, 'SKILL.md');
34
+ if (await isBrokenSymlink(skillMd)) {
35
+ let target = 'unknown';
36
+ try {
37
+ target = await readlink(skillMd);
38
+ }
39
+ catch { /* */ }
40
+ brokenSymlinks.push({ name: entry, path: skillMd, target });
41
+ return;
42
+ }
43
+ const content = await safeReadFile(skillMd);
44
+ if (content !== null) {
45
+ contents.set(skillMd, content);
46
+ const tokens = countTokensCached(content, skillMd);
47
+ const realMdPath = await resolveRealPath(skillMd);
48
+ candidates.push({
49
+ skill: {
50
+ name: entry,
51
+ path: dirPath,
52
+ sizeBytes: Buffer.byteLength(content),
53
+ tokens,
54
+ source: 'local',
55
+ },
56
+ realMdPath,
57
+ });
58
+ }
59
+ // Nested skills (e.g., @internal-sys/commit-guide)
60
+ const subEntries = await safeReaddir(dirPath);
61
+ for (const sub of subEntries) {
62
+ const subDir = join(dirPath, sub);
63
+ if (!(await isDirectory(subDir)))
64
+ continue;
65
+ const subSkillMd = join(subDir, 'SKILL.md');
66
+ if (await isBrokenSymlink(subSkillMd)) {
67
+ let target = 'unknown';
68
+ try {
69
+ target = await readlink(subSkillMd);
70
+ }
71
+ catch { /* */ }
72
+ brokenSymlinks.push({ name: `${entry}/${sub}`, path: subSkillMd, target });
73
+ continue;
74
+ }
75
+ const subContent = await safeReadFile(subSkillMd);
76
+ if (subContent !== null) {
77
+ const name = `${entry}/${sub}`;
78
+ contents.set(subSkillMd, subContent);
79
+ const tokens = countTokensCached(subContent, subSkillMd);
80
+ const realMdPath = await resolveRealPath(subSkillMd);
81
+ candidates.push({
82
+ skill: {
83
+ name,
84
+ path: subDir,
85
+ sizeBytes: Buffer.byteLength(subContent),
86
+ tokens,
87
+ source: 'local',
88
+ },
89
+ realMdPath,
90
+ });
91
+ }
92
+ }
93
+ });
94
+ await Promise.all(scanPromises);
95
+ const skills = dedupeBySymlink(candidates);
96
+ return { skills, brokenSymlinks, contents };
97
+ }
@@ -0,0 +1,5 @@
1
+ export interface McpScanResult {
2
+ count: number;
3
+ names: string[];
4
+ }
5
+ export declare function scanMcpServers(): Promise<McpScanResult>;
@@ -0,0 +1,17 @@
1
+ import { join } from 'node:path';
2
+ import { getClaudeDir } from '../paths.js';
3
+ import { safeReadFile } from './fs-walk.js';
4
+ export async function scanMcpServers() {
5
+ const content = await safeReadFile(join(getClaudeDir(), 'settings.json'));
6
+ if (!content)
7
+ return { count: 0, names: [] };
8
+ try {
9
+ const data = JSON.parse(content);
10
+ const servers = data.mcpServers || {};
11
+ const names = Object.keys(servers).sort();
12
+ return { count: names.length, names };
13
+ }
14
+ catch {
15
+ return { count: 0, names: [] };
16
+ }
17
+ }
@@ -0,0 +1,13 @@
1
+ import type { MemoryFile } from '../types.js';
2
+ export interface StaleProject {
3
+ project: string;
4
+ path: string;
5
+ ageDays: number;
6
+ fileCount: number;
7
+ totalBytes: number;
8
+ }
9
+ export interface MemoryScanResult {
10
+ memoryFiles: MemoryFile[];
11
+ staleProjects: StaleProject[];
12
+ }
13
+ export declare function scanMemoryFiles(): Promise<MemoryScanResult>;
@@ -0,0 +1,50 @@
1
+ import { stat } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { countTokensCached } from '../tokenizer.js';
4
+ import { getProjectsDir } from '../paths.js';
5
+ import { safeReadFile, safeReaddir } from './fs-walk.js';
6
+ import { STALE_DAYS } from './constants.js';
7
+ export async function scanMemoryFiles() {
8
+ const memoryFiles = [];
9
+ const staleProjects = [];
10
+ const projectsDir = getProjectsDir();
11
+ const projectDirs = await safeReaddir(projectsDir);
12
+ const now = Date.now();
13
+ const scanPromises = projectDirs.map(async (project) => {
14
+ const memDir = join(projectsDir, project, 'memory');
15
+ const files = await safeReaddir(memDir);
16
+ const mdFiles = files.filter((f) => f.endsWith('.md'));
17
+ let newestMtime = 0;
18
+ let totalBytes = 0;
19
+ for (const file of mdFiles) {
20
+ const filePath = join(memDir, file);
21
+ const content = await safeReadFile(filePath);
22
+ if (content !== null) {
23
+ const sizeBytes = Buffer.byteLength(content);
24
+ memoryFiles.push({
25
+ project,
26
+ name: file,
27
+ path: filePath,
28
+ sizeBytes,
29
+ tokens: countTokensCached(content, filePath),
30
+ });
31
+ totalBytes += sizeBytes;
32
+ try {
33
+ const s = await stat(filePath);
34
+ if (s.mtimeMs > newestMtime)
35
+ newestMtime = s.mtimeMs;
36
+ }
37
+ catch { /* skip */ }
38
+ }
39
+ }
40
+ // Check for stale project (no files modified in 90+ days)
41
+ if (mdFiles.length > 0 && newestMtime > 0) {
42
+ const ageDays = Math.floor((now - newestMtime) / (1000 * 60 * 60 * 24));
43
+ if (ageDays > STALE_DAYS) {
44
+ staleProjects.push({ project, path: memDir, ageDays, fileCount: mdFiles.length, totalBytes });
45
+ }
46
+ }
47
+ });
48
+ await Promise.all(scanPromises);
49
+ return { memoryFiles, staleProjects };
50
+ }
@@ -0,0 +1,12 @@
1
+ import type { SkillInfo, PluginInfo } from '../types.js';
2
+ export interface TempCache {
3
+ name: string;
4
+ path: string;
5
+ sizeKB: number;
6
+ }
7
+ export interface PluginSkillsResult {
8
+ skills: SkillInfo[];
9
+ plugins: PluginInfo[];
10
+ tempCaches: TempCache[];
11
+ }
12
+ export declare function scanPluginSkills(): Promise<PluginSkillsResult>;
@@ -0,0 +1,65 @@
1
+ import { join } from 'node:path';
2
+ import { countTokensCached } from '../tokenizer.js';
3
+ import { getPluginsDir } from '../paths.js';
4
+ import { safeReadFile, safeReaddir, isDirectory, getDirSize } from './fs-walk.js';
5
+ export async function scanPluginSkills() {
6
+ const skills = [];
7
+ const plugins = [];
8
+ const tempCaches = [];
9
+ const pluginsDir = getPluginsDir();
10
+ const pluginDirs = await safeReaddir(pluginsDir);
11
+ const scanPromises = pluginDirs.map(async (pluginName) => {
12
+ const pluginDir = join(pluginsDir, pluginName);
13
+ if (!(await isDirectory(pluginDir)))
14
+ return;
15
+ // Detect temp_local_* cache dirs (failed plugin installs)
16
+ if (pluginName.startsWith('temp_local_')) {
17
+ const size = await getDirSize(pluginDir);
18
+ tempCaches.push({ name: pluginName, path: pluginDir, sizeKB: Math.round(size / 1024) });
19
+ return;
20
+ }
21
+ const pluginSkillNames = [];
22
+ const walkDir = async (dir) => {
23
+ const entries = await safeReaddir(dir);
24
+ for (const entry of entries) {
25
+ const entryPath = join(dir, entry);
26
+ if (!(await isDirectory(entryPath)))
27
+ continue;
28
+ if (entry === 'skills') {
29
+ const skillDirs = await safeReaddir(entryPath);
30
+ for (const skillDir of skillDirs) {
31
+ const skillPath = join(entryPath, skillDir);
32
+ if (!(await isDirectory(skillPath)))
33
+ continue;
34
+ const skillMd = join(skillPath, 'SKILL.md');
35
+ const content = await safeReadFile(skillMd);
36
+ if (content !== null) {
37
+ pluginSkillNames.push(skillDir);
38
+ skills.push({
39
+ name: skillDir,
40
+ path: skillPath,
41
+ sizeBytes: Buffer.byteLength(content),
42
+ tokens: countTokensCached(content, skillMd),
43
+ source: 'plugin',
44
+ pluginName,
45
+ });
46
+ }
47
+ }
48
+ }
49
+ else {
50
+ await walkDir(entryPath);
51
+ }
52
+ }
53
+ };
54
+ await walkDir(pluginDir);
55
+ if (pluginSkillNames.length > 0) {
56
+ plugins.push({
57
+ name: pluginName,
58
+ skillCount: pluginSkillNames.length,
59
+ skills: pluginSkillNames,
60
+ });
61
+ }
62
+ });
63
+ await Promise.all(scanPromises);
64
+ return { skills, plugins, tempCaches };
65
+ }
package/dist/scanner.d.ts CHANGED
@@ -1,15 +1,5 @@
1
- import type { ScanResult, SkillInfo } from './types.js';
2
- export declare const SKILL_PROMPT_OVERHEAD_TOKENS = 30;
3
- interface SkillCandidate {
4
- skill: SkillInfo;
5
- realMdPath: string;
6
- }
7
- export declare function dedupeBySymlink(candidates: SkillCandidate[]): SkillInfo[];
8
- export declare function parseDisabledPlugins(output: string): Set<string>;
9
- export declare function parseClaudeMdSections(content: string): Array<{
10
- name: string;
11
- sizeBytes: number;
12
- tokens: number;
13
- }>;
14
- export declare function scan(): Promise<ScanResult>;
15
- export {};
1
+ export { scan } from './scanner/index.js';
2
+ export { SKILL_PROMPT_OVERHEAD_TOKENS } from './scanner/constants.js';
3
+ export { dedupeBySymlink } from './scanner/local-skills.js';
4
+ export { parseDisabledPlugins } from './scanner/disabled-plugins.js';
5
+ export { parseClaudeMdSections } from './scanner/claude-md.js';