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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"build": "esbuild src/vscode/extension.ts --bundle --platform=node --format=cjs --external:vscode --outfile=dist/extension.js && esbuild src/core/xhtml.ts --bundle --platform=node --format=cjs --outfile=dist/xhtml.js && esbuild src/core/epub.ts --bundle --platform=node --format=cjs --external:vscode --outfile=dist/epub.js && esbuild src/core/state-manager.ts --bundle --platform=node --format=cjs --outfile=dist/state-manager.js && esbuild src/core/archive.ts --bundle --platform=node --format=cjs --outfile=dist/archive.js && npm run build:sidecar && npm run build:mcp",
"build:sidecar": "esbuild src/antigravity/sidecar-server.ts --bundle --platform=node --format=cjs --outfile=dist/sidecar-server.cjs",
"build:mcp": "esbuild src/antigravity/mcp-server.ts --bundle --platform=node --format=cjs --outfile=dist/mcp-server.cjs",
"install:plugin": "node scripts/install-plugin.js",
"check": "tsc --noEmit",
"check:core": "tsc -p tsconfig.core.json --noEmit",
"test": "npm run build && node --test test/*.test.mjs",
Expand Down
27 changes: 27 additions & 0 deletions plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# XHTML & EPUB Reader β€” Antigravity 2.0 Plugin

Interactive reader previewer for EPUB and XHTML publications with native Antigravity 2.0 Auxiliary Pane sidecar and autonomous MCP agent tools.

## Features
- **Auxiliary Pane Sidecar UI (`sidecar://xhtml-reader-plugin/xhtml-previewer/`)**:
- Standalone reader shell served over lightweight local HTTP server.
- Responsive layout tailored for narrow auxiliary pane (~320px - 480px).
- Light, Dark, and Sepia themes, multi-column paginated & continuous scroll modes, typography controls, and Moon+ Reader style continuous overscroll transitions.
- Heuristic & semantic cross-file footnote preview popovers.
- Live Server-Sent Events (SSE) synchronization.
- **Model Context Protocol (MCP) Tools**:
- `xhtml_open_preview`: Autonomous document loading into the Sidecar previewer.
- `xhtml_get_toc`: Autonomous Table of Contents and spine inspection.
- `xhtml_get_metadata`: Publication metadata extraction (title, creator, language, spine count).

## Quick Start
1. Ensure bundles are built:
```bash
npm run build
```
2. Install the plugin into local Antigravity config:
```bash
node scripts/install-plugin.js
```
3. Open Antigravity 2.0 and ask the agent:
> *"Show me a preview of sample-book/OEBPS/ch_1.xhtml"*
Binary file added plugin/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions plugin/mcp_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"mcpServers": {
"xhtml_reader_mcp": {
"command": "node",
"type": "stdio",
"args": [
"dist/mcp-server.cjs"
]
}
}
}
18 changes: 18 additions & 0 deletions plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "xhtml-reader-plugin",
"displayName": "XHTML & EPUB Reader",
"version": "0.1.0",
"description": "Interactive reader and previewer for XHTML and EPUB publications with auxiliary pane sidecar and MCP agent tools.",
"author": "selvagant",
"homepage": "https://github.com/intxdv/XHTML-Reader-Previewer",
"repository": {
"type": "git",
"url": "https://github.com/intxdv/XHTML-Reader-Previewer.git"
},
"logo": "assets/logo.png",
"suggestedPrompts": [
"Open sample-book/OEBPS/ch_1.xhtml in the reader previewer",
"Inspect the Table of Contents of sample-book/OEBPS/ch_1.xhtml",
"Show publication metadata for sample-book/OEBPS/ch_1.xhtml"
]
}
16 changes: 16 additions & 0 deletions plugin/rules/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# XHTML & EPUB Reader Presentation Rules

When working with digital publications, books, or eBook markup:

1. **Prioritize the Interactive Sidecar Viewer:**
Whenever the user asks to view, preview, read, or inspect an `.epub`, `.xhtml`, or `.html` file, prefer loading it into the reader previewer over dumping raw HTML or plain text into the chat.

2. **Always Surface the Sidecar Pill Link:**
Whenever you load or update a document using `xhtml_open_preview` (or when discussing an active publication), you **MUST** include the reader sidecar pill link on its own line or within the summary so the user can open or focus the viewer in the Auxiliary Pane with one click:
```markdown
[Buka XHTML Reader](sidecar://xhtml-reader-plugin/xhtml-previewer/)
```
*(Or in English: `[Open Reader Preview](sidecar://xhtml-reader-plugin/xhtml-previewer/)`)*

3. **Autonomous Information Retrieval:**
When the user asks questions about chapter structure, table of contents, or book metadata, call `xhtml_get_toc` or `xhtml_get_metadata` directly rather than manually executing shell scripts or extracting archives.
20 changes: 20 additions & 0 deletions plugin/sidecars/xhtml-previewer/sidecar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"command": "node",
"args": [
"../../dist/sidecar-server.cjs"
],
"display_name": "XHTML & EPUB Reader",
"description": "Interactive reader and previewer for XHTML and EPUB publications in the auxiliary pane.",
"has_web_ui": true,
"restart_policy": "always",
"ui_config": {
"display_name": "XHTML Reader",
"views": [
{
"title": "XHTML Reader",
"path": "/",
"entrypoint": "SIDECAR_UI_ENTRYPOINT_AUX_PANE"
}
]
}
}
60 changes: 60 additions & 0 deletions plugin/skills/xhtml-reader/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
name: xhtml-reader
description: Live interactive preview and inspection of XHTML and EPUB publications inside Antigravity 2.0. Use when the user asks to preview, read, or inspect an EPUB book, XHTML chapter, or digital publication. Provides autonomous tools to open the reader preview in the Auxiliary Pane, inspect publication metadata, and retrieve the Table of Contents (TOC).
---

# XHTML & EPUB Reader Skill

This skill allows the agent to interact with and preview `.epub` archives, extracted EPUB directories, and standalone `.xhtml`/`.html` publications using the integrated **XHTML Reader Previewer Sidecar** and **MCP Tools**.

## When to Use

Activate this skill when:
- The user asks to preview, view, or read an `.epub`, `.xhtml`, or `.html` file.
- The user is editing or reviewing EPUB publication markup, CSS styles, or chapter layouts.
- The user wants to inspect a book's Table of Contents (TOC) or spine reading order without manually unzipping.
- The user asks for publication metadata (title, author, language, total chapters, manifest items).

## Autonomous MCP Tools

The plugin exposes 3 tools via the `xhtml_reader_mcp` server:

### 1. `xhtml_open_preview`
Opens a publication file inside the Antigravity Reader Sidecar and prepares the interactive reader shell in the Auxiliary Pane.

**Arguments:**
- `filePath` *(string, required)*: Absolute path or workspace-relative path to the `.epub` file, extracted EPUB directory, or `.xhtml` file.
- `spineIndex` *(number, optional)*: 0-based index of the spine chapter to open directly.
- `targetId` *(string, optional)*: Element or anchor ID to scroll into view upon loading.

**Always emit the Sidecar Pill Link:**
Whenever you call `xhtml_open_preview`, you MUST present the interactive sidecar pill link to the user in the response:
```markdown
[Buka XHTML Reader](sidecar://xhtml-reader-plugin/xhtml-previewer/)
```
*(Or in English: `[Open Reader Preview](sidecar://xhtml-reader-plugin/xhtml-previewer/)`)*

### 2. `xhtml_get_toc`
Extracts and parses the Table of Contents (`toc.xhtml` / `toc.ncx`) and spine reading sequence of an EPUB publication without opening the GUI.

**Arguments:**
- `filePath` *(string, required)*: Path to the publication.

**Use Case:** Quick chapter lookups, book structure analysis, or finding a specific chapter file path.

### 3. `xhtml_get_metadata`
Extracts publication metadata from the package document (`content.opf`).

**Arguments:**
- `filePath` *(string, required)*: Path to the publication.

**Returns:** Title, creator/author, language, identifier, publisher, date, spine chapter count, and total manifest resources.

## Best Practices & Guidelines

1. **Prefer Interactive Preview Over Raw Dumps:**
When the user asks about an eBook or chapter, load it with `xhtml_open_preview` and share the `sidecar://` pill so the user can comfortably read it in the Auxiliary Pane alongside their code.
2. **Path Resolution:**
Always provide a valid workspace-relative or absolute path. If the user mentions a file name casually (e.g. "preview ch1"), verify its existence first before calling `xhtml_open_preview`.
3. **Graceful Fallback:**
If the Sidecar server is not yet active, the tool will return a helpful message with instructions to start `node dist/sidecar-server.cjs`. Inform the user or launch the sidecar accordingly.
92 changes: 92 additions & 0 deletions scripts/install-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env node
const fs = require('node:fs');
const fsp = require('node:fs/promises');
const path = require('node:path');
const os = require('node:os');

async function installPlugin() {
const rootDir = path.resolve(__dirname, '..');
const pluginSourceDir = path.join(rootDir, 'plugin');
const distDir = path.join(rootDir, 'dist');

console.log('[XHTML Plugin Installer] Checking prerequisites...');

// 1. Verify build artifacts
const sidecarBundle = path.join(distDir, 'sidecar-server.cjs');
const mcpBundle = path.join(distDir, 'mcp-server.cjs');

if (!fs.existsSync(sidecarBundle) || !fs.existsSync(mcpBundle)) {
console.error('❌ Build artifacts missing. Please run "npm run build" first.');
process.exit(1);
}

// 2. Resolve Antigravity Plugins directory
const homeDir = os.homedir();
const configBase = process.env.ANTIGRAVITY_CONFIG_DIR || path.join(homeDir, '.gemini', 'config');
const pluginsDir = path.join(configBase, 'plugins');
const targetDir = path.join(pluginsDir, 'xhtml-reader-plugin');

console.log(`[XHTML Plugin Installer] Target directory: ${targetDir}`);

// 3. Ensure target directories exist
await fsp.mkdir(targetDir, { recursive: true });

// 4. Recursive copy helper
async function copyDir(src, dest) {
await fsp.mkdir(dest, { recursive: true });
const entries = await fsp.readdir(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
await copyDir(srcPath, destPath);
} else {
await fsp.copyFile(srcPath, destPath);
}
}
}

// 5. Copy plugin manifest and components
const itemsToCopy = [
'plugin.json',
'mcp_config.json',
'assets',
'sidecars',
'skills',
'rules',
'README.md'
];

for (const item of itemsToCopy) {
const srcPath = path.join(pluginSourceDir, item);
const destPath = path.join(targetDir, item);
if (!fs.existsSync(srcPath)) continue;

const stat = await fsp.stat(srcPath);
if (stat.isDirectory()) {
await copyDir(srcPath, destPath);
} else {
await fsp.copyFile(srcPath, destPath);
}
}

// 6. Copy dist artifacts into plugin directory
const targetDistDir = path.join(targetDir, 'dist');
await copyDir(distDir, targetDistDir);

console.log('βœ… Antigravity 2.0 Plugin successfully deployed!');
console.log('--------------------------------------------------');
console.log(`Plugin ID: xhtml-reader-plugin`);
console.log(`Location: ${targetDir}`);
console.log(`MCP Server: dist/mcp-server.cjs (3 tools)`);
console.log(`Sidecar: dist/sidecar-server.cjs (Auxiliary Pane)`);
console.log(`Skill: skills/xhtml-reader/SKILL.md`);
console.log(`Rule: rules/AGENTS.md`);
console.log('--------------------------------------------------');
console.log('Open Antigravity 2.0 -> Settings / Customizations to inspect the plugin.');
}

installPlugin().catch((err) => {
console.error('❌ Installation failed:', err);
process.exit(1);
});
Loading
Loading