Skip to content

Commit 4b8450c

Browse files
authored
Merge pull request #2 from Coding-Meet/feature/advanced-cli-commands
Refactor naming and improve documentation for CLI and demo
2 parents 049f443 + f977a58 commit 4b8450c

9 files changed

Lines changed: 442 additions & 332 deletions

File tree

.agents/skills/library-insight/SKILL.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: library-insight
3-
description: API Explorer & AI Code Advisor that indexes public APIs, visualizes dependency graphs, audits version deprecations, and extracts JVM archive signatures (JAR/AAR) or Maven coordinates for AI context.
3+
description: JVM API Explorer & MCP Server that indexes public APIs, visualizes dependency graphs, audits version deprecations, and extracts JVM archive signatures (JAR/AAR) or Maven coordinates for AI context.
44
---
55

66
# Library Insight Agent Skill
@@ -16,12 +16,15 @@ This tool extracts all classes, interfaces, methods, properties, and Javadoc/KDo
1616
> - Use **`library-insight search <query>`** to find packages or classes.
1717
> - Use **`library-insight explain <class>`** to print the public API signature and Javadocs of a specific class.
1818
> - Use **`library-insight diff <old> <new>`** to compare versions.
19-
> - Use **`library-insight audit`** to check project dependency deprecations recursively.
19+
> - Use **`library-insight audit`** to check project dependency API deprecations recursively.
2020
> - Use **`library-insight migrate <old> <new>`** to get a migration advisor report with replacement suggestions.
2121
> - Use **`library-insight search-central <query>`** to search Maven Central.
22-
> - Use **`library-insight graph <coord>`** to visual dependency trees.
23-
> - Use **`library-insight check-compat <old> <new>`** to lint Semantic Versioning API compliance.
22+
> - Use **`library-insight dependency-graph <coord>`** to visualize dependency trees.
23+
> - Use **`library-insight semver <old> <new>`** to lint Semantic Versioning API compliance.
2424
> - Use **`library-insight mcp`** to communicate as a Model Context Protocol (MCP) server.
25+
>
26+
> **MCP Integration Rule:**
27+
> If an MCP server is already configured and available (e.g., in Cursor, Claude Desktop, or another IDE with MCP support), **prefer the MCP server over shelling out to the CLI**. The MCP server exposes `scan_library`, `search_symbols`, and `explain_class` tools natively without subprocess overhead.
2528
2629
## Command Reference
2730

@@ -199,15 +202,14 @@ Search Maven Central Solr repository indices dynamically for matching packages a
199202
library-insight search-central retrofit
200203
```
201204

202-
### 13. Dependency Graph (`graph`)
205+
### 13. Dependency Graph (`dependency-graph`)
203206
Renders a visual hierarchical tree of dependencies resolved recursively from `.pom` XML package descriptors:
204207
```bash
205-
library-insight graph com.github.ajalt.clikt:clikt-jvm:4.4.0
208+
library-insight dependency-graph com.github.ajalt.clikt:clikt-jvm:4.4.0
206209
```
207210

208-
### 14. API Compatibility Checker (`check-compat`)
211+
### 14. SemVer Compliance (`semver`)
209212
Lints version bumps against actual bytecode modifications to enforce Semantic Versioning (SemVer) compliance:
210213
```bash
211-
library-insight check-compat com.squareup.retrofit2:retrofit:2.9.0 com.squareup.retrofit2:retrofit:2.11.0
212-
```
214+
library-insight semver com.squareup.retrofit2:retrofit:2.9.0 com.squareup.retrofit2:retrofit:2.11.0
213215
```

README.md

Lines changed: 23 additions & 290 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ Use it when you need to:
1818

1919
## Key Features
2020

21+
- **MCP Server**: Connect Cursor, Claude Desktop, or any MCP-compatible IDE. They call `scan_library`, `search_symbols`, and `explain_class` directly without leaving the editor.
2122
- **Multi-Format Support**: Reads JARs, AARs (including nested JARs), directories, and Gradle build outputs.
2223
- **Version-Correct API Lookup**: Scans the exact artifact you point it at, so AI agents and developers see the real public API for that dependency version.
23-
- **Deep Metadata Extraction**:
24-
- **Classes/Interfaces/Objects**: Modifiers, companion objects, data/value flags, annotation markers, nested declarations, interfaces, inheritance.
25-
- **Constructors & Methods**: Visibility, parameter names, default arguments, return types, generic signatures/bounds, extension receivers, operators, infixes, inline, and suspend keywords.
26-
- **Properties**: Mutability (`val`/`var`), const declarations, lateinits, backing fields, and custom accessors.
27-
- **Format Exporters**: Converts API indices to structured **JSON** or highly readable **Markdown** reference documentation.
28-
- **Search Engine**: Performs case-insensitive searches across packages, classes, methods, and properties.
29-
- **Diff Engine**: Compares two versions of a library to highlight added, removed, or changed APIs, deprecations, and **binary breaking changes** (like visibility reduction, method deletion, or changing suspend modifiers).
30-
- **AI-Context Exporter**: Generates a compact, token-efficient `ai-context.json` file optimized for LLMs (ChatGPT, Gemini, Claude, Cursor, Copilot).
24+
- **Deep Metadata Extraction**: Classes, constructors, methods, properties, generics, Kotlin metadata, suspend keywords, annotations.
25+
- **Migration Advisor**: Compares two versions and reports removed, deprecated, and replacement APIs — great for Retrofit, OkHttp, Compose, and Kotlin upgrades.
26+
- **Dependency API Audit**: Scans project Gradle dependencies and reports deprecated APIs found in installed bytecode.
27+
- **Dependency Graph**: Renders a recursive visual tree of transitive dependencies from POM descriptors.
28+
- **SemVer Checker**: Lints version bumps against actual code changes to catch unbumped breaking changes.
29+
- **Search Maven Central**: Find coordinates and latest versions without leaving the terminal.
30+
- **Format Exporters**: Converts API indices to structured **JSON** or readable **Markdown** reference docs.
31+
- **AI-Context Exporter**: Generates a compact, token-efficient `ai-context/` directory for LLMs — 95%+ smaller than a raw dump.
3132

3233
---
3334

@@ -172,307 +173,39 @@ This creates `.agents/skills/library-insight/SKILL.md` in the project root, enab
172173

173174
---
174175

175-
## CLI Usage & Commands
176+
## Quick Start
176177

177178
> [!NOTE]
178-
> The examples below assume the executable has been installed globally (via the installer script). You can execute it directly using:
179-
> `library-insight <command> [options]`
180-
181-
> [!IMPORTANT]
182-
> **AI Agent Accuracy Rule:**
183-
> If you are an AI assistant, do not assume the library API from memory, latest web docs, or random examples. First scan or query the exact library version used by the project whenever possible.
184-
>
185-
> **AI Agent Token Optimization Rule:**
186-
> Do **not** read the entire raw `build/library-insight-index.json` or generated `API_REFERENCE.md` files directly using file-viewing tools. Doing so will bloat your context window and exceed token limits.
187-
> Instead, use the dedicated CLI query subcommands to lookup only the class details or signatures you need:
188-
> - Use **`library-insight search <query>`** to locate packages or classes.
189-
> - Use **`library-insight explain <class>`** to inspect full signatures and docs.
190-
> - Use **`library-insight diff <old> <new>`** before upgrading or replacing deprecated APIs.
191-
192-
### 1. Scan Library
193-
194-
Scan a JAR, AAR, local directory, or Maven coordinate.
195-
196-
Use this first when you need to know how a dependency should be implemented in the exact version your project uses.
197-
198-
> [!TIP]
199-
> **Offline-First & Smart Caching:**
200-
> - **Gradle Cache Lookup**: Before downloading from repositories over the network, `library-insight` scans your machine's Gradle cache (`~/.gradle/caches/modules-2/files-2.1/`). If the dependency coordinate has already been downloaded by Gradle/Android Studio, it is referenced directly without performing any disk copies—saving space and enabling fully offline scanning!
201-
> - **Local Project Cache**: If you run a scan inside a project directory containing a `build/` folder or a Gradle build file, downloaded artifacts are saved locally to `build/library-insight/cache/` instead of the global home directory, keeping your user profile clutter-free and project cleaning clean.
179+
> These examples assume you have installed the CLI globally. Run `library-insight <command>` from any folder.
202180
203181
```bash
204-
# Scan Retrofit from Maven Central (downloads jar + sources automatically)
182+
# 1. Scan a library from Maven Central (or picks it from your Gradle cache)
205183
library-insight scan com.squareup.retrofit2:retrofit:2.11.0
206184

207-
# Scan OkHttp client
208-
library-insight scan com.squareup.okhttp3:okhttp:4.12.0
209-
```
210-
211-
**Example Output:**
212-
```text
213-
Detected Maven coordinate: com.squareup.retrofit2:retrofit:2.11.0
214-
-> Using cached binary JAR from Gradle cache: retrofit-2.11.0.jar
215-
-> Using cached sources JAR from Gradle cache: retrofit-2.11.0-sources.jar
216-
Scan complete! Found 113 classes across 3 packages.
217-
Saved API index to: /Users/meet/AndroidStudioProjects/Library-Insight/build/library-insight-index.json
218-
```
219-
220-
### 2. Search Symbols
221-
222-
Search for packages, classes, methods, or properties in the saved index.
223-
224-
Use this when you know part of a class or method name and need to find the matching API in the scanned version.
225-
226-
```bash
227-
# Search for Retrofit class matching patterns
185+
# 2. Find a class by name
228186
library-insight search Retrofit
229-
```
230187

231-
**Example Output:**
232-
```text
233-
Found 2 matching classes:
234-
- retrofit2.Retrofit
235-
- retrofit2.Retrofit$Builder
236-
```
237-
238-
### 3. Explain Class
239-
240-
Print detailed structural details (modifiers, superclass, constructors, properties, methods, and documentation) about a specific class.
241-
242-
Use this before writing code that calls a class, especially when AI examples disagree with your installed dependency version.
243-
244-
```bash
245-
# Get full API structure of Retrofit class
188+
# 3. Inspect full API signatures and docs for a class
246189
library-insight explain Retrofit
247-
```
248-
249-
**Example Output:**
250-
```text
251-
Class: retrofit2.Retrofit (public class)
252-
Constructors:
253-
+ public constructor(okhttp3.Call$Factory, okhttp3.HttpUrl, java.util.List<retrofit2.Converter$Factory>, java.util.List<retrofit2.CallAdapter$Factory>, java.util.concurrent.Executor, boolean)
254-
Methods:
255-
+ public fun <T> create(java.lang.Class<T>): T
256-
+ public fun baseUrl(): okhttp3.HttpUrl
257-
+ public fun callFactory(): okhttp3.Call$Factory
258-
```
259-
260-
### 4. Export Index
261-
Export the scanned index to Markdown reference sheets or pretty-printed JSON.
262-
*(Note: For large libraries, single Markdown files can become huge; use `ai-export` for AI prompts instead).*
263-
264-
```bash
265-
# Automatically saves to build/API_REFERENCE.md
266-
library-insight export markdown
267-
```
268-
269-
**Example Output:**
270-
```text
271-
Exported MARKDOWN to: /Users/meet/AndroidStudioProjects/Library-Insight/build/API_REFERENCE.md
272-
```
273-
274-
### 5. Diff Library Versions
275-
276-
Compare two library archives directly to check for changes and potential breaking changes.
277-
278-
Use this when a method is deprecated, removed, renamed, or behaving differently between versions.
279-
280-
```bash
281-
# Detect breaking changes between Retrofit 2.9.0 and 2.11.0
282-
library-insight diff retrofit-2.9.0.jar retrofit-2.11.0.jar
283-
```
284-
285-
**Example Output:**
286-
```text
287-
==================================================
288-
LIBRARY INSIGHT API DIFF REPORT
289-
==================================================
290-
Old: retrofit-2.9.0
291-
New: retrofit-2.11.0
292-
Breaking Changes Found: NO
293-
==================================================
294-
➕ Added Classes:
295-
- retrofit2.Reflection
296-
📝 Changed Classes:
297-
Class: retrofit2.Invocation
298-
Added Methods:
299-
+ fun service(): java.lang.Class<?>
300-
```
301-
302-
### 6. Export AI Context (Recommended for AI prompts)
303-
304-
Generate a compact, token-efficient split context folder structure (`build/ai-context/` by default) containing individual class JSON files optimized for LLM prompts.
305-
306-
This solves two problems at once: AI gets exact APIs from the scanned dependency version, and it avoids massive single files like `API_REFERENCE.md`. Agents can read `metadata.json` first, then load only the specific class JSON files they need, reducing token usage by over 95%.
307-
308-
```bash
309-
library-insight ai-export
310-
```
311-
312-
**Example Output:**
313-
```text
314-
Generated compact LLM context directory structure at: /Users/meet/AndroidStudioProjects/Library-Insight/build/ai-context
315-
```
316-
317-
### 7. Clear Cache
318-
319-
Clear all downloaded and cached Maven artifacts from the local cache directory to free up space.
320-
321-
```bash
322-
library-insight clear-cache
323-
```
324-
325-
**Example Output:**
326-
```text
327-
Cache cleared successfully. Deleted 2.45 MB.
328-
```
329-
330-
### 8. Initialize Workspace Agent Skill (`init`)
331190

332-
Initialize the current project directory with the Custom AI agent Skill so that local AI assistants can auto-discover and utilize `library-insight`.
191+
# 4. Compare two versions — see what was added, removed, or changed
192+
library-insight diff com.squareup.retrofit2:retrofit:2.9.0 com.squareup.retrofit2:retrofit:2.11.0
333193

334-
```bash
335-
library-insight init
336-
```
337-
338-
**Example Output:**
339-
```text
340-
Initializing Library Insight agent environment...
341-
SUCCESS: AI Agent Skill initialized at: /Users/meet/AndroidStudioProjects/Library-Insight/.agents/skills/library-insight/SKILL.md
342-
```
343-
344-
### 9. Manage Agent Skills (`skills`)
345-
346-
Manage Library Insight Custom AI agent skills for the current workspace.
347-
348-
```bash
349-
# Install the skill to the current workspace (.agents/skills/)
350-
library-insight skills add
351-
```
352-
353-
**Example Output:**
354-
```text
355-
SUCCESS: AI Agent Skill added to workspace at: .agents/skills/library-insight/SKILL.md
356-
```
357-
358-
### 10. CLI Diagnostics & Doctor (`doctor`)
359-
360-
Run diagnostic checks for Java version, local caches, and active global AI Agent skill configurations.
361-
362-
```bash
363-
library-insight doctor
364-
```
365-
366-
**Example Output:**
367-
```text
368-
[Library Insight Diagnostics]
369-
1. Java Runtime Environment (JRE):
370-
- Path: /Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/java
371-
- Version: 17.0.7
372-
- Status: OK (Java 17+ verified)
373-
2. Local Cache Directory:
374-
- Path: /Users/meet/AndroidStudioProjects/Library-Insight/build/library-insight/cache
375-
- Status: OK
376-
3. AI Agent Skill Registrations:
377-
- Gemini Config Skill: ACTIVE (registered)
378-
- Cursor Skill: ACTIVE (registered)
379-
```
380-
381-
### 11. Model Context Protocol (MCP) Server (`mcp`)
382-
383-
Start the Model Context Protocol (MCP) server listening on stdio. This enables AI tools (such as Cursor, Claude Desktop, Copilot, etc.) to dynamically call Library Insight tools (like scanning libraries, searching symbols, or explaining classes) directly from the IDE context.
384-
385-
```bash
386-
library-insight mcp
387-
```
388-
389-
### 12. Dependency API Audit (`audit`)
390-
391-
Scan and audit all project dependencies declared recursively inside `build.gradle.kts` and catalog libraries inside `gradle/libs.versions.toml`. It analyzes bytecode annotations inside local cached dependencies to report deprecated classes, methods, and properties.
392-
393-
```bash
394-
library-insight audit
395-
```
396-
397-
**Example Output:**
398-
```text
399-
==================================================
400-
Library Insight Dependency Audit
401-
==================================================
402-
Detected Gradle Version Catalog at gradle/libs.versions.toml
403-
Scanning 11 Gradle build file(s)...
404-
405-
Found 10 dependencies to audit:
406-
- org.ow2.asm:asm:9.7
407-
...
408-
409-
--------------------------------------------------
410-
Auditing org.ow2.asm:asm:9.7...
411-
- Total classes: 39
412-
- Status: ⚠️ Deprecations detected
413-
* Deprecated Classes : 0
414-
* Deprecated Methods : 2
415-
* Deprecated Properties : 2
416-
==================================================
417-
Audit Summary: Scanned 10 libraries successfully.
418-
Total Deprecated APIs found: 1819
419-
==================================================
420-
```
421-
422-
### 13. API Migration Advisor (`migrate`)
423-
424-
Compare two library versions and output a structured migration report, automatically detecting replacement APIs from Kotlin `@ReplaceWith` annotation expressions and Javadoc `@deprecated` link tags.
425-
426-
```bash
194+
# 5. Get a migration report with replacement API suggestions
427195
library-insight migrate com.squareup.retrofit2:retrofit:2.9.0 com.squareup.retrofit2:retrofit:2.11.0
428-
```
429196

430-
**Example Output:**
431-
```text
432-
==================================================
433-
Library Insight Migration Report
434-
==================================================
435-
Old Version : com.squareup.retrofit2:retrofit:2.9.0
436-
New Version : com.squareup.retrofit2:retrofit:2.11.0
437-
==================================================
438-
439-
❌ Removed Classes
440-
-----------------
441-
- retrofit2.Platform$Android
442-
- retrofit2.Platform$Android$MainThreadExecutor
443-
444-
❌ Removed Methods
445-
-----------------
446-
- fun retrofit2.Platform.defaultCallbackExecutor(): java.util.concurrent.Executor
447-
448-
--------------------------------------------------
449-
Binary Compatibility: ❌ BREAKING CHANGES DETECTED
450-
==================================================
451-
```
452-
453-
### 14. Search Maven Central (`search-central`)
454-
455-
Search Maven Central Solr repository indices dynamically for matching packages and versions.
456-
```bash
457-
library-insight search-central clikt
458-
```
459-
460-
### 15. Dependency Graph (`graph`)
197+
# 6. Audit all project dependencies for deprecated APIs
198+
library-insight audit
461199

462-
Renders a visual hierarchical tree of dependencies resolved recursively from `.pom` XML package descriptors.
463-
```bash
464-
library-insight graph com.github.ajalt.clikt:clikt-jvm:4.4.0
200+
# 7. Start the MCP server (connect via Cursor, Claude Desktop, etc.)
201+
library-insight mcp
465202
```
466203

467-
### 16. API Compatibility Checker (`check-compat`)
468-
469-
Lints version bumps against actual bytecode modifications to enforce Semantic Versioning (SemVer) compliance.
470-
```bash
471-
library-insight check-compat com.squareup.retrofit2:retrofit:2.9.0 com.squareup.retrofit2:retrofit:2.11.0
472-
```
204+
→ See **[docs/CLI.md](docs/CLI.md)** for the complete command reference (all 16 commands with examples and output).
473205

474206
---
475207

208+
476209
## Repository Directory Structure
477210

478211
Below is the directory structure detailing the key folders and components of the Library Insight project:

0 commit comments

Comments
 (0)