Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
kardolus
GitHub Repository: kardolus/chatgpt-cli
Path: blob/main/agent/types/types.go
3434 views
1
package types
2
3
import (
4
"strings"
5
"time"
6
)
7
8
type ToolKind string
9
10
const (
11
ToolShell ToolKind = "shell"
12
ToolLLM ToolKind = "llm"
13
ToolFiles ToolKind = "file"
14
)
15
16
type OutcomeKind string
17
18
const (
19
OutcomeOK OutcomeKind = "ok"
20
OutcomeDryRun OutcomeKind = "dry-run"
21
OutcomeError OutcomeKind = "error"
22
)
23
24
type Config struct {
25
MaxSteps int
26
DryRun bool
27
WorkDir string
28
}
29
30
type Plan struct {
31
Goal string
32
Steps []Step
33
}
34
35
type Step struct {
36
Type ToolKind
37
38
Description string
39
40
// Shell
41
Command string
42
Args []string
43
44
// LLM
45
Prompt string
46
47
// Files
48
Path string
49
Op string
50
51
// For write/patch: Data is the full content or unified diff
52
Data string
53
54
// For replace:
55
Old string
56
New string
57
N int
58
}
59
60
type ExecContext struct {
61
Goal string
62
Plan Plan
63
Results []StepResult
64
}
65
66
type StepResult struct {
67
Step Step
68
Outcome OutcomeKind
69
Transcript string
70
Duration time.Duration
71
Exec *Result
72
Output string
73
Effects Effects
74
}
75
76
type Result struct {
77
Stdout string
78
Stderr string
79
ExitCode int
80
Duration time.Duration
81
}
82
83
type StepEffect struct {
84
Kind string // "file.write" | "file.patch" | "file.replace" | "shell.exec" | ...
85
Path string // for file ops
86
Bytes int // for writes (optional)
87
Meta map[string]any // extra stats, like hunks, replaced count, exit code, etc.
88
}
89
90
type Effects []StepEffect
91
92
func (e Effects) HasKind(kind string) bool {
93
for _, eff := range e {
94
if eff.Kind == kind {
95
return true
96
}
97
}
98
return false
99
}
100
101
func (e Effects) HasPrefix(prefix string) bool {
102
for _, eff := range e {
103
if strings.HasPrefix(eff.Kind, prefix) {
104
return true
105
}
106
}
107
return false
108
}
109
110