jinn

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const Schema = `` /* 11038-byte string literal not displayed */

Schema is the tool definitions in OpenAI function-calling format.

Variables

This section is empty.

Functions

func ExplainRisk added in v0.6.0

func ExplainRisk(r RiskLevel, reason string) string

ExplainRisk returns a one-line formatted explanation for the user, e.g. "dangerous: rm with force flags — irreversible".

func ResolveVersion

func ResolveVersion(ldVersion string) string

ResolveVersion returns a human-readable version string, preferring ldflags-injected version, then VCS revision, then module version.

Types

type Classification added in v0.6.0

type Classification string

Classification describes how a shell exit code should be interpreted by the calling LLM. Expected-nonzero exits are semantic signals, not failures.

const (
	// ClassSuccess means exit 0 — command completed normally.
	ClassSuccess Classification = "success"
	// ClassExpectedNonzero means a non-zero exit that is a semantic signal
	// (e.g., grep exit 1 = no matches). The LLM should NOT retry.
	ClassExpectedNonzero Classification = "expected_nonzero"
	// ClassError means an unexpected non-zero exit indicating failure.
	ClassError Classification = "error"
	// ClassTimeout means the command exceeded its time limit (exit 124).
	ClassTimeout Classification = "timeout"
	// ClassSignal means the process was killed by a signal.
	ClassSignal Classification = "signal"
)

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine is a sandboxed tool executor bound to a working directory.

func New

func New(workDir string) *Engine

New creates an Engine rooted at the given working directory. The workDir is resolved via EvalSymlinks so that path boundary checks work correctly on platforms where temp dirs are symlinks (e.g., macOS).

func (*Engine) Dispatch

func (e *Engine) Dispatch(ctx context.Context, tool string, args map[string]interface{}) (string, map[string]string, error)

Dispatch routes a tool call to the appropriate handler and returns structured metadata alongside the result string. Meta keys:

  • "risk": pre-execution risk level set by run_shell ("safe", "caution", "dangerous")
  • "classification": exit-code class set by run_shell ("success", "expected_nonzero", "error", "timeout", "signal")

Tools that don't set meta return a nil map. Callers should treat nil as empty. Option A: meta map in return signature keeps Dispatch pure and thread-safe.

type ErrWithSuggestion added in v0.6.0

type ErrWithSuggestion struct {
	Err        error
	Suggestion string
}

ErrWithSuggestion wraps an error with a one-sentence next-step suggestion for the calling LLM. Suggestions follow the style guide below so future maintainers add new suggestions consistently.

Style guide for suggestion strings:

  • Imperative mood ("use list_dir", "verify the path", "check ownership")
  • One sentence only — no hedging words ("might", "perhaps", "try to")
  • Name the specific tool or parameter the agent should use next
  • No trailing period

func (*ErrWithSuggestion) Error added in v0.6.0

func (e *ErrWithSuggestion) Error() string

func (*ErrWithSuggestion) Unwrap added in v0.6.0

func (e *ErrWithSuggestion) Unwrap() error

type Request

type Request struct {
	Tool string                 `json:"tool"`
	Args map[string]interface{} `json:"args"`
}

Request is the one-shot tool invocation envelope.

type Response

type Response struct {
	OK             bool   `json:"ok"`
	Result         string `json:"result,omitempty"`
	Error          string `json:"error,omitempty"`
	Suggestion     string `json:"suggestion,omitempty"`
	Classification string `json:"classification,omitempty"` // exit-code class: "success", "expected_nonzero", "error", "timeout", "signal"
	Risk           string `json:"risk,omitempty"`           // pre-execution risk: "safe", "caution", "dangerous" — only set by run_shell
}

Response is the one-shot tool result envelope.

type RiskLevel added in v0.6.0

type RiskLevel int

RiskLevel describes how dangerous a shell command is to execute.

const (
	// RiskSafe — read-only, no side effects visible outside stdout.
	RiskSafe RiskLevel = iota
	// RiskCaution — modifies state, but generally recoverable.
	RiskCaution
	// RiskDangerous — destructive or irreversible.
	RiskDangerous
)

func ClassifyCommand added in v0.6.0

func ClassifyCommand(cmdline string) (RiskLevel, string)

ClassifyCommand parses cmdline (a bash-style command string) and returns the highest risk level it can detect plus a human reason.

Conservative: unknown verbs default to RiskCaution, not RiskSafe. Pipelines (cmd1 | cmd2) return the MAX risk of any component. Heredocs and subshells are treated as opaque — RiskCaution minimum unless the content contains dangerous verbs.

func (RiskLevel) String added in v0.6.0

func (r RiskLevel) String() string

String returns the lowercase label used in user-visible output.

Jump to

Keyboard shortcuts

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