operators

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const StateFileName = ".nexss.srcpack.state"

StateFileName is the on-disk name of the incremental cache. Written in the workspace root; overwritten on every successful run.

Variables

This section is empty.

Functions

func ASTParseOperator

func ASTParseOperator() action.NamedOperator

func AnalysisLibrary

func AnalysisLibrary() action.Library

AnalysisLibrary returns the AST extractor and SRCPACK's stats adapters. They operate on the file stream produced by srcpack.source and never write to disk; pack.batch only materializes records for the downstream Flow fold.

func Clipboard

Clipboard copies the rendered stream to the system clipboard when enabled, then forwards the original items unchanged.

func ClipboardOperator

func ClipboardOperator() action.NamedOperator

func DensifyBody

func DensifyBody(content string) string

func DensifySnippets

func DensifySnippets(lang string, snippets []string) string

func DocumentInputAction

func DocumentInputAction() action.AnyAction

DocumentInputAction exposes typed domain facts. Placeholder names, aliases, defaults and the document bundle's file shape belong to render.nflow.

func GenerateContextTree

func GenerateContextTree(files []ParsedFile, depth int, color, showFiles bool) string

GenerateContextTree is the compatibility string API.

func GenerateFullProjectTree

func GenerateFullProjectTree(root string, files []ParsedFile, depth int, color, showFiles bool) string

func GitActions

func GitActions() []action.AnyAction

GitActions returns the Git actions used by source scans and available to NFlow.

func GitChangedPathsAction

func GitChangedPathsAction() action.AnyAction

GitChangedPathsAction exposes the changed-path set used by incremental source scans.

func GitLSFilesAction

func GitLSFilesAction() action.AnyAction

GitLSFilesAction exposes Git's reusable untracked-file query.

func GitUnifiedDiff

func GitUnifiedDiff(ctx context.Context, root string, filter GitFilter) (string, error)

GitUnifiedDiff returns the raw patch for the filter's active mode.

func IOLibrary

func IOLibrary() action.Library

IOLibrary returns the write-side operators: state cache, stdout sink, and clipboard.

func JoinRendered

func JoinRendered(files []fs.FileContent) string

JoinRendered concatenates already-rendered content chunks without adding separators. RenderMarkdown owns all framing and newline semantics.

func JoinRenderedAction

func JoinRenderedAction() action.AnyAction

JoinRenderedAction turns the []FileContent result of Flow's collect boundary into a plain string, which transports such as tcli can emit as text.

func Library

func Library() action.Library

Library returns every srcpack library in one value. Kept for callers that want the whole surface without enumerating each subsystem.

func MaskSecrets

func MaskSecrets(input string) string

func MaskSecretsFast

func MaskSecretsFast(src []byte, dst *bytes.Buffer)

func OutputActions

func OutputActions() []action.AnyAction

OutputActions exposes output effects and their data-only rendering adapter.

func PackBatchOperator

func PackBatchOperator() action.NamedOperator

PackBatchOperator exposes the append-only materializer to NFlow.

func PackStatsInputOperator

func PackStatsInputOperator() action.NamedOperator

PackStatsInputOperator prepares ParsedFile facts for the NFlow-owned stats fold without moving source selection, parsing, or rendering out of SRCPACK.

func RenderLibrary

func RenderLibrary() action.Library

RenderLibrary exposes the domain adapter for the document NFlow bundle. srcpack.render remains a compatibility operator for external/legacy flows.

func RenderMarkdown

func RenderMarkdown(cfg RenderConfig) action.StreamOp[any, fs.FileContent]

func RenderMarkdownOperator

func RenderMarkdownOperator() action.NamedOperator

func SaveState

func SaveState(path string, files []ParsedFile) error

SaveState writes the current set of files as the new state cache. Omitted files are skipped; a nil cache target path is a no-op.

func SaveStateOperator

func SaveStateOperator() action.NamedOperator

func SourceLibrary

func SourceLibrary() action.Library

SourceLibrary returns the stream source that scans a workspace.

func SourceOperator

func SourceOperator() action.AnyStreamAction

func StatsCollect

func StatsCollect(cfg StatsCollectConfig) action.StreamOp[any, any]

func StatsCollectOperator

func StatsCollectOperator() action.NamedOperator

func StatsCollectWithContext

func StatsCollectWithContext(ctx context.Context, cfg StatsCollectConfig) action.StreamOp[any, any]

StatsCollectWithContext observes cancellation for callers that have an action context.

func Stdout

func Stdout(_ struct{}) action.StreamOp[fs.FileContent, fs.FileContent]

func StdoutOperator

func StdoutOperator() action.NamedOperator

Types

type ASTConfig

type ASTConfig struct {
	OnlySig        bool `json:"only_sig"         cli:"only-sig"`
	Dense          bool `json:"dense"            cli:"dense"`
	Comments       bool `json:"comments"         cli:"comments"`
	Mask           bool `json:"mask"             cli:"mask"`
	MaxLines       int  `json:"max_lines"        cli:"max-lines"`
	MaxLinesHead   int  `json:"max_lines_head"`
	MaxLinesTail   int  `json:"max_lines_tail"`
	ExportedOnly   bool `json:"exported_only"`
	TrimIndent     bool `json:"trim_indent"`
	TrimBlankLines bool `json:"trim_blank_lines"`
}

type ClipboardConfig

type ClipboardConfig struct {
	Enabled bool `json:"enabled"`
	Quiet   bool `json:"quiet"`
}

func (*ClipboardConfig) UnmarshalJSON

func (cfg *ClipboardConfig) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts Flow v0.10 modifier values, which arrive as strings, as well as boolean values from direct Go callers.

type FileState

type FileState struct {
	Hash    string    `json:"hash"`
	ModTime time.Time `json:"mod_time"`
	Size    int64     `json:"size"`
}

FileState is one file's last-seen hash and metadata. Keyed by RelPath in StateCache so the cache is portable across machines.

type GitChangedPathsRequest

type GitChangedPathsRequest struct {
	Root   string    `json:"root"`
	Filter GitFilter `json:"filter"`
}

GitChangedPathsRequest selects changed paths using a Git change filter.

type GitFilter

type GitFilter struct {
	Since    string `json:"since"`
	Modified bool   `json:"modified"`
	Staged   bool   `json:"staged"`
}

GitFilter selects which Git change sets to include. Since takes precedence over Modified; Staged is additive to either selection.

func (GitFilter) Active

func (f GitFilter) Active() bool

type GitLSFilesRequest

type GitLSFilesRequest struct {
	Root string `json:"root"`
}

GitLSFilesRequest asks Git for untracked, non-ignored working-tree paths.

type Guardrails

type Guardrails struct {
	MaxFileSize  int64
	MaxFilesScan int64
	// contains filtered or unexported fields
}

Guardrails enforces per-scan safety limits. A non-positive limit is treated as "use the default" rather than "unlimited" — an unbounded scan is never the caller's intent.

func NewGuardrails

func NewGuardrails(maxFileSize, maxFilesScan int64) *Guardrails

NewGuardrails returns a Guardrails with defaults applied for any non-positive limit.

func (*Guardrails) CheckFile

func (g *Guardrails) CheckFile(path string, info os.FileInfo) error

CheckFile counts the file against MaxFilesScan and rejects files larger than MaxFileSize with xerr.Forbidden. A nil receiver is a no-op so callers can disable the limits.

type OutputEnvelope

type OutputEnvelope struct {
	Policy        OutputPolicy `json:"policy"`
	Content       string       `json:"content"`
	Status        string       `json:"status,omitempty"`
	RenderedItems int          `json:"rendered_items"`
	ReportPrefix  string       `json:"report_prefix,omitempty"`
	ReportSuffix  string       `json:"report_suffix,omitempty"`
}

OutputEnvelope carries the content and policy through output actions.

type OutputPolicy

type OutputPolicy struct {
	Mode            string `json:"mode"`
	SaveState       bool   `json:"save_state"`
	Path            string `json:"path"`
	Copy            bool   `json:"copy"`
	Quiet           bool   `json:"quiet"`
	JSON            bool   `json:"json"`
	TrailingNewline bool   `json:"trailing_newline"`
	StartedAt       int64  `json:"started_at"`
}

OutputPolicy describes the already-resolved output behavior. Actions execute the selected operation; they do not choose which operations are appropriate.

type PackConfig

type PackConfig struct {
	Targets        []string          `json:"targets" cli:"targets,target,t"`
	Files          []string          `json:"files" cli:"files,file,f"`
	TargetProfiles map[string]string `json:"target_profiles"`
	TargetExcludes map[string]string `json:"target_excludes"`
	TargetPrompts  map[string]string `json:"target_prompts"`
	// Remote materialization keeps filesystem roots separate from stable labels.
	TargetRoots    map[string]string `json:"target_roots,omitempty"`
	TargetLabels   map[string]string `json:"target_labels,omitempty"`
	Ext            string            `json:"ext" cli:"ext"`
	Tests          bool              `json:"tests" cli:"tests"`
	NoTests        bool              `json:"no_tests" cli:"no-tests"`
	NoGenerated    bool              `json:"no_generated" cli:"no-generated"`
	NoDeps         bool              `json:"no_deps" cli:"no-deps"`
	NoExamples     bool              `json:"no_examples" cli:"no-examples"`
	Examples       []string          `json:"examples"`
	Comments       bool              `json:"comments" cli:"comments"`
	OnlySig        bool              `json:"only_sig" cli:"only-sig"`
	Dense          bool              `json:"dense" cli:"dense"`
	Mask           bool              `json:"mask" cli:"mask"`
	MaxLines       int               `json:"max_lines" cli:"max-lines"`
	MaxLinesHead   int               `json:"max_lines_head"`
	MaxLinesTail   int               `json:"max_lines_tail"`
	TrimBlankLines bool              `json:"trim_blank_lines" cli:"trim-blank-lines"`
	TrimIndent     bool              `json:"trim_indent" cli:"trim-indent"`
	ExportedOnly   bool              `json:"exported_only" cli:"exported-only"`
	Exclude        string            `json:"exclude" cli:"exclude,x"`
	Prompt         string            `json:"prompt" cli:"prompt"`
	Editor         string            `json:"editor" cli:"editor,e"`
	Output         string            `json:"output" cli:"o,output"`
	Copy           bool              `json:"copy" cli:"copy,c"`
	NoCopy         bool              `json:"no_copy" cli:"no-copy"`
	TreeOnly       bool              `json:"tree_only" cli:"tree-only"`
	FullTree       bool              `json:"full_tree" cli:"full-tree"`
	Depth          int               `json:"depth" cli:"depth,L"`
	Changed        bool              `json:"changed" cli:"changed,m"`
	Since          string            `json:"since" cli:"since"`
	Modified       bool              `json:"modified"`
	Staged         bool              `json:"staged"`
	DiffOnly       bool              `json:"diff_only"`
	DiffContent    string            `json:"diff_content"`
	Quiet          bool              `json:"quiet" cli:"quiet,q"`
	Color          string            `json:"color" cli:"color"`
	CostROI        bool              `json:"cost"`
	DirPrefix      bool              `json:"dir_prefix"`
	NoHeader       bool              `json:"no_header"`
	NoPrompt       bool              `json:"no_prompt"`
	NoStart        bool              `json:"no_start"`
	NoEnd          bool              `json:"no_end"`

	MaxFileSize  int64 `json:"max_file_size"`
	MaxFilesScan int64 `json:"max_files_scan"`

	DenseOverride    *bool `json:"dense_override"`
	OnlySigOverride  *bool `json:"only_sig_override"`
	CommentsOverride *bool `json:"comments_override"`
	NoTestsOverride  *bool `json:"no_tests_override"`
}

type PackStats

type PackStats struct {
	FileCount       int
	FuncCount       int
	PackedBytes     int64
	RawBytes        int64
	EstimatedTokens int64
}

PackStats is the shared aggregate contract for terminal summaries and rendered-document placeholders. AggregatePackStats remains the Go reference for NFlow-fold parity and the fallback used by legacy stream callers.

func AggregatePackStats

func AggregatePackStats(files []ParsedFile) PackStats

AggregatePackStats computes the totals for files that contribute content to a pack. Omitted files and empty signature-only results are intentionally excluded, matching both the terminal summary and document header behavior.

func (PackStats) SavedPercent

func (stats PackStats) SavedPercent() float64

SavedPercent returns the fraction of raw input bytes removed by packing. Zero-sized input reports 0, preserving the existing summary semantics.

type ParseOptions

type ParseOptions struct {
	OnlySig        bool
	Dense          bool
	Comments       bool
	Mask           bool
	MaxLines       int
	MaxLinesHead   int
	MaxLinesTail   int
	ExportedOnly   bool
	TrimIndent     bool
	TrimBlankLines bool
}

type ParsedFile

type ParsedFile struct {
	fs.FileMeta
	Content         []byte
	Snippets        []string
	FuncCount       int
	Lines           int
	IsRaw           bool
	IsFull          bool
	Omitted         bool
	OmitReason      string
	Hash            string
	AbsPath         string
	Profile         string
	Prompt          string
	ParseOptions    ParseOptions
	ParseOptionsSet bool
}

type RenderConfig

type RenderConfig struct {
	Editor string `json:"editor"`
	Prompt string `json:"prompt"`

	Start     string `json:"start"`
	End       string `json:"end"`
	FileStart string `json:"file_start"`
	FileEnd   string `json:"file_end"`

	ProfileName string `json:"profile_name"`
	Targets     string `json:"targets"`
	Dirs        string `json:"dirs"`
	OutputFile  string `json:"output_file"`
	PromptName  string `json:"prompt_name"`
	GitCommit   string `json:"git_commit"`
	GitTag      string `json:"git_tag"`
	GitBranch   string `json:"git_branch"`
	CurrentDate string `json:"current_date"`
	Directory   string `json:"directory"`
	DiffContent string `json:"diff_content"`

	NoHeader  bool   `json:"no_header"`
	NoPrompt  bool   `json:"no_prompt"`
	NoStart   bool   `json:"no_start"`
	NoEnd     bool   `json:"no_end"`
	Tree      bool   `json:"tree"`
	FullTree  bool   `json:"full_tree"`
	TreeFiles bool   `json:"tree_files"`
	TreeDepth string `json:"tree_depth"`
}

RenderConfig controls srcpack.render. Fields with no JSON tag left in the struct are intentionally absent: this operator receives its values from CLI modifiers, and modifier values are strings. Bool fields use bare modifiers (:no_header); string fields use :k="v".

type SaveStateConfig

type SaveStateConfig struct {
	Enabled *bool `json:"enabled"`
}

func (*SaveStateConfig) UnmarshalJSON

func (cfg *SaveStateConfig) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts Flow modifier boolean strings as well as JSON booleans.

type StatEntry

type StatEntry struct {
	RelPath   string
	Size      int64
	FuncCount int
}

type StateCache

type StateCache struct {
	LastRun time.Time            `json:"last_run"`
	Files   map[string]FileState `json:"files"`
}

StateCache is the on-disk form of the incremental cache.

func LoadState

func LoadState(path string) *StateCache

LoadState reads the cache from path. A missing or unreadable file returns (nil, nil) — the cache is best-effort, never authoritative. A corrupt file is also treated as absent.

func (*StateCache) IsChanged

func (s *StateCache) IsChanged(relPath, absPath string, modTime time.Time) (bool, error)

IsChanged reports whether relPath needs reprocessing. A file not present in the cache is always considered changed. An unchanged ModTime short-circuits the hash comparison.

type StatsCollectConfig

type StatsCollectConfig struct {
	TreeOnly    bool             `json:"tree_only"  cli:"tree-only"`
	CommandLine string           `json:"command_line"`
	FullTree    bool             `json:"full_tree"  cli:"full-tree"`
	TreeFiles   bool             `json:"tree_files" cli:"tree-files"`
	Depth       string           `json:"depth"      cli:"depth"`
	Quiet       bool             `json:"quiet"      cli:"quiet"`
	Color       string           `json:"color"      cli:"color"`
	Profile     string           `json:"profile"    cli:"profile"`
	Targets     string           `json:"targets"    cli:"targets"`
	Prompt      string           `json:"prompt"     cli:"prompt"`
	Editor      string           `json:"editor"     cli:"editor"`
	Directory   string           `json:"directory"  cli:"directory"`
	Output      string           `json:"output"     cli:"output"`
	Clipboard   string           `json:"clipboard"  cli:"clipboard"`
	StartedAt   string           `json:"started_at" cli:"started-at"`
	ShowCost    bool             `json:"cost"       cli:"cost"`
	Pricing     []map[string]any `json:"pricing"`
}

Jump to

Keyboard shortcuts

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