2026-11-10 16:55:56 +00:00
package cli
import (
2026-11-10 17:18:30 +00:00
"fmt"
2026-11-10 16:55:56 +00:00
"strconv"
commandkit "go.maximumdirect.net/commandkit"
ck "go.maximumdirect.net/configkit"
)
type processInput struct {
2026-11-26 18:18:34 +00:00
Config commandkit . Supplied [ string ]
Overlay commandkit . Supplied [ string ]
Transcript string
Output commandkit . Supplied [ string ]
Debug commandkit . Supplied [ bool ]
2026-11-27 01:19:17 +00:00
Smoke commandkit . Supplied [ bool ]
2026-11-26 18:18:34 +00:00
Overrides [ ] ck . Override
GlossaryFiles [ ] string
2026-11-10 16:55:56 +00:00
}
2026-11-27 01:19:17 +00:00
func processingFlags ( ) [ ] commandkit . Flag [ processInput ] {
2026-11-10 16:55:56 +00:00
stringValue := func ( s string ) ( string , error ) { return s , nil }
flags := [ ] commandkit . Flag [ processInput ] {
2026-11-26 18:18:34 +00:00
commandkit . RepeatFlag ( commandkit . FlagMeta { Name : "glossary-file" , Usage : "Runtime glossary file (repeatable)." } , nil , stringValue , func ( in * processInput , v commandkit . Supplied [ [ ] string ] ) { in . GlossaryFiles = v . Value } ) ,
2026-11-10 16:55:56 +00:00
commandkit . ValueFlag ( commandkit . FlagMeta { Name : "config" , Usage : "Application configuration file." } , ( * string ) ( nil ) , stringValue , func ( in * processInput , v commandkit . Supplied [ string ] ) { in . Config = v } ) ,
commandkit . ValueFlag ( commandkit . FlagMeta { Name : "overlay" , Usage : "Configuration overlay." } , ( * string ) ( nil ) , stringValue , func ( in * processInput , v commandkit . Supplied [ string ] ) { in . Overlay = v } ) ,
commandkit . ValueFlag ( commandkit . FlagMeta { Name : "output" , Usage : "Transcript output file." } , ( * string ) ( nil ) , stringValue , func ( in * processInput , v commandkit . Supplied [ string ] ) { in . Output = v } ) ,
commandkit . BoolFlag ( commandkit . FlagMeta { Name : "debug" , Usage : "Capture diagnostic artifacts." } , false , func ( in * processInput , v commandkit . Supplied [ bool ] ) { in . Debug = v } ) ,
}
for _ , item := range [ ] struct {
name string
path ck . Path
} {
{ "proposal-profile" , ck . Keys ( "llm" , "proposal_profile" ) } , { "validation-profile" , ck . Keys ( "llm" , "validation_profile" ) } ,
{ "output-schema" , ck . Keys ( "output" , "schema" ) } , { "transcript-description" , ck . Keys ( "context" , "description" ) } ,
{ "report-dir" , ck . Keys ( "reporting" , "stdout_dir" ) } , { "work-dir" , ck . Keys ( "diagnostics" , "work_dir" ) } ,
} {
name , path := item . name , item . path
flags = append ( flags , commandkit . ValueFlag ( commandkit . FlagMeta { Name : name , Usage : "Override application setting." } , ( * string ) ( nil ) , stringValue ,
func ( in * processInput , v commandkit . Supplied [ string ] ) {
if v . Set {
in . Overrides = append ( in . Overrides , ck . Override { Path : path , Value : v . Value , Flag : "--" + name } )
}
} ) )
}
for _ , item := range [ ] struct {
name string
path ck . Path
} {
{ "validation-max-prompt-tokens" , ck . Keys ( "validation" , "max_prompt_tokens" ) } , { "target-sections" , ck . Keys ( "chunking" , "target_sections" ) } ,
{ "max-section-tokens" , ck . Keys ( "chunking" , "max_section_tokens" ) } , { "min-section-tokens" , ck . Keys ( "chunking" , "min_section_tokens" ) } ,
{ "normalize-max-segment-tokens" , ck . Keys ( "normalization" , "max_segment_tokens" ) } ,
} {
name , path := item . name , item . path
flags = append ( flags , commandkit . ValueFlag ( commandkit . FlagMeta { Name : name , Usage : "Override application setting." } , ( * int ) ( nil ) , strconv . Atoi ,
func ( in * processInput , v commandkit . Supplied [ int ] ) {
if v . Set {
in . Overrides = append ( in . Overrides , ck . Override { Path : path , Value : v . Value , Flag : "--" + name } )
}
} ) )
}
for _ , item := range [ ] struct {
name string
path ck . Path
} {
{ "normalize-max-segment-gap" , ck . Keys ( "normalization" , "max_segment_gap" ) } , { "normalize-ellipsis-gap" , ck . Keys ( "normalization" , "ellipsis_gap" ) } ,
2026-11-11 17:05:52 +00:00
{ "normalize-max-segment-duration" , ck . Keys ( "normalization" , "max_segment_duration" ) } ,
2026-11-10 16:55:56 +00:00
} {
name , path := item . name , item . path
flags = append ( flags , commandkit . ValueFlag ( commandkit . FlagMeta { Name : name , Usage : "Override application setting." } , ( * float64 ) ( nil ) , func ( s string ) ( float64 , error ) { return strconv . ParseFloat ( s , 64 ) } ,
func ( in * processInput , v commandkit . Supplied [ float64 ] ) {
if v . Set {
in . Overrides = append ( in . Overrides , ck . Override { Path : path , Value : v . Value , Flag : "--" + name } )
}
} ) )
}
2026-11-10 17:18:30 +00:00
for _ , item := range [ ] struct {
name string
path ck . Path
} {
{ "glossaries" , ck . Keys ( "glossaries" ) } , { "protected-terms" , ck . Keys ( "protected_terms" ) } ,
} {
name , path := item . name , item . path
flags = append ( flags , commandkit . ValueFlag ( commandkit . FlagMeta { Name : name , Usage : "JSON array of collection names, or null." } , ( * any ) ( nil ) , parseCollectionNames ,
func ( in * processInput , value commandkit . Supplied [ any ] ) {
if value . Set {
in . Overrides = append ( in . Overrides , ck . Override { Path : path , Value : value . Value , Flag : "--" + name } )
}
} ) )
}
2026-11-10 16:55:56 +00:00
flags = append ( flags , commandkit . BoolFlag ( commandkit . FlagMeta { Name : "reporting" , Usage : "Enable ordinary reports." } , false ,
func ( in * processInput , v commandkit . Supplied [ bool ] ) {
if v . Set {
in . Overrides = append ( in . Overrides , ck . Override { Path : ck . Keys ( "reporting" , "enabled" ) , Value : v . Value , Flag : "--reporting" } )
}
} ) )
2026-11-27 01:19:17 +00:00
return flags
}
func transcriptArguments ( ) [ ] commandkit . Argument [ processInput ] {
return [ ] commandkit . Argument [ processInput ] { commandkit . ValueArgument ( commandkit . ArgumentMeta { Name : "transcript" , Usage : "Transcript JSON file." } , true , func ( s string ) ( string , error ) { return s , nil } , func ( in * processInput , v commandkit . Supplied [ string ] ) { in . Transcript = v . Value } ) }
}
func processCommand ( ) commandkit . Command {
return commandkit . NewCommand ( commandkit . CommandSpec [ processInput ] { Name : "process" , Summary : "Polish a transcript." , Flags : processingFlags ( ) , Run : runProcess , Arguments : transcriptArguments ( ) } )
}
func preflightCommand ( ) commandkit . Command {
flags := append ( processingFlags ( ) , commandkit . BoolFlag ( commandkit . FlagMeta { Name : "smoke" , Usage : "Verify structured output with selected profiles." } , true , func ( in * processInput , v commandkit . Supplied [ bool ] ) { in . Smoke = v } ) )
return commandkit . NewCommand ( commandkit . CommandSpec [ processInput ] { Name : "preflight" , Summary : "Check processing readiness." , Flags : flags , Run : runPreflight , Arguments : transcriptArguments ( ) } )
2026-11-10 16:55:56 +00:00
}
2026-11-10 17:18:30 +00:00
func parseCollectionNames ( raw string ) ( any , error ) {
value , err := commandkit . ParseCLIJSON ( raw )
if err != nil {
return nil , err
}
if value == nil {
return nil , nil
}
names , ok := value . ( [ ] any )
if ! ok {
return nil , fmt . Errorf ( "expected a JSON array of collection names or null" )
}
for _ , name := range names {
if _ , ok := name . ( string ) ; ! ok {
return nil , fmt . Errorf ( "collection names must be strings" )
}
}
return names , nil
}