feat: L0b bootstrap scripts + L1 Go CLI structure

L0b (factory bootstrap):
- bootstrap.ps1 (Windows): pre-checks, interactive config, clone .factory, home.toml
- bootstrap.sh (Linux/Mac): same functionality for bash
- Idempotent re-run with home.toml verification

L1 (Go CLI):
- factory.yaml: manifest schema with components, deps, health-checks
- cmd/factory: Cobra CLI (install/update/status/diagnose)
- pkg/config: home.toml reader
- pkg/manifest: factory.yaml parser + topological sort
- pkg/health: health-check logic (file/dir/mcp_tool/command)

Scripts:
- build.sh: cross-compile for linux/win/darwin × amd64/arm64
- build.ps1: PowerShell cross-compile

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-06 23:59:09 +03:00
parent 47b41aa2f7
commit 561a7fd66f
12 changed files with 1380 additions and 43 deletions

203
bootstrap.ps1 Normal file
View File

@@ -0,0 +1,203 @@
#!/usr/bin/env pwsh
# L0b Factory Bootstrap — Windows
# Auto-generated from install-log.md field-test 2026-05-06
$ErrorActionPreference = "Stop"
$PSVersionTable.PSVersion.Major -ge 7 -or (Write-Error "Bootstrap requires PowerShell 7+. Install: winget install Microsoft.PowerShell"; exit 1)
$GITEA_DEFAULT = "https://git.kzntsv.site"
$ORG_DEFAULT = "OpeItcLoc03"
$FACTORY_REPO_DEFAULT = "factory"
$HOME_TOML = "$env:USERPROFILE\.config\factory\home.toml"
$PROJECTS_DIR_DEFAULT = "C:\Users\$env:USERNAME\projects"
function Test-Command {
param([string]$Name)
$null = Get-Command $Name -ErrorAction SilentlyContinue
}
function Write-Step {
param([string]$Msg)
Write-Host "`n$Msg" -ForegroundColor Cyan
}
function Write-Ok {
param([string]$Msg)
Write-Host "$Msg" -ForegroundColor Green
}
function Write-Skip {
param([string]$Msg)
Write-Host "$Msg" -ForegroundColor Yellow
}
function Write-Gap {
param([string]$Msg)
Write-Host "$Msg" -ForegroundColor Red
}
# Pre-checks
Write-Step "L0b Pre-checks"
$missed = @()
if (-not (Test-Command git)) { $missed += "git (install: winget install Git.Git)" }
if (-not (Test-Command curl)) { $missed += "curl (install: winget install curl.curl)" }
if (-not (Test-Command mise)) { $missed += "mise (install: winget install jdx.mise)" }
if (-not (Test-Command claude)) { $missed += "claude (install: irm https://claude.ai/install.ps1 | iex)" }
if ($missed) {
Write-Gap "Missing dependencies:"
$missed | ForEach-Object { Write-Host " - $_" }
Write-Host "`nInstall missing tools and re-run bootstrap."
exit 1
}
Write-Ok "Pre-checks passed"
# Check if already bootstrapped
if (Test-Path $HOME_TOML) {
Write-Skip "Already bootstrapped. Re-run mode: verify only."
$toml = Get-Content $HOME_TOML -Raw
if ($toml -match 'projects_dir\s*=\s*''([^'']+)''') {
$existing_dir = $matches[1]
Write-Host " projects_dir: $existing_dir"
if (Test-Path "$existing_dir\.factory") {
Write-Ok ".factory exists"
} else {
Write-Gap ".factory missing at $existing_dir\.factory"
exit 1
}
}
Write-Ok "Bootstrap verified. Exiting (no-op)."
exit 0
}
# Interactive: ask for configuration
Write-Step "Configuration"
$gitea = Read-Host "Gitea URL [$GITEA_DEFAULT]"
$gitea = if ($gitea) { $gitea } else { $GITEA_DEFAULT }
$org = Read-Host "Gitea org/user [$ORG_DEFAULT]"
$org = if ($org) { $org } else { $ORG_DEFAULT }
$factoryRepo = Read-Host "Factory repo name [$FACTORY_REPO_DEFAULT]"
$factoryRepo = if ($factoryRepo) { $factoryRepo } else { $FACTORY_REPO_DEFAULT }
$projectsDir = Read-Host "Projects directory [$PROJECTS_DIR_DEFAULT]"
$projectsDir = if ($projectsDir) { $projectsDir } else { $PROJECTS_DIR_DEFAULT }
$client = Read-Host "AI client [claude-code/copilot-cli/gemini-cli] (default: claude-code)"
$client = if ($client) { $client } else { "claude-code" }
# Validate projects_dir
if (-not (Test-Path $projectsDir)) {
$create = Read-Host "Directory '$projectsDir' does not exist. Create? [Y/n]"
if ($create -ne "n") {
New-Item -ItemType Directory -Force -Path $projectsDir | Out-Null
Write-Ok "Created $projectsDir"
} else {
Write-Gap "Cannot continue without projects_dir"
exit 1
}
}
# Clone .factory
Write-Step "Cloning .factory repo"
$factoryLocal = "$projectsDir\.factory"
$factoryUrl = "$gitea/$org/$factoryRepo.git"
if (Test-Path $factoryLocal) {
Write-Skip ".factory already exists, skipping clone"
# Verify it's a git repo
if (-not (Test-Path "$factoryLocal\.git")) {
Write-Gap "$factoryLocal exists but is not a git repo. Remove it and re-run."
exit 1
}
} else {
Write-Host "Cloning from: $factoryUrl"
# Check if we have credentials for gitea
$needAuth = $false
try {
$null = git ls-remote "$factoryUrl" 2>&1
} catch {
$needAuth = $true
}
if ($needAuth) {
Write-Host "`n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Cyan
Write-Host " PAT REQUIRED" -ForegroundColor Yellow
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Cyan
Write-Host "`n1. Open in browser: $gitea/user/settings/applications"
Write-Host "2. Generate PAT with scopes: read:repository, write:repository, read:user"
Write-Host "3. Press Enter when ready...`n"
Read-Host
Write-Host "Cloning with Git Credential Manager prompt..."
}
git clone "$factoryUrl" "$factoryLocal"
if (-not $?) {
Write-Gap "Clone failed. Check URL and credentials."
exit 1
}
Write-Ok "Cloned to $factoryLocal"
}
# Write home.toml
Write-Step "Writing ~/.config/factory/home.toml"
$configDir = "$env:USERPROFILE\.config\factory"
New-Item -ItemType Directory -Force -Path $configDir | Out-Null
$installedAt = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
$lines = @(
"# factory home — single source of machine-level state",
"# auto-generated by L0b bootstrap; safe to edit by hand",
"",
"projects_dir = '$projectsDir'",
"client = '$client'",
"installed_at = '$installedAt'"
)
[System.IO.File]::WriteAllLines(
"$configDir\home.toml",
$lines,
[System.Text.UTF8Encoding]::new($false)
)
Write-Ok "Wrote $HOME_TOML"
# Print next steps
Write-Host "`n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Green
Write-Host " L0b COMPLETE" -ForegroundColor Green
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Green
Write-Host "`nFactory bootstrapped. Next steps (manual):`n"
Write-Host "1. Start Claude Code:" -ForegroundColor Cyan
Write-Host " cd $factoryLocal"
Write-Host " claude`n"
Write-Host "2. In Claude, run:" -ForegroundColor Cyan
Write-Host " /login"
Write-Host " /plugin install superpowers@claude-plugins-official"
Write-Host " /plugin install context7@claude-plugins-official"
Write-Host " /reload-plugins"
Write-Host " /exit`n"
Write-Host "3. Run setup skills:" -ForegroundColor Cyan
Write-Host " cd $projectsDir"
Write-Host " claude"
Write-Host " /setup-projects-meta"
Write-Host " /setup-interns"
Write-Host " /setup-tasks"
Write-Host " /setup-wiki`n"
Write-Host "See .wiki/concepts/factory-bootstrap.md for full design."
Write-Host "`nRe-run this script anytime — it's idempotent."