feat(client): implement remote registry search, git installer, and applet removal
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
# LEX - Hardcore Offline Terminal Dictionary
|
||||
|
||||
```text
|
||||
_ _______ __
|
||||
| | | ____\ \/ /
|
||||
| | | _| \ /
|
||||
| |___| |___ / \
|
||||
|_____|_____/_/\_\
|
||||
```
|
||||
|
||||
> **Author:** BeerSlayer `<slayer@luxhebros.com>`
|
||||
> **License:** MIT
|
||||
> **Runtime:** Python 3.10+ / Gravitiny Applet
|
||||
|
||||
---
|
||||
|
||||
## What Is This?
|
||||
|
||||
Tired of opening bloated web browsers just to look up a word while debugging in a terminal?
|
||||
`lex` is a zero-latency, completely offline, heavy-metal bilingual dictionary CLI for your console.
|
||||
|
||||
Powered by a pre-indexed **SQLite FTS5** database with **250,000+ definitions** (WordNet 3.0 + Wiktionary TR-EN). Zero cloud calls, zero network lag. Instant lookup.
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
# English WordNet lookup
|
||||
lex algorithm
|
||||
lex concurrency
|
||||
|
||||
# Turkish to English lookup
|
||||
lex araba
|
||||
lex gelistirici
|
||||
|
||||
# Multi-word compound lookups
|
||||
lex "machine learning"
|
||||
lex "operating system"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Features
|
||||
|
||||
- **Blazing Fast (<5ms lookup):** Instant SQLite query execution.
|
||||
- **Auto-Detect Language:** Automatically routes between English and Turkish inputs.
|
||||
- **Fuzzy Tolerance:** Typo in your query? 3-stage candidate pruning suggests what you actually meant.
|
||||
- **Clean ANSI Boxes:** Rich terminal card renderer with definitions, synonyms, and examples.
|
||||
@@ -1,49 +1,34 @@
|
||||
{
|
||||
"id": "lex",
|
||||
"name": "Lex",
|
||||
"display_name": "LEX - Offline CLI Dictionary & Context Assistant",
|
||||
"description": "Lightweight, fast, and offline command-line bilingual English/Turkish dictionary and context assistant.",
|
||||
"description": "Brutally fast, offline CLI dictionary engine powered by WordNet & Wiktionary FTS5.",
|
||||
"version": "1.1.0",
|
||||
"stage": "Beta",
|
||||
"release_type": "Minor",
|
||||
"created_at": "2026-10-02",
|
||||
"updated_at": "2026-10-02",
|
||||
"author": "BeerSlayer <slayer@luxhebros.com>",
|
||||
"license": "MIT",
|
||||
"author": "Gravitiny Team",
|
||||
"runtime": "python",
|
||||
"entrypoint": "main.py",
|
||||
"shims": ["lex"],
|
||||
"network": "offline",
|
||||
"dependencies": [
|
||||
"rich>=13.0.0"
|
||||
],
|
||||
"tags": [
|
||||
"dictionary",
|
||||
"offline",
|
||||
"wordnet",
|
||||
"wiktionary",
|
||||
"turkish",
|
||||
"english",
|
||||
"fast",
|
||||
"fuzzy"
|
||||
],
|
||||
"features": [
|
||||
"Offline WordNet 3.0 English Lexicon (206k+ entries)",
|
||||
"Offline Wiktionary Turkish-to-English Lexicon (45k+ entries)",
|
||||
"Sub-millisecond automatic language detection (EN <-> TR)",
|
||||
"3-Stage Candidate Pruning & Fuzzy Search (Levenshtein / SequenceMatcher)",
|
||||
"Centralized JSON Message and UI Catalog",
|
||||
"Lightweight native Windows launcher and GUI installer"
|
||||
],
|
||||
"changelog": [
|
||||
{
|
||||
"version": "1.1.0",
|
||||
"date": "2026-10-02",
|
||||
"stage": "Beta",
|
||||
"type": "Minor Feature Release",
|
||||
"changes": [
|
||||
"Added comprehensive offline Turkish-to-English lexicon (45,899 entries).",
|
||||
"Implemented instant language detection with zero perceptual latency.",
|
||||
"Added distinct Turkish-to-English card renderer with nuances and examples.",
|
||||
"Added bilingual fuzzy search across English and Turkish entries."
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"date": "2026-10-02",
|
||||
"stage": "Beta",
|
||||
"type": "Initial Release",
|
||||
"changes": [
|
||||
"Initial release of LEX CLI with Quick Mode card view.",
|
||||
"Integrated offline SQLite database with 206k WordNet entries.",
|
||||
"Implemented multi-word phrase queries and fuzzy search.",
|
||||
"Added standalone GUI installer and Windows Settings integration."
|
||||
]
|
||||
}
|
||||
"Centralized JSON Message and UI Catalog"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
# SEC - Structured Ergonomic Cheatsheet & Code Assistant
|
||||
|
||||
```text
|
||||
____ _____ ____
|
||||
/ ___|| ____/ ___|
|
||||
\___ \| _|| |
|
||||
___) | |__| |___
|
||||
|____/|_____\____|
|
||||
```
|
||||
|
||||
> **Author:** Simon the Coder `<simon@luxhebros.com>`
|
||||
> **Specification Version:** 1.0.0-alpha
|
||||
> **Runtime Environment:** Python 3.10+ / Gravitiny Applet Platform
|
||||
> **License:** MIT Open Source License
|
||||
|
||||
---
|
||||
|
||||
## 1. Abstract & Motivation
|
||||
|
||||
Developers in drop-down/modal terminal environments frequently execute queries under tight spatial and temporal constraints. `sec` is designed to minimize motor latency by constraining command naming to the left-hand QWERTY region (`s`, `e`, `c`) while providing deterministic query routing and semantic AST-style snippet extraction.
|
||||
|
||||
---
|
||||
|
||||
## 2. Mathematical & Heuristic Routing Architecture
|
||||
|
||||
The `QueryRouter` class decomposes freeform CLI tokens $T = \{t_1, t_2, \dots, t_n\}$ through prioritized candidate generation:
|
||||
|
||||
1. **Programming Language Scoping:** Maps $t_1 \in \mathcal{L}$ to canonical StackOverflow question endpoints.
|
||||
2. **Deterministic Synonym Permutation:** Dynamically expands programmatic verbs ($\text{serialize} \to \{\text{dump}, \text{dumps}, \text{write}, \text{stringify}\}$).
|
||||
3. **Dual-Mode Clipboard Pipeline:**
|
||||
- `-c` (Code Extraction): Strips commentary and markdown headers, isolating executable syntax trees.
|
||||
- `-c a` (Full Context): Captures complete documentation cards.
|
||||
|
||||
---
|
||||
|
||||
## 3. Invocation Examples
|
||||
|
||||
```bash
|
||||
# Language-scoped snippet retrieval
|
||||
sec python json serialize -c
|
||||
|
||||
# System utility lookup
|
||||
sec tar extract
|
||||
|
||||
# Diagnostic query
|
||||
sec linux memory usage
|
||||
|
||||
# Full context clipboard copy
|
||||
sec docker container prune -c a
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Technical Invariants
|
||||
|
||||
- **Asynchronous & Offline Fallback:** Persistent SQLite response cache (`data/cache.db`).
|
||||
- **Zero ANSI Pollution:** Strict stream sanitization on pipeline redirection.
|
||||
- **Pure Dependency Decoupling:** Fully compliant with Gravitiny specification v0.1.0.
|
||||
@@ -1,34 +1,35 @@
|
||||
{
|
||||
"id": "sec",
|
||||
"name": "Sec",
|
||||
"display_name": "SEC - CLI Cheat Sheet & Code Snippet Assistant",
|
||||
"description": "Lightning-fast CLI cheat sheet and code snippet assistant powered by cheat.sh with smart routing and clipboard copy.",
|
||||
"display_name": "SEC - Ergonomic CLI Cheat Sheet & Code Snippet Assistant",
|
||||
"description": "Ergonomic, heuristic-routed CLI cheat sheet and code snippet assistant powered by cheat.sh.",
|
||||
"version": "1.0.0",
|
||||
"stage": "Alpha",
|
||||
"release_type": "Initial",
|
||||
"created_at": "2026-10-02",
|
||||
"updated_at": "2026-10-02",
|
||||
"author": "Simon the Coder <simon@luxhebros.com>",
|
||||
"license": "MIT",
|
||||
"author": "Gravitiny Team",
|
||||
"runtime": "python",
|
||||
"entrypoint": "main.py",
|
||||
"shims": ["sec"],
|
||||
"network": "live",
|
||||
"dependencies": [
|
||||
"requests>=2.28.0",
|
||||
"rich>=13.0.0"
|
||||
],
|
||||
"features": [
|
||||
"Smart Multi-Token cheat.sh Query Router",
|
||||
"Left-Hand Optimized QWERTY Command Name (sec)",
|
||||
"Clipboard Code Extraction (--copy / -c)",
|
||||
"Offline Query Cache",
|
||||
"Centralized JSON Message and UI Catalog"
|
||||
"tags": [
|
||||
"cheatsheet",
|
||||
"snippets",
|
||||
"cheat.sh",
|
||||
"routing",
|
||||
"clipboard",
|
||||
"productivity",
|
||||
"python",
|
||||
"bash"
|
||||
],
|
||||
"changelog": [
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"date": "2026-10-02",
|
||||
"stage": "Alpha",
|
||||
"type": "Initial Scaffold",
|
||||
"changes": [
|
||||
"Initial project scaffold and architecture definition for SEC."
|
||||
]
|
||||
}
|
||||
"features": [
|
||||
"Ergonomic left-hand QWERTY command invocation (optimized for dropdown terminals)",
|
||||
"Deterministic multi-token candidate URL permutation and developer synonym expansion",
|
||||
"Dual-mode native Win32/POSIX clipboard integration (-c for code only, -c a for full snippet)",
|
||||
"Offline query caching in local SQLite database",
|
||||
"Centralized JSON UI and interaction catalog"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -66,7 +66,24 @@
|
||||
"usage": "Usage: gravitiny search <query>",
|
||||
"missing_query": "Error: Search query is required.",
|
||||
"searching": "Searching registry for '{query}'...",
|
||||
"no_results": "No applets matching '{query}' found in remote registry."
|
||||
"no_results": "No applets matching '{query}' found in remote registry.",
|
||||
"results_header": "Remote Registry Search Results ({count}):"
|
||||
},
|
||||
"install": {
|
||||
"description": "Install an applet from registry, git repository URL, or local path",
|
||||
"usage": "Usage: gravitiny install <applet_id | git_url | local_path>",
|
||||
"missing_source": "Error: Installation source (applet ID, git URL, or path) is required.",
|
||||
"installing": "Installing '{source}'...",
|
||||
"success": "{message}",
|
||||
"failed": "Installation failed: {error}"
|
||||
},
|
||||
"remove": {
|
||||
"description": "Uninstall an applet and remove its command shims",
|
||||
"usage": "Usage: gravitiny remove <applet_id>",
|
||||
"missing_applet": "Error: Applet ID is required for 'remove' command.",
|
||||
"removing": "Removing applet '{applet_id}'...",
|
||||
"success": "{message}",
|
||||
"failed": "Removal failed: {error}"
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
+104
-2
@@ -6,14 +6,18 @@ from typing import List, Optional
|
||||
try:
|
||||
from gravitiny.src.catalog import catalog
|
||||
from gravitiny.src.discovery import AppletDiscovery
|
||||
from gravitiny.src.installer import AppletInstaller
|
||||
from gravitiny.src.launcher import AppletLauncher
|
||||
from gravitiny.src.manifest import load_manager_manifest
|
||||
from gravitiny.src.registry import RegistryClient
|
||||
from gravitiny.src.shims import ShimGenerator
|
||||
except ImportError:
|
||||
from src.catalog import catalog
|
||||
from src.discovery import AppletDiscovery
|
||||
from src.installer import AppletInstaller
|
||||
from src.launcher import AppletLauncher
|
||||
from src.manifest import load_manager_manifest
|
||||
from src.registry import RegistryClient
|
||||
from src.shims import ShimGenerator
|
||||
|
||||
|
||||
@@ -22,6 +26,9 @@ def print_help() -> None:
|
||||
print(f"{manifest.get('name', 'Gravitiny')} v{manifest.get('version', '0.1.0')} [{manifest.get('stage', 'Alpha')}] - {catalog.get('app.tagline')}")
|
||||
print()
|
||||
print(catalog.get("app.usage_header"))
|
||||
print(" gravitiny search <query> " + catalog.get("commands.search.description"))
|
||||
print(" gravitiny install <applet|git_url> " + catalog.get("commands.install.description"))
|
||||
print(" gravitiny remove <applet_id> " + catalog.get("commands.remove.description"))
|
||||
print(" gravitiny list " + catalog.get("commands.list.description"))
|
||||
print(" gravitiny run <applet_id> [args...] " + catalog.get("commands.run.description"))
|
||||
print(" gravitiny info <applet_id> " + catalog.get("commands.info.description"))
|
||||
@@ -32,12 +39,85 @@ def print_help() -> None:
|
||||
print(" gravitiny <applet_id> [args...]")
|
||||
print()
|
||||
print("Examples:")
|
||||
print(" gravitiny search dictionary")
|
||||
print(" gravitiny install sec")
|
||||
print(" gravitiny list")
|
||||
print(" gravitiny run lex algorithm")
|
||||
print(" gravitiny sec python json serialize -c")
|
||||
print(" gravitiny setup")
|
||||
|
||||
|
||||
def cmd_search(args: List[str]) -> int:
|
||||
if not args:
|
||||
print(catalog.get("commands.search.missing_query"))
|
||||
print(catalog.get("commands.search.usage"))
|
||||
return 1
|
||||
|
||||
query = " ".join(args)
|
||||
client = RegistryClient()
|
||||
results = client.search(query)
|
||||
|
||||
if not results:
|
||||
print(catalog.format("commands.search.no_results", query=query))
|
||||
return 0
|
||||
|
||||
print(catalog.format("commands.search.results_header", count=len(results)))
|
||||
print()
|
||||
|
||||
id_w = max(len("ID"), max(len(r.get("id", "")) for r in results)) + 2
|
||||
name_w = max(len("Name"), max(len(r.get("name", "")) for r in results)) + 2
|
||||
ver_w = max(len("Version"), max(len(r.get("version", "")) for r in results)) + 2
|
||||
auth_w = max(len("Author"), max(len(r.get("author", "")) for r in results)) + 2
|
||||
|
||||
header = f"{'ID':<{id_w}} {'Name':<{name_w}} {'Version':<{ver_w}} {'Author':<{auth_w}} Description"
|
||||
separator = "-" * max(len(header), 75)
|
||||
|
||||
print(header)
|
||||
print(separator)
|
||||
|
||||
for r in results:
|
||||
print(f"{r.get('id', ''):<{id_w}} {r.get('name', ''):<{name_w}} {r.get('version', ''):<{ver_w}} {r.get('author', ''):<{auth_w}} {r.get('description', '')}")
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_install(args: List[str]) -> int:
|
||||
if not args:
|
||||
print(catalog.get("commands.install.missing_source"))
|
||||
print(catalog.get("commands.install.usage"))
|
||||
return 1
|
||||
|
||||
source = args[0]
|
||||
print(catalog.format("commands.install.installing", source=source))
|
||||
installer = AppletInstaller()
|
||||
success, message = installer.install(source)
|
||||
|
||||
if success:
|
||||
print(catalog.format("commands.install.success", message=message))
|
||||
return 0
|
||||
else:
|
||||
print(catalog.format("commands.install.failed", error=message))
|
||||
return 1
|
||||
|
||||
|
||||
def cmd_remove(args: List[str]) -> int:
|
||||
if not args:
|
||||
print(catalog.get("commands.remove.missing_applet"))
|
||||
print(catalog.get("commands.remove.usage"))
|
||||
return 1
|
||||
|
||||
applet_id = args[0]
|
||||
print(catalog.format("commands.remove.removing", applet_id=applet_id))
|
||||
installer = AppletInstaller()
|
||||
success, message = installer.remove(applet_id)
|
||||
|
||||
if success:
|
||||
print(catalog.format("commands.remove.success", message=message))
|
||||
return 0
|
||||
else:
|
||||
print(catalog.format("commands.remove.failed", error=message))
|
||||
return 1
|
||||
|
||||
|
||||
def cmd_list() -> int:
|
||||
discovery = AppletDiscovery()
|
||||
applets = discovery.discover_all()
|
||||
@@ -110,6 +190,21 @@ def cmd_info(args: List[str]) -> int:
|
||||
applet = discovery.get_applet(applet_id)
|
||||
|
||||
if not applet:
|
||||
# Check remote registry if not installed locally
|
||||
client = RegistryClient()
|
||||
remote_info = client.get_applet(applet_id)
|
||||
if remote_info:
|
||||
print(f"Applet Metadata (Remote Registry): {remote_info.get('name')}")
|
||||
print("-" * 50)
|
||||
print(f" ID : {remote_info.get('id')}")
|
||||
print(f" Version : {remote_info.get('version')}")
|
||||
print(f" Author : {remote_info.get('author')}")
|
||||
print(f" License : {remote_info.get('license')}")
|
||||
print(f" Runtime : {remote_info.get('runtime')}")
|
||||
print(f" Repository : {remote_info.get('repo_url')}")
|
||||
print(f" Description : {remote_info.get('description')}")
|
||||
return 0
|
||||
|
||||
print(catalog.format("commands.info.applet_not_found", applet_id=applet_id))
|
||||
return 1
|
||||
|
||||
@@ -240,7 +335,13 @@ def run_cli(args: Optional[List[str]] = None) -> int:
|
||||
command = raw_args[0].lower()
|
||||
sub_args = raw_args[1:]
|
||||
|
||||
if command == "list":
|
||||
if command == "search":
|
||||
return cmd_search(sub_args)
|
||||
elif command == "install":
|
||||
return cmd_install(sub_args)
|
||||
elif command == "remove":
|
||||
return cmd_remove(sub_args)
|
||||
elif command == "list":
|
||||
return cmd_list()
|
||||
elif command == "run":
|
||||
return cmd_run(sub_args)
|
||||
@@ -259,3 +360,4 @@ def run_cli(args: Optional[List[str]] = None) -> int:
|
||||
|
||||
print(catalog.format("errors.unknown_command", command=command))
|
||||
return 1
|
||||
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
import io
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
from typing import Optional, Tuple
|
||||
import requests
|
||||
|
||||
from gravitiny.src.manifest import parse_applet_manifest
|
||||
from gravitiny.src.registry import RegistryClient
|
||||
from gravitiny.src.shims import ShimGenerator
|
||||
|
||||
|
||||
class AppletInstaller:
|
||||
"""Installs, updates, and removes applets from remote registry, git repositories, or local directories."""
|
||||
|
||||
def __init__(self, applets_dir: Optional[Path] = None, bin_dir: Optional[Path] = None):
|
||||
user_home = Path.home()
|
||||
self.applets_dir = Path(applets_dir or (user_home / ".gravitiny" / "applets"))
|
||||
self.bin_dir = Path(bin_dir or (user_home / ".gravitiny" / "bin"))
|
||||
self.applets_dir.mkdir(parents=True, exist_ok=True)
|
||||
self.bin_dir.mkdir(parents=True, exist_ok=True)
|
||||
self.registry = RegistryClient()
|
||||
self.shim_gen = ShimGenerator(bin_dir=self.bin_dir)
|
||||
|
||||
def _clone_git_repo(self, git_url: str, dest_dir: Path) -> bool:
|
||||
"""Clones a git repository into destination directory."""
|
||||
if dest_dir.exists():
|
||||
shutil.rmtree(dest_dir, ignore_errors=True)
|
||||
try:
|
||||
res = subprocess.run(["git", "clone", "--depth", "1", git_url, str(dest_dir)], capture_output=True)
|
||||
return res.returncode == 0
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def _download_and_extract_zip(self, zip_url: str, dest_dir: Path) -> bool:
|
||||
"""Downloads a zip archive and extracts it into destination directory."""
|
||||
try:
|
||||
resp = requests.get(zip_url, timeout=10)
|
||||
if resp.status_code == 200:
|
||||
with zipfile.ZipFile(io.BytesIO(resp.content)) as zf:
|
||||
# Find root folder in zip if nested
|
||||
temp_extract = dest_dir.parent / f"_tmp_{dest_dir.name}"
|
||||
zf.extractall(temp_extract)
|
||||
|
||||
# If single subfolder exists, move contents
|
||||
extracted_children = list(temp_extract.iterdir())
|
||||
if len(extracted_children) == 1 and extracted_children[0].is_dir():
|
||||
if dest_dir.exists():
|
||||
shutil.rmtree(dest_dir, ignore_errors=True)
|
||||
shutil.move(str(extracted_children[0]), str(dest_dir))
|
||||
shutil.rmtree(temp_extract, ignore_errors=True)
|
||||
else:
|
||||
if dest_dir.exists():
|
||||
shutil.rmtree(dest_dir, ignore_errors=True)
|
||||
shutil.move(str(temp_extract), str(dest_dir))
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
def install(self, source: str) -> Tuple[bool, str]:
|
||||
"""Installs an applet from an ID, a Git repository URL, or a local directory path."""
|
||||
clean_source = source.strip()
|
||||
target_dir = None
|
||||
applet_id = None
|
||||
|
||||
# 1. Local directory source
|
||||
local_path = Path(clean_source)
|
||||
if local_path.exists() and local_path.is_dir():
|
||||
manifest = parse_applet_manifest(local_path)
|
||||
if not manifest:
|
||||
return False, f"Directory '{clean_source}' does not contain a valid manifest.json."
|
||||
applet_id = manifest.id
|
||||
target_dir = self.applets_dir / applet_id
|
||||
if target_dir.exists():
|
||||
shutil.rmtree(target_dir, ignore_errors=True)
|
||||
shutil.copytree(local_path, target_dir)
|
||||
|
||||
# 2. Remote Git URL source
|
||||
elif clean_source.startswith(("http://", "https://", "git@")) and clean_source.endswith(".git"):
|
||||
# Derive name
|
||||
repo_name = clean_source.rstrip("/").split("/")[-1][:-4].lower()
|
||||
target_dir = self.applets_dir / repo_name
|
||||
success = self._clone_git_repo(clean_source, target_dir)
|
||||
if not success:
|
||||
return False, f"Failed to clone git repository '{clean_source}'."
|
||||
manifest = parse_applet_manifest(target_dir)
|
||||
applet_id = manifest.id if manifest else repo_name
|
||||
|
||||
# 3. Registry Applet ID source
|
||||
else:
|
||||
applet_info = self.registry.get_applet(clean_source)
|
||||
if not applet_info:
|
||||
return False, f"Applet '{clean_source}' not found in remote registry."
|
||||
|
||||
applet_id = applet_info.get("id", clean_source.lower())
|
||||
target_dir = self.applets_dir / applet_id
|
||||
clone_url = applet_info.get("clone_url")
|
||||
download_url = applet_info.get("download_url")
|
||||
|
||||
installed = False
|
||||
# Try git clone first
|
||||
if clone_url:
|
||||
installed = self._clone_git_repo(clone_url, target_dir)
|
||||
# Fallback to zip download
|
||||
if not installed and download_url:
|
||||
installed = self._download_and_extract_zip(download_url, target_dir)
|
||||
|
||||
if not installed:
|
||||
return False, f"Failed to download and install applet '{applet_id}'."
|
||||
|
||||
# Parse installed manifest and generate shims
|
||||
installed_manifest = parse_applet_manifest(target_dir)
|
||||
if not installed_manifest:
|
||||
return False, f"Installed files in '{target_dir}' are missing a valid manifest."
|
||||
|
||||
created_shims = self.shim_gen.generate_shim(installed_manifest)
|
||||
shims_text = ", ".join(s.name for s in created_shims) if created_shims else "none"
|
||||
|
||||
return True, f"Successfully installed {installed_manifest.name} v{installed_manifest.version} by {installed_manifest.author} (Shims: {shims_text})"
|
||||
|
||||
def remove(self, applet_id: str) -> Tuple[bool, str]:
|
||||
"""Uninstalls an applet and removes its shims."""
|
||||
clean_id = applet_id.strip().lower()
|
||||
target_dir = self.applets_dir / clean_id
|
||||
|
||||
if not target_dir.exists():
|
||||
return False, f"Applet '{clean_id}' is not installed in '{self.applets_dir}'."
|
||||
|
||||
manifest = parse_applet_manifest(target_dir)
|
||||
if manifest:
|
||||
for shim in manifest.shims:
|
||||
self.shim_gen.remove_shim(shim)
|
||||
|
||||
try:
|
||||
shutil.rmtree(target_dir)
|
||||
return True, f"Successfully removed applet '{clean_id}' and all associated shims."
|
||||
except Exception as e:
|
||||
return False, f"Failed to remove applet directory: {e}"
|
||||
@@ -0,0 +1,104 @@
|
||||
import json
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
import requests
|
||||
|
||||
|
||||
DEFAULT_REGISTRY_URL = "https://git.luxhebros.com/api/v1/repos/admin/gravitiny/raw/registry/index.json"
|
||||
|
||||
|
||||
class RegistryClient:
|
||||
"""Fetches, caches, and searches remote applets from the central Gravitiny registry."""
|
||||
|
||||
def __init__(self, registry_url: Optional[str] = None, cache_ttl_seconds: int = 300):
|
||||
self.registry_url = registry_url or DEFAULT_REGISTRY_URL
|
||||
self.cache_ttl = cache_ttl_seconds
|
||||
self.cache_file = Path.home() / ".gravitiny" / "registry_cache.json"
|
||||
|
||||
def _get_local_fallback(self) -> Optional[Dict[str, Any]]:
|
||||
"""Checks for local workspace registry/index.json if offline or developing."""
|
||||
base_dir = Path(__file__).resolve().parent.parent.parent
|
||||
local_index = base_dir / "registry" / "index.json"
|
||||
if local_index.exists():
|
||||
try:
|
||||
with open(local_index, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
def fetch_index(self, force_refresh: bool = False) -> Dict[str, Any]:
|
||||
"""Fetches the remote registry index, using cache when fresh."""
|
||||
# 1. Check local cache
|
||||
if not force_refresh and self.cache_file.exists():
|
||||
try:
|
||||
with open(self.cache_file, "r", encoding="utf-8") as f:
|
||||
cached = json.load(f)
|
||||
cache_time = cached.get("_cached_at", 0)
|
||||
if time.time() - cache_time < self.cache_ttl:
|
||||
return cached.get("data", {})
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 2. Fetch from remote HTTP
|
||||
try:
|
||||
resp = requests.get(self.registry_url, timeout=5)
|
||||
if resp.status_code == 200:
|
||||
data = resp.json()
|
||||
# Save to cache
|
||||
self.cache_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(self.cache_file, "w", encoding="utf-8") as f:
|
||||
json.dump({"_cached_at": time.time(), "data": data}, f, indent=2)
|
||||
return data
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 3. Fallback to cached version even if expired
|
||||
if self.cache_file.exists():
|
||||
try:
|
||||
with open(self.cache_file, "r", encoding="utf-8") as f:
|
||||
return json.load(f).get("data", {})
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 4. Fallback to local workspace index
|
||||
local_fallback = self._get_local_fallback()
|
||||
if local_fallback:
|
||||
return local_fallback
|
||||
|
||||
return {}
|
||||
|
||||
def search(self, query: str) -> List[Dict[str, Any]]:
|
||||
"""Searches across applet id, name, description, tags, and author."""
|
||||
clean_q = query.strip().lower()
|
||||
if not clean_q:
|
||||
return []
|
||||
|
||||
index = self.fetch_index()
|
||||
applets = index.get("applets", {})
|
||||
results: List[Dict[str, Any]] = []
|
||||
|
||||
for applet_id, info in applets.items():
|
||||
name = info.get("name", "").lower()
|
||||
desc = info.get("description", "").lower()
|
||||
author = info.get("author", "").lower()
|
||||
tags = [t.lower() for t in info.get("tags", [])]
|
||||
|
||||
if (
|
||||
clean_q in applet_id.lower()
|
||||
or clean_q in name
|
||||
or clean_q in desc
|
||||
or clean_q in author
|
||||
or any(clean_q in t for t in tags)
|
||||
):
|
||||
results.append(info)
|
||||
|
||||
return results
|
||||
|
||||
def get_applet(self, applet_id: str) -> Optional[Dict[str, Any]]:
|
||||
"""Retrieves metadata for a specific remote applet."""
|
||||
clean_id = applet_id.strip().lower()
|
||||
index = self.fetch_index()
|
||||
applets = index.get("applets", {})
|
||||
return applets.get(clean_id)
|
||||
Reference in New Issue
Block a user