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

161 lines
5.3 KiB
Go

package workspace
import (
"context"
"errors"
"time"
workspaceissues "github.com/tutti-os/tutti/packages/workspace/issues"
)
// IssueRunLauncher is the execution-side port of Issue dispatch. Issue Manager
// owns which task may run and durably claims the Run; the adapter owns creating
// the Agent session after the Issue mutation lock has been released.
type IssueRunLauncher interface {
Launch(context.Context, IssueRunLaunch) error
}
type issueRunLaunchNotStartedError struct {
cause error
}
func (err issueRunLaunchNotStartedError) Error() string {
return err.cause.Error()
}
func (err issueRunLaunchNotStartedError) Unwrap() error {
return err.cause
}
func (issueRunLaunchNotStartedError) issueRunLaunchNotStarted() {}
// NewIssueRunLaunchNotStartedError classifies authoritative adapter evidence
// that no canonical Agent Turn was created. Unclassified launch errors remain
// recoverable because they may be lost responses after canonical creation.
func NewIssueRunLaunchNotStartedError(cause error) error {
if cause == nil {
cause = errors.New("issue Run launch did not start")
}
return issueRunLaunchNotStartedError{cause: cause}
}
func isIssueRunLaunchNotStartedError(err error) bool {
var marker interface{ issueRunLaunchNotStarted() }
return errors.As(err, &marker)
}
// IssueRunLaunchLeaseRenewalScheduler owns periodic renewal while an external
// launch is in flight. The production implementation is ticker-backed; tests
// inject a deterministic scheduler so lease expiry races need no sleeps.
type IssueRunLaunchLeaseRenewalScheduler interface {
Start(context.Context, time.Duration, func() error) func()
}
type IssueRunLaunch struct {
WorkspaceID string
ClientSubmitID string
AgentSessionID string
AgentTargetID string
RunID string
TaskID string
IssueID string
Title string
Prompt string
Attachments []IssueRunImageAttachment
ExecutionDirectory string
ModelPlanID string
Model string
ReasoningIntensity int
ReasoningEffort string
PermissionModeID string
WorktreeBase string
WorktreeBranch string
// HideSession creates the delegate Agent session with visible=false so it
// never enters the conversation rail. The session stays openable by id
// (task click-through opens it as a transient conversation). The zero
// value keeps today's visible-session behavior.
HideSession bool
RailPlacement *IssueRunRailPlacement
}
type IssueRunImageAttachment struct {
MimeType string
Name string
Path string
}
// IssueRunRailPlacement is the source conversation's logical rail identity.
// It stays independent from ExecutionDirectory because a delegate may execute
// inside an isolated worktree while remaining grouped with the source project.
type IssueRunRailPlacement struct {
Kind string
ProjectPath string
SectionKey string
}
// IssueSourceSessionContext is the narrow source-session projection needed by
// Issue dispatch. Agent lifecycle and persistence DTOs stay outside Issue
// Manager.
type IssueSourceSessionContext struct {
WorkingDirectory string
RailPlacement *IssueRunRailPlacement
}
type IssueSourceSessionContextResolver interface {
ResolveSourceSessionContext(workspaceID string, agentSessionID string) (IssueSourceSessionContext, bool)
}
type IssueRunCancelState string
const (
// IssueRunCancelAccepted means Agent Host accepted the cancellation
// request; exact Turn settlement remains authoritative.
IssueRunCancelAccepted IssueRunCancelState = "accepted"
// IssueRunCancelCanceled means the adapter has authoritative evidence that
// the exact initiating Turn settled canceled.
IssueRunCancelCanceled IssueRunCancelState = "canceled"
IssueRunCancelNotFound IssueRunCancelState = "not_found"
IssueRunCancelSettled IssueRunCancelState = "settled"
)
type IssueRunCancelResult struct {
State IssueRunCancelState
Settlement *IssueRunSettlement
}
type IssueRunCancellationRequest struct {
WorkspaceID string
AgentSessionID string
RunID string
ClientSubmitID string
}
// IssueRunSessionCanceller requests cancellation of one Run's delegate
// session and explicitly distinguishes accepted intent from canonical outcome.
type IssueRunSessionCanceller interface {
RequestRunCancellation(ctx context.Context, request IssueRunCancellationRequest) (IssueRunCancelResult, error)
}
// IssueRunSettlement is the typed fact the coordinator consumes. Agent
// projection details are translated at the coordinator adapter boundary.
type IssueRunSettlement struct {
WorkspaceID string
AgentSessionID string
TurnID string
Status workspaceissues.Status
ErrorMessage string
Usage workspaceissues.TokenUsage
RemainingQuotaPercent float64
HasRemainingQuotaPercent bool
}
// IssueRunSettlementReader resolves the Run's initiating submit to its exact
// canonical Turn and returns a terminal fact only after that Turn settled.
type IssueRunSettlementReader interface {
ReadRunSettlement(ctx context.Context, workspaceID string, agentSessionID string, clientSubmitID string) (IssueRunSettlement, bool, error)
}
type IssueRunReconciler interface {
ReconcileRunningRuns(context.Context, string) (IssueRunReconcileResult, error)
}