Files
agent-radar 2ed3415fb7
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
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

757 lines
27 KiB
Go

package agentextension
import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
"unicode"
"unicode/utf8"
"github.com/tutti-os/tutti/packages/agent/daemon/providerregistry"
agentruntime "github.com/tutti-os/tutti/packages/agent/daemon/runtime"
runtimeprep "github.com/tutti-os/tutti/packages/agent/runtimeprep"
)
type ComposerProfile struct {
SchemaVersion string `json:"schemaVersion"`
Model json.RawMessage `json:"model"`
Permission json.RawMessage `json:"permission"`
ConfigOptions *struct {
Model ComposerModelConfigOptionReference `json:"model"`
Permission ComposerConfigOptionReference `json:"permission"`
Reasoning ComposerConfigOptionReference `json:"reasoning"`
} `json:"configOptions,omitempty"`
PermissionModes []ComposerPermissionMode `json:"permissionModes"`
LaunchSettings *struct {
Permission *struct {
Placeholder string `json:"placeholder"`
DefaultSemantic string `json:"defaultSemantic"`
} `json:"permission,omitempty"`
} `json:"launchSettings,omitempty"`
WorkflowModes *struct {
Plan *struct {
EnabledRuntimeID string `json:"enabledRuntimeId"`
DisabledRuntimeID string `json:"disabledRuntimeId"`
UpdateStrategy string `json:"updateStrategy,omitempty"`
} `json:"plan,omitempty"`
} `json:"workflowModes,omitempty"`
SetModel *struct {
ReasoningEffortMeta bool `json:"reasoningEffortMeta"`
} `json:"setModel,omitempty"`
SlashCommands *struct {
CommandCatalogAuthoritative bool `json:"commandCatalogAuthoritative"`
Commands []struct {
Name string `json:"name"`
Effect string `json:"effect,omitempty"`
} `json:"commands"`
} `json:"slashCommands,omitempty"`
Skills *struct {
Invocation string `json:"invocation"`
TriggerPrefix string `json:"triggerPrefix"`
RuntimeCommandProjection string `json:"runtimeCommandProjection,omitempty"`
Roots []struct {
Scope string `json:"scope"`
Path string `json:"path"`
} `json:"roots"`
} `json:"skills,omitempty"`
RuntimePrep *runtimeprep.ExtensionRuntimePrep `json:"runtimePrep,omitempty"`
}
type ComposerPermissionMode struct {
RuntimeID string `json:"runtimeId"`
Semantic string `json:"semantic"`
AutomaticDecision string `json:"automaticDecision,omitempty"`
}
const composerPermissionLaunchPlaceholder = "${permissionMode}"
type ComposerLaunchPermissionSetting struct {
Placeholder string
DefaultSemantic string
Values map[string]string
}
func (profile ComposerProfile) LaunchPermissionSetting() *ComposerLaunchPermissionSetting {
if profile.LaunchSettings == nil || profile.LaunchSettings.Permission == nil {
return nil
}
values := make(map[string]string, len(profile.PermissionModes))
for _, mode := range profile.PermissionModes {
values[strings.TrimSpace(mode.Semantic)] = strings.TrimSpace(mode.RuntimeID)
}
return &ComposerLaunchPermissionSetting{
Placeholder: strings.TrimSpace(profile.LaunchSettings.Permission.Placeholder),
DefaultSemantic: strings.TrimSpace(profile.LaunchSettings.Permission.DefaultSemantic),
Values: values,
}
}
func (profile ComposerProfile) PlanRuntimeIDs() (enabled string, disabled string) {
if profile.WorkflowModes == nil || profile.WorkflowModes.Plan == nil {
return "", ""
}
return strings.TrimSpace(profile.WorkflowModes.Plan.EnabledRuntimeID),
strings.TrimSpace(profile.WorkflowModes.Plan.DisabledRuntimeID)
}
func (profile ComposerProfile) PlanUpdateStrategy() string {
if profile.WorkflowModes == nil || profile.WorkflowModes.Plan == nil {
return ""
}
return strings.TrimSpace(profile.WorkflowModes.Plan.UpdateStrategy)
}
func (profile ComposerProfile) SetModelReasoningEffortMeta() bool {
return profile.SetModel != nil && profile.SetModel.ReasoningEffortMeta
}
func (profile ComposerProfile) AutomaticPermissionDecisions() map[string]string {
decisions := map[string]string{}
for _, mode := range profile.PermissionModes {
decision := strings.TrimSpace(mode.AutomaticDecision)
if decision == "" {
continue
}
for _, id := range []string{mode.RuntimeID, mode.Semantic} {
if normalized := strings.ToLower(strings.TrimSpace(id)); normalized != "" {
decisions[normalized] = decision
}
}
}
return decisions
}
type ComposerConfigOptionReference struct {
ACPOptionID string `json:"acpOptionId"`
}
type ComposerModelConfigOptionReference struct {
ACPOptionID string `json:"acpOptionId"`
DescriptionMetadataFormat string `json:"descriptionMetadataFormat,omitempty"`
}
func (profile ComposerProfile) ACPConfigOptionIDs() (model string, permission string, reasoning string) {
if strings.TrimSpace(profile.SchemaVersion) == "" {
return "", "", ""
}
if profile.ConfigOptions != nil {
return strings.TrimSpace(profile.ConfigOptions.Model.ACPOptionID),
strings.TrimSpace(profile.ConfigOptions.Permission.ACPOptionID),
strings.TrimSpace(profile.ConfigOptions.Reasoning.ACPOptionID)
}
// Compatibility for profiles written before configOptions became the
// canonical shape. Legacy profiles only declared model/mode sources;
// reasoning used the established standard ACP alias.
if len(profile.Model) > 0 && strings.TrimSpace(string(profile.Model)) != "null" {
model = "model"
}
if len(profile.Permission) > 0 && strings.TrimSpace(string(profile.Permission)) != "null" {
permission = "mode"
}
return model, permission, "reasoning_effort"
}
func (profile ComposerProfile) ModelDescriptionMetadataFormat() string {
if profile.ConfigOptions == nil {
return ""
}
return strings.TrimSpace(profile.ConfigOptions.Model.DescriptionMetadataFormat)
}
type CapabilitiesProfile struct {
SchemaVersion string `json:"schemaVersion"`
Declared map[string]bool `json:"declared"`
}
type AuthenticationProfile struct {
SchemaVersion string `json:"schemaVersion"`
Methods []AuthenticationMethodProfile `json:"methods"`
}
type AuthenticationMethodProfile struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Type string `json:"type"`
Command struct {
Strategy string `json:"strategy"`
Args []string `json:"args"`
ReadyText string `json:"readyText,omitempty"`
} `json:"command"`
}
func (m *Manager) LoadComposerProfile(installationID string) (ComposerProfile, error) {
installation, err := m.loadInstallationByID(strings.TrimSpace(installationID))
if err != nil {
return ComposerProfile{}, err
}
if installation.Manifest.Profiles.Composer == "" {
return ComposerProfile{}, nil
}
var profile ComposerProfile
path := filepath.Join(installation.PackageDir, filepath.FromSlash(installation.Manifest.Profiles.Composer))
if err := readJSON(path, &profile); err != nil {
return ComposerProfile{}, err
}
if err := validateComposerProfile(profile); err != nil {
return ComposerProfile{}, err
}
return profile, nil
}
func loadAuthenticationMethods(installation Installation) (map[string]AuthenticationMethodProfile, error) {
if installation.Manifest.Profiles.Authentication == "" {
return nil, nil
}
var profile AuthenticationProfile
path := filepath.Join(installation.PackageDir, filepath.FromSlash(installation.Manifest.Profiles.Authentication))
if err := readJSON(path, &profile); err != nil {
return nil, err
}
if err := validateAuthenticationProfile(profile); err != nil {
return nil, err
}
methods := make(map[string]AuthenticationMethodProfile, len(profile.Methods))
for _, method := range profile.Methods {
method.ID = strings.TrimSpace(method.ID)
method.Type = strings.TrimSpace(method.Type)
method.Command.Strategy = strings.TrimSpace(method.Command.Strategy)
methods[method.ID] = method
}
return methods, nil
}
func (m *Manager) LoadDeclaredCapabilities(installationID string) ([]string, error) {
installation, err := m.loadInstallationByID(strings.TrimSpace(installationID))
if err != nil {
return nil, err
}
return loadDeclaredCapabilities(installation)
}
func loadComposerModes(installation Installation) (map[string]string, string, error) {
if installation.Manifest.Profiles.Composer == "" {
return nil, "", nil
}
var profile ComposerProfile
path := filepath.Join(installation.PackageDir, filepath.FromSlash(installation.Manifest.Profiles.Composer))
if err := readJSON(path, &profile); err != nil {
return nil, "", err
}
if err := validateComposerProfile(profile); err != nil {
return nil, "", err
}
modes := map[string]string{}
planMode := ""
// Runtime IDs are the exact public launch contract. Register every exact
// ID before compatibility aliases so an alias can never redirect an
// advertised ID to a different permission tier.
for _, mode := range profile.PermissionModes {
runtimeID := strings.TrimSpace(mode.RuntimeID)
modes[strings.ToLower(runtimeID)] = runtimeID
}
for _, mode := range profile.PermissionModes {
runtimeID := strings.TrimSpace(mode.RuntimeID)
if runtimeID == "" {
return nil, "", errors.New("composer permission runtimeId is required")
}
semantic := strings.TrimSpace(mode.Semantic)
setComposerModeAlias(modes, semantic, runtimeID)
switch semantic {
case "ask-before-write":
setComposerModeAlias(modes, "read-only", runtimeID)
case "accept-edits":
setComposerModeAlias(modes, "accept-edits", runtimeID)
setComposerModeAlias(modes, "auto", runtimeID)
case "auto":
setComposerModeAlias(modes, "auto", runtimeID)
setComposerModeAlias(modes, "agent", runtimeID)
case "locked-down":
setComposerModeAlias(modes, "locked-down", runtimeID)
setComposerModeAlias(modes, "dont-ask", runtimeID)
case "full-access":
setComposerModeAlias(modes, "full-access", runtimeID)
case "read-only":
setComposerModeAlias(modes, "plan", runtimeID)
planMode = runtimeID
default:
return nil, "", errors.New("composer permission semantic is unsupported")
}
}
return modes, planMode, nil
}
func loadDeclaredCapabilities(installation Installation) ([]string, error) {
if installation.Manifest.Profiles.Capabilities == "" {
return nil, nil
}
var profile CapabilitiesProfile
path := filepath.Join(installation.PackageDir, filepath.FromSlash(installation.Manifest.Profiles.Capabilities))
if err := readJSON(path, &profile); err != nil {
return nil, err
}
if profile.SchemaVersion != "tutti.agent.capabilities.v1" {
return nil, errors.New("unsupported capabilities profile schema")
}
capabilities := make([]string, 0, len(profile.Declared))
for _, capability := range knownExtensionCapabilities() {
if profile.Declared[capability] {
capabilities = append(capabilities, capability)
}
}
return capabilities, nil
}
func knownExtensionCapabilities() []string {
return []string{
providerregistry.CapabilityImageInput,
providerregistry.CapabilityModelImageInputRequired,
providerregistry.CapabilitySkills,
providerregistry.CapabilityCompact,
providerregistry.CapabilityTokenUsage,
providerregistry.CapabilityRateLimits,
providerregistry.CapabilityPlanMode,
providerregistry.CapabilityInterrupt,
providerregistry.CapabilityActiveTurnGuidance,
providerregistry.CapabilityBrowserUse,
providerregistry.CapabilityComputerUse,
providerregistry.CapabilityGoalPause,
providerregistry.CapabilityPlanImplementation,
providerregistry.CapabilityPermissionModeChangeDuringTurn,
providerregistry.CapabilityPermissionModeChangeDeferred,
providerregistry.CapabilityReview,
providerregistry.CapabilityResumeRunningTurn,
}
}
func setComposerModeAlias(modes map[string]string, alias string, runtimeID string) {
alias = strings.ToLower(strings.TrimSpace(alias))
runtimeID = strings.TrimSpace(runtimeID)
if alias == "" || runtimeID == "" {
return
}
if _, exists := modes[alias]; exists {
return
}
modes[alias] = runtimeID
}
func validateComposerProfile(profile ComposerProfile) error {
if profile.SchemaVersion != "tutti.agent.composer.v1" {
return errors.New("unsupported composer profile schema")
}
if err := validateComposerPermissionModes(profile.PermissionModes); err != nil {
return err
}
if profile.SlashCommands != nil {
if len(profile.SlashCommands.Commands) == 0 {
return errors.New("composer slashCommands requires at least one command")
}
seen := map[string]struct{}{}
for _, command := range profile.SlashCommands.Commands {
name := strings.ToLower(strings.TrimSpace(command.Name))
if name == "" {
return errors.New("composer slash command name is required")
}
if !composerSlashCommandName.MatchString(name) {
return errors.New("composer slash command name is unsupported")
}
if _, exists := seen[name]; exists {
return errors.New("composer slash command name must be unique")
}
seen[name] = struct{}{}
if effect := strings.TrimSpace(command.Effect); effect != "" && !composerSlashCommandEffectSupported(effect) {
return errors.New("composer slash command effect is unsupported")
}
}
}
if profile.ConfigOptions != nil {
for _, id := range []string{
profile.ConfigOptions.Model.ACPOptionID,
profile.ConfigOptions.Permission.ACPOptionID,
profile.ConfigOptions.Reasoning.ACPOptionID,
} {
if optionID := strings.TrimSpace(id); optionID != "" && !composerConfigOptionID.MatchString(optionID) {
return errors.New("composer ACP config option id is unsupported")
}
}
if metadataFormat := profile.ModelDescriptionMetadataFormat(); metadataFormat != "" && metadataFormat != agentruntime.StandardACPModelDescriptionMetadataFormatCreditConsumptionMultiplierV1 {
return errors.New("composer model description metadata format is unsupported")
} else if metadataFormat != "" && strings.TrimSpace(profile.ConfigOptions.Model.ACPOptionID) == "" {
return errors.New("composer model description metadata format requires a model ACP config option")
}
}
for _, mode := range profile.PermissionModes {
decision := strings.TrimSpace(mode.AutomaticDecision)
if decision == "" {
continue
}
semantic := strings.TrimSpace(mode.Semantic)
if decision == "approved" && semantic == "full-access" {
continue
}
if decision == "denied" && (semantic == "read-only" || semantic == "locked-down") {
continue
}
return errors.New("composer automatic permission decision is unsafe")
}
if err := validateComposerLaunchSettings(profile); err != nil {
return err
}
if err := validateComposerWorkflowModes(profile); err != nil {
return err
}
if profile.RuntimePrep != nil {
if err := runtimeprep.ValidateExtensionRuntimePrep(*profile.RuntimePrep); err != nil {
return err
}
}
if profile.Skills == nil {
return nil
}
if profile.Skills.Invocation != "textTrigger" && profile.Skills.Invocation != "promptItem" {
return errors.New("composer skill invocation is unsupported")
}
if !isSupportedComposerSkillTriggerPrefix(profile.Skills.TriggerPrefix) {
return errors.New("composer skill triggerPrefix is unsupported")
}
if projection := strings.TrimSpace(profile.Skills.RuntimeCommandProjection); projection != "" {
if projection != "unlisted-as-skills" {
return errors.New("composer skill runtimeCommandProjection is unsupported")
}
if profile.SlashCommands == nil || !profile.SlashCommands.CommandCatalogAuthoritative {
return errors.New("composer skill runtimeCommandProjection requires an authoritative slash command catalog")
}
}
if len(profile.Skills.Roots) == 0 {
return errors.New("composer skills require at least one root")
}
for _, root := range profile.Skills.Roots {
if root.Scope != "workspace" && root.Scope != "user" {
return errors.New("composer skill root scope is unsupported")
}
cleaned := filepath.Clean(strings.TrimSpace(root.Path))
if cleaned == "." || filepath.IsAbs(cleaned) || cleaned == ".." || strings.HasPrefix(cleaned, ".."+string(filepath.Separator)) {
return errors.New("composer skill root path must be a safe relative path")
}
}
return nil
}
func isSupportedComposerSkillTriggerPrefix(prefix string) bool {
if prefix == "" || prefix != strings.TrimSpace(prefix) || utf8.RuneCountInString(prefix) > 8 {
return false
}
if !strings.HasPrefix(prefix, "/") && !strings.HasPrefix(prefix, "$") {
return false
}
return !strings.ContainsFunc(prefix, unicode.IsSpace)
}
func validateComposerPermissionModes(modes []ComposerPermissionMode) error {
seenRuntimeIDs := make(map[string]string, len(modes))
for _, mode := range modes {
runtimeID := strings.TrimSpace(mode.RuntimeID)
if runtimeID == "" {
return errors.New("composer permission runtimeId is required")
}
normalizedRuntimeID := strings.ToLower(runtimeID)
if existing, duplicate := seenRuntimeIDs[normalizedRuntimeID]; duplicate {
return fmt.Errorf(
"composer permission runtimeId %q conflicts with %q; runtime IDs must be unique ignoring case",
runtimeID,
existing,
)
}
seenRuntimeIDs[normalizedRuntimeID] = runtimeID
semantic := strings.TrimSpace(mode.Semantic)
switch semantic {
case "ask-before-write", "accept-edits", "auto", "locked-down", "full-access", "read-only":
default:
return fmt.Errorf(
"composer permission runtimeId %q has unsupported semantic %q",
runtimeID,
semantic,
)
}
}
return nil
}
func validateComposerLaunchSettings(profile ComposerProfile) error {
setting := profile.LaunchPermissionSetting()
if setting == nil {
return nil
}
if setting.Placeholder != composerPermissionLaunchPlaceholder {
return errors.New("composer launch permission placeholder is unsupported")
}
if setting.DefaultSemantic == "" {
setting.DefaultSemantic = "ask-before-write"
}
if setting.DefaultSemantic != "ask-before-write" {
return errors.New("composer launch permission default semantic is unsupported")
}
wanted := map[string]struct{}{
"ask-before-write": {},
"auto": {},
"full-access": {},
}
seenSemantic := map[string]struct{}{}
seenRuntime := map[string]struct{}{}
for _, mode := range profile.PermissionModes {
semantic := strings.TrimSpace(mode.Semantic)
runtimeID := strings.TrimSpace(mode.RuntimeID)
if _, ok := wanted[semantic]; !ok {
return errors.New("composer launch permission semantic is unsupported")
}
if _, exists := seenSemantic[semantic]; exists {
return errors.New("composer launch permission semantic must be unique")
}
if !composerLaunchSettingValue.MatchString(runtimeID) {
return errors.New("composer launch permission runtime value is unsupported")
}
if _, exists := seenRuntime[runtimeID]; exists {
return errors.New("composer launch permission runtime value must be unique")
}
seenSemantic[semantic] = struct{}{}
seenRuntime[runtimeID] = struct{}{}
delete(wanted, semantic)
}
if len(wanted) != 0 {
return errors.New("composer launch permission requires ask-before-write, auto, and full-access mappings")
}
return nil
}
func validateComposerWorkflowModes(profile ComposerProfile) error {
enabled, disabled := profile.PlanRuntimeIDs()
if enabled == "" && disabled == "" {
if profile.PlanUpdateStrategy() != "" {
return errors.New("composer plan workflow update strategy requires runtime ids")
}
return nil
}
if !composerLaunchSettingValue.MatchString(enabled) || !composerLaunchSettingValue.MatchString(disabled) || enabled == disabled {
return errors.New("composer plan workflow runtime ids are invalid")
}
strategy := profile.PlanUpdateStrategy()
if strategy != "" && strategy != "session-mode" && strategy != "restart-with-launch-permission" {
return errors.New("composer plan workflow update strategy is invalid")
}
if strategy == "restart-with-launch-permission" && profile.LaunchPermissionSetting() == nil {
return errors.New("composer plan workflow launch restart requires launch permission settings")
}
if strategy == "restart-with-launch-permission" {
for _, permissionMode := range profile.PermissionModes {
if enabled == strings.TrimSpace(permissionMode.RuntimeID) {
return errors.New("composer launch-restart Plan mode must use a distinct runtime value")
}
}
}
return nil
}
var composerSlashCommandName = regexp.MustCompile(`^[a-z0-9][a-z0-9._:-]{0,63}$`)
var composerConfigOptionID = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$`)
var composerLaunchSettingValue = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$`)
var authenticationMethodID = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$`)
func validateAuthenticationProfile(profile AuthenticationProfile) error {
if profile.SchemaVersion != "tutti.agent.authentication.v1" {
return errors.New("unsupported authentication profile schema")
}
if len(profile.Methods) == 0 || len(profile.Methods) > 16 {
return errors.New("authentication profile must declare 1..16 methods")
}
seen := map[string]struct{}{}
for _, method := range profile.Methods {
id := strings.TrimSpace(method.ID)
if !authenticationMethodID.MatchString(id) {
return errors.New("authentication method id is invalid")
}
if _, exists := seen[id]; exists {
return errors.New("authentication method id must be unique")
}
seen[id] = struct{}{}
if method.Name != "" && !validAuthenticationPresentation(method.Name, 128) {
return errors.New("authentication method name is invalid")
}
if method.Description != "" && !validAuthenticationPresentation(method.Description, 512) {
return errors.New("authentication method description is invalid")
}
if strings.TrimSpace(method.Type) != "terminal" {
return errors.New("authentication method type is unsupported")
}
strategy := strings.TrimSpace(method.Command.Strategy)
switch strategy {
case "runtime-subcommand":
if len(method.Command.Args) == 0 || len(method.Command.Args) > 16 {
return errors.New("authentication terminal command must declare 1..16 args")
}
for _, argument := range method.Command.Args {
if !validAuthenticationCommandArgument(argument) {
return errors.New("authentication terminal command arg is invalid")
}
}
if method.Command.ReadyText != "" {
return errors.New("authentication runtime subcommand must not declare ready text")
}
case "runtime-slash-command":
if len(method.Command.Args) != 1 || !composerSlashCommandName.MatchString(method.Command.Args[0]) {
return errors.New("authentication runtime slash command must declare one safe command name")
}
if !validAuthenticationPresentation(method.Command.ReadyText, 256) {
return errors.New("authentication runtime slash command ready text is invalid")
}
default:
return errors.New("authentication terminal command strategy is unsupported")
}
}
return nil
}
func validAuthenticationPresentation(value string, maxRunes int) bool {
if value == "" || value != strings.TrimSpace(value) || utf8.RuneCountInString(value) > maxRunes {
return false
}
return !strings.ContainsFunc(value, unicode.IsControl)
}
func validAuthenticationCommandArgument(argument string) bool {
if argument == "" || utf8.RuneCountInString(argument) > 256 {
return false
}
for _, character := range argument {
if unicode.IsControl(character) {
return false
}
}
return true
}
func validateInstalledProfiles(root string, manifest Manifest) error {
for file, schema := range map[string]string{
manifest.Profiles.Discovery: "tutti.agent.discovery.v1",
manifest.Profiles.Tools: "tutti.agent.tools.v1",
manifest.Profiles.Capabilities: "tutti.agent.capabilities.v1",
manifest.Profiles.Composer: "tutti.agent.composer.v1",
manifest.Profiles.Authentication: "tutti.agent.authentication.v1",
manifest.Profiles.AccountUsage: "tutti.agent.account-usage-probe.v1",
manifest.Profiles.Events: "tutti.agent.events.v1",
} {
if file == "" {
continue
}
var header struct {
SchemaVersion string `json:"schemaVersion"`
}
raw, readErr := os.ReadFile(filepath.Join(root, filepath.FromSlash(file)))
if readErr != nil || json.Unmarshal(raw, &header) != nil || header.SchemaVersion != schema {
return fmt.Errorf("installed extension profile %s must use %s", file, schema)
}
}
var discovery DiscoveryProfile
if err := readJSON(filepath.Join(root, filepath.FromSlash(manifest.Profiles.Discovery)), &discovery); err != nil {
return err
}
if err := validateDiscoveryProfile(discovery); err != nil {
return err
}
var composer ComposerProfile
if manifest.Profiles.Composer != "" {
if err := readJSON(filepath.Join(root, filepath.FromSlash(manifest.Profiles.Composer)), &composer); err != nil {
return err
}
if err := validateComposerProfile(composer); err != nil {
return err
}
}
if err := validateDiscoveryLaunchPlaceholders(discovery, composer); err != nil {
return err
}
if err := validateManifestLaunchPlaceholders(manifest, composer); err != nil {
return err
}
installation := Installation{PackageDir: root, Manifest: manifest}
if _, _, err := loadComposerModes(installation); err != nil {
return err
}
if _, err := loadDeclaredCapabilities(installation); err != nil {
return err
}
if _, err := loadToolAliases(installation); err != nil {
return err
}
if _, err := loadAuthenticationMethods(installation); err != nil {
return err
}
accountUsage, err := loadAccountUsageProfile(installation)
if err != nil {
return err
}
if accountUsage != nil && accountUsage.Runtime.Install == nil &&
manifest.Runtime.Install.Runner != "npm" && manifest.Runtime.Install.Runner != "pnpm" {
return errors.New("account usage companion requires an npm-compatible managed runtime unless the profile declares an independent installer")
}
return nil
}
func composerSlashCommandEffectSupported(effect string) bool {
switch providerregistry.SlashCommandEffect(strings.TrimSpace(effect)) {
case "",
providerregistry.SlashCommandEffectSubmitImmediate,
providerregistry.SlashCommandEffectShowReviewPicker,
providerregistry.SlashCommandEffectActivateGoalMode,
providerregistry.SlashCommandEffectTogglePlanMode,
providerregistry.SlashCommandEffectShowStatus,
providerregistry.SlashCommandEffectToggleSpeed:
return true
default:
return false
}
}
func loadToolAliases(installation Installation) (map[string]string, error) {
if installation.Manifest.Profiles.Tools == "" {
return nil, nil
}
var profile struct {
SchemaVersion string `json:"schemaVersion"`
Tools []struct {
Match struct {
IDs []string `json:"ids"`
} `json:"match"`
CanonicalID string `json:"canonicalId"`
Category string `json:"category"`
Presentation json.RawMessage `json:"presentation"`
FileEffect json.RawMessage `json:"fileEffect"`
Command json.RawMessage `json:"command"`
} `json:"tools"`
}
path := filepath.Join(installation.PackageDir, filepath.FromSlash(installation.Manifest.Profiles.Tools))
if err := readJSON(path, &profile); err != nil {
return nil, err
}
if profile.SchemaVersion != "tutti.agent.tools.v1" {
return nil, errors.New("unsupported tool profile schema")
}
aliases := map[string]string{}
for _, tool := range profile.Tools {
canonical := strings.TrimSpace(tool.CanonicalID)
if canonical == "" {
return nil, errors.New("tool profile canonicalId is required")
}
for _, id := range tool.Match.IDs {
normalized := strings.ToLower(strings.TrimSpace(id))
if normalized == "" {
return nil, errors.New("tool profile id is required")
}
aliases[normalized] = canonical
}
}
return aliases, nil
}