saferscope

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

Documentation

Overview

Package saferscope plans safe workspace boundary changes.

Package saferscope turns workspace token-risk findings into reversible scope changes.

Index

Constants

View Source
const (
	StateFileName           = "safer-scope.json"
	IgnoreMarker            = "# Codog safer-scope exclusions"
	ActionAppendIgnoreBlock = "append_ignore_block"
	ActionCreateIgnoreFile  = "create_ignore_file"
)

Variables

This section is empty.

Functions

func RenderText

func RenderText(w io.Writer, report Report)

RenderText writes a human-readable safer-scope report.

func SaveState

func SaveState(workspace string, state State) error

SaveState writes safer-scope state below the given workspace.

func StatePath

func StatePath(workspace string) string

StatePath returns the workspace-local safer-scope state path.

Types

type Choice

type Choice struct {
	ID              string   `json:"id"`
	Action          string   `json:"action"`
	Status          string   `json:"status"`
	Target          string   `json:"target,omitempty"`
	PreviewIncludes []string `json:"preview_includes,omitempty"`
	PreviewExcludes []string `json:"preview_excludes,omitempty"`
	IgnoreFile      string   `json:"ignore_file,omitempty"`
	IgnoreEntries   []string `json:"ignore_entries,omitempty"`
	Description     string   `json:"description"`
}

Choice describes one actionable safer-scope option.

type Options

type Options struct {
	Choice           string
	Target           string
	RespectGitignore bool
	Now              time.Time
}

Options controls safer-scope planning and application.

type Report

type Report struct {
	Kind              string                  `json:"kind"`
	Action            string                  `json:"action"`
	Status            string                  `json:"status"`
	Advisory          bool                    `json:"advisory"`
	Confirmed         bool                    `json:"confirmed"`
	Workspace         string                  `json:"workspace"`
	OriginalWorkspace string                  `json:"original_workspace,omitempty"`
	ActiveWorkspace   string                  `json:"active_workspace,omitempty"`
	AppliedChoice     string                  `json:"applied_choice,omitempty"`
	Restored          bool                    `json:"restored,omitempty"`
	Message           string                  `json:"message,omitempty"`
	Risk              fileinventory.ScopeRisk `json:"scope_risk"`
	Choices           []Choice                `json:"choices,omitempty"`
	Applied           []Choice                `json:"applied,omitempty"`
	RestoreCommand    string                  `json:"restore_command,omitempty"`
}

Report is the stable payload returned by safer-scope preview/apply/restore.

func Apply

func Apply(workspace string, opts Options) (Report, error)

Apply executes selected safer-scope choices and writes restore metadata.

func Preview

func Preview(workspace string, opts Options) (Report, error)

Preview builds actionable safer-scope choices without changing workspace state.

func Restore

func Restore(workspace string) (Report, error)

Restore loads safer-scope state and returns the original workspace.

func Status

func Status(workspace string) (Report, error)

Status reports any safer-scope state recorded for the current workspace.

type State

type State struct {
	Kind              string    `json:"kind"`
	OriginalWorkspace string    `json:"original_workspace"`
	ActiveWorkspace   string    `json:"active_workspace,omitempty"`
	AppliedChoice     string    `json:"applied_choice"`
	IgnoreFile        string    `json:"ignore_file,omitempty"`
	IgnoreEntries     []string  `json:"ignore_entries,omitempty"`
	AppliedAt         time.Time `json:"applied_at"`
}

State records the broader scope so an applied safer scope can be restored.

func LoadState

func LoadState(workspace string) (State, error)

LoadState reads safer-scope state from a workspace.

Jump to

Keyboard shortcuts

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