Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
177 lines
6.0 KiB
Go
177 lines
6.0 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
runtimeprep "github.com/tutti-os/tutti/packages/agent/runtimeprep"
|
|
"github.com/tutti-os/tutti/services/tuttid/biz/agentprovider"
|
|
)
|
|
|
|
func (s *Service) extensionComposerProfileForLaunch(ctx context.Context, providerTargetRef map[string]any) (ExtensionComposerProfile, error) {
|
|
if providerTargetRefKind(providerTargetRef) != "agent_extension" {
|
|
return ExtensionComposerProfile{}, nil
|
|
}
|
|
installationID := strings.TrimSpace(stringFromAny(providerTargetRef["extensionInstallationId"]))
|
|
if s.ExtensionComposerProfiles == nil || installationID == "" {
|
|
return ExtensionComposerProfile{}, nil
|
|
}
|
|
return s.ExtensionComposerProfiles.ResolveExtensionComposerProfile(ctx, installationID)
|
|
}
|
|
|
|
// resolveExtensionSkillRoots returns the workspace-scope skill root paths an
|
|
// agent extension declared in its composer profile. Native tutti skills are
|
|
// materialized into these roots so acp: extension agents load the same
|
|
// tutti-handoff/tutti-cli content as built-in providers. Returns nil for
|
|
// non-extension providers or profiles without skills.
|
|
func (s *Service) resolveExtensionSkillRoots(ctx context.Context, providerTargetRef map[string]any) []string {
|
|
profile, err := s.extensionComposerProfileForLaunch(ctx, providerTargetRef)
|
|
if err != nil || profile.Skills == nil {
|
|
return nil
|
|
}
|
|
roots := make([]string, 0, len(profile.Skills.Roots))
|
|
for _, root := range profile.Skills.Roots {
|
|
if strings.TrimSpace(root.Scope) != "workspace" {
|
|
continue
|
|
}
|
|
if path, ok := safeExtensionSkillRootPath(root.Path); ok {
|
|
roots = append(roots, path)
|
|
}
|
|
}
|
|
return roots
|
|
}
|
|
|
|
func safeExtensionSkillRootPath(path string) (string, bool) {
|
|
cleaned := filepath.Clean(strings.TrimSpace(path))
|
|
if cleaned == "." || filepath.IsAbs(cleaned) || cleaned == ".." || strings.HasPrefix(cleaned, ".."+string(filepath.Separator)) {
|
|
return "", false
|
|
}
|
|
return cleaned, true
|
|
}
|
|
|
|
func (s *Service) resolveExtensionRuntimePrep(ctx context.Context, providerTargetRef map[string]any) *runtimeprep.ExtensionRuntimePrep {
|
|
profile, err := s.extensionComposerProfileForLaunch(ctx, providerTargetRef)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return profile.RuntimePrep
|
|
}
|
|
|
|
func composerProviderCapabilities(provider string, computerUseAvailable, browserUseAvailable bool) []string {
|
|
if !composerProfileKnown(provider) {
|
|
return nil
|
|
}
|
|
capabilities := append([]string(nil), composerProfileFor(provider).Capabilities...)
|
|
if browserUseAvailable && runtimeprep.BrowserUseDefaultEnabled() {
|
|
capabilities = append(capabilities, "browserUse")
|
|
}
|
|
if computerUseAvailable && runtimeprep.ComputerUseDefaultEnabled() {
|
|
capabilities = append(capabilities, "computerUse")
|
|
}
|
|
return capabilities
|
|
}
|
|
|
|
func (s *Service) computerUseAvailable() bool {
|
|
if s == nil || s.ComputerUseAvailable == nil {
|
|
return true
|
|
}
|
|
return s.ComputerUseAvailable()
|
|
}
|
|
|
|
func (s *Service) browserUseAvailable() bool {
|
|
if s == nil || s.BrowserUseAvailable == nil {
|
|
return true
|
|
}
|
|
return s.BrowserUseAvailable()
|
|
}
|
|
|
|
func composerProviderSupportsPlanMode(provider string) bool {
|
|
return composerProviderSupportsCapability(provider, "planMode")
|
|
}
|
|
|
|
func (s *Service) clampComposerBrowserUseForLaunch(ctx context.Context, provider string, providerTargetRef map[string]any, browserUse *bool) bool {
|
|
if composerProviderSupportsBrowserUse(agentprovider.Normalize(provider)) {
|
|
return s.browserUseAvailable() && runtimeprep.BrowserUseDefaultEnabled() && (browserUse == nil || *browserUse)
|
|
}
|
|
profile, err := s.extensionComposerProfileForLaunch(ctx, providerTargetRef)
|
|
if err != nil || !extensionProfileDeclaresCapability(profile, "browserUse") {
|
|
return false
|
|
}
|
|
if !s.browserUseAvailable() || !runtimeprep.BrowserUseDefaultEnabled() {
|
|
return false
|
|
}
|
|
return browserUse == nil || *browserUse
|
|
}
|
|
|
|
func clampComposerBrowserUseForProvider(provider string, browserUse *bool) bool {
|
|
if !composerProviderSupportsBrowserUse(agentprovider.Normalize(provider)) {
|
|
return false
|
|
}
|
|
return browserUse == nil || *browserUse
|
|
}
|
|
|
|
func composerProviderSupportsBrowserUse(provider string) bool {
|
|
return composerProviderSupportsCapability(provider, "browserUse")
|
|
}
|
|
|
|
func (s *Service) clampComposerComputerUseForLaunch(ctx context.Context, provider string, providerTargetRef map[string]any, computerUse *bool) bool {
|
|
if composerProviderSupportsComputerUse(agentprovider.Normalize(provider)) {
|
|
return s.computerUseAvailable() && runtimeprep.ComputerUseDefaultEnabled() && (computerUse == nil || *computerUse)
|
|
}
|
|
profile, err := s.extensionComposerProfileForLaunch(ctx, providerTargetRef)
|
|
if err != nil || !extensionProfileDeclaresCapability(profile, "computerUse") {
|
|
return false
|
|
}
|
|
if !s.computerUseAvailable() || !runtimeprep.ComputerUseDefaultEnabled() {
|
|
return false
|
|
}
|
|
return computerUse == nil || *computerUse
|
|
}
|
|
|
|
// effectiveCapabilitySetting keeps the historical nil-as-default representation
|
|
// when a capability remains available, but persists an explicit false when a
|
|
// requested/default capability was clamped by provider or host readiness.
|
|
func effectiveCapabilitySetting(requested *bool, effective bool) *bool {
|
|
if requested == nil && effective {
|
|
return nil
|
|
}
|
|
value := effective
|
|
return &value
|
|
}
|
|
|
|
func composerProviderSupportsComputerUse(provider string) bool {
|
|
return composerProviderSupportsCapability(provider, "computerUse")
|
|
}
|
|
|
|
func composerProviderSupportsCapability(provider string, capability string) bool {
|
|
if !composerProfileKnown(provider) {
|
|
return false
|
|
}
|
|
if capability == "browserUse" {
|
|
return runtimeprep.BrowserUseDefaultEnabled()
|
|
}
|
|
if capability == "computerUse" {
|
|
return runtimeprep.ComputerUseDefaultEnabled()
|
|
}
|
|
for _, advertised := range composerProfileFor(provider).Capabilities {
|
|
if advertised == capability {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func extensionProfileDeclaresCapability(profile ExtensionComposerProfile, capability string) bool {
|
|
capability = strings.TrimSpace(capability)
|
|
if capability == "" {
|
|
return false
|
|
}
|
|
for _, declared := range profile.Capabilities {
|
|
if strings.TrimSpace(declared) == capability {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|