mirror of
https://github.com/lukaszraczylo/claude-mnemonic.git
synced 2026-06-08 23:39:40 +00:00
Add the statusline. Fix the installation.
This commit is contained in:
+44
-2
@@ -27,9 +27,28 @@ function Write-Error { param($Message) Write-Host "[ERROR] $Message" -Foreground
|
||||
|
||||
function Get-LatestVersion {
|
||||
try {
|
||||
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$GitHubRepo/releases/latest"
|
||||
$headers = @{}
|
||||
if ($env:GITHUB_TOKEN) {
|
||||
$headers["Authorization"] = "token $env:GITHUB_TOKEN"
|
||||
}
|
||||
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$GitHubRepo/releases/latest" -Headers $headers
|
||||
return $release.tag_name
|
||||
} catch {
|
||||
$errorMsg = $_.Exception.Message
|
||||
if ($errorMsg -match "rate limit" -or $_.Exception.Response.StatusCode -eq 403) {
|
||||
Write-Host ""
|
||||
Write-Host "[ERROR] GitHub API rate limit exceeded." -ForegroundColor Red
|
||||
Write-Host ""
|
||||
Write-Host "You have a few options:" -ForegroundColor Yellow
|
||||
Write-Host " 1. Wait ~1 hour for the rate limit to reset"
|
||||
Write-Host " 2. Specify a version manually:"
|
||||
Write-Host " `$env:MNEMONIC_VERSION = 'v0.6.1'; irm https://raw.githubusercontent.com/$GitHubRepo/main/scripts/install.ps1 | iex" -ForegroundColor Cyan
|
||||
Write-Host " 3. Use a GitHub token (set `$env:GITHUB_TOKEN)"
|
||||
Write-Host " 4. Clone and build from source:"
|
||||
Write-Host " git clone https://github.com/$GitHubRepo.git" -ForegroundColor Cyan
|
||||
Write-Host " cd claude-mnemonic; make build; make install" -ForegroundColor Cyan
|
||||
exit 1
|
||||
}
|
||||
Write-Error "Failed to fetch latest version from GitHub: $_"
|
||||
}
|
||||
}
|
||||
@@ -88,6 +107,14 @@ function Register-Plugin {
|
||||
|
||||
# Ensure directories exist
|
||||
New-Item -ItemType Directory -Path "$env:USERPROFILE\.claude\plugins" -Force | Out-Null
|
||||
|
||||
# Clean up old cache versions to prevent stale binaries
|
||||
$CacheBase = Split-Path $CachePath -Parent
|
||||
if (Test-Path $CacheBase) {
|
||||
Write-Info "Cleaning up old cache versions..."
|
||||
Get-ChildItem -Path $CacheBase -Directory | Where-Object { $_.Name -ne $VersionClean } | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Path $CachePath -Force | Out-Null
|
||||
|
||||
# Create JSON files if they don't exist
|
||||
@@ -132,8 +159,19 @@ function Register-Plugin {
|
||||
$Settings | Add-Member -NotePropertyName "enabledPlugins" -NotePropertyValue @{} -Force
|
||||
}
|
||||
$Settings.enabledPlugins | Add-Member -NotePropertyName $PluginKey -NotePropertyValue $true -Force
|
||||
|
||||
# Configure statusline
|
||||
$StatuslineCmd = "$InstallDir\hooks\statusline.exe"
|
||||
$StatuslineEntry = @{
|
||||
type = "command"
|
||||
command = $StatuslineCmd
|
||||
padding = 0
|
||||
}
|
||||
$Settings | Add-Member -NotePropertyName "statusLine" -NotePropertyValue $StatuslineEntry -Force
|
||||
|
||||
$Settings | ConvertTo-Json -Depth 10 | Out-File -Encoding UTF8 $SettingsFile
|
||||
Write-Success "Plugin enabled in settings.json"
|
||||
Write-Success "Statusline configured in settings.json"
|
||||
|
||||
# Update known_marketplaces.json
|
||||
$Marketplaces = Get-Content $MarketplacesFile -Raw | ConvertFrom-Json
|
||||
@@ -194,8 +232,12 @@ function Uninstall-ClaudeMnemonic {
|
||||
$Settings = Get-Content $SettingsFile -Raw | ConvertFrom-Json
|
||||
if ($Settings.enabledPlugins) {
|
||||
$Settings.enabledPlugins.PSObject.Properties.Remove($PluginKey)
|
||||
$Settings | ConvertTo-Json -Depth 10 | Out-File -Encoding UTF8 $SettingsFile
|
||||
}
|
||||
# Remove statusline if it's ours
|
||||
if ($Settings.statusLine -and $Settings.statusLine.command -match "claude-mnemonic") {
|
||||
$Settings.PSObject.Properties.Remove("statusLine")
|
||||
}
|
||||
$Settings | ConvertTo-Json -Depth 10 | Out-File -Encoding UTF8 $SettingsFile
|
||||
}
|
||||
if (Test-Path $MarketplacesFile) {
|
||||
$Marketplaces = Get-Content $MarketplacesFile -Raw | ConvertFrom-Json
|
||||
|
||||
+62
-7
@@ -81,11 +81,44 @@ detect_platform() {
|
||||
|
||||
# Get the latest release version from GitHub
|
||||
get_latest_version() {
|
||||
local version
|
||||
version=$(curl -sS "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
|
||||
local response version curl_opts
|
||||
|
||||
# Use GitHub token if available (higher rate limit)
|
||||
curl_opts=(-sS)
|
||||
if [[ -n "${GITHUB_TOKEN:-}" ]]; then
|
||||
curl_opts+=(-H "Authorization: token ${GITHUB_TOKEN}")
|
||||
fi
|
||||
|
||||
# Fetch with error handling
|
||||
response=$(curl "${curl_opts[@]}" "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" 2>&1)
|
||||
|
||||
# Check for rate limiting
|
||||
if echo "$response" | grep -q "API rate limit exceeded"; then
|
||||
echo ""
|
||||
error "GitHub API rate limit exceeded.
|
||||
|
||||
You have a few options:
|
||||
1. Wait ~1 hour for the rate limit to reset
|
||||
2. Specify a version manually:
|
||||
curl -sSL https://raw.githubusercontent.com/${GITHUB_REPO}/main/scripts/install.sh | bash -s -- v0.6.1
|
||||
3. Use a GitHub token (set GITHUB_TOKEN environment variable)
|
||||
4. Clone and build from source:
|
||||
git clone https://github.com/${GITHUB_REPO}.git
|
||||
cd claude-mnemonic && make build && make install"
|
||||
fi
|
||||
|
||||
# Check for other API errors
|
||||
if echo "$response" | grep -q '"message":'; then
|
||||
local msg
|
||||
msg=$(echo "$response" | grep '"message":' | sed -E 's/.*"message": *"([^"]+)".*/\1/')
|
||||
error "GitHub API error: $msg"
|
||||
fi
|
||||
|
||||
# Extract version
|
||||
version=$(echo "$response" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
|
||||
|
||||
if [[ -z "$version" ]]; then
|
||||
error "Failed to fetch latest version from GitHub"
|
||||
error "Failed to fetch latest version from GitHub. Response: $response"
|
||||
fi
|
||||
|
||||
echo "$version"
|
||||
@@ -151,6 +184,15 @@ register_plugin() {
|
||||
|
||||
# Ensure directories exist
|
||||
mkdir -p "$HOME/.claude/plugins"
|
||||
|
||||
# Clean up old cache versions to prevent stale binaries
|
||||
local cache_base
|
||||
cache_base=$(dirname "$CACHE_DIR")
|
||||
if [[ -d "$cache_base" ]]; then
|
||||
info "Cleaning up old cache versions..."
|
||||
find "$cache_base" -mindepth 1 -maxdepth 1 -type d ! -name "${version#v}" -exec rm -rf {} \; 2>/dev/null || true
|
||||
fi
|
||||
|
||||
mkdir -p "${CACHE_DIR}/${version}"
|
||||
|
||||
# Create JSON files if they don't exist
|
||||
@@ -193,12 +235,24 @@ EOF
|
||||
|
||||
success "Plugin registered in installed_plugins.json"
|
||||
|
||||
# Enable in settings.json
|
||||
jq --arg key "$PLUGIN_KEY" \
|
||||
'.enabledPlugins //= {} | .enabledPlugins[$key] = true' "$SETTINGS_FILE" > "${SETTINGS_FILE}.tmp" \
|
||||
# Enable in settings.json and configure statusline
|
||||
local statusline_cmd="$INSTALL_DIR/hooks/statusline"
|
||||
local statusline_entry
|
||||
statusline_entry=$(cat <<EOF
|
||||
{
|
||||
"type": "command",
|
||||
"command": "$statusline_cmd",
|
||||
"padding": 0
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
jq --arg key "$PLUGIN_KEY" --argjson statusline "$statusline_entry" \
|
||||
'.enabledPlugins //= {} | .enabledPlugins[$key] = true | .statusLine = $statusline' "$SETTINGS_FILE" > "${SETTINGS_FILE}.tmp" \
|
||||
&& mv "${SETTINGS_FILE}.tmp" "$SETTINGS_FILE"
|
||||
|
||||
success "Plugin enabled in settings.json"
|
||||
success "Statusline configured in settings.json"
|
||||
|
||||
# Register marketplace
|
||||
local marketplace_entry
|
||||
@@ -394,7 +448,8 @@ if [[ "${1:-}" == "--uninstall" ]]; then
|
||||
jq 'del(.plugins["'"$PLUGIN_KEY"'"])' "$PLUGINS_FILE" > "${PLUGINS_FILE}.tmp" && mv "${PLUGINS_FILE}.tmp" "$PLUGINS_FILE"
|
||||
fi
|
||||
if [[ -f "$SETTINGS_FILE" ]]; then
|
||||
jq 'del(.enabledPlugins["'"$PLUGIN_KEY"'"])' "$SETTINGS_FILE" > "${SETTINGS_FILE}.tmp" && mv "${SETTINGS_FILE}.tmp" "$SETTINGS_FILE"
|
||||
# Remove plugin from enabled plugins and remove statusline if it's ours
|
||||
jq 'del(.enabledPlugins["'"$PLUGIN_KEY"'"]) | if .statusLine.command | test("claude-mnemonic") then del(.statusLine) else . end' "$SETTINGS_FILE" > "${SETTINGS_FILE}.tmp" && mv "${SETTINGS_FILE}.tmp" "$SETTINGS_FILE"
|
||||
fi
|
||||
if [[ -f "$MARKETPLACES_FILE" ]]; then
|
||||
jq 'del(.["claude-mnemonic"])' "$MARKETPLACES_FILE" > "${MARKETPLACES_FILE}.tmp" && mv "${MARKETPLACES_FILE}.tmp" "$MARKETPLACES_FILE"
|
||||
|
||||
@@ -9,13 +9,22 @@ MARKETPLACES_FILE="$HOME/.claude/plugins/known_marketplaces.json"
|
||||
PLUGIN_KEY="claude-mnemonic@claude-mnemonic"
|
||||
MARKETPLACE_NAME="claude-mnemonic"
|
||||
MARKETPLACE_PATH="$HOME/.claude/plugins/marketplaces/claude-mnemonic"
|
||||
CACHE_PATH="$HOME/.claude/plugins/cache/claude-mnemonic/claude-mnemonic/1.0.0"
|
||||
VERSION="1.0.0"
|
||||
|
||||
# Get version from git tags (same as Makefile), or use argument if provided
|
||||
VERSION="${1:-$(git describe --tags --always --dirty 2>/dev/null || echo "dev")}"
|
||||
CACHE_BASE="$HOME/.claude/plugins/cache/claude-mnemonic/claude-mnemonic"
|
||||
CACHE_PATH="$CACHE_BASE/$VERSION"
|
||||
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
|
||||
|
||||
# Ensure plugins directory exists
|
||||
mkdir -p "$HOME/.claude/plugins"
|
||||
|
||||
# Clean up old cache versions to prevent stale binaries
|
||||
if [ -d "$CACHE_BASE" ]; then
|
||||
echo "Cleaning up old cache versions..."
|
||||
find "$CACHE_BASE" -mindepth 1 -maxdepth 1 -type d ! -name "$VERSION" -exec rm -rf {} \; 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Create installed_plugins.json if it doesn't exist
|
||||
if [ ! -f "$PLUGINS_FILE" ]; then
|
||||
echo '{"version": 2, "plugins": {}}' > "$PLUGINS_FILE"
|
||||
@@ -60,13 +69,24 @@ EOF
|
||||
|
||||
echo "Plugin registered in installed_plugins.json"
|
||||
|
||||
# Enable the plugin in settings.json
|
||||
# Enable the plugin in settings.json and configure statusline
|
||||
# First ensure enabledPlugins object exists, then add our plugin
|
||||
jq --arg key "$PLUGIN_KEY" \
|
||||
'.enabledPlugins //= {} | .enabledPlugins[$key] = true' "$SETTINGS_FILE" > "${SETTINGS_FILE}.tmp" \
|
||||
STATUSLINE_CMD="$MARKETPLACE_PATH/hooks/statusline"
|
||||
STATUSLINE_ENTRY=$(cat <<EOF
|
||||
{
|
||||
"type": "command",
|
||||
"command": "$STATUSLINE_CMD",
|
||||
"padding": 0
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
jq --arg key "$PLUGIN_KEY" --argjson statusline "$STATUSLINE_ENTRY" \
|
||||
'.enabledPlugins //= {} | .enabledPlugins[$key] = true | .statusLine = $statusline' "$SETTINGS_FILE" > "${SETTINGS_FILE}.tmp" \
|
||||
&& mv "${SETTINGS_FILE}.tmp" "$SETTINGS_FILE"
|
||||
|
||||
echo "Plugin enabled in settings.json"
|
||||
echo "Statusline configured in settings.json"
|
||||
|
||||
# Register the marketplace in known_marketplaces.json
|
||||
MARKETPLACE_ENTRY=$(cat <<EOF
|
||||
|
||||
Reference in New Issue
Block a user