2026-03-16 11:10:33 +00:00
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
|
|
|
|
|
package agentic
|
|
|
|
|
|
|
|
|
|
import (
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
"strconv"
|
2026-03-16 11:10:33 +00:00
|
|
|
"syscall"
|
|
|
|
|
"time"
|
|
|
|
|
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
core "dappco.re/go/core"
|
2026-03-16 11:10:33 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// DispatchConfig controls agent dispatch behaviour.
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
//
|
|
|
|
|
// cfg := agentic.DispatchConfig{DefaultAgent: "claude", DefaultTemplate: "coding"}
|
2026-03-16 11:10:33 +00:00
|
|
|
type DispatchConfig struct {
|
|
|
|
|
DefaultAgent string `yaml:"default_agent"`
|
|
|
|
|
DefaultTemplate string `yaml:"default_template"`
|
|
|
|
|
WorkspaceRoot string `yaml:"workspace_root"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RateConfig controls pacing between task dispatches.
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
//
|
|
|
|
|
// rate := agentic.RateConfig{ResetUTC: "06:00", SustainedDelay: 120, BurstWindow: 2, BurstDelay: 15}
|
2026-03-16 11:10:33 +00:00
|
|
|
type RateConfig struct {
|
|
|
|
|
ResetUTC string `yaml:"reset_utc"` // Daily quota reset time (UTC), e.g. "06:00"
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
DailyLimit int `yaml:"daily_limit"` // Max requests per day (0 = unknown)
|
|
|
|
|
MinDelay int `yaml:"min_delay"` // Minimum seconds between task starts
|
|
|
|
|
SustainedDelay int `yaml:"sustained_delay"` // Delay when pacing for full-day use
|
|
|
|
|
BurstWindow int `yaml:"burst_window"` // Hours before reset where burst kicks in
|
|
|
|
|
BurstDelay int `yaml:"burst_delay"` // Delay during burst window
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 13:05:41 +00:00
|
|
|
// ConcurrencyLimit supports both flat (int) and nested (map with total + per-model) formats.
|
|
|
|
|
//
|
|
|
|
|
// claude: 1 → Total=1, Models=nil
|
|
|
|
|
// codex: → Total=2, Models={"gpt-5.4": 1, "gpt-5.3-codex-spark": 1}
|
|
|
|
|
// total: 2
|
|
|
|
|
// gpt-5.4: 1
|
|
|
|
|
// gpt-5.3-codex-spark: 1
|
|
|
|
|
type ConcurrencyLimit struct {
|
|
|
|
|
Total int
|
|
|
|
|
Models map[string]int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UnmarshalYAML handles both int and map forms.
|
|
|
|
|
func (c *ConcurrencyLimit) UnmarshalYAML(value *yaml.Node) error {
|
|
|
|
|
// Try int first
|
|
|
|
|
var n int
|
|
|
|
|
if err := value.Decode(&n); err == nil {
|
|
|
|
|
c.Total = n
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
// Try map
|
|
|
|
|
var m map[string]int
|
|
|
|
|
if err := value.Decode(&m); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
c.Total = m["total"]
|
|
|
|
|
c.Models = make(map[string]int)
|
|
|
|
|
for k, v := range m {
|
|
|
|
|
if k != "total" {
|
|
|
|
|
c.Models[k] = v
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-16 11:10:33 +00:00
|
|
|
// AgentsConfig is the root of config/agents.yaml.
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
//
|
|
|
|
|
// cfg := agentic.AgentsConfig{Version: 1, Dispatch: agentic.DispatchConfig{DefaultAgent: "claude"}}
|
2026-03-16 11:10:33 +00:00
|
|
|
type AgentsConfig struct {
|
2026-03-24 13:05:41 +00:00
|
|
|
Version int `yaml:"version"`
|
|
|
|
|
Dispatch DispatchConfig `yaml:"dispatch"`
|
|
|
|
|
Concurrency map[string]ConcurrencyLimit `yaml:"concurrency"`
|
|
|
|
|
Rates map[string]RateConfig `yaml:"rates"`
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// loadAgentsConfig reads config/agents.yaml from the code path.
|
|
|
|
|
func (s *PrepSubsystem) loadAgentsConfig() *AgentsConfig {
|
|
|
|
|
paths := []string{
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
core.JoinPath(CoreRoot(), "agents.yaml"),
|
|
|
|
|
core.JoinPath(s.codePath, "core", "agent", "config", "agents.yaml"),
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, path := range paths {
|
2026-03-22 03:41:07 +00:00
|
|
|
r := fs.Read(path)
|
|
|
|
|
if !r.OK {
|
2026-03-16 11:10:33 +00:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
var cfg AgentsConfig
|
2026-03-22 03:41:07 +00:00
|
|
|
if err := yaml.Unmarshal([]byte(r.Value.(string)), &cfg); err != nil {
|
2026-03-16 11:10:33 +00:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
return &cfg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &AgentsConfig{
|
|
|
|
|
Dispatch: DispatchConfig{
|
|
|
|
|
DefaultAgent: "claude",
|
|
|
|
|
DefaultTemplate: "coding",
|
|
|
|
|
},
|
2026-03-24 13:05:41 +00:00
|
|
|
Concurrency: map[string]ConcurrencyLimit{
|
|
|
|
|
"claude": {Total: 1},
|
|
|
|
|
"gemini": {Total: 3},
|
2026-03-16 11:10:33 +00:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// delayForAgent calculates how long to wait before spawning the next task
|
|
|
|
|
// for a given agent type, based on rate config and time of day.
|
|
|
|
|
func (s *PrepSubsystem) delayForAgent(agent string) time.Duration {
|
2026-03-26 06:38:02 +00:00
|
|
|
// Read from Core Config (loaded once at registration)
|
|
|
|
|
var rates map[string]RateConfig
|
|
|
|
|
if s.ServiceRuntime != nil {
|
|
|
|
|
rates, _ = s.Core().Config().Get("agents.rates").Value.(map[string]RateConfig)
|
|
|
|
|
}
|
|
|
|
|
if rates == nil {
|
|
|
|
|
cfg := s.loadAgentsConfig()
|
|
|
|
|
rates = cfg.Rates
|
|
|
|
|
}
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
base := baseAgent(agent)
|
2026-03-26 06:38:02 +00:00
|
|
|
rate, ok := rates[base]
|
2026-03-16 11:10:33 +00:00
|
|
|
if !ok || rate.SustainedDelay == 0 {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parse reset time
|
|
|
|
|
resetHour, resetMin := 6, 0
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
parts := core.Split(rate.ResetUTC, ":")
|
|
|
|
|
if len(parts) >= 2 {
|
|
|
|
|
if hour, err := strconv.Atoi(core.Trim(parts[0])); err == nil {
|
|
|
|
|
resetHour = hour
|
|
|
|
|
}
|
|
|
|
|
if min, err := strconv.Atoi(core.Trim(parts[1])); err == nil {
|
|
|
|
|
resetMin = min
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-16 11:10:33 +00:00
|
|
|
|
|
|
|
|
now := time.Now().UTC()
|
|
|
|
|
resetToday := time.Date(now.Year(), now.Month(), now.Day(), resetHour, resetMin, 0, 0, time.UTC)
|
|
|
|
|
if now.Before(resetToday) {
|
|
|
|
|
// Reset hasn't happened yet today — reset was yesterday
|
|
|
|
|
resetToday = resetToday.AddDate(0, 0, -1)
|
|
|
|
|
}
|
|
|
|
|
nextReset := resetToday.AddDate(0, 0, 1)
|
|
|
|
|
hoursUntilReset := nextReset.Sub(now).Hours()
|
|
|
|
|
|
|
|
|
|
// Burst mode: if within burst window of reset, use burst delay
|
|
|
|
|
if rate.BurstWindow > 0 && hoursUntilReset <= float64(rate.BurstWindow) {
|
|
|
|
|
return time.Duration(rate.BurstDelay) * time.Second
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sustained mode
|
|
|
|
|
return time.Duration(rate.SustainedDelay) * time.Second
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// countRunningByAgent counts running workspaces for a specific agent type.
|
2026-03-22 15:34:43 +00:00
|
|
|
// Scans both old (*/status.json) and new (*/*/*/status.json) workspace layouts.
|
2026-03-16 11:10:33 +00:00
|
|
|
func (s *PrepSubsystem) countRunningByAgent(agent string) int {
|
2026-03-17 18:13:44 +00:00
|
|
|
wsRoot := WorkspaceRoot()
|
2026-03-16 11:10:33 +00:00
|
|
|
|
2026-03-22 15:34:43 +00:00
|
|
|
// Scan both old and new workspace layouts
|
|
|
|
|
old := core.PathGlob(core.JoinPath(wsRoot, "*", "status.json"))
|
|
|
|
|
new := core.PathGlob(core.JoinPath(wsRoot, "*", "*", "*", "status.json"))
|
|
|
|
|
paths := append(old, new...)
|
2026-03-16 11:10:33 +00:00
|
|
|
|
|
|
|
|
count := 0
|
2026-03-22 15:34:43 +00:00
|
|
|
for _, statusPath := range paths {
|
2026-03-24 13:02:41 +00:00
|
|
|
st, err := ReadStatus(core.PathDir(statusPath))
|
2026-03-16 11:10:33 +00:00
|
|
|
if err != nil || st.Status != "running" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2026-03-17 19:35:15 +00:00
|
|
|
if baseAgent(st.Agent) != agent {
|
2026-03-16 11:10:33 +00:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 19:35:15 +00:00
|
|
|
if st.PID > 0 && syscall.Kill(st.PID, 0) == nil {
|
|
|
|
|
count++
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return count
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 13:05:41 +00:00
|
|
|
// countRunningByModel counts running workspaces for a specific agent:model string.
|
|
|
|
|
func (s *PrepSubsystem) countRunningByModel(agent string) int {
|
|
|
|
|
wsRoot := WorkspaceRoot()
|
|
|
|
|
old := core.PathGlob(core.JoinPath(wsRoot, "*", "status.json"))
|
|
|
|
|
deep := core.PathGlob(core.JoinPath(wsRoot, "*", "*", "*", "status.json"))
|
|
|
|
|
|
|
|
|
|
count := 0
|
|
|
|
|
for _, statusPath := range append(old, deep...) {
|
|
|
|
|
st, err := ReadStatus(core.PathDir(statusPath))
|
|
|
|
|
if err != nil || st.Status != "running" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if st.Agent != agent {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if st.PID > 0 && syscall.Kill(st.PID, 0) == nil {
|
|
|
|
|
count++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-16 11:10:33 +00:00
|
|
|
// baseAgent strips the model variant (gemini:flash → gemini).
|
|
|
|
|
func baseAgent(agent string) string {
|
2026-03-23 16:08:08 +00:00
|
|
|
// codex:gpt-5.3-codex-spark → codex-spark (separate pool)
|
|
|
|
|
if core.Contains(agent, "codex-spark") {
|
|
|
|
|
return "codex-spark"
|
|
|
|
|
}
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
return core.SplitN(agent, ":", 2)[0]
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 13:05:41 +00:00
|
|
|
// canDispatchAgent checks both pool-level and per-model concurrency limits.
|
|
|
|
|
//
|
|
|
|
|
// codex: {total: 2, models: {gpt-5.4: 1}} → max 2 codex total, max 1 gpt-5.4
|
2026-03-16 11:10:33 +00:00
|
|
|
func (s *PrepSubsystem) canDispatchAgent(agent string) bool {
|
2026-03-24 16:44:19 +00:00
|
|
|
// Read concurrency from shared config (loaded once at startup)
|
|
|
|
|
var concurrency map[string]ConcurrencyLimit
|
feat(v0.8.0): full AX migration — ServiceRuntime, Actions, quality gates, transport
go-process:
- Register factory, Result lifecycle, 5 named Action handlers
- Start/Run/StartWithOptions/RunWithOptions all return core.Result
- core.ID() replaces fmt.Sprintf, core.As replaces errors.As
core/agent:
- PrepSubsystem + monitor.Subsystem + setup.Service embed ServiceRuntime[T]
- 22 named Actions + agent.completion Task pipeline in OnStartup
- ChannelNotifier removed — all IPC via c.ACTION(messages.X{})
- proc.go: all methods via s.Core().Process(), returns core.Result
- status.go: WriteAtomic + JSONMarshalString
- paths.go: Fs.NewUnrestricted() replaces unsafe.Pointer
- transport.go: ONE net/http file — HTTPGet/HTTPPost/HTTPDo/MCP transport
- All disallowed imports eliminated from source files (13 quality gates)
- String concat eliminated — core.Concat() throughout
- 1:1 _test.go + _example_test.go for every source file
- Reference docs synced from core/go v0.8.0
- RFC-025 updated with net/http, net/url, io/fs quality gates
- lib.go: io/fs eliminated via Data.ListNames, Array[T].Deduplicate
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 01:27:46 +00:00
|
|
|
if s.ServiceRuntime != nil {
|
|
|
|
|
concurrency = core.ConfigGet[map[string]ConcurrencyLimit](s.Core().Config(), "agents.concurrency")
|
2026-03-24 16:44:19 +00:00
|
|
|
}
|
|
|
|
|
if concurrency == nil {
|
|
|
|
|
cfg := s.loadAgentsConfig()
|
|
|
|
|
concurrency = cfg.Concurrency
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-16 11:10:33 +00:00
|
|
|
base := baseAgent(agent)
|
2026-03-24 16:44:19 +00:00
|
|
|
limit, ok := concurrency[base]
|
2026-03-24 13:05:41 +00:00
|
|
|
if !ok || limit.Total <= 0 {
|
2026-03-16 11:10:33 +00:00
|
|
|
return true
|
|
|
|
|
}
|
2026-03-24 13:05:41 +00:00
|
|
|
|
|
|
|
|
// Check pool total
|
|
|
|
|
if s.countRunningByAgent(base) >= limit.Total {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check per-model limit if configured
|
|
|
|
|
if limit.Models != nil {
|
|
|
|
|
model := modelVariant(agent)
|
|
|
|
|
if model != "" {
|
|
|
|
|
if modelLimit, has := limit.Models[model]; has && modelLimit > 0 {
|
|
|
|
|
if s.countRunningByModel(agent) >= modelLimit {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// modelVariant extracts the model name from an agent string.
|
|
|
|
|
//
|
|
|
|
|
// codex:gpt-5.4 → gpt-5.4
|
|
|
|
|
// codex:gpt-5.3-codex-spark → gpt-5.3-codex-spark
|
|
|
|
|
// claude → ""
|
|
|
|
|
func modelVariant(agent string) string {
|
|
|
|
|
parts := core.SplitN(agent, ":", 2)
|
|
|
|
|
if len(parts) < 2 {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
return parts[1]
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:53:33 +00:00
|
|
|
// drainQueue fills all available concurrency slots from queued workspaces.
|
2026-03-24 16:44:19 +00:00
|
|
|
// Serialised via c.Lock("drain") when Core is available, falls back to local mutex.
|
2026-03-16 11:10:33 +00:00
|
|
|
func (s *PrepSubsystem) drainQueue() {
|
2026-03-23 16:08:08 +00:00
|
|
|
if s.frozen {
|
|
|
|
|
return
|
|
|
|
|
}
|
feat(v0.8.0): full AX migration — ServiceRuntime, Actions, quality gates, transport
go-process:
- Register factory, Result lifecycle, 5 named Action handlers
- Start/Run/StartWithOptions/RunWithOptions all return core.Result
- core.ID() replaces fmt.Sprintf, core.As replaces errors.As
core/agent:
- PrepSubsystem + monitor.Subsystem + setup.Service embed ServiceRuntime[T]
- 22 named Actions + agent.completion Task pipeline in OnStartup
- ChannelNotifier removed — all IPC via c.ACTION(messages.X{})
- proc.go: all methods via s.Core().Process(), returns core.Result
- status.go: WriteAtomic + JSONMarshalString
- paths.go: Fs.NewUnrestricted() replaces unsafe.Pointer
- transport.go: ONE net/http file — HTTPGet/HTTPPost/HTTPDo/MCP transport
- All disallowed imports eliminated from source files (13 quality gates)
- String concat eliminated — core.Concat() throughout
- 1:1 _test.go + _example_test.go for every source file
- Reference docs synced from core/go v0.8.0
- RFC-025 updated with net/http, net/url, io/fs quality gates
- lib.go: io/fs eliminated via Data.ListNames, Array[T].Deduplicate
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 01:27:46 +00:00
|
|
|
if s.ServiceRuntime != nil {
|
|
|
|
|
s.Core().Lock("drain").Mutex.Lock()
|
|
|
|
|
defer s.Core().Lock("drain").Mutex.Unlock()
|
2026-03-24 16:44:19 +00:00
|
|
|
} else {
|
|
|
|
|
s.drainMu.Lock()
|
|
|
|
|
defer s.drainMu.Unlock()
|
|
|
|
|
}
|
2026-03-21 17:10:43 +00:00
|
|
|
|
2026-03-23 12:53:33 +00:00
|
|
|
for s.drainOne() {
|
|
|
|
|
// keep filling slots
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
2026-03-23 12:53:33 +00:00
|
|
|
}
|
2026-03-16 11:10:33 +00:00
|
|
|
|
2026-03-23 12:53:33 +00:00
|
|
|
// drainOne finds the oldest queued workspace and spawns it if a slot is available.
|
|
|
|
|
// Returns true if a task was spawned, false if nothing to do.
|
|
|
|
|
func (s *PrepSubsystem) drainOne() bool {
|
|
|
|
|
wsRoot := WorkspaceRoot()
|
2026-03-16 11:10:33 +00:00
|
|
|
|
2026-03-23 12:53:33 +00:00
|
|
|
// Scan both old and new workspace layouts
|
|
|
|
|
old := core.PathGlob(core.JoinPath(wsRoot, "*", "status.json"))
|
|
|
|
|
deep := core.PathGlob(core.JoinPath(wsRoot, "*", "*", "*", "status.json"))
|
|
|
|
|
statusFiles := append(old, deep...)
|
|
|
|
|
|
|
|
|
|
for _, statusPath := range statusFiles {
|
|
|
|
|
wsDir := core.PathDir(statusPath)
|
2026-03-24 13:02:41 +00:00
|
|
|
st, err := ReadStatus(wsDir)
|
2026-03-16 11:10:33 +00:00
|
|
|
if err != nil || st.Status != "queued" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !s.canDispatchAgent(st.Agent) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 16:08:08 +00:00
|
|
|
// Skip if agent pool is in rate-limit backoff
|
|
|
|
|
pool := baseAgent(st.Agent)
|
|
|
|
|
if until, ok := s.backoff[pool]; ok && time.Now().Before(until) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-16 11:10:33 +00:00
|
|
|
// Apply rate delay before spawning
|
|
|
|
|
delay := s.delayForAgent(st.Agent)
|
|
|
|
|
if delay > 0 {
|
|
|
|
|
time.Sleep(delay)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Re-check concurrency after delay (another task may have started)
|
|
|
|
|
if !s.canDispatchAgent(st.Agent) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
feat(v0.8.0): full AX migration — ServiceRuntime, Actions, quality gates, transport
go-process:
- Register factory, Result lifecycle, 5 named Action handlers
- Start/Run/StartWithOptions/RunWithOptions all return core.Result
- core.ID() replaces fmt.Sprintf, core.As replaces errors.As
core/agent:
- PrepSubsystem + monitor.Subsystem + setup.Service embed ServiceRuntime[T]
- 22 named Actions + agent.completion Task pipeline in OnStartup
- ChannelNotifier removed — all IPC via c.ACTION(messages.X{})
- proc.go: all methods via s.Core().Process(), returns core.Result
- status.go: WriteAtomic + JSONMarshalString
- paths.go: Fs.NewUnrestricted() replaces unsafe.Pointer
- transport.go: ONE net/http file — HTTPGet/HTTPPost/HTTPDo/MCP transport
- All disallowed imports eliminated from source files (13 quality gates)
- String concat eliminated — core.Concat() throughout
- 1:1 _test.go + _example_test.go for every source file
- Reference docs synced from core/go v0.8.0
- RFC-025 updated with net/http, net/url, io/fs quality gates
- lib.go: io/fs eliminated via Data.ListNames, Array[T].Deduplicate
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 01:27:46 +00:00
|
|
|
prompt := core.Concat("TASK: ", st.Task, "\n\nResume from where you left off. Read CODEX.md for conventions. Commit when done.")
|
2026-03-16 11:10:33 +00:00
|
|
|
|
refactor(agentic): workspace = clone, prompt replaces files
Major simplification of the dispatch model:
- Workspace dir: .core/workspace/{org}/{repo}/{pr|task|branch|tag}/
- Clone into repo/ (not src/), metadata in .meta/
- One of issue, pr, branch, or tag required for dispatch
- All context (brain, consumers, git log, wiki, plan) assembled
into prompt string — no TODO.md, PROMPT.md, CONTEXT.md files
- Resume detection: skip clone if repo/.git exists
- Default agent changed to codex
- spawnAgent drops srcDir param, runs from repo/
- No --skip-git-repo-check (repo/ IS a git repo)
- All downstream files: srcDir → repoDir
Track PRs, not workspace iterations.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 13:41:59 +00:00
|
|
|
pid, _, err := s.spawnAgent(st.Agent, prompt, wsDir)
|
2026-03-16 11:10:33 +00:00
|
|
|
if err != nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
st.Status = "running"
|
2026-03-16 17:52:55 +00:00
|
|
|
st.PID = pid
|
2026-03-16 11:10:33 +00:00
|
|
|
st.Runs++
|
|
|
|
|
writeStatus(wsDir, st)
|
2026-03-26 06:38:02 +00:00
|
|
|
s.TrackWorkspace(core.PathBase(wsDir), st)
|
2026-03-16 11:10:33 +00:00
|
|
|
|
2026-03-23 12:53:33 +00:00
|
|
|
return true
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
2026-03-23 12:53:33 +00:00
|
|
|
|
|
|
|
|
return false
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|