| 1 |
package clnkr |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
|
| 6 |
"github.com/clnkr-ai/clnkr/internal/core/transcript" |
| 7 |
) |
| 8 |
|
| 9 |
// Message is one message in the conversation. |
| 10 |
type Message = transcript.Message |
| 11 |
|
| 12 |
// BashToolCall records a provider-native bash tool call in provider-neutral form. |
| 13 |
type BashToolCall = transcript.BashToolCall |
| 14 |
|
| 15 |
// BashToolResult records the provider-native result for a bash tool call. |
| 16 |
type BashToolResult = transcript.BashToolResult |
| 17 |
|
| 18 |
// ProviderReplayItem carries opaque provider/API-scoped data needed for replay. |
| 19 |
type ProviderReplayItem = transcript.ProviderReplayItem |
| 20 |
|
| 21 |
// Usage tracks token consumption for a single LLM call. |
| 22 |
type Usage struct { |
| 23 |
InputTokens int |
| 24 |
OutputTokens int |
| 25 |
} |
| 26 |
|
| 27 |
// Response captures one model reply. |
| 28 |
// On success Turn is non-nil and ProtocolErr is nil. |
| 29 |
// On protocol failure Raw preserves the provider's original assistant text. |
| 30 |
type Response struct { |
| 31 |
Turn Turn |
| 32 |
Raw string |
| 33 |
Usage Usage |
| 34 |
ProtocolErr error |
| 35 |
BashToolCalls []BashToolCall |
| 36 |
ProviderReplay []ProviderReplayItem |
| 37 |
} |
| 38 |
|
| 39 |
// ActDecisionKind is the policy decision for an act turn. |
| 40 |
type ActDecisionKind string |
| 41 |
|
| 42 |
const ( |
| 43 |
// ActDecisionApprove allows the act turn to execute. |
| 44 |
ActDecisionApprove ActDecisionKind = "approve" |
| 45 |
// ActDecisionReject records guidance instead of executing the act turn. |
| 46 |
ActDecisionReject ActDecisionKind = "reject" |
| 47 |
) |
| 48 |
|
| 49 |
// ActProposal describes an act turn being considered by a run policy. |
| 50 |
type ActProposal struct { |
| 51 |
Turn *ActTurn |
| 52 |
Skipped []BashAction |
| 53 |
Commands []BashAction |
| 54 |
Prompt string |
| 55 |
} |
| 56 |
|
| 57 |
// ActDecision is a policy response for an act proposal. |
| 58 |
type ActDecision struct { |
| 59 |
Kind ActDecisionKind |
| 60 |
Guidance string |
| 61 |
} |
| 62 |
|
| 63 |
// RunPolicy supplies decisions for act and clarify turns during RunWithPolicy. |
| 64 |
type RunPolicy interface { |
| 65 |
DecideAct(context.Context, ActProposal) (ActDecision, error) |
| 66 |
Clarify(context.Context, string) (string, error) |
| 67 |
} |
| 68 |
|
| 69 |
// FullSendPolicy approves every act turn and does not answer clarifications. |
| 70 |
type FullSendPolicy struct{} |
| 71 |
|
| 72 |
// DecideAct approves every act turn. |
| 73 |
func (FullSendPolicy) DecideAct(context.Context, ActProposal) (ActDecision, error) { |
| 74 |
return ActDecision{Kind: ActDecisionApprove}, nil |
| 75 |
} |
| 76 |
|
| 77 |
// Clarify returns ErrClarificationNeeded. |
| 78 |
func (FullSendPolicy) Clarify(context.Context, string) (string, error) { |
| 79 |
return "", ErrClarificationNeeded |
| 80 |
} |
| 81 |
|
| 82 |
// CommandFeedback captures git-backed host feedback for the last command. |
| 83 |
type CommandFeedback = transcript.CommandFeedback |
| 84 |
|
| 85 |
// CommandOutcomeType describes how a command finished or why it did not run. |
| 86 |
type CommandOutcomeType = transcript.CommandOutcomeType |
| 87 |
|
| 88 |
const ( |
| 89 |
CommandOutcomeExit = transcript.CommandOutcomeExit |
| 90 |
CommandOutcomeTimeout = transcript.CommandOutcomeTimeout |
| 91 |
CommandOutcomeCancelled = transcript.CommandOutcomeCancelled |
| 92 |
CommandOutcomeDenied = transcript.CommandOutcomeDenied |
| 93 |
CommandOutcomeSkipped = transcript.CommandOutcomeSkipped |
| 94 |
CommandOutcomeError = transcript.CommandOutcomeError |
| 95 |
) |
| 96 |
|
| 97 |
// CommandOutcome captures a command's completion state. |
| 98 |
type CommandOutcome = transcript.CommandOutcome |
| 99 |
|
| 100 |
// CommandResult captures one shell command execution. |
| 101 |
// Zero PostCwd = no change; nil PostEnv = no snapshot. |
| 102 |
type CommandResult struct { |
| 103 |
Command string |
| 104 |
Stdout string |
| 105 |
Stderr string |
| 106 |
ExitCode int |
| 107 |
PostCwd string |
| 108 |
PostEnv map[string]string |
| 109 |
Outcome CommandOutcome |
| 110 |
Feedback CommandFeedback |
| 111 |
} |
| 112 |
|
| 113 |
// Model sends messages to an LLM and returns a response. |
| 114 |
type Model interface { |
| 115 |
Query(ctx context.Context, messages []Message) (Response, error) |
| 116 |
} |
| 117 |
|
| 118 |
// FinalSummaryModel is implemented by models that can make a final done-only |
| 119 |
// query without exposing command tools. |
| 120 |
type FinalSummaryModel interface { |
| 121 |
QueryFinal(ctx context.Context, messages []Message) (Response, error) |
| 122 |
} |
| 123 |
|
| 124 |
// Executor runs a shell command and returns its structured result. |
| 125 |
type Executor interface { |
| 126 |
Execute(ctx context.Context, command string, dir string) (CommandResult, error) |
| 127 |
} |