1
package main
1
package main
2
2
3
import "fmt"
3
import "fmt"
4
import "os"
4
import "os"
5
5
6
// commands maps each top-level subcommand to its handler.
7
// printUsage's sections need to stay in sync with this list.
8
var commands = map[string]func([]string) error{
9
"pr": runPR,
10
"repo": runRepo,
11
"auth": runAuth,
12
"embed": runEmbed,
13
"one": runOne,
14
"group": runGroup,
15
"authz": runAuthz,
16
"chat": runChat,
17
}
18
6
func main() {
19
func main() {
7
args := os.Args[1:]
20
args := os.Args[1:]
8
if len(args) == 0 {
21
if len(args) == 0 {
9
printUsage()
22
printUsage()
10
os.Exit(1)
23
os.Exit(1)
11
}
24
}
12
13
var err error
14
switch args[0] {
25
switch args[0] {
15
case "pr":
16
err = runPR(args[1:])
17
case "repo":
18
err = runRepo(args[1:])
19
case "auth":
20
err = runAuth(args[1:])
21
case "embed":
22
err = runEmbed(args[1:])
23
case "one":
24
err = runOne(args[1:])
25
case "group":
26
err = runGroup(args[1:])
27
case "authz":
28
err = runAuthz(args[1:])
29
case "chat":
30
err = runChat(args[1:])
31
case "help", "--help", "-h":
26
case "help", "--help", "-h":
32
printUsage()
27
printUsage()
33
return
28
return
34
29
35
fno commandsargs[0]
30
fno commandsargs[0]
31
if !ok {
32
fmt.Fprintf(
33
os.Stderr, "unknown command: %s\n", args[0])
36
printUsage()
34
printUsage()
37
os.Exit(1)
35
os.Exit(1)
38
}
36
}
39
37
40
if err != nil {
41
fmt.Fprintf(os.Stderr, "error: %v\n", err)
38
fmt.Fprintf(os.Stderr, "error: %v\n", err)
42
os.Exit(1)
39
os.Exit(1)
43
}
40
}
44
}
41
}
45
42
46
func printUsage() {
43
func printUsage() {
47
fmt.Fprintf(os.Stderr, `NAME
44
fmt.Fprintf(os.Stderr, `NAME
48
okg — Oscar Kilo Goodness
45
okg — Oscar Kilo Goodness
49
46
50
SETUP
47
SETUP
51
okg auth login
48
okg auth login
52
--key KEY API key (also accepted via stdin)
49
--key KEY API key (also accepted via stdin)
53
--host HOST klee host (default: production)
50
--host HOST klee host (default: production)
54
51
55
GIT REPOS
52
GIT REPOS
56
okg repo list
53
okg repo list
57
--json output raw JSON
54
--json output raw JSON
58
55
59
okg repo create NAME
56
okg repo create NAME
60
--reader USER grant read to USER (default: anyone)
57
--reader USER grant read to USER (default: anyone)
61
58
62
GROUPS
59
GROUPS
63
okg group list
60
okg group list
64
--json output raw JSON
61
--json output raw JSON
65
62
66
okg group create NAME
63
okg group create NAME
67
--full-name TEXT display name (default: NAME)
64
--full-name TEXT display name (default: NAME)
68
--owner USER owner username (default: caller)
65
--owner USER owner username (default: caller)
69
66
70
okg group add-member GROUP USER [USER ...]
67
okg group add-member GROUP USER [USER ...]
71
68
72
okg group remove-member GROUP USER [USER ...]
69
okg group remove-member GROUP USER [USER ...]
73
70
74
okg group members GROUP
71
okg group members GROUP
75
--json full DAG (Up/Down/Usernames) as raw JSON
72
--json full DAG (Up/Down/Usernames) as raw JSON
76
73
77
okg group delete NAME
74
okg group delete NAME
78
75
79
AUTHZ
76
AUTHZ
80
okg authz list
77
okg authz list
81
--json output raw JSON
78
--json output raw JSON
82
79
83
okg authz set URI OWNER READER
80
okg authz set URI OWNER READER
84
81
85
okg authz delete URI
82
okg authz delete URI
86
83
87
CHAT
84
CHAT
88
okg chat send TO TEXT
85
okg chat send TO TEXT
89
86
90
okg chat fetch
87
okg chat fetch
91
--to GROUP filter by destination group
88
--to GROUP filter by destination group
92
--json output raw JSON
89
--json output raw JSON
93
90
94
PULL REQUESTS
91
PULL REQUESTS
95
okg pr list
92
okg pr list
96
--state STATE open or closed (default: open)
93
--state STATE open or closed (default: open)
97
--json output raw JSON
94
--json output raw JSON
98
95
99
okg pr create
96
okg pr create
100
--head BRANCH source branch
97
--head BRANCH source branch
101
--base BRANCH target branch (default: master)
98
--base BRANCH target branch (default: master)
102
--title TITLE PR title
99
--title TITLE PR title
103
--body BODY PR body (optional)
100
--body BODY PR body (optional)
104
--json output raw JSON
101
--json output raw JSON
105
102
106
okg pr view NUMBER
103
okg pr view NUMBER
107
--json output raw JSON
104
--json output raw JSON
108
105
109
okg pr diff NUMBER
106
okg pr diff NUMBER
110
107
111
okg pr comment NUMBER
108
okg pr comment NUMBER
112
--body BODY comment body
109
--body BODY comment body
113
--approve also approve the PR
110
--approve also approve the PR
114
--request-changes also request changes
111
--request-changes also request changes
115
112
116
okg pr merge NUMBER
113
okg pr merge NUMBER
117
--json output raw JSON
114
--json output raw JSON
118
115
119
okg pr close NUMBER
116
okg pr close NUMBER
120
--json output raw JSON
117
--json output raw JSON
121
118
122
okg pr reopen NUMBER
119
okg pr reopen NUMBER
123
--json output raw JSON
120
--json output raw JSON
124
121
125
ARTIFICIAL INTELLIGENCE
122
ARTIFICIAL INTELLIGENCE
126
okg embed
123
okg embed
127
--model NAME embedding model
124
--model NAME embedding model
128
(default: openai:text-embedding-3-small)
125
(default: openai:text-embedding-3-small)
129
--dims N number of dimensions (default: 1536)
126
--dims N number of dimensions (default: 1536)
130
--full-path one vector per prefix of input
127
--full-path one vector per prefix of input
131
(reads stdin; writes vectors to stdout, one per line)
128
(reads stdin; writes vectors to stdout, one per line)
132
129
133
okg one
130
okg one
134
--model NAME override .Model in the request
131
--model NAME override .Model in the request
135
--system-file FILE override .System with contents of FILE
132
--system-file FILE override .System with contents of FILE
136
--prompt-file FILE append FILE as a user prompt
133
--prompt-file FILE append FILE as a user prompt
137
--attach FILE attach an image or PDF to the prompt
134
--attach FILE attach an image or PDF to the prompt
138
--format FORMAT text | json | jsonindent (default: text)
135
--format FORMAT text | json | jsonindent (default: text)
139
--fast-fail preflight attachment MIME (default: on)
136
--fast-fail preflight attachment MIME (default: on)
140
(reads stdin as a JSON MessagesRequest; flags override
137
(reads stdin as a JSON MessagesRequest; flags override
141
its fields)
138
its fields)
142
139
143
GLOBAL FLAGS
140
GLOBAL FLAGS
144
--repo REPO override auto-detected repo name
141
--repo REPO override auto-detected repo name
145
--json output raw JSON (where applicable)
142
--json output raw JSON (where applicable)
146
143
147
EXAMPLES
144
EXAMPLES
148
Setup
145
Setup
149
okg auth login --key sk-...
146
okg auth login --key sk-...
150
cat ~/.klex.key | okg auth login
147
cat ~/.klex.key | okg auth login
151
148
152
Git repos
149
Git repos
153
okg repo list
150
okg repo list
154
okg repo create my-new-repo
151
okg repo create my-new-repo
155
152
156
Groups
153
Groups
157
okg group list
154
okg group list
158
okg group create chat-bots
155
okg group create chat-bots
159
okg group add-member chat-bots claude openclaw
156
okg group add-member chat-bots claude openclaw
160
okg group remove-member chat-bots openclaw
157
okg group remove-member chat-bots openclaw
161
okg group members chat-bots
158
okg group members chat-bots
162
okg group delete chat-bots
159
okg group delete chat-bots
163
160
164
Authz
161
Authz
165
okg authz set chat://chat-bots#post chat-bots chat-bots
162
okg authz set chat://chat-bots#post chat-bots chat-bots
166
okg authz list
163
okg authz list
167
164
168
Chat
165
Chat
169
okg chat send chat-bots 'hello team'
166
okg chat send chat-bots 'hello team'
170
okg chat fetch --to chat-bots
167
okg chat fetch --to chat-bots
171
168
172
Pull requests
169
Pull requests
173
okg pr list --state open
170
okg pr list --state open
174
okg pr view 42
171
okg pr view 42
175
okg pr comment 42 --body 'LGTM' --approve
172
okg pr comment 42 --body 'LGTM' --approve
176
173
177
Artificial intelligence
174
Artificial intelligence
178
echo 'hello world' | okg embed --dims 384
175
echo 'hello world' | okg embed --dims 384
179
echo Hello? > /tmp/q.txt && \
176
echo Hello? > /tmp/q.txt && \
180
okg one --model openai:gpt-4o-mini --prompt-file /tmp/q.txt
177
okg one --model openai:gpt-4o-mini --prompt-file /tmp/q.txt
181
`)
178
`)
182
}
179
}