tool

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package tool contains the concrete Lightcode tools and compatibility aliases for the engine-owned generic tool contracts.

Index

Constants

This section is empty.

Variables

View Source
var ErrDenied = enginetool.ErrDenied
View Source
var NewPendingQueue = enginetool.NewPendingQueue
View Source
var NewRegistry = enginetool.NewRegistry

Functions

func PermissionArg

func PermissionArg(toolName string, params map[string]any) string

PermissionArg pulls the permission-relevant argument from the tool params. File paths are resolved to absolute so they match against resolved rule patterns.

func PermissionArgAtRoot

func PermissionArgAtRoot(root, toolName string, params map[string]any) string

func PermissionCheckArg

func PermissionCheckArg(toolName string, params map[string]any) string

func PermissionCheckArgAtRoot

func PermissionCheckArgAtRoot(root, toolName string, params map[string]any) string

Types

type ApplyWriteResult

type ApplyWriteResult struct {
	UpdatedContent string
	Summary        string
}

ApplyWriteResult holds the result of a write applied to a string buffer.

func ApplyWrite

func ApplyWrite(content, path string) *ApplyWriteResult

ApplyWrite returns the result for a write_file applied to a buffer.

type ArgumentNormalizer

type ArgumentNormalizer = enginetool.ArgumentNormalizer

type AskActionFunc

type AskActionFunc func(ctx context.Context, req permission.Request) permission.ResponseAction

AskActionFunc blocks until the user answers a staged permission prompt.

type AskFunc

AskFunc blocks until the user responds to a permission prompt. Returns a response action from the user.

type BatchResult

type BatchResult = enginetool.BatchResult

type CheckFunc

type CheckFunc func(toolName, arg string) permission.Decision

CheckFunc evaluates rules for a tool call and returns a Decision.

type DefaultPendingCoordinator

type DefaultPendingCoordinator = enginetool.DefaultPendingCoordinator

func NewPendingCoordinator

func NewPendingCoordinator(executor PendingExecutor) *DefaultPendingCoordinator

NewPendingCoordinator returns the default pending flush coordinator.

type DiagFileMeta

type DiagFileMeta struct {
	OriginalPath string
}

type DiagStore

type DiagStore interface {
	CurrentTurn() int
	ListTurns() ([]DiagTurnEntry, error)
}

type DiagTurnEntry

type DiagTurnEntry struct {
	Turn  int
	Files []DiagFileMeta
}

type DiagnosticsClient

type DiagnosticsClient interface {
	GetDiagnostics(ctx context.Context, paths []string) (string, error)
}

type DisplayMetadataProvider

type DisplayMetadataProvider = enginetool.DisplayMetadataProvider

type EditBufferResult

type EditBufferResult struct {
	UpdatedContent string
	Summary        string
	LineRanges     string
	Count          int
}

EditBufferResult holds the result of an edit applied to a string buffer.

func ApplyEdit

func ApplyEdit(content, oldString, newString string, replaceAll bool, path string) (*EditBufferResult, error)

ApplyEdit performs a string replacement on content without touching the filesystem. Used by the staging system to apply sequential edits to a running buffer.

type EditFile

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

EditFile implements the edit_file tool with mtime enforcement, O(1) results with line ranges, and pending support.

func NewEditFile

func NewEditFile(tracker *FileTracker, cfg config.ToolsConfig) *EditFile

NewEditFile creates an EditFile tool.

func NewEditFileAtRoot

func NewEditFileAtRoot(tracker *FileTracker, cfg config.ToolsConfig, workspaceRoot string) *EditFile

func (*EditFile) Description

func (e *EditFile) Description() string

func (*EditFile) DisplayMetadata

func (e *EditFile) DisplayMetadata(_ context.Context, args json.RawMessage, result string) map[string]any

func (*EditFile) Execute

func (e *EditFile) Execute(_ context.Context, params map[string]any) (string, error)

func (*EditFile) Name

func (e *EditFile) Name() string

func (*EditFile) ParametersSchema

func (e *EditFile) ParametersSchema() map[string]any

func (*EditFile) SetToolsConfig added in v0.0.2

func (e *EditFile) SetToolsConfig(cfg config.ToolsConfig)

func (*EditFile) StagedResultMessage

func (e *EditFile) StagedResultMessage() string

func (*EditFile) ValidateStaged

func (e *EditFile) ValidateStaged(_ context.Context, args json.RawMessage) error

type EditFileWithSnapshot

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

EditFileWithSnapshot wraps EditFile so the pre-edit file content is captured by the snapshot store before the edit is applied.

func NewEditFileWithSnapshot

func NewEditFileWithSnapshot(store SnapshotStore, tracker *FileTracker, cfg config.ToolsConfig) *EditFileWithSnapshot

NewEditFileWithSnapshot returns a snapshot-aware edit_file tool.

func NewEditFileWithSnapshotAtRoot

func NewEditFileWithSnapshotAtRoot(store SnapshotStore, tracker *FileTracker, cfg config.ToolsConfig, workspaceRoot string) *EditFileWithSnapshot

func (*EditFileWithSnapshot) Description

func (*EditFileWithSnapshot) Description() string

func (*EditFileWithSnapshot) DisplayMetadata

func (*EditFileWithSnapshot) DisplayMetadata(_ context.Context, args json.RawMessage, result string) map[string]any

func (*EditFileWithSnapshot) Execute

func (e *EditFileWithSnapshot) Execute(_ context.Context, params map[string]any) (string, error)

func (*EditFileWithSnapshot) Name

func (*EditFileWithSnapshot) Name() string

func (*EditFileWithSnapshot) ParametersSchema

func (*EditFileWithSnapshot) ParametersSchema() map[string]any

func (*EditFileWithSnapshot) SetToolsConfig added in v0.0.2

func (e *EditFileWithSnapshot) SetToolsConfig(cfg config.ToolsConfig)

func (*EditFileWithSnapshot) StagedResultMessage

func (*EditFileWithSnapshot) StagedResultMessage() string

func (*EditFileWithSnapshot) ValidateStaged

func (*EditFileWithSnapshot) ValidateStaged(_ context.Context, args json.RawMessage) error

type ExecutePending

type ExecutePending struct{}

ExecutePending implements the execute_pending tool. The actual flush is handled by the loop's dispatch; this tool is registered for schema visibility but Execute is a no-op.

func (ExecutePending) Description

func (ExecutePending) Description() string

func (ExecutePending) Execute

func (ExecutePending) Execute(_ context.Context, params map[string]any) (string, error)

func (ExecutePending) Name

func (ExecutePending) Name() string

func (ExecutePending) ParametersSchema

func (ExecutePending) ParametersSchema() map[string]any

type ExitError

type ExitError = enginetool.ExitError

type FileChangedError

type FileChangedError struct {
	Path string
}

FileChangedError is returned when a file was modified since last read.

func (*FileChangedError) Error

func (e *FileChangedError) Error() string

type FileIdentity

type FileIdentity struct {
	Mtime   time.Time
	Ctime   time.Time
	Dev     uint64
	Ino     uint64
	Mode    os.FileMode
	Hash    [32]byte
	Valid   bool
	HasHash bool
}

FileIdentity records the kernel identity of a file observed through an already-open descriptor.

func FileIdentityFromFileInfo

func FileIdentityFromFileInfo(info os.FileInfo) FileIdentity

func FileIdentityFromFileInfoAndData

func FileIdentityFromFileInfoAndData(info os.FileInfo, data []byte) FileIdentity

func FileIdentityFromOpenFile

func FileIdentityFromOpenFile(f *os.File, info os.FileInfo) (FileIdentity, error)

type FileTracker

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

FileTracker tracks which files have been read and their mtimes. It is populated from conversation history on session load and updated by read_file executions.

func NewFileTracker

func NewFileTracker() *FileTracker

NewFileTracker returns an empty FileTracker.

func (*FileTracker) HasRead

func (t *FileTracker) HasRead(path string) bool

func (*FileTracker) IsDuplicateIdentity

func (t *FileTracker) IsDuplicateIdentity(path string, offset, limit int, current FileIdentity) (bool, ReadRecord)

IsDuplicateIdentity checks duplicate status against identity metadata from an already-opened file.

func (*FileTracker) PopulateFromMessages

func (t *FileTracker) PopulateFromMessages(messages []PersistedMessage)

PopulateFromMessages scans historical tool result messages and marks read_file paths as having been read. Since we don't have mtime in persisted messages, we mark them with a zero time, which means the "was read" check passes but "modified since" check always fails (forces a re-read on first edit after session load).

func (*FileTracker) Reset

func (t *FileTracker) Reset()

Reset clears all tracked reads. Call this when visible conversation history changes so hidden or old reads cannot authorize future edits.

func (*FileTracker) Restore

func (t *FileTracker) Restore(reads []ReadRecord)

Restore resets the tracker to a prior read snapshot.

func (*FileTracker) Snapshot

func (t *FileTracker) Snapshot() []ReadRecord

Snapshot returns a copy of the tracked read state.

func (*FileTracker) TrackIdentity

func (t *FileTracker) TrackIdentity(path string, offset, limit int, identity FileIdentity)

TrackIdentity records a read using identity metadata from the already-opened file.

func (*FileTracker) UpdateAfterWriteIdentity

func (t *FileTracker) UpdateAfterWriteIdentity(path string, identity FileIdentity)

UpdateAfterWriteIdentity refreshes the tracked identity using metadata from the already-opened file after a successful write.

func (*FileTracker) WasReadCheckIdentity

func (t *FileTracker) WasReadCheckIdentity(path string, current FileIdentity) error

WasReadCheckIdentity checks read authorization against identity metadata from an already-opened file.

type HistorySearcher

type HistorySearcher interface {
	SearchHistory(query, projectID string, allProjects bool, limit int) ([]memory.HistoryResult, error)
}

type LSPDiagnostics

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

func NewLSPDiagnostics

func NewLSPDiagnostics(client DiagnosticsClient, store DiagStore) *LSPDiagnostics

func (*LSPDiagnostics) Description

func (t *LSPDiagnostics) Description() string

func (*LSPDiagnostics) Execute

func (t *LSPDiagnostics) Execute(ctx context.Context, params map[string]any) (string, error)

func (*LSPDiagnostics) Name

func (t *LSPDiagnostics) Name() string

func (*LSPDiagnostics) ParametersSchema

func (t *LSPDiagnostics) ParametersSchema() map[string]any

func (*LSPDiagnostics) Reset

func (t *LSPDiagnostics) Reset()

type MemorySaver

type MemorySaver interface {
	SaveMemory(memoriesDir, title, content string) (string, error)
}

type MemorySearcher

type MemorySearcher interface {
	SearchMemory(query, projectID string, allProjects bool, limit int) ([]memory.MemoryResult, error)
}

type PendingCoordinator

type PendingCoordinator = enginetool.PendingCoordinator

type PendingExecutor

type PendingExecutor = enginetool.PendingExecutor

type PendingQueue

type PendingQueue = enginetool.PendingQueue

type PermWrapped

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

PermWrapped wraps a Tool with permission enforcement. The wrapped tool's Execute is only called if the check allows it or the user approves via ask.

func WrapWithPermission

func WrapWithPermission(t Tool, check CheckFunc, ask AskFunc) *PermWrapped

WrapWithPermission wraps t so that every Execute call is gated by the check and ask functions.

func WrapWithPermissionAtRoot

func WrapWithPermissionAtRoot(t Tool, workspaceRoot string, check CheckFunc, ask AskFunc) *PermWrapped

func (*PermWrapped) Description

func (p *PermWrapped) Description() string

func (*PermWrapped) Execute

func (p *PermWrapped) Execute(ctx context.Context, params map[string]any) (string, error)

func (*PermWrapped) Name

func (p *PermWrapped) Name() string

func (*PermWrapped) ParametersSchema

func (p *PermWrapped) ParametersSchema() map[string]any

func (*PermWrapped) WrappedTool

func (p *PermWrapped) WrappedTool() Tool

type PersistedMessage

type PersistedMessage struct {
	Role     string
	ToolName string
	Path     string
}

PersistedMessage is a simplified message for tracker population.

type ProcessController

type ProcessController interface {
	Read(id string) (string, error)
	Kill(id string) error
	List() string
}

type ProcessManager

type ProcessManager interface {
	Start(command string, timeoutSec int) (id string, err error)
}

ProcessManager is the interface for background process management. The concrete implementation lives in internal/process/ and is wired in by the agent. May be nil if background process support is not loaded.

type ProcessTool

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

ProcessTool implements the process management tool for background commands.

func NewProcessTool

func NewProcessTool(mgr ProcessController) *ProcessTool

NewProcessTool creates a process management tool.

func (*ProcessTool) Description

func (*ProcessTool) Description() string

func (*ProcessTool) Execute

func (p *ProcessTool) Execute(_ context.Context, params map[string]any) (string, error)

func (*ProcessTool) Name

func (*ProcessTool) Name() string

func (*ProcessTool) ParametersSchema

func (*ProcessTool) ParametersSchema() map[string]any

type ReadFile

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

ReadFile implements the read_file tool with line-numbered output, pagination, byte caps, binary detection, mtime tracking, and re-read deduplication.

func NewReadFile

func NewReadFile(cfg config.ToolsConfig, tracker *FileTracker) *ReadFile

NewReadFile creates a ReadFile tool with the given config and tracker.

func NewReadFileAtRoot

func NewReadFileAtRoot(cfg config.ToolsConfig, tracker *FileTracker, workspaceRoot string) *ReadFile

func (*ReadFile) Description

func (r *ReadFile) Description() string

func (*ReadFile) Execute

func (r *ReadFile) Execute(_ context.Context, params map[string]any) (string, error)

func (*ReadFile) Name

func (r *ReadFile) Name() string

func (*ReadFile) ParametersSchema

func (r *ReadFile) ParametersSchema() map[string]any

func (*ReadFile) SetToolsConfig added in v0.0.2

func (r *ReadFile) SetToolsConfig(cfg config.ToolsConfig)

type ReadOnlyRunCommand

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

ReadOnlyRunCommand wraps RunCommand and restricts commands to a whitelist of non-destructive operations (ls, cat, grep, git log, etc.).

func NewReadOnlyRunCommand

func NewReadOnlyRunCommand(inner *RunCommand) *ReadOnlyRunCommand

NewReadOnlyRunCommand creates a read-only command tool.

func (*ReadOnlyRunCommand) Description

func (*ReadOnlyRunCommand) Description() string

func (*ReadOnlyRunCommand) Execute

func (r *ReadOnlyRunCommand) Execute(ctx context.Context, params map[string]any) (string, error)

func (*ReadOnlyRunCommand) Name

func (*ReadOnlyRunCommand) Name() string

func (*ReadOnlyRunCommand) ParametersSchema

func (r *ReadOnlyRunCommand) ParametersSchema() map[string]any

type ReadRecord

type ReadRecord struct {
	Path     string
	Offset   int
	Limit    int
	Identity FileIdentity
	Mtime    time.Time
}

ReadRecord records a read_file call for deduplication and edit enforcement.

type ReadRequiredError

type ReadRequiredError struct {
	Path string
}

ReadRequiredError is returned when a file was not read before editing.

func (*ReadRequiredError) Error

func (e *ReadRequiredError) Error() string

type Registry

type Registry = enginetool.Registry

type RunCommand

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

RunCommand implements the run_command tool.

func NewRunCommand

func NewRunCommand(cfg config.ToolsConfig, homeDir string, procMgr ProcessManager) *RunCommand

NewRunCommand creates a RunCommand tool.

func NewRunCommandAtRoot

func NewRunCommandAtRoot(cfg config.ToolsConfig, homeDir, workspaceRoot string, procMgr ProcessManager) *RunCommand

func (*RunCommand) Description

func (*RunCommand) Description() string

func (*RunCommand) Execute

func (r *RunCommand) Execute(ctx context.Context, params map[string]any) (string, error)

func (*RunCommand) Name

func (*RunCommand) Name() string

func (*RunCommand) ParametersSchema

func (*RunCommand) ParametersSchema() map[string]any

func (*RunCommand) SetToolsConfig added in v0.0.2

func (r *RunCommand) SetToolsConfig(cfg config.ToolsConfig)

type SaveMemory

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

func NewSaveMemory

func NewSaveMemory(store MemorySaver, memoriesDir string) *SaveMemory

func (*SaveMemory) Description

func (t *SaveMemory) Description() string

func (*SaveMemory) Execute

func (t *SaveMemory) Execute(_ context.Context, params map[string]any) (string, error)

func (*SaveMemory) Name

func (t *SaveMemory) Name() string

func (*SaveMemory) ParametersSchema

func (t *SaveMemory) ParametersSchema() map[string]any

type SearchHistory

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

func NewSearchHistory

func NewSearchHistory(store HistorySearcher, projectID string) *SearchHistory

func (*SearchHistory) Description

func (t *SearchHistory) Description() string

func (*SearchHistory) Execute

func (t *SearchHistory) Execute(_ context.Context, params map[string]any) (string, error)

func (*SearchHistory) Name

func (t *SearchHistory) Name() string

func (*SearchHistory) ParametersSchema

func (t *SearchHistory) ParametersSchema() map[string]any

type SearchMemory

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

func NewSearchMemory

func NewSearchMemory(store MemorySearcher, projectID string) *SearchMemory

func (*SearchMemory) Description

func (t *SearchMemory) Description() string

func (*SearchMemory) Execute

func (t *SearchMemory) Execute(_ context.Context, params map[string]any) (string, error)

func (*SearchMemory) Name

func (t *SearchMemory) Name() string

func (*SearchMemory) ParametersSchema

func (t *SearchMemory) ParametersSchema() map[string]any

type Sleep

type Sleep struct{}

Sleep implements a sleep/wait tool for the model to pause before checking background process output or waiting for servers.

func (Sleep) Description

func (Sleep) Description() string

func (Sleep) Execute

func (Sleep) Execute(ctx context.Context, params map[string]any) (string, error)

func (Sleep) Name

func (Sleep) Name() string

func (Sleep) NormalizeArguments

func (Sleep) NormalizeArguments(args json.RawMessage) (json.RawMessage, error)

func (Sleep) ParametersSchema

func (Sleep) ParametersSchema() map[string]any

type SnapshotStore

type SnapshotStore interface {
	Snapshot(turn int, absPath string) error
	CurrentTurn() int
}

SnapshotStore is the minimum surface WriteFileWithSnapshot and EditFileWithSnapshot need from the snapshot store.

type StageableTool

type StageableTool = enginetool.StageableTool

type StagedCall

type StagedCall = enginetool.StagedCall

type StagedExecutor

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

StagedExecutor executes pending edit/write calls as a batch while preserving the normal permission, snapshot, and read-before-edit rules.

func NewStagedExecutor

func NewStagedExecutor(store SnapshotStore, tracker *FileTracker, cfg config.ToolsConfig, check CheckFunc, ask AskActionFunc) *StagedExecutor

NewStagedExecutor creates a staged batch executor.

func NewStagedExecutorAtRoot

func NewStagedExecutorAtRoot(store SnapshotStore, tracker *FileTracker, cfg config.ToolsConfig, workspaceRoot string, check CheckFunc, ask AskActionFunc) *StagedExecutor

func (*StagedExecutor) ExecutePending

func (e *StagedExecutor) ExecutePending(ctx context.Context, staged []StagedCall) []BatchResult

ExecutePending applies staged calls in emission order, using a running buffer per file and a single final disk write per changed file.

func (*StagedExecutor) SetToolsConfig added in v0.0.2

func (e *StagedExecutor) SetToolsConfig(cfg config.ToolsConfig)

type Tool

type Tool = enginetool.Tool

type ToolCall

type ToolCall = enginetool.ToolCall

type WorkspaceSymbol

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

func NewWorkspaceSymbol

func NewWorkspaceSymbol(client WorkspaceSymbolClient) *WorkspaceSymbol

func (*WorkspaceSymbol) Description

func (t *WorkspaceSymbol) Description() string

func (*WorkspaceSymbol) Execute

func (t *WorkspaceSymbol) Execute(ctx context.Context, params map[string]any) (string, error)

func (*WorkspaceSymbol) Name

func (t *WorkspaceSymbol) Name() string

func (*WorkspaceSymbol) ParametersSchema

func (t *WorkspaceSymbol) ParametersSchema() map[string]any

type WorkspaceSymbolClient

type WorkspaceSymbolClient interface {
	WorkspaceSymbol(ctx context.Context, query string) (string, error)
}

type WriteFile

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

WriteFile implements the write_file tool with mtime enforcement and pending support.

func NewWriteFile

func NewWriteFile(tracker *FileTracker, cfg config.ToolsConfig) *WriteFile

NewWriteFile creates a WriteFile tool.

func NewWriteFileAtRoot

func NewWriteFileAtRoot(tracker *FileTracker, cfg config.ToolsConfig, workspaceRoot string) *WriteFile

func (*WriteFile) Description

func (w *WriteFile) Description() string

func (*WriteFile) Execute

func (w *WriteFile) Execute(_ context.Context, params map[string]any) (string, error)

func (*WriteFile) Name

func (w *WriteFile) Name() string

func (*WriteFile) ParametersSchema

func (w *WriteFile) ParametersSchema() map[string]any

func (*WriteFile) SetToolsConfig added in v0.0.2

func (w *WriteFile) SetToolsConfig(cfg config.ToolsConfig)

func (*WriteFile) StagedResultMessage

func (w *WriteFile) StagedResultMessage() string

func (*WriteFile) ValidateStaged

func (w *WriteFile) ValidateStaged(_ context.Context, args json.RawMessage) error

type WriteFileWithSnapshot

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

WriteFileWithSnapshot wraps WriteFile so that every successful write is preceded by a call to the snapshot store.

func NewWriteFileWithSnapshot

func NewWriteFileWithSnapshot(store SnapshotStore, tracker *FileTracker, cfg config.ToolsConfig) *WriteFileWithSnapshot

NewWriteFileWithSnapshot returns a snapshot-aware write_file tool.

func NewWriteFileWithSnapshotAtRoot

func NewWriteFileWithSnapshotAtRoot(store SnapshotStore, tracker *FileTracker, cfg config.ToolsConfig, workspaceRoot string) *WriteFileWithSnapshot

func (*WriteFileWithSnapshot) Description

func (*WriteFileWithSnapshot) Description() string

func (*WriteFileWithSnapshot) Execute

func (w *WriteFileWithSnapshot) Execute(_ context.Context, params map[string]any) (string, error)

func (*WriteFileWithSnapshot) Name

func (*WriteFileWithSnapshot) Name() string

func (*WriteFileWithSnapshot) ParametersSchema

func (*WriteFileWithSnapshot) ParametersSchema() map[string]any

func (*WriteFileWithSnapshot) SetToolsConfig added in v0.0.2

func (w *WriteFileWithSnapshot) SetToolsConfig(cfg config.ToolsConfig)

func (*WriteFileWithSnapshot) StagedResultMessage

func (*WriteFileWithSnapshot) StagedResultMessage() string

func (*WriteFileWithSnapshot) ValidateStaged

func (*WriteFileWithSnapshot) ValidateStaged(_ context.Context, args json.RawMessage) error

Jump to

Keyboard shortcuts

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