-
Notifications
You must be signed in to change notification settings - Fork 0
feat(cmd): add vocab façade command surface #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bf7410e
add vocab command scaffold
mdheller f0315f6
feat(cmd): add vocab runtime plumbing
mdheller 3866cf9
Merge pull request #12 from SocioProphet/feat/vocab-runtime-plumbing
mdheller b587da6
Initial plan noted
Copilot ef0d2b7
Merge branch 'main' into feat/vocab-surface
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/socioprophet/prophet-cli/internal/vocab" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func newVocabCmd() *cobra.Command { | ||
| cmd := &cobra.Command{Use: "vocab", Short: "Ontogenesis vocabulary and policy-pack façade"} | ||
| cmd.AddCommand( | ||
| &cobra.Command{Use: "fetch", Short: "fetch or refresh Ontogenesis semantic assets", RunE: func(cmd *cobra.Command, args []string) error { | ||
| resp, err := vocab.Fetch(cmd.Context()) | ||
| if err != nil { return err } | ||
| resp["command"] = "prophet vocab fetch" | ||
| return emit(resp) | ||
| }}, | ||
| &cobra.Command{Use: "validate [graph-path ...]", Short: "Run Ontogenesis semantic-core validation", Args: cobra.ArbitraryArgs, RunE: func(cmd *cobra.Command, args []string) error { | ||
| resp, err := vocab.Validate(cmd.Context(), args) | ||
| if err != nil { return err } | ||
| resp["command"] = "prophet vocab validate" | ||
| return emit(resp) | ||
| }}, | ||
| &cobra.Command{Use: "promote", Short: "Promote the current validated context set", RunE: func(cmd *cobra.Command, args []string) error { | ||
| resp, err := vocab.Promote(cmd.Context()) | ||
| if err != nil { return err } | ||
| resp["command"] = "prophet vocab promote" | ||
| return emit(resp) | ||
| }}, | ||
| newVocabSRCmd(), | ||
| ) | ||
| return cmd | ||
| } | ||
|
|
||
| func newVocabSRCmd() *cobra.Command { | ||
| cmd := &cobra.Command{Use: "sr", Short: "Symbolic regression façade over Ontogenesis runners"} | ||
| cmd.AddCommand( | ||
| &cobra.Command{Use: "run <module>", Short: "Extract, train, and register SR for a module", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { | ||
| resp, err := vocab.SRRun(cmd.Context(), args[0]) | ||
| if err != nil { return err } | ||
| resp["command"] = "prophet vocab sr run" | ||
| return emit(resp) | ||
| }}, | ||
| &cobra.Command{Use: "gate", Short: "Evaluate SR promotion thresholds", RunE: func(cmd *cobra.Command, args []string) error { | ||
| resp, err := vocab.SRGate(cmd.Context()) | ||
| if err != nil { return err } | ||
| resp["command"] = "prophet vocab sr gate" | ||
| return emit(resp) | ||
| }}, | ||
| ) | ||
| return cmd | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package cmd | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestVocabCommandHasExpectedSubcommands(t *testing.T) { | ||
| cmd := newVocabCmd() | ||
| want := map[string]bool{ | ||
| "fetch": false, | ||
| "validate": false, | ||
| "promote": false, | ||
| "sr": false, | ||
| } | ||
| for _, c := range cmd.Commands() { | ||
| if _, ok := want[c.Name()]; ok { | ||
| want[c.Name()] = true | ||
| } | ||
| } | ||
| for name, seen := range want { | ||
| if !seen { | ||
| t.Fatalf("missing vocab subcommand: %s", name) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package executil | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "os/exec" | ||
| "time" | ||
| ) | ||
|
|
||
| type Result struct { | ||
| Command []string `json:"command"` | ||
| Stdout string `json:"stdout,omitempty"` | ||
| Stderr string `json:"stderr,omitempty"` | ||
| ExitCode int `json:"exit_code"` | ||
| Duration time.Duration `json:"duration_ns"` | ||
| } | ||
|
|
||
| func Run(ctx context.Context, argv []string) (Result, error) { | ||
| res := Result{Command: append([]string(nil), argv...)} | ||
| if len(argv) == 0 { | ||
| return res, nil | ||
| } | ||
| start := time.Now() | ||
| cmd := exec.CommandContext(ctx, argv[0], argv[1:]...) | ||
| var outb, errb bytes.Buffer | ||
| cmd.Stdout = &outb | ||
| cmd.Stderr = &errb | ||
| err := cmd.Run() | ||
| res.Stdout = outb.String() | ||
| res.Stderr = errb.String() | ||
| res.Duration = time.Since(start) | ||
| if cmd.ProcessState != nil { | ||
| res.ExitCode = cmd.ProcessState.ExitCode() | ||
| } | ||
| return res, err | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package vocab | ||
|
|
||
| import ( | ||
| "context" | ||
| "path/filepath" | ||
|
|
||
| executil "github.com/socioprophet/prophet-cli/internal/exec" | ||
| ) | ||
|
|
||
| type Response map[string]any | ||
|
|
||
| func Fetch(_ context.Context) (Response, error) { | ||
| return Response{ | ||
| "delegated_to": "socioprophet-standards-knowledge", | ||
| "status": "scaffold", | ||
| "operation": "fetch", | ||
| }, nil | ||
| } | ||
|
|
||
| func Validate(ctx context.Context, graphPaths []string) (Response, error) { | ||
| cmd := []string{"python3", filepath.ToSlash("policy/tools/validate_all.py"), "--data"} | ||
| cmd = append(cmd, graphPaths...) | ||
| res, _ := executil.Run(ctx, cmd) | ||
| return Response{ | ||
| "delegated_to": "socioprophet-standards-knowledge", | ||
| "status": "scaffold", | ||
| "operation": "validate", | ||
| "graph_paths": graphPaths, | ||
| "validator": "policy/tools/validate_all.py", | ||
| "probe": res, | ||
| }, nil | ||
| } | ||
|
|
||
| func Promote(_ context.Context) (Response, error) { | ||
| return Response{ | ||
| "delegated_to": "socioprophet-standards-knowledge", | ||
| "status": "scaffold", | ||
| "operation": "promote", | ||
| "record_target": "/ontology/promotions/<ts>.jsonld", | ||
| }, nil | ||
| } | ||
|
|
||
| func SRRun(_ context.Context, module string) (Response, error) { | ||
| return Response{ | ||
| "delegated_to": "socioprophet-standards-knowledge", | ||
| "status": "scaffold", | ||
| "operation": "sr_run", | ||
| "module": module, | ||
| }, nil | ||
| } | ||
|
|
||
| func SRGate(_ context.Context) (Response, error) { | ||
| return Response{ | ||
| "delegated_to": "socioprophet-standards-knowledge", | ||
| "status": "scaffold", | ||
| "operation": "sr_gate", | ||
| }, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package vocab | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestValidateReportsValidatorPath(t *testing.T) { | ||
| resp, err := Validate(context.Background(), []string{"graphs/demo.ttl"}) | ||
| if err != nil { | ||
| t.Fatalf("Validate returned error: %v", err) | ||
| } | ||
| if got := resp["validator"]; got != "policy/tools/validate_all.py" { | ||
| t.Fatalf("unexpected validator path: %v", got) | ||
| } | ||
| if got := resp["operation"]; got != "validate" { | ||
| t.Fatalf("unexpected operation: %v", got) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
promotesubcommand setsRunEwithout anArgsvalidator, so Cobra will accept extra positional arguments and still return success (for example,prophet vocab promote typo). That makes automation and operator mistakes hard to detect because invalid invocations look successful. AddingArgs: cobra.NoArgshere (and similarly on other no-arg verbs likesr gate) would make this command fail fast on malformed input.Useful? React with 👍 / 👎.