forked from aden-hive/hive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhive.ps1
More file actions
83 lines (72 loc) · 3.58 KB
/
hive.ps1
File metadata and controls
83 lines (72 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env pwsh
# Wrapper script for the Hive CLI (Windows).
# Uses uv to run the hive command in the project's virtual environment.
#
# On Windows, User-level environment variables (set via quickstart.ps1) are
# stored in the registry but may not be loaded into the current terminal
# session (VS Code terminals, Windows Terminal tabs, etc.). This script
# explicitly loads them before running the agent — the Windows equivalent
# of Linux shells sourcing ~/.bashrc.
$ErrorActionPreference = "Stop"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
# ── Validate project directory ──────────────────────────────────────
if ((Get-Location).Path -ne $ScriptDir) {
Write-Error "hive must be run from the project directory.`nCurrent directory: $(Get-Location)`nExpected directory: $ScriptDir`n`nRun: cd $ScriptDir"
exit 1
}
if (-not (Test-Path (Join-Path $ScriptDir "pyproject.toml")) -or -not (Test-Path (Join-Path $ScriptDir "core"))) {
Write-Error "Not a valid Hive project directory: $ScriptDir"
exit 1
}
if (-not (Test-Path (Join-Path $ScriptDir ".venv"))) {
Write-Error "Virtual environment not found. Run .\quickstart.ps1 first to set up the project."
exit 1
}
# ── Ensure uv is available ──────────────────────────────────────────
if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
# Check default install location before giving up
$uvExe = Join-Path $env:USERPROFILE ".local\bin\uv.exe"
if (Test-Path $uvExe) {
$env:Path = (Split-Path $uvExe) + ";" + $env:Path
} else {
Write-Error "uv is not installed. Run .\quickstart.ps1 first."
exit 1
}
}
# ── Load environment variables from Windows Registry ────────────────
# Windows stores User-level env vars in the registry. New terminal
# sessions may not have them (especially VS Code integrated terminals).
# Load them explicitly so agents can find their API keys.
$configPath = Join-Path (Join-Path $env:USERPROFILE ".hive") "configuration.json"
if (Test-Path $configPath) {
try {
$config = Get-Content $configPath -Raw | ConvertFrom-Json
$envVarName = $config.llm.api_key_env_var
if ($envVarName) {
$val = [System.Environment]::GetEnvironmentVariable($envVarName, "User")
if ($val -and -not (Test-Path "Env:\$envVarName" -ErrorAction SilentlyContinue)) {
Set-Item -Path "Env:\$envVarName" -Value $val
}
}
} catch {
# Non-fatal: agent may still work if env vars are already set
}
}
# Load HIVE_CREDENTIAL_KEY for encrypted credential store
if (-not $env:HIVE_CREDENTIAL_KEY) {
# 1. Windows User env var (legacy quickstart installs)
$credKey = [System.Environment]::GetEnvironmentVariable("HIVE_CREDENTIAL_KEY", "User")
if ($credKey) {
$env:HIVE_CREDENTIAL_KEY = $credKey
} else {
# 2. File-based storage (new quickstart + matches quickstart.sh)
$credKeyFile = Join-Path $env:USERPROFILE ".hive\secrets\credential_key"
if (Test-Path $credKeyFile) {
$env:HIVE_CREDENTIAL_KEY = (Get-Content $credKeyFile -Raw).Trim()
}
}
}
# ── Run the Hive CLI ────────────────────────────────────────────────
# PYTHONUTF8=1: use UTF-8 for default encoding (fixes charmap decode errors on Windows)
$env:PYTHONUTF8 = "1"
& uv run hive @args