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
72 lines
2.8 KiB
Go
72 lines
2.8 KiB
Go
package agenthost
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
storesqlite "github.com/tutti-os/tutti/packages/agent/store-sqlite"
|
|
)
|
|
|
|
const providerGoalAdoptionSource = "provider_goal_adoption"
|
|
|
|
// AdoptProviderGoal promotes a provider-authored active Goal into the durable
|
|
// Host Goal lane without dispatching a second provider mutation.
|
|
func (h *Host) AdoptProviderGoal(ctx context.Context, input ProviderGoalAdoptionInput) (ProviderGoalAdoptionResult, error) {
|
|
if h == nil || h.store == nil || h.goals == nil {
|
|
return ProviderGoalAdoptionResult{}, ErrInvalidArgument
|
|
}
|
|
workspaceID := strings.TrimSpace(input.WorkspaceID)
|
|
agentSessionID := strings.TrimSpace(input.AgentSessionID)
|
|
providerSessionID := strings.TrimSpace(input.ProviderSessionID)
|
|
fingerprint := strings.TrimSpace(input.Fingerprint)
|
|
goal := clonePayload(input.Goal)
|
|
if workspaceID == "" || agentSessionID == "" || providerSessionID == "" || fingerprint == "" ||
|
|
input.ExpectedRevision < 0 ||
|
|
strings.TrimSpace(metadataString(goal, "objective")) == "" ||
|
|
strings.TrimSpace(metadataString(goal, "status")) != "active" {
|
|
return ProviderGoalAdoptionResult{}, ErrInvalidArgument
|
|
}
|
|
|
|
var result ProviderGoalAdoptionResult
|
|
err := h.withSessionMutationActor(ctx, workspaceID, agentSessionID, func(actorCtx context.Context) error {
|
|
canonical, found, err := h.store.GetSession(actorCtx, workspaceID, agentSessionID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !found {
|
|
return ErrSessionNotFound
|
|
}
|
|
if current := strings.TrimSpace(canonical.ProviderSessionID); current != "" && current != providerSessionID {
|
|
return ErrInvalidArgument
|
|
}
|
|
clientSubmitID := strings.Join([]string{providerGoalAdoptionSource, providerSessionID, fingerprint}, ":")
|
|
operationID := goalControlOperationID(workspaceID, agentSessionID, clientSubmitID)
|
|
var operation storesqlite.GoalControlOperation
|
|
var state storesqlite.SessionGoalState
|
|
if err := h.withGoalActor(actorCtx, workspaceID, agentSessionID, func(goalCtx context.Context) error {
|
|
var adoptErr error
|
|
operation, state, _, adoptErr = h.goals.AdoptProviderGoalOperation(goalCtx, storesqlite.ProviderGoalAdoption{
|
|
OperationID: operationID, WorkspaceID: workspaceID, AgentSessionID: agentSessionID,
|
|
ClientSubmitID: clientSubmitID, ExpectedRevision: input.ExpectedRevision, Goal: goal,
|
|
Evidence: map[string]any{
|
|
"source": providerGoalAdoptionSource,
|
|
"confidence": "authoritative",
|
|
"providerSessionId": providerSessionID,
|
|
"fingerprint": fingerprint,
|
|
},
|
|
OccurredAtUnixMS: h.goalOperationNow().UnixMilli(),
|
|
})
|
|
return adoptErr
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
result = ProviderGoalAdoptionResult{
|
|
Canonical: canonical, Goal: durableGoalForResponse(state),
|
|
OperationID: operation.OperationID, Revision: operation.GoalRevision,
|
|
RepairEpoch: operation.RepairEpoch,
|
|
}
|
|
return nil
|
|
})
|
|
return result, err
|
|
}
|