callercontext

package
v0.153.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package callercontext names the AI harness (and its session) a DataTug command runs under, from the harness's own environment, so local records such as policy exception proposals and their audit events can say who proposed or used what.

It is self-reported: any process can set these variables. It never grants authority and is never sent to telemetry. Besides attribution it may only make a read stricter: a detected agent is refused, rather than warned about, columns that read-time suggestions mark sensitive. Hiding the harness drops a caller to the owner's baseline, never above it.

Index

Constants

View Source
const (
	HarnessEnv = "DATATUG_CALLER_HARNESS"
	SessionEnv = "DATATUG_CALLER_SESSION"
	// AIAgentEnv is the generic agent marker some harnesses set:
	// <name>[_<version with dashes>[_agent]] (Claude Code sets
	// claude-code_2-1-317_agent; OpenCode sets opencode).
	AIAgentEnv = "AI_AGENT"
)

Explicit overrides any harness, or the person, may set; they take precedence over everything detected.

View Source
const (
	SourceOverride   = "override"
	SourceHarnessEnv = "harness-env"
	SourceAIAgent    = "ai-agent"
)

Sources of a detected caller.

Variables

View Source
var Harnesses = []Harness{

	{Name: "claude-code", Marker: "CLAUDECODE", MarkerValue: "1", SessionVars: []string{"CLAUDE_CODE_SESSION_ID"}, AIAgentVersion: true},

	{Name: "codex", Marker: "CODEX_THREAD_ID", SessionVars: []string{"CODEX_SESSION_ID", "CODEX_THREAD_ID"}, VersionVar: "CODEX_VERSION"},

	{Name: "opencode", Marker: "OPENCODE", MarkerValue: "1", SessionVars: []string{"OPENCODE_SESSION_ID"}},

	{Name: "deepseek-harness", Marker: "DSH_SHELL", MarkerValue: "1", SessionVars: []string{"DSH_SESSION_ID"}},
}

Harnesses are the known harnesses. They are mutually exclusive: when several markers are set (nested harnesses) the one with a session wins, and a tie goes to the harness AI_AGENT names, else the first listed.

Functions

This section is empty.

Types

type Caller

type Caller struct {
	Harness        string `json:"harness,omitempty"`
	HarnessVersion string `json:"harnessVersion,omitempty"`
	Session        string `json:"session,omitempty"`
	// Source says where the first known field came from: override,
	// harness-env or ai-agent.
	Source string `json:"source,omitempty"`
}

Caller is who a command says it runs for. Empty fields are unknown.

func Detect

func Detect(lookup func(string) (string, bool)) Caller

Detect reads the caller from the environment lookup gives: the explicit DATATUG_CALLER_* overrides first, then the known harness whose marker is set (see Harnesses for nested ones), then a generic AI_AGENT value; each field falls back separately. A value that does not match its conservative pattern (at most 128 characters) is dropped.

func (Caller) Empty

func (c Caller) Empty() bool

Empty reports whether nothing is known.

func (Caller) Line

func (c Caller) Line() string

Line is the one-line, self-reported description the apply and reject screens show: "claude-code 2.1.317 · session 0f88afc6… (self-reported)".

type Harness

type Harness struct {
	Name string
	// Marker marks a process the harness runs: set to MarkerValue, or to any
	// non-empty value when MarkerValue is "".
	Marker, MarkerValue string
	// SessionVars hold the session id, first non-empty wins.
	SessionVars []string
	// VersionVar holds the version as is; AIAgentVersion reads it from
	// AI_AGENT instead.
	VersionVar     string
	AIAgentVersion bool
}

Harness is one harness the detector knows, read from its own environment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL