Split the Windows script into modules; drop the Arkylx Index pieces
claude-mode.ps1 was 2,407 lines. It is now 153: the help block, parameters, paths, the managed-key list, a loader, and the dispatch. The rest moved, verbatim, into eleven files under lib/ - providers, output, files, core, vault, switch, guards, health, catalogue, commands, menu - dot-sourced into the script's scope in their original order, with the same check as the bash split that every original line landed in exactly one file. Inside a module $PSScriptRoot is lib\, so the one path beside the main script (providers.json) now goes through $script:Here. install.ps1 ships lib\, clearing old modules first. The Windows suite parses every module and install.ps1 (36 checks, all green on Windows PowerShell 5.1); install.ps1 is parsed but never run, since it edits the real profile and User PATH. linux/bootstrap.sh and scripts/build-package.ps1 existed only to build and serve packages for the Arkylx Index. Both installers fetch the repository's own archive, so a push to master is the release; the two scripts, the dist/ ignore and their mentions in the docs are gone. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
# lib/providers.ps1 - every gateway provider, read from providers.json, and lookups into them.
|
||||
#
|
||||
# Part of claude-mode.ps1, which dot-sources it into its own script scope after
|
||||
# the settings at its top. Not meant to run on its own. ASCII only: Windows
|
||||
# PowerShell 5.1 reads a .ps1 without a BOM as ANSI. $PSScriptRoot here would be
|
||||
# lib\, so paths beside the main script go through $script:Here.
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Providers
|
||||
#
|
||||
# Every gateway provider is an entry in providers.json, next to this script and
|
||||
# shared with the POSIX build: endpoint, auth, how its model list is fetched,
|
||||
# which doctor checks apply. This script only knows the *kinds* of behaviour
|
||||
# (Get-ProviderCatalogue, Test-PresetCatalogue) and picks one by name from the
|
||||
# entry, so a provider that reuses them needs no change here. anthropic is
|
||||
# built in: it is the native login, not a gateway.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
$script:ProvidersPath = Join-Path $script:Here 'providers.json'
|
||||
$script:Providers = @()
|
||||
try {
|
||||
$__pj = Get-Content -LiteralPath $script:ProvidersPath -Raw -Encoding UTF8 | ConvertFrom-Json
|
||||
$script:Providers = @($__pj.providers | Where-Object { $_.id })
|
||||
} catch { }
|
||||
if ($script:Providers.Count -eq 0) {
|
||||
Write-Host " FAIL providers.json missing or unreadable at $($script:ProvidersPath) - re-run install.ps1" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
$script:Modes = @('anthropic') + @($script:Providers | ForEach-Object { [string]$_.id })
|
||||
$script:ModeLabel = @{ 'anthropic' = 'Anthropic - your subscription login, no gateway' }
|
||||
|
||||
# `claude-mode <provider>` with no preset named uses this one. Deliberately a
|
||||
# fixed choice rather than "most recently used", so the command is predictable.
|
||||
$script:ProviderDefaultPreset = @{}
|
||||
foreach ($__p in $script:Providers) {
|
||||
$script:ModeLabel[[string]$__p.id] = [string]$__p.label
|
||||
$script:ProviderDefaultPreset[[string]$__p.id] = $(if ($__p.defaultPreset) { [string]$__p.defaultPreset } else { [string]$__p.id })
|
||||
}
|
||||
|
||||
function Get-Provider {
|
||||
param([string] $Id)
|
||||
return ($script:Providers | Where-Object { $_.id -eq $Id } | Select-Object -First 1)
|
||||
}
|
||||
|
||||
# An id or an alias (z.ai, z-ai) to the provider id; $null if neither.
|
||||
function Resolve-ProviderId {
|
||||
param([string] $Word)
|
||||
$w = ([string]$Word).ToLower()
|
||||
foreach ($p in $script:Providers) {
|
||||
if ([string]$p.id -eq $w -or (@($p.aliases) -contains $w)) { return [string]$p.id }
|
||||
}
|
||||
return $null
|
||||
}
|
||||
|
||||
function Test-ProviderDoctor {
|
||||
param([string] $Id, [string] $Check)
|
||||
$p = Get-Provider $Id
|
||||
return [bool]($p -and (@($p.doctor) -contains $Check))
|
||||
}
|
||||
Reference in New Issue
Block a user