11package api
22
33import (
4+ "slices"
45 "time"
56)
67
8+ // Valid values for the Source field on flag and score entries.
9+ const (
10+ SourceUnknown = "unknown"
11+ SourceCLI = "cli"
12+ SourceCLIAgent = "cli+agent"
13+ SourceMCP = "mcp"
14+ SourceWeb = "web"
15+ SourceWebAgent = "web+agent"
16+ )
17+
18+ // validSources lists every accepted Source value (excluding the empty string,
19+ // which is normalized to SourceUnknown by NormalizeSource).
20+ var validSources = []string {
21+ SourceUnknown ,
22+ SourceCLI ,
23+ SourceCLIAgent ,
24+ SourceMCP ,
25+ SourceWeb ,
26+ SourceWebAgent ,
27+ }
28+
29+ // NormalizeSource validates the provided source and returns the canonical
30+ // value to store. An empty source is translated to SourceUnknown for
31+ // compatibility with older clients. The returned bool indicates whether the
32+ // input was a recognized value.
33+ func NormalizeSource (source string ) (string , bool ) {
34+ if source == "" {
35+ return SourceUnknown , true
36+ }
37+
38+ if slices .Contains (validSources , source ) {
39+ return source , true
40+ }
41+
42+ return source , false
43+ }
44+
745// URL: /1.0/team/flags
846// Access: team
947
@@ -15,6 +53,7 @@ type Flag struct {
1553 Description string `json:"description" yaml:"description"`
1654 ReturnString string `json:"return_string" yaml:"return_string"`
1755 Value int64 `json:"value" yaml:"value"`
56+ Source string `json:"source" yaml:"source"`
1857 SubmitTime time.Time `json:"submit_time" yaml:"submit_time"`
1958}
2059
@@ -24,10 +63,19 @@ type FlagPut struct {
2463}
2564
2665// FlagPost represents the fields used to submit a new score entry.
66+ //
67+ // Source tracks where the flag submission came from. Valid values are:
68+ // - "" => compatibility mechanism, translated to "unknown" internally
69+ // - "cli" => human submission through CLI
70+ // - "cli+agent" => agent submission through CLI
71+ // - "mcp" => submitted through the MCP server
72+ // - "web" => human submission through website
73+ // - "web+agent" => agent submission through website
2774type FlagPost struct {
2875 FlagPut `yaml:",inline"`
2976
30- Flag string `json:"flag" yaml:"flag"`
77+ Flag string `json:"flag" yaml:"flag"`
78+ Source string `json:"source" yaml:"source"`
3179}
3280
3381// URL: /1.0/flags
0 commit comments