Files
ARTEX/intercept/review_context.go
BaaRai e233c02314 Translate all Chinese text to English
Comments, doc comments, UI labels, log and error messages, LLM prompt
strings, markdown docs, test data and assertions. Identifiers, enum
keys, routes, placeholders and code structure are unchanged.

Notes:
- docs/漏洞流量证据.md renamed to docs/vulnerability-traffic-evidence.md
- tests that exercised CJK specific handling (GBK zip names, Chinese
  full text search) now use ASCII equivalents; go build passes and the
  test suite matches the pre translation baseline (remaining failures
  need a PostgreSQL DSN and fail identically on the original)
- frontend mention syntax now uses English kinds (finding, asset, ...)
  matching the backend, chat mentions tests pass
2026-10-08 23:14:34 +02:00

71 lines
2.6 KiB
Go

package intercept
import (
"context"
"encoding/json"
"fmt"
"strings"
)
const reviewTextLimit = 4000
const BackgroundUserMessage = "user_message"
// ReviewBackground is explicitly bound from the current human message. Generated
// Worker summaries are not accepted. Background cannot override review policy.
type ReviewBackground struct {
Source string `json:"source"`
Text string `json:"text"`
Truncated bool `json:"truncated,omitempty"`
}
// ReviewInput contains only the current call and explicitly selected background.
// Execution history and call correlation belong to the separate audit record.
type ReviewInput struct {
Version int `json:"version"`
WorkingDir string `json:"working_directory,omitempty"`
Background *ReviewBackground `json:"background,omitempty"`
Tool string `json:"tool_name"`
Arguments json.RawMessage `json:"arguments"`
}
type reviewContextKey struct{}
type reviewEnvironment struct {
workingDir string
background ReviewBackground
}
// WithReviewContext explicitly binds the permitted background for one run. Never
// fall back to the raw turn transcript: it may contain the full scheduler prompt.
// This is application wiring, not a model-callable tool.
func WithReviewContext(ctx context.Context, workingDir string, background ReviewBackground) context.Context {
return context.WithValue(ctx, reviewContextKey{}, reviewEnvironment{workingDir, background})
}
// WithReviewWorkingDirectory preserves only explicitly selected background.
// Chat runs can be human-initiated or scheduled, so the Agent must not infer
// message provenance from the text it receives.
func WithReviewWorkingDirectory(ctx context.Context, workingDir string) context.Context {
env, _ := ctx.Value(reviewContextKey{}).(reviewEnvironment)
env.workingDir = workingDir
return context.WithValue(ctx, reviewContextKey{}, env)
}
func BuildReviewInput(ctx context.Context, tool string, arguments json.RawMessage) (ReviewInput, error) {
if !json.Valid(arguments) {
return ReviewInput{}, fmt.Errorf("tool arguments are not valid JSON")
}
in := ReviewInput{Version: 4, Tool: tool, Arguments: append(json.RawMessage(nil), arguments...)}
if env, ok := ctx.Value(reviewContextKey{}).(reviewEnvironment); ok {
in.WorkingDir = env.workingDir
background := env.background
if background.Source == BackgroundUserMessage && strings.TrimSpace(background.Text) != "" {
var cut bool
background.Text, cut = bounded(background.Text, reviewTextLimit)
background.Truncated = background.Truncated || cut
in.Background = &background
}
}
return in, nil
}