Migrate all pkg/ files from strings.Contains/HasPrefix/HasSuffix/TrimSpace/ Split/SplitN/Join/ReplaceAll/ToLower/ToUpper/TrimPrefix/TrimSuffix/NewReader/ Builder and fmt.Sprintf/Sprint to their core.* equivalents from dappco.re/go/core. Retained stdlib where no Core equivalent exists: strings.Map, strings.Trim (cutset), strings.TrimRight, strings.Index, strings.ContainsAny, strings.Replace (count), fmt.Sscanf, fmt.Fprintf. Note: core.Join swaps args vs strings.Join (separator first, then parts...). Co-Authored-By: Virgil <virgil@lethean.io>
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
package agentic
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
|
|
core "dappco.re/go/core"
|
|
)
|
|
|
|
// WorkspaceRoot returns the root directory for agent workspaces.
|
|
// Checks CORE_WORKSPACE env var first, falls back to ~/Code/.core/workspace.
|
|
func WorkspaceRoot() string {
|
|
return filepath.Join(CoreRoot(), "workspace")
|
|
}
|
|
|
|
// CoreRoot returns the root directory for core ecosystem files.
|
|
// Checks CORE_WORKSPACE env var first, falls back to ~/Code/.core.
|
|
func CoreRoot() string {
|
|
if root := os.Getenv("CORE_WORKSPACE"); root != "" {
|
|
return root
|
|
}
|
|
home, _ := os.UserHomeDir()
|
|
return filepath.Join(home, "Code", ".core")
|
|
}
|
|
|
|
// PlansRoot returns the root directory for agent plans.
|
|
func PlansRoot() string {
|
|
return filepath.Join(CoreRoot(), "plans")
|
|
}
|
|
|
|
// AgentName returns the name of this agent based on hostname.
|
|
// Checks AGENT_NAME env var first.
|
|
func AgentName() string {
|
|
if name := os.Getenv("AGENT_NAME"); name != "" {
|
|
return name
|
|
}
|
|
hostname, _ := os.Hostname()
|
|
h := core.Lower(hostname)
|
|
if core.Contains(h, "snider") || core.Contains(h, "studio") || core.Contains(h, "mac") {
|
|
return "cladius"
|
|
}
|
|
return "charon"
|
|
}
|
|
|
|
// gitDefaultBranch detects the default branch of a repo (main, master, etc.).
|
|
func gitDefaultBranch(repoDir string) string {
|
|
cmd := exec.Command("git", "symbolic-ref", "refs/remotes/origin/HEAD", "--short")
|
|
cmd.Dir = repoDir
|
|
if out, err := cmd.Output(); err == nil {
|
|
ref := core.Trim(string(out))
|
|
if core.HasPrefix(ref, "origin/") {
|
|
return core.TrimPrefix(ref, "origin/")
|
|
}
|
|
return ref
|
|
}
|
|
for _, branch := range []string{"main", "master"} {
|
|
cmd := exec.Command("git", "rev-parse", "--verify", branch)
|
|
cmd.Dir = repoDir
|
|
if cmd.Run() == nil {
|
|
return branch
|
|
}
|
|
}
|
|
return "main"
|
|
}
|
|
|
|
// GitHubOrg returns the GitHub org for mirror operations.
|
|
func GitHubOrg() string {
|
|
if org := os.Getenv("GITHUB_ORG"); org != "" {
|
|
return org
|
|
}
|
|
return "dAppCore"
|
|
}
|