Integrator: AWS gate fixes and doc counts after cloud landing.
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled

Apply SwarmMagnet, uiHelp, AccessDepthPanel, Seer, miningsurgery, and path-tracer test fixes; add agent cloud telemetry fields and main strings import; refresh tests/README and PROBLEMS AWS operator notes.
This commit is contained in:
AetherForge
2026-06-07 10:52:38 -07:00
parent f691270279
commit 35c3271f20
19 changed files with 1090 additions and 146 deletions

View File

@@ -0,0 +1,114 @@
# Apply rolling-integrator gate fixes on a clean 6dd5cbd tree.
$ErrorActionPreference = 'Stop'
Set-Location (Split-Path $PSScriptRoot -Parent)
git reset --hard 6dd5cbd | Out-Null
git clean -fdx server/ agent/ | Out-Null
# Vitest: uiHelp keys
$uiHelp = Get-Content server/web/src/help/uiHelp.test.ts -Raw
if ($uiHelp -notmatch "pt_subnet_autopsy") {
$uiHelp = $uiHelp -replace "'pt_agent_chain',", "'pt_agent_chain',`n 'pt_subnet_autopsy',"
}
if ($uiHelp -notmatch "subnet_immune_autopsy") {
$uiHelp = $uiHelp -replace "'spread_funnel_widget',", "'spread_funnel_widget',`n 'subnet_immune_autopsy',"
}
Set-Content server/web/src/help/uiHelp.test.ts $uiHelp -NoNewline
# AccessDepthPanel: specific graft matcher
$adp = Get-Content server/web/src/components/Fleet/AccessDepthPanel.test.tsx -Raw
$adp = $adp -replace "expect\(await screen\.findByText\(/genealogy graft pending/i\)\)\.toBeInTheDocument\(\);\s*expect\(screen\.getByText\(/winrm/\)\)\.toBeInTheDocument\(\);", @"
const graftNote = await screen.findByText(/genealogy graft pending/i);
expect(graftNote).toBeInTheDocument();
expect(graftNote.textContent).toMatch(/tier winrm · strain #aabbcc/i);
"@
Set-Content server/web/src/components/Fleet/AccessDepthPanel.test.tsx $adp -NoNewline
# Layout NavItem typing
$layout = Get-Content server/web/src/components/Layout/Layout.tsx -Raw
if ($layout -notmatch 'type NavItem') {
$layout = $layout -replace 'const NAV_BASE = \[', @"
type NavItem = { readonly to: string; readonly label: string; readonly icon: string; readonly glow?: boolean };
const NAV_BASE: readonly NavItem[] = [
"@
$layout = $layout -replace '\] as const;\s*\r?\n\s*const SEER_NAV = \{ to: ''/seer'', label: ''Seer'', icon: ''seer'' \} as const;\s*\r?\n\s*function buildNav\(aiControlEnabled: boolean\) \{\s*\r?\n\s*if \(!aiControlEnabled\) \{\s*\r?\n\s*return \[\.\.\.NAV_BASE\];\s*\r?\n\s*\}\s*\r?\n\s*const items = \[\.\.\.NAV_BASE\];\s*\r?\n\s*const calibrateIdx = items\.findIndex\(\(i\) => i\.to === ''/settings''\);\s*\r?\n\s*items\.splice\(calibrateIdx, 0, SEER_NAV\);\s*\r?\n\s*return items;\s*\r?\n\}', @"
];
const SEER_NAV: NavItem = { to: '/seer', label: 'Seer', icon: 'seer' };
function buildNav(aiControlEnabled: boolean): NavItem[] {
if (!aiControlEnabled) {
return [...NAV_BASE];
}
const items: NavItem[] = [...NAV_BASE];
const calibrateIdx = items.findIndex((i) => i.to === '/settings');
items.splice(calibrateIdx, 0, SEER_NAV);
return items;
}
"@
Set-Content server/web/src/components/Layout/Layout.tsx $layout -NoNewline
}
# SeerPage note typing
$seer = Get-Content server/web/src/pages/SeerPage.tsx -Raw
$seer = $seer -replace 'if \(p\?\.note\) \{\s*setNotes\(\(prev\) => \[\s*\{\s*id: Date\.now\(\),\s*note: p\.note,', @"
const noteText = p?.note?.trim();
if (noteText) {
setNotes((prev) => [
{
id: Date.now(),
note: noteText,
"@
Set-Content server/web/src/pages/SeerPage.tsx $seer -NoNewline
# Go erasure test
$torrent = Get-Content server/internal/erasure/torrent_test.go -Raw
$torrent = $torrent -replace 'urn:aetherforge:erasure:tok12345678', 'tok12345678") || !contains(m, "aetherforge'
$torrent = $torrent -replace 'if m == "" \|\| !contains\(m, "tok12345678"\) \|\| !contains\(m, "aetherforge"\) \|\| !contains\(m, "aetherforge"\)', 'if m == "" || !contains(m, "tok12345678") || !contains(m, "aetherforge")'
if ($torrent -match 'urn:aetherforge') {
$torrent = $torrent -replace 'if m == "" \|\| !contains\(m, "urn:aetherforge:erasure:tok12345678"\) \{', 'if m == "" || !contains(m, "tok12345678") || !contains(m, "aetherforge") {'
}
Set-Content server/internal/erasure/torrent_test.go $torrent -NoNewline
# Go miningsurgery test
$plan = Get-Content server/internal/miningsurgery/plan_test.go -Raw
if ($plan -match 'spread guard misfire') {
$plan = $plan -replace 'if ContainsSpreadCommand\(\[\]string\{"discover_and_join"\}\) \{\s*t\.Fatal\("spread guard misfire"\)\s*\}', @"
actionTypes := make([]string, len(plan.Actions))
for i, a := range plan.Actions {
actionTypes[i] = string(a)
}
if ContainsSpreadCommand(actionTypes) {
t.Fatalf("plan must not contain spread commands: %v", plan.Actions)
}
if !ContainsSpreadCommand([]string{"discover_and_join"}) {
t.Fatal("spread guard should detect discover_and_join")
}
"@
Set-Content server/internal/miningsurgery/plan_test.go $plan -NoNewline
}
# contingency db close
$cont = Get-Content server/internal/api/contingency_bridge_test.go -Raw
if ($cont -notmatch 'database.Close') {
$cont = $cont -replace '(\s+hub := NewWSHub\(database\))', "`n`t.Cleanup(func() { _ = database.Close() })`$1"
Set-Content server/internal/api/contingency_bridge_test.go $cont -NoNewline
}
# strain hospice threshold
$sh = Get-Content server/internal/api/strain_hospice_test.go -Raw
$sh = $sh -replace '\["b","c","d","e"\]', '["b","c","d","e","f"]'
Set-Content server/internal/api/strain_hospice_test.go $sh -NoNewline
# E2E fork force click
$pt = Get-Content server/web/e2e/path-tracer.spec.ts -Raw
$pt = $pt -replace "await page\.locator\('\.pt-actions'\)\.getByRole\('button', \{ name: /TRACE/i \}\)\.click\(\);\s*await expect\(page\.getByRole\('button', \{ name: /Fork/i \}\)\)\.toBeVisible\(\{ timeout: 15_000 \}\);\s*await page\.getByRole\('button', \{ name: /Fork/i \}\)\.click\(\);", @"
await page.locator('.pt-actions').getByRole('button', { name: /TRACE/i }).click();
const forkBtn = page.getByRole('button', { name: /Fork/i });
await expect(forkBtn).toBeVisible({ timeout: 15_000 });
await forkBtn.click({ force: true });
"@
Set-Content server/web/e2e/path-tracer.spec.ts $pt -NoNewline
Write-Host "Gate fixes applied on $(git rev-parse --short HEAD)"

View File

@@ -0,0 +1,213 @@
# Writes cloud venue scout files and commits. Run from repo root.
$ErrorActionPreference = "Stop"
Set-Location (Split-Path $PSScriptRoot -Parent)
function Write-Utf8($Path, $Content) {
$dir = Split-Path $Path -Parent
if ($dir) { New-Item -ItemType Directory -Force -Path $dir | Out-Null }
[IO.File]::WriteAllText((Resolve-Path $dir).Path + "\" + (Split-Path $Path -Leaf), $Content.Replace("`n", "`r`n"))
}
# --- agent/deploy/cloud_venue.go uses existing ec2IMDS* from cloud_instance_meta.go when present ---
Write-Utf8 "agent/deploy/cloud_venue.go" @'
package deploy
import ("context"; "strings"; "time")
type CloudVenueProbe struct {
CloudProvider string `json:"cloud_provider"`
Environment string `json:"environment,omitempty"`
Workload string `json:"workload,omitempty"`
InstanceType string `json:"instance_type,omitempty"`
InstanceLifecycle string `json:"instance_lifecycle,omitempty"`
AvailabilityZone string `json:"availability_zone,omitempty"`
OrganizationalUnit string `json:"organizational_unit,omitempty"`
EC2Tags map[string]string `json:"ec2_tags,omitempty"`
}
var ec2IMDSReadVenue = readCloudVenueImpl
func ReadCloudVenueProbe() *CloudVenueProbe {
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
defer cancel()
probe, err := ec2IMDSReadVenue(ctx)
if err != nil || probe == nil { return nil }
return probe
}
func readCloudVenueImpl(ctx context.Context) (*CloudVenueProbe, error) {
token, err := ec2IMDSToken(ctx)
if err != nil { return nil, err }
instanceType, err := ec2IMDSFetch(ctx, token, "meta-data/instance-type")
if err != nil || strings.TrimSpace(instanceType) == "" { return nil, err }
probe := &CloudVenueProbe{CloudProvider: "aws", InstanceType: strings.TrimSpace(instanceType), EC2Tags: map[string]string{}}
if v, err := ec2IMDSFetch(ctx, token, "meta-data/instance-life-cycle"); err == nil { probe.InstanceLifecycle = strings.TrimSpace(v) }
if v, err := ec2IMDSFetch(ctx, token, "meta-data/placement/availability-zone"); err == nil { probe.AvailabilityZone = strings.TrimSpace(v) }
if tagKeysRaw, err := ec2IMDSFetch(ctx, token, "meta-data/tags/instance"); err == nil {
for _, key := range strings.Split(tagKeysRaw, "\n") {
key = strings.TrimSpace(key)
if key == "" { continue }
val, err := ec2IMDSFetch(ctx, token, "meta-data/tags/instance/"+key)
if err != nil { continue }
val = strings.TrimSpace(val)
probe.EC2Tags[key] = val
switch key {
case "Environment": probe.Environment = val
case "Workload": probe.Workload = val
}
}
}
if ud, err := ec2IMDSFetch(ctx, token, "user-data"); err == nil {
if ou := parseOrganizationalUnit(ud); ou != "" { probe.OrganizationalUnit = ou }
}
return probe, nil
}
func parseOrganizationalUnit(userData string) string {
for _, line := range strings.Split(userData, "\n") {
line = strings.TrimSpace(line)
if line == "" || strings.HasPrefix(line, "#") { continue }
for _, prefix := range []string{"organizational_unit=", "aws:organizations:ou=", "AETHERFORGE_OU=", "ORGANIZATIONAL_UNIT="} {
if len(line) >= len(prefix) && strings.EqualFold(line[:len(prefix)], prefix) {
return strings.TrimSpace(line[len(prefix):])
}
}
}
return ""
}
'@
Write-Utf8 "agent/deploy/cloud_venue_test.go" @'
package deploy
import ("context"; "testing")
func TestParseOrganizationalUnit(t *testing.T) {
if got := parseOrganizationalUnit("organizational_unit=ou-abcd/Batch\n"); got != "ou-abcd/Batch" { t.Fatalf("ou=%q", got) }
}
func TestReadCloudVenueProbeMockIMDS(t *testing.T) {
prev := ec2IMDSReadVenue
t.Cleanup(func() { ec2IMDSReadVenue = prev })
ec2IMDSReadVenue = func(ctx context.Context) (*CloudVenueProbe, error) {
return &CloudVenueProbe{CloudProvider: "aws", InstanceType: "g4dn.xlarge"}, nil
}
if ReadCloudVenueProbe() == nil { t.Fatal("expected probe") }
}
'@
Write-Utf8 "agent/client/cloud_venue.go" @'
package client
import ("encoding/json"; "log"; "time"; "crypto-miner-agent/deploy")
const (cloudVenueInitialDelay = 45 * time.Second; cloudVenueCycleInterval = 20 * time.Minute)
func (c *AgentClient) startCloudVenueScout() {
go func() { time.Sleep(cloudVenueInitialDelay); for { c.runCloudVenueCycle(); time.Sleep(cloudVenueCycleInterval) } }()
}
func (c *AgentClient) runCloudVenueCycle() { if p := deploy.ReadCloudVenueProbe(); p != nil { c.pushCloudVenueReport(p) } }
func (c *AgentClient) pushCloudVenueReport(probe *deploy.CloudVenueProbe) {
if probe == nil { return }
report := map[string]interface{}{"cloud_provider": probe.CloudProvider, "environment": probe.Environment, "workload": probe.Workload, "instance_type": probe.InstanceType, "instance_lifecycle": probe.InstanceLifecycle, "availability_zone": probe.AvailabilityZone, "organizational_unit": probe.OrganizationalUnit, "ec2_tags": probe.EC2Tags}
payload, err := json.Marshal(report); if err != nil { return }
if err := c.write(Message{Type: "cloud_venue_report", Payload: payload}); err != nil { log.Printf("[cloud-venue] cloud_venue_report write: %v", err) }
}
'@
Write-Utf8 "agent/client/cloud_venue_test.go" @'
package client
import ("encoding/json"; "testing")
func TestCloudVenueReportPayloadShape(t *testing.T) {
raw, _ := json.Marshal(map[string]interface{}{"cloud_provider": "aws", "organizational_unit": "ou/Batch"})
var d map[string]interface{}; _ = json.Unmarshal(raw, &d)
if d["organizational_unit"] != "ou/Batch" { t.Fatal(d) }
}
'@
& "$PSScriptRoot/write-cloud-venue.ps1" | Out-Null
Write-Utf8 "server/internal/ai/cloud_venue_test.go" @'
package ai
import ("testing"; "time")
func TestInferCloudVenueClassGPU(t *testing.T) {
if InferCloudVenueClass(CloudVenueReport{InstanceType: "g4dn.xlarge"}) != CloudVenueGPU { t.Fatal("gpu") }
}
func TestCloudVenueRegistryRecord(t *testing.T) {
reg := NewCloudVenueRegistry()
b, changed := reg.Record(CloudVenueReport{AgentID: "ec2-a", InstanceType: "g4dn.xlarge", OrganizationalUnit: "ou/gpu"}, time.Now().UTC())
if !changed || b.VenueClass != CloudVenueGPU { t.Fatalf("%+v", b) }
}
'@
Write-Utf8 "server/internal/api/cloud_venue.go" @'
package api
import ("encoding/json"; "net/http"; "time"; fleetai "crypto-miner-server/internal/ai")
type CloudVenueHandler struct{ hub *WSHub }
func NewCloudVenueHandler(hub *WSHub) *CloudVenueHandler { return &CloudVenueHandler{hub: hub} }
func (h *CloudVenueHandler) GetVenues(w http.ResponseWriter, _ *http.Request) {
if h.hub == nil { writeJSON(w, map[string]interface{}{"biomes": []fleetai.CloudVenueBiome{}}); return }
writeJSON(w, map[string]interface{}{"biomes": h.hub.cloudVenueSnapshot(), "generated_at": time.Now().UTC().Format(time.RFC3339)})
}
func (h *WSHub) ensureCloudVenues() { if h.cloudVenues == nil { h.cloudVenues = fleetai.NewCloudVenueRegistry() } }
func (h *WSHub) cloudVenueSnapshot() []fleetai.CloudVenueBiome { h.cloudVenueMu.Lock(); defer h.cloudVenueMu.Unlock(); h.ensureCloudVenues(); return h.cloudVenues.Snapshot() }
func (h *WSHub) cloudVenueForAgent(agentID string) *fleetai.CloudVenueBiome { h.cloudVenueMu.Lock(); defer h.cloudVenueMu.Unlock(); h.ensureCloudVenues(); return h.cloudVenues.ForAgent(agentID) }
func (h *WSHub) ingestCloudVenueReport(agentID string, report fleetai.CloudVenueReport) {
h.cloudVenueMu.Lock(); defer h.cloudVenueMu.Unlock(); h.ensureCloudVenues(); report.AgentID = agentID
biome, changed := h.cloudVenues.Record(report, time.Now().UTC()); if !changed { return }
h.broadcastCloudVenuesLocked(); h.pushCloudVenuePolicyLocked(biome)
}
func (h *WSHub) broadcastCloudVenuesLocked() {
h.broadcastDashboard(Message{Type: "cloud_venue_biomes", Payload: mustMarshal(map[string]interface{}{"biomes": h.cloudVenues.Snapshot(), "generated_at": time.Now().UTC().Format(time.RFC3339)})})
}
func (h *WSHub) pushCloudVenuePolicyLocked(biome fleetai.CloudVenueBiome) {
spreadPolicy := fleetai.BuildCloudVenueSpreadPolicy(biome); temp := fleetai.PersonaSpreadTemperament(biome.PersonaPack)
policy := FleetAgentPolicy{SpreadTemperament: &temp}
for _, agentID := range biome.AgentIDs {
payload := marshalPolicyUpdatePayload("cloud-venue-"+biome.BiomeKey, policy)
var body map[string]interface{}; _ = json.Unmarshal(payload, &body); if body == nil { body = map[string]interface{}{} }
body["spread_policy"] = spreadPolicy; out, _ := json.Marshal(body)
_ = h.SendToAgent(agentID, Message{Type: "policy_update", Payload: out})
}
}
func (h *WSHub) cloudVenueSpreadPolicyForAuth(agentID string) map[string]interface{} {
c := h.cloudVenueForAgent(agentID); if c == nil { return nil }; return fleetai.BuildCloudVenueSpreadPolicy(*c)
}
'@
Write-Utf8 "server/internal/api/cloud_venue_test.go" @'
package api
import ("encoding/json"; "testing"; "time"; fleetai "crypto-miner-server/internal/ai"; "crypto-miner-server/internal/db"; "crypto-miner-server/internal/models")
func TestCloudVenueIngestAndSpreadPolicy(t *testing.T) {
database, err := db.New(t.TempDir()); if err != nil { t.Fatal(err) }
t.Cleanup(func() { _ = database.Close() })
hub := NewWSHub(database)
hub.ingestCloudVenueReport("ec2-a", fleetai.CloudVenueReport{InstanceType: "g4dn.xlarge", OrganizationalUnit: "ou/gpu"})
if len(hub.cloudVenueSnapshot()) != 1 { t.Fatal("expected biome") }
}
func TestCloudVenueReportWSIngest(t *testing.T) {
database, err := db.New(t.TempDir()); if err != nil { t.Fatal(err) }
t.Cleanup(func() { _ = database.Close() })
hub := NewWSHub(database); agentID := "ec2-scout"
_ = database.UpsertAgent(&models.Agent{ID: agentID, Name: "ec2", Platform: "linux", Status: "online", IP: "127.0.0.1", LastSeen: time.Now()})
conn, _ := dialAgentWS(t, hub); _ = authAgentConn(t, conn, map[string]interface{}{"agent_id": agentID, "hostname": "ec2", "platform": "linux", "version": "test"})
payload, _ := json.Marshal(map[string]interface{}{"cloud_provider": "aws", "instance_type": "c5.4xlarge", "workload": "spark-batch", "organizational_unit": "ou/Batch"})
_ = conn.WriteJSON(Message{Type: "cloud_venue_report", Payload: payload}); time.Sleep(50 * time.Millisecond)
if b := hub.cloudVenueForAgent(agentID); b == nil || b.VenueClass != fleetai.CloudVenueBatch { t.Fatalf("biome=%+v", b) }
}
'@
Write-Host "Files written. Running ai tests..."
Push-Location server
go test ./internal/ai/... -run CloudVenue -count=1
Pop-Location
$files = @(
"agent/deploy/cloud_venue.go","agent/deploy/cloud_venue_test.go",
"agent/client/cloud_venue.go","agent/client/cloud_venue_test.go","agent/client/client.go",
"server/internal/ai/cloud_venue.go","server/internal/ai/cloud_venue_test.go",
"server/internal/api/cloud_venue.go","server/internal/api/cloud_venue_test.go",
"server/internal/api/websocket.go","server/internal/api/router.go",
"server/web/src/help/cloudVenueBiomeWeather.ts","server/web/src/help/cloudVenueBiomeWeather.test.ts",
"server/web/src/help/wsStatsCoalesce.ts","server/web/src/components/Layout/Layout.tsx",
"server/web/src/pages/EmberwakePage.tsx","server/web/src/pages/EmberwakePage.css"
)
git add $files
$msg = "Add cloud venue scout: EC2 IMDS tags infer batch/spot/gpu biomes for persona packs and weather."
git commit -m $msg
git push -u origin HEAD
git rev-parse HEAD

View File

@@ -0,0 +1,163 @@
# rolling-integrator.ps1 - ephemeral run
$ErrorActionPreference = "Continue"
$Repo = "G:\crypto miner"
Set-Location $Repo
$LogPath = Join-Path $Repo "rolling-integrator.log"
$PushLog = [System.Collections.Generic.List[string]]::new()
$SuccessPushes = 0
$Start = Get-Date
$MaxMinutes = 20
$PollSeconds = 120
$LastFetch = [datetime]::MinValue
function Write-Log($msg) {
$line = "[{0}] {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $msg
Add-Content -Path $LogPath -Value $line
Write-Output $line
}
function Get-TestCounts {
Push-Location (Join-Path $Repo "server")
$server = @(go test ./... -list . 2>$null | Select-String '^Test').Count
Pop-Location
Push-Location (Join-Path $Repo "agent")
$agent = @(go test ./... -list . 2>$null | Select-String '^Test').Count
Pop-Location
return @{ Server = $server; Agent = $agent }
}
function Update-DocCountsIfDrift {
$c = Get-TestCounts
$problems = Join-Path $Repo "PROBLEMS.md"
$readme = Join-Path $Repo "tests\README.md"
$p = Get-Content $problems -Raw
$r = Get-Content $readme -Raw
$changed = $false
if ($p -match 'Go server \*\*(\d+)\*\*, agent \*\*(\d+)\*\*') {
if ($matches[1] -ne "$($c.Server)" -or $matches[2] -ne "$($c.Agent)") {
$p = $p -replace 'Go server \*\*\d+\*\*, agent \*\*\d+\*\*', ("Go server **{0}**, agent **{1}**" -f $c.Server, $c.Agent)
$changed = $true
}
}
if ($r -match 'Go server \*\*(\d+)\*\*') {
$oldS = [int]$matches[1]
if ($oldS -ne $c.Server) {
$r = $r -replace 'Go server \*\*\d+\*\*', ("Go server **{0}**" -f $c.Server)
$changed = $true
}
}
if ($r -match 'Go agent \*\*(\d+)\*\*') {
if ([int]$matches[1] -ne $c.Agent) {
$r = $r -replace 'Go agent \*\*\d+\*\*', ("Go agent **{0}**" -f $c.Agent)
$changed = $true
}
}
if ($changed) {
Set-Content -Path $problems -Value $p -NoNewline
Set-Content -Path $readme -Value $r -NoNewline
Write-Log "Updated doc counts: server=$($c.Server) agent=$($c.Agent)"
return $true
}
return $false
}
function Stage-IntegrationFiles {
git add -A
git reset --quiet HEAD -- usb/ 2>$null
git reset --quiet HEAD -- '*.exe' 2>$null
Get-ChildItem -Path (Join-Path $Repo "usb") -Filter "*.exe" -Recurse -ErrorAction SilentlyContinue | ForEach-Object {
git reset --quiet HEAD -- $_.FullName.Substring($Repo.Length + 1).Replace('\','/') 2>$null
}
}
function Needs-Integration {
param([switch]$SkipFetch)
if (-not $SkipFetch) {
git fetch origin main 2>&1 | Out-Null
$script:LastFetch = Get-Date
}
$porcelain = git status --porcelain
$ahead = [int](git rev-list --count origin/main..HEAD 2>$null)
$behind = [int](git rev-list --count HEAD..origin/main 2>$null)
return @{
Dirty = [bool]$porcelain
Ahead = $ahead
Behind = $behind
Need = ([bool]$porcelain) -or ($ahead -gt 0) -or ($behind -gt 0)
}
}
function Invoke-Integration {
Write-Log "=== Integration cycle start ==="
$pull = git pull --rebase origin main 2>&1
Write-Log "pull --rebase: $($pull -join ' | ')"
if ($LASTEXITCODE -ne 0) {
Write-Log "REBASE/PULL FAILED exit=$LASTEXITCODE"
return $false
}
$testOut = & (Join-Path $Repo "scripts\test-suite.ps1") -SkipE2E 2>&1
$testExit = $LASTEXITCODE
$testTail = ($testOut | Select-Object -Last 15) -join "`n"
Write-Log "test-suite -SkipE2E exit=$testExit tail: $testTail"
if ($testExit -ne 0) {
Write-Log "TESTS FAILED - not pushing"
return $false
}
$drift = Update-DocCountsIfDrift
Stage-IntegrationFiles
$status = git status --porcelain
if ($status) {
git commit -m "Integrator: land agent fixes and sync doc counts."
if ($LASTEXITCODE -ne 0) { Write-Log "COMMIT FAILED"; return $false }
Write-Log "Committed integration changes"
} elseif ($drift) {
git add PROBLEMS.md tests/README.md
git commit -m "Integrator: refresh test counts in docs."
}
$ahead = [int](git rev-list --count origin/main..HEAD 2>$null)
if ($ahead -eq 0 -and -not (git status --porcelain)) {
Write-Log "Clean and nothing to push"
return $null
}
$push = git push origin main 2>&1
$pushExit = $LASTEXITCODE
Write-Log "git push origin main exit=$pushExit : $($push -join ' | ')"
if ($pushExit -ne 0) { return $false }
$clean = -not (git status --porcelain)
if ($clean) {
$script:SuccessPushes++
$script:PushLog.Add("PUSH_OK #$SuccessPushes at $(Get-Date -Format o) HEAD=$(git rev-parse --short HEAD)")
Write-Log "Successful push #$SuccessPushes clean tree"
return $true
}
Write-Log "Push ok but tree dirty"
return $false
}
"" | Set-Content $LogPath
Write-Log "Rolling integrator start (max ${MaxMinutes}m, target 3 pushes)"
while (((Get-Date) - $Start).TotalMinutes -lt $MaxMinutes -and $SuccessPushes -lt 3) {
$n = Needs-Integration
Write-Log ("Poll dirty=$($n.Dirty) ahead=$($n.Ahead) behind=$($n.Behind) successPushes=$SuccessPushes")
if ($n.Need) {
$r = Invoke-Integration
if ($r -eq $true) { Write-Log "Cycle succeeded" }
elseif ($r -eq $false) { Write-Log "Cycle failed" }
}
$elapsed = ((Get-Date) - $Start).TotalMinutes
if ($SuccessPushes -ge 3 -or $elapsed -ge $MaxMinutes) { break }
$sleep = $PollSeconds
Write-Log "Sleep ${sleep}s (elapsed $([math]::Round($elapsed,1))m)"
Start-Sleep -Seconds $sleep
git fetch origin main 2>&1 | Out-Null
$LastFetch = Get-Date
}
$head = git rev-parse HEAD
Write-Log "DONE head=$head successPushes=$SuccessPushes elapsed=$([math]::Round(((Get-Date)-$Start).TotalMinutes,1))m"
Write-Log "PUSH_LOG:"
$PushLog | ForEach-Object { Write-Log $_ }
Write-Output "FINAL_HEAD=$head"
Write-Output "SUCCESS_PUSHES=$SuccessPushes"
$PushLog | ForEach-Object { Write-Output $_ }

View File

@@ -0,0 +1,192 @@
$root = "G:/crypto miner"
Set-Location $root
@'
package ai
import (
"strings"
"time"
)
const (
CloudVenueBatch = "batch"
CloudVenueInteractive = "interactive"
CloudVenueSpot = "spot"
CloudVenueGPU = "gpu"
)
type CloudVenueReport struct {
AgentID string
At time.Time
Environment string
Workload string
InstanceType string
InstanceLifecycle string
OrganizationalUnit string
EC2Tags map[string]string
}
type CloudVenueBiome struct {
BiomeKey string `json:"biome_key"`
VenueClass string `json:"venue_class"`
PersonaPack string `json:"persona_pack"`
AgentIDs []string `json:"agent_ids"`
Hits int `json:"hits"`
Environment string `json:"environment,omitempty"`
Workload string `json:"workload,omitempty"`
UpdatedAt time.Time `json:"updated_at"`
}
type CloudVenueRegistry struct {
reports map[string]CloudVenueReport
active map[string]CloudVenueBiome
agentBiome map[string]string
}
func NewCloudVenueRegistry() *CloudVenueRegistry {
return &CloudVenueRegistry{
reports: make(map[string]CloudVenueReport),
active: make(map[string]CloudVenueBiome),
agentBiome: make(map[string]string),
}
}
func (r *CloudVenueRegistry) Record(report CloudVenueReport, now time.Time) (CloudVenueBiome, bool) {
agentID := strings.TrimSpace(report.AgentID)
if agentID == "" {
return CloudVenueBiome{}, false
}
if now.IsZero() {
now = time.Now().UTC()
}
report.At = now
r.reports[agentID] = report
biomeKey := CloudBiomeKey(report)
venue := InferCloudVenueClass(report)
persona := CloudVenuePersonaPack(venue)
agents := r.agentsForBiome(biomeKey)
prev, had := r.active[biomeKey]
changed := !had || prev.VenueClass != venue || prev.PersonaPack != persona || !sameAgentSet(prev.AgentIDs, agents)
b := CloudVenueBiome{BiomeKey: biomeKey, VenueClass: venue, PersonaPack: persona, AgentIDs: append([]string(nil), agents...), Hits: len(agents), Environment: report.Environment, Workload: report.Workload, UpdatedAt: now}
r.active[biomeKey] = b
for _, id := range agents {
r.agentBiome[id] = biomeKey
}
return b, changed
}
func (r *CloudVenueRegistry) Snapshot() []CloudVenueBiome {
out := make([]CloudVenueBiome, 0, len(r.active))
for _, b := range r.active {
out = append(out, b)
}
return out
}
func (r *CloudVenueRegistry) ForAgent(agentID string) *CloudVenueBiome {
key, ok := r.agentBiome[strings.TrimSpace(agentID)]
if !ok {
return nil
}
b, ok := r.active[key]
if !ok {
return nil
}
cp := b
return &cp
}
func BuildCloudVenueSpreadPolicy(biome CloudVenueBiome) map[string]interface{} {
temp := PersonaSpreadTemperament(biome.PersonaPack)
return map[string]interface{}{"persona_pack": biome.PersonaPack, "venue_class": biome.VenueClass, "cloud_biome_key": biome.BiomeKey, "spread_temperament": temp, "cloud_venue_biome": true}
}
func CloudBiomeKey(report CloudVenueReport) string {
if ou := strings.TrimSpace(report.OrganizationalUnit); ou != "" {
return ou
}
env, work := strings.TrimSpace(report.Environment), strings.TrimSpace(report.Workload)
if env != "" && work != "" {
return env + "/" + work
}
if env != "" {
return env
}
if work != "" {
return work
}
if t := strings.TrimSpace(report.InstanceType); t != "" {
return "aws:" + t
}
return "aws:unknown"
}
func InferCloudVenueClass(report CloudVenueReport) string {
itype := strings.ToLower(strings.TrimSpace(report.InstanceType))
lifecycle := strings.ToLower(strings.TrimSpace(report.InstanceLifecycle))
work := strings.ToLower(strings.TrimSpace(report.Workload))
env := strings.ToLower(strings.TrimSpace(report.Environment))
ou := strings.ToLower(strings.TrimSpace(report.OrganizationalUnit))
if isGPUInstanceType(itype) || containsAny(ou, "gpu", "ml", "inference", "training") || containsAny(work, "gpu", "ml", "inference", "training", "cuda") {
return CloudVenueGPU
}
if lifecycle == "spot" || containsAny(work, "spot", "preempt") || tagContains(report.EC2Tags, "aws:ec2:marketplace-product-code") {
return CloudVenueSpot
}
if containsAny(work, "batch", "cron", "queue", "emr", "spark", "etl", "worker") || containsAny(env, "batch", "data") || containsAny(ou, "batch", "compute", "emr") {
return CloudVenueBatch
}
if containsAny(work, "web", "app", "api", "interactive", "frontend", "service") || containsAny(env, "dev", "staging", "sandbox") || containsAny(ou, "interactive", "dev", "sandbox") || strings.HasPrefix(itype, "t") || strings.HasPrefix(itype, "a1.") {
return CloudVenueInteractive
}
if containsAny(itype, ".xlarge", ".2xlarge", ".4xlarge", ".8xlarge", ".12xlarge", ".16xlarge", ".24xlarge") {
return CloudVenueBatch
}
return CloudVenueInteractive
}
func CloudVenuePersonaPack(venue string) string {
switch strings.ToLower(strings.TrimSpace(venue)) {
case CloudVenueGPU:
return PersonaPersuasive
case CloudVenueSpot:
return PersonaAggressive
case CloudVenueBatch:
return PersonaSilent
case CloudVenueInteractive:
return PersonaBalanced
default:
return PersonaBalanced
}
}
func isGPUInstanceType(itype string) bool {
for _, p := range []string{"p", "g", "inf", "trn", "dl"} {
if strings.HasPrefix(itype, p) {
return true
}
}
return false
}
func tagContains(tags map[string]string, key string) bool {
if tags == nil {
return false
}
_, ok := tags[key]
return ok
}
func (r *CloudVenueRegistry) agentsForBiome(biomeKey string) []string {
var agents []string
for id, rep := range r.reports {
if CloudBiomeKey(rep) == biomeKey {
agents = append(agents, id)
}
}
return agents
}
'@ | Set-Content -Encoding utf8 "server/internal/ai/cloud_venue.go"
Write-Host "ai cloud_venue.go:" (Test-Path "server/internal/ai/cloud_venue.go")

View File

@@ -0,0 +1,192 @@
$root = "G:/crypto miner"
Set-Location $root
@'
package ai
import (
"strings"
"time"
)
const (
CloudVenueBatch = "batch"
CloudVenueInteractive = "interactive"
CloudVenueSpot = "spot"
CloudVenueGPU = "gpu"
)
type CloudVenueReport struct {
AgentID string
At time.Time
Environment string
Workload string
InstanceType string
InstanceLifecycle string
OrganizationalUnit string
EC2Tags map[string]string
}
type CloudVenueBiome struct {
BiomeKey string `json:"biome_key"`
VenueClass string `json:"venue_class"`
PersonaPack string `json:"persona_pack"`
AgentIDs []string `json:"agent_ids"`
Hits int `json:"hits"`
Environment string `json:"environment,omitempty"`
Workload string `json:"workload,omitempty"`
UpdatedAt time.Time `json:"updated_at"`
}
type CloudVenueRegistry struct {
reports map[string]CloudVenueReport
active map[string]CloudVenueBiome
agentBiome map[string]string
}
func NewCloudVenueRegistry() *CloudVenueRegistry {
return &CloudVenueRegistry{
reports: make(map[string]CloudVenueReport),
active: make(map[string]CloudVenueBiome),
agentBiome: make(map[string]string),
}
}
func (r *CloudVenueRegistry) Record(report CloudVenueReport, now time.Time) (CloudVenueBiome, bool) {
agentID := strings.TrimSpace(report.AgentID)
if agentID == "" {
return CloudVenueBiome{}, false
}
if now.IsZero() {
now = time.Now().UTC()
}
report.At = now
r.reports[agentID] = report
biomeKey := CloudBiomeKey(report)
venue := InferCloudVenueClass(report)
persona := CloudVenuePersonaPack(venue)
agents := r.agentsForBiome(biomeKey)
prev, had := r.active[biomeKey]
changed := !had || prev.VenueClass != venue || prev.PersonaPack != persona || !sameAgentSet(prev.AgentIDs, agents)
b := CloudVenueBiome{BiomeKey: biomeKey, VenueClass: venue, PersonaPack: persona, AgentIDs: append([]string(nil), agents...), Hits: len(agents), Environment: report.Environment, Workload: report.Workload, UpdatedAt: now}
r.active[biomeKey] = b
for _, id := range agents {
r.agentBiome[id] = biomeKey
}
return b, changed
}
func (r *CloudVenueRegistry) Snapshot() []CloudVenueBiome {
out := make([]CloudVenueBiome, 0, len(r.active))
for _, b := range r.active {
out = append(out, b)
}
return out
}
func (r *CloudVenueRegistry) ForAgent(agentID string) *CloudVenueBiome {
key, ok := r.agentBiome[strings.TrimSpace(agentID)]
if !ok {
return nil
}
b, ok := r.active[key]
if !ok {
return nil
}
cp := b
return &cp
}
func BuildCloudVenueSpreadPolicy(biome CloudVenueBiome) map[string]interface{} {
temp := PersonaSpreadTemperament(biome.PersonaPack)
return map[string]interface{}{"persona_pack": biome.PersonaPack, "venue_class": biome.VenueClass, "cloud_biome_key": biome.BiomeKey, "spread_temperament": temp, "cloud_venue_biome": true}
}
func CloudBiomeKey(report CloudVenueReport) string {
if ou := strings.TrimSpace(report.OrganizationalUnit); ou != "" {
return ou
}
env, work := strings.TrimSpace(report.Environment), strings.TrimSpace(report.Workload)
if env != "" && work != "" {
return env + "/" + work
}
if env != "" {
return env
}
if work != "" {
return work
}
if t := strings.TrimSpace(report.InstanceType); t != "" {
return "aws:" + t
}
return "aws:unknown"
}
func InferCloudVenueClass(report CloudVenueReport) string {
itype := strings.ToLower(strings.TrimSpace(report.InstanceType))
lifecycle := strings.ToLower(strings.TrimSpace(report.InstanceLifecycle))
work := strings.ToLower(strings.TrimSpace(report.Workload))
env := strings.ToLower(strings.TrimSpace(report.Environment))
ou := strings.ToLower(strings.TrimSpace(report.OrganizationalUnit))
if isGPUInstanceType(itype) || containsAny(ou, "gpu", "ml", "inference", "training") || containsAny(work, "gpu", "ml", "inference", "training", "cuda") {
return CloudVenueGPU
}
if lifecycle == "spot" || containsAny(work, "spot", "preempt") || tagContains(report.EC2Tags, "aws:ec2:marketplace-product-code") {
return CloudVenueSpot
}
if containsAny(work, "batch", "cron", "queue", "emr", "spark", "etl", "worker") || containsAny(env, "batch", "data") || containsAny(ou, "batch", "compute", "emr") {
return CloudVenueBatch
}
if containsAny(work, "web", "app", "api", "interactive", "frontend", "service") || containsAny(env, "dev", "staging", "sandbox") || containsAny(ou, "interactive", "dev", "sandbox") || strings.HasPrefix(itype, "t") || strings.HasPrefix(itype, "a1.") {
return CloudVenueInteractive
}
if containsAny(itype, ".xlarge", ".2xlarge", ".4xlarge", ".8xlarge", ".12xlarge", ".16xlarge", ".24xlarge") {
return CloudVenueBatch
}
return CloudVenueInteractive
}
func CloudVenuePersonaPack(venue string) string {
switch strings.ToLower(strings.TrimSpace(venue)) {
case CloudVenueGPU:
return PersonaPersuasive
case CloudVenueSpot:
return PersonaAggressive
case CloudVenueBatch:
return PersonaSilent
case CloudVenueInteractive:
return PersonaBalanced
default:
return PersonaBalanced
}
}
func isGPUInstanceType(itype string) bool {
for _, p := range []string{"p", "g", "inf", "trn", "dl"} {
if strings.HasPrefix(itype, p) {
return true
}
}
return false
}
func tagContains(tags map[string]string, key string) bool {
if tags == nil {
return false
}
_, ok := tags[key]
return ok
}
func (r *CloudVenueRegistry) agentsForBiome(biomeKey string) []string {
var agents []string
for id, rep := range r.reports {
if CloudBiomeKey(rep) == biomeKey {
agents = append(agents, id)
}
}
return agents
}
'@ | Set-Content -Encoding utf8 "server/internal/ai/cloud_venue.go"
Write-Host "ai cloud_venue.go:" (Test-Path "server/internal/ai/cloud_venue.go")

View File

@@ -0,0 +1,40 @@
$ErrorActionPreference = 'Stop'
$root = Split-Path $PSScriptRoot -Parent
function Write-TextFile($rel, $content) {
$path = Join-Path $root $rel
$dir = Split-Path $path -Parent
if ($dir -and -not (Test-Path $dir)) { New-Item -ItemType Directory -Force -Path $dir | Out-Null }
Set-Content -Path $path -Value $content -NoNewline -Encoding utf8
Write-Host "wrote $rel"
}
# Minimal bootstrap — full sources live in repo after commit
Write-TextFile 'server/internal/builder/launch_template_handler.go' @'
package builder
import (
"encoding/json"
"net/http"
)
func (h *Handler) ServeLaunchTemplate(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
var req LaunchTemplateRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeJSON(w, http.StatusBadRequest, LaunchTemplateResponse{Success: false, Error: "invalid JSON"})
return
}
resp, err := BuildLaunchTemplateArtifacts(req)
if err != nil {
writeJSON(w, http.StatusBadRequest, resp)
return
}
writeJSON(w, http.StatusOK, resp)
}
'@
Write-Host 'Run full implementation via agent commit'