GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — keep/helpers.go at v0.7.0 · majorcontext/keep

Expand file tree

/

helpers.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
78 lines (72 loc) · 2.96 KB
/

helpers.go

Copy path

File metadata and controls

78 lines (72 loc) · 2.96 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package keep
import (
"context"
"fmt"
"strings"
"time"
"github.com/majorcontext/keep/internal/engine"
)
// SafeEvaluate wraps Engine.Evaluate with panic recovery so the host process
// never crashes due to a policy evaluation bug. On panic it returns
// EvalResult{Decision: Deny} and an error describing the panic (fail-closed).
func SafeEvaluate(ctx context.Context, eng *Engine, call Call, scope string) (result EvalResult, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("keep: panic during evaluation: %v", r)
result = EvalResult{Decision: Deny}
}
}()
return eng.Evaluate(ctx, call, scope)
}
// NewHTTPCall constructs a Call for HTTP request policy evaluation.
// The operation is formatted as "METHOD host/path" (e.g. "GET api.github.com/repos").
// Method is uppercased. Path is expected to include a leading slash.
// Context.Scope is not set — callers should assign it based on their deployment convention.
func NewHTTPCall(method, host, path string) Call {
m := strings.ToUpper(method)
return Call{
Operation: m + " " + host + path,
Params: map[string]any{
"method": m,
"host": host,
"path": path,
},
Context: engine.CallContext{
Timestamp: time.Now(),
},
}
}
// NewHTTPCallWithBody constructs a Call for HTTP request policy evaluation,
// including the parsed request body under params.body. It behaves exactly like
// NewHTTPCall (method is uppercased, path is expected to include a leading
// slash, Context.Scope is left unset) but additionally exposes the body to
// rules that inspect it (e.g. `params.body.model == 'gpt-4'`, a scalar-field
// scan `hasSecrets(params.body.prompt)`, or a whole-body scan
// `hasSecrets(params.body)` which recurses over every string leaf).
//
// body is the decoded request body and may be any JSON-shaped value: an object
// (map[string]any), an array ([]any), or a scalar. It is stored as-is, so a nil
// body still sets params.body (to nil). With a nil body, content-inspection
// rules such as params.body.model == 'gpt-4' will not match, because CEL treats
// the nil navigation as a missing value and the engine resolves that to false;
// has(params.body) is nonetheless always true for calls built with this helper,
// so test for a populated body with params.body != null instead. Use
// Engine.RequiresBody to decide whether buffering and parsing the body is
// worthwhile before calling this.
func NewHTTPCallWithBody(method, host, path string, body any) Call {
call := NewHTTPCall(method, host, path)
call.Params[engine.ParamBody] = body
return call
}
// NewMCPCall constructs a Call for MCP tool-use policy evaluation.
// The operation is the tool name as-is. Params are passed through directly (may be nil).
// Context.Scope is not set — callers should assign it based on their deployment convention.
func NewMCPCall(tool string, params map[string]any) Call {
return Call{
Operation: tool,
Params: params,
Context: engine.CallContext{
Timestamp: time.Now(),
},
}
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.