pathscope

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pathscope checks whether filesystem paths are inside allowed roots.

Index

Constants

View Source
const FileName = "additional-dirs.json"

Variables

This section is empty.

Functions

func EffectiveDirs

func EffectiveDirs(workspace string, configDirs []string) ([]string, error)

func ExtractPathCandidates

func ExtractPathCandidates(payload string) []string

ExtractPathCandidates returns conservative path-like operands from a shell or tool payload.

func NormalizeDir

func NormalizeDir(workspace, requested string) (string, error)

func Path

func Path(workspace string) string

func RenderPrompt

func RenderPrompt(workspace string, configDirs []string) string

func RenderText

func RenderText(w io.Writer, report Report)

func RenderValidationText

func RenderValidationText(w io.Writer, report ValidationReport)

func Save

func Save(workspace string, state State) error

Types

type Entry

type Entry struct {
	Path   string `json:"path"`
	Source string `json:"source"`
	Exists bool   `json:"exists"`
}

type PayloadScopeDecision

type PayloadScopeDecision struct {
	Allowed   bool   `json:"allowed"`
	Reason    string `json:"reason"`
	Candidate string `json:"candidate,omitempty"`
	Resolved  string `json:"resolved,omitempty"`
}

PayloadScopeDecision records whether path-like payload operands stay within the configured workspace scope.

func ValidatePayloadScope

func ValidatePayloadScope(workspace string, additionalDirs []string, payload string, cwd string) PayloadScopeDecision

ValidatePayloadScope validates path-like shell/tool payload operands against the workspace and explicitly allowed additional directories.

type Report

type Report struct {
	Kind      string  `json:"kind"`
	Action    string  `json:"action"`
	Workspace string  `json:"workspace"`
	Total     int     `json:"total"`
	Entries   []Entry `json:"entries"`
}

func Add

func Add(workspace string, paths []string) (Report, error)

func BuildReport

func BuildReport(workspace string, configDirs []string, action string) (Report, error)

func Clear

func Clear(workspace string) (Report, error)

func Remove

func Remove(workspace string, paths []string) (Report, error)

type State

type State struct {
	Kind      string    `json:"kind"`
	Workspace string    `json:"workspace"`
	UpdatedAt time.Time `json:"updated_at"`
	Dirs      []string  `json:"dirs"`
}

func Load

func Load(workspace string) (State, error)

type ValidationEntry

type ValidationEntry struct {
	Input          string `json:"input,omitempty"`
	Path           string `json:"path,omitempty"`
	Source         string `json:"source,omitempty"`
	Valid          bool   `json:"valid"`
	Exists         bool   `json:"exists"`
	IsDir          bool   `json:"is_dir"`
	AlreadyAllowed bool   `json:"already_allowed"`
	Error          string `json:"error,omitempty"`
}

type ValidationReport

type ValidationReport struct {
	Kind         string            `json:"kind"`
	Action       string            `json:"action"`
	Status       string            `json:"status"`
	Workspace    string            `json:"workspace"`
	Total        int               `json:"total"`
	ValidCount   int               `json:"valid_count"`
	InvalidCount int               `json:"invalid_count"`
	Entries      []ValidationEntry `json:"entries"`
}

func Validate

func Validate(workspace string, configDirs []string, paths []string) (ValidationReport, error)

Jump to

Keyboard shortcuts

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