MCPcopy Create free account
hub / github.com/ByteYellow/AgentProvenance / policyCmd

Function policyCmd

internal/cli/policy_cmd.go:13–90  ·  view source on GitHub ↗
(dataDir *string)

Source from the content-addressed store, hash-verified

11)
12
13func policyCmd(dataDir *string) *cobra.Command {
14 var rulesPath string
15 test := &cobra.Command{
16 Use: "test <events.jsonl>",
17 Short: "evaluate JSONL events with the policy engine",
18 Args: cobra.ExactArgs(1),
19 RunE: func(cmd *cobra.Command, args []string) error {
20 paths, err := store.Init(*dataDir)
21 if err != nil {
22 return err
23 }
24 db, err := store.Open(paths)
25 if err != nil {
26 return err
27 }
28 defer db.Close()
29 engine, err := security.LoadEngine(rulesPath)
30 if err != nil {
31 return err
32 }
33 return security.EvaluateJSONLWithEngine(db, args[0], cmd.OutOrStdout(), engine)
34 },
35 }
36 test.Flags().StringVar(&rulesPath, "rules", "", "YAML policy rules file")
37 var runID string
38 decisions := &cobra.Command{
39 Use: "decisions",
40 Short: "list policy decisions",
41 RunE: func(cmd *cobra.Command, args []string) error {
42 paths, err := store.Init(*dataDir)
43 if err != nil {
44 return err
45 }
46 db, err := store.Open(paths)
47 if err != nil {
48 return err
49 }
50 defer db.Close()
51 records, err := security.ListDecisions(db, runID)
52 if err != nil {
53 return err
54 }
55 w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 2, ' ', 0)
56 fmt.Fprintln(w, "ID\tRUN\tSESSION\tRULE\tDECISION\tREASON\tCREATED_AT")
57 for _, record := range records {
58 fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", record.ID, record.RunID, record.SessionID, record.RuleID, record.Decision, record.Reason, record.CreatedAt)
59 }
60 return w.Flush()
61 },
62 }
63 decisions.Flags().StringVar(&runID, "run", "", "filter decisions by run id")
64 var outPath string
65 rules := &cobra.Command{
66 Use: "rules",
67 Short: "dump the default policy rules as an editable YAML file",
68 Long: "Emits the built-in policy (allow/detect/enforce rules) as YAML you can edit and " +
69 "load back with `policy test --rules <file>`. Use it to tune, e.g., which credential " +
70 "paths count as the agent's own infra (allow, no alert) vs an exfil target (kill).",

Callers 1

NewRootCommandFunction · 0.85

Calls 10

InitFunction · 0.92
OpenFunction · 0.92
LoadEngineFunction · 0.92
EvaluateJSONLWithEngineFunction · 0.92
ListDecisionsFunction · 0.92
DefaultRulesYAMLFunction · 0.92
FlushMethod · 0.80
WriteFileMethod · 0.80
WriteMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected