shared

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DangerousDirectories = []string{
	".git",
	".vscode",
	".idea",
	".claude",
	".openclaude",

	".ssh",

	".aws",
	".gcp",
	".azure",

	".gnupg",
}

DangerousDirectories are directories that should never be auto-edited. Aligned with OpenClaude's DANGEROUS_DIRECTORIES (filesystem.ts:527-534).

View Source
var DangerousFiles = []string{

	".bashrc",
	".bash_profile",
	".zshrc",
	".zprofile",
	".profile",
	".bash_logout",

	".gitconfig",
	".gitmodules",

	"authorized_keys",
	"known_hosts",
	"id_rsa",
	"id_ed25519",
	"id_ecdsa",

	".env",
	".env.local",
	".env.production",
	".env.staging",
	".envrc",
	".netrc",

	".npmrc",
	".yarnrc",
	".pypirc",

	"credentials",
	"config",

	".mcp.json",
	".claude.json",
	".ripgreprc",

	".travis.yml",
}

DangerousFiles are files that should never be auto-edited. Aligned with OpenClaude's DANGEROUS_FILES (filesystem.ts:516-525).

Functions

func CheckDangerousRemovalPath

func CheckDangerousRemovalPath(path string, cwd string) error

CheckDangerousRemovalPath checks if a removal path is dangerous. Aligned with OpenClaude's checkDangerousRemovalPaths (pathValidation.ts:331-367).

func FormatNotFoundError

func FormatNotFoundError(path string, workingDir string) error

FormatNotFoundError formats a helpful "not found" error with optional suggestion

func GetAbsolutePath

func GetAbsolutePath(path string) (string, error)

GetAbsolutePath returns the real absolute path with symlinks resolved. If the path doesn't exist, the parent is resolved to prevent escape.

func GetFileReadIgnorePatterns

func GetFileReadIgnorePatterns(_ context.Context) []string

GetFileReadIgnorePatterns returns patterns to ignore during file reads.

func GetVCSDirectoriesToExclude

func GetVCSDirectoriesToExclude() []string

GetVCSDirectoriesToExclude returns VCS directories to exclude from searches.

func HasSuspiciousPattern

func HasSuspiciousPattern(path string) bool

HasSuspiciousPattern checks if a path has suspicious patterns that could bypass safety checks. Aligned with OpenClaude's Windows path patterns (pathValidation.ts:546-611).

func IsBlockedDevicePath

func IsBlockedDevicePath(filePath string) bool

IsBlockedDevicePath reports whether filePath is (or is under) a blocked device node.

func IsDangerousDirectory

func IsDangerousDirectory(path string) bool

IsDangerousDirectory checks if a path is in or points to a dangerous directory.

func IsDangerousFile

func IsDangerousFile(path string) bool

IsDangerousFile checks if a file path points to a dangerous file.

func IsInWorkingDirectory

func IsInWorkingDirectory(path, workingDir string) bool

IsInWorkingDirectory checks if a path is within the working directory after resolving all symlinks to prevent escape attacks.

func IsPathWithin

func IsPathWithin(base, path string) (bool, error)

IsPathWithin checks if a path is within a base directory (after symlink resolution).

func IsUNCPath

func IsUNCPath(path string) bool

IsUNCPath reports whether path is a UNC/network path (\\server\share or //server/share). These can leak NTLM credentials on Windows and are blocked unconditionally.

func Plural

func Plural(count int) string

Plural returns the plural suffix for a count

func RipgrepNotFoundError

func RipgrepNotFoundError() error

RipgrepNotFoundError returns a clear, OS-specific error when ripgrep is missing.

func SuggestPathUnderCwd

func SuggestPathUnderCwd(requestedPath string, workingDir string) (string, error)

SuggestPathUnderCwd suggests a corrected path if the requested path exists under the parent of the current working directory but not under cwd itself. This helps users who accidentally type paths like "../project/file.go" when they mean "file.go" (assuming the file exists in both locations).

IMPORTANT: This function only suggests if the requested path DOES NOT exist. If the requested path exists, no suggestion is made even if a similar file exists under cwd.

func ValidateFilePath

func ValidateFilePath(filePath, operation string) error

ValidateFilePath rejects device paths and path-traversal sequences. operation is a short label used in error messages (e.g. "writing", "editing").

func ValidatePathExists

func ValidatePathExists(path string) error

ValidatePathExists checks if a path exists

func ValidatePathIsDirectory

func ValidatePathIsDirectory(path string) error

ValidatePathIsDirectory checks if a path exists and is a directory

func ValidateSensitivePath

func ValidateSensitivePath(absolutePath, toolName, content string) error

ValidateSensitivePath rejects edits to credential / settings files that would leave them in an unsafe state. toolName is used in error messages.

func ValidateUNCPathSecurity

func ValidateUNCPathSecurity(path string) error

ValidateUNCPathSecurity returns an error when path is a UNC/network path.

Types

type GitDiff

type GitDiff struct {
	Filename  string `json:"filename"`
	Status    string `json:"status"`
	Additions int    `json:"additions"`
	Deletions int    `json:"deletions"`
	Changes   int    `json:"changes"`
	Patch     string `json:"patch"`
}

GitDiff holds a minimal summary of git changes for a file.

func ComputeGitDiff

func ComputeGitDiff(absolutePath string) (*GitDiff, bool)

ComputeGitDiff computes a git diff summary for absolutePath. Returns (diff, true) when inside a git repo; (nil, false) otherwise.

Jump to

Keyboard shortcuts

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