Index > stdlib

Namespace: stdlib

Exposes the standard library of Grit steps.

These actions are included:

apply

ApplyMatch

A single match within a file. One file may have multiple matches.

Properties

PropertyType
file_pathstring
rangeobject
range.endobject
range.end.charOffsetnumber
range.startobject
range.start.charOffsetnumber

Extraction

Values extracted from inside a file, with positional information.

Properties

PropertyTypeDescription
contentstringThe literal string content found at the given range in the file.
file_pathstring-
rangeRange-
variablestring-

ApplySettings

ApplySettings: object

Settings for applying a GritQL pattern.

Type declaration

MemberTypeDescription
extract?string[]Metavariables you want to extract the value of.<br /><br />Example<br /><br />['$name', '$my_function']
maxResults?numberThe maximum number of files with matches to return.<br />If set, Grit will stop searching after this many files are returned.
querystringThe GritQL pattern to apply.

apply

apply(arg, options): Promise< {files: string[]; matches: ApplyMatch[]; outputs: Extraction[]; success: true;} | {message: string; success: false;} >

Apply a GritQL pattern to the given paths.

Parameters

ParameterType
argApplySettings
optionsStepInputOptions

Returns

Promise< {files: string[]; matches: ApplyMatch[]; outputs: Extraction[]; success: true;} | {message: string; success: false;} >

autoreview

AutoReviewRule

Rule information for the current repo

Properties

PropertyType
descriptionstring
idstring
levelEnforcementLevel
titlestring

RulesResult

Rule information for the current repo

Extends

Properties

PropertyType
__typename"RulesResult"
message?string
rulesAutoReviewRule[]
successboolean

getRules

getRules(arg, options): Promise< RulesResult | {message: string; success: false;} >

Get info about the current workflow execution context.

Parameters

ParameterType
argobject
arg.repoUrlstring
optionsStepInputOptions

Returns

Promise< RulesResult | {message: string; success: false;} >

check

CheckItem

A standardized name/level identifier for a check criterion, such as a GritQL pattern.

Properties

PropertyType
levelEnforcementLevel
namestring

CheckResult

Extends

Properties

PropertyTypeDescription
__typename"CheckResult"-
checksCheckItem[]Criteria that were validated by the check.
message?string-
rewriteMessagesRewriteLike[]-
successboolean-

CheckSettings

Properties

PropertyTypeDescription
level?EnforcementLevelThe minimum level of enforcement to check.<br /><br />Default<br /><br />'warn'

check

check(arg, options): Promise< CheckResult | {message: string; success: false;} >

Run all enforced GritQL patterns on a repository.

Parameters

ParameterType
argCheckSettings
optionsStepInputOptions

Returns

Promise< CheckResult | {message: string; success: false;} >

getcontext

WorkflowContextResult

The result of getting the current workflow context.

Extends

Properties

PropertyTypeDescription
__typename"WorkflowContextResult"-
message?string-
mode"regular" | "scan"The mode of the current execution context.<br />"regular" means actively running a workflow to generate changes.<br />"scan" means running a workflow to scan for issues, typically in a background context.
pathsstring[]The current paths targeted by the workflow.
successtrue-

getContext

getContext(arg, options): Promise< WorkflowContextResult | {message: string; success: false;} >

Get info about the current execution context.

Parameters

ParameterType
argobject
optionsStepInputOptions

Returns

Promise< WorkflowContextResult | {message: string; success: false;} >

heal_tailwind

HealTailwindOptions

Extends

Properties

PropertyTypeDescription
originalFilesTransformHistory-
pathsstring[]The paths that this workflow will operate on.<br /><br />Todo<br /><br />This should be a list of glob patterns.

heal_tailwind

heal_tailwind(arg, options): Promise< WorkflowResult | {message: string; success: false;} >

Heal malformed Tailwind CSS classes using AI

Parameters

ParameterType
argHealTailwindOptions
optionsStepInputOptions

Returns

Promise< WorkflowResult | {message: string; success: false;} >

llm

ChatMessage

ChatMessage: object

Type declaration

MemberType
contentstring
role"user" | "system" | "assistant"

LLMQuery

LLMQuery: object

Settings for an LLM call

Type declaration

MemberType
messagesChatMessage[]
modelSupportedModel

LLMResult

LLMResult: object

Result of running an LLM call

Type declaration

MemberType
parsed?any
resultstring
successtrue

llm

llm(settings, options): Promise< LLMResult | {message: string; success: false;} >

Retrieve a result from an LLM call

Parameters

ParameterType
settingsLLMQuery
optionsOmit< StepInputOptions, "paths" >

Returns

Promise< LLMResult | {message: string; success: false;} >

query

QueryResult

QueryResult: object

Result of running a query on synthetic files

Type declaration

MemberType
matchesApplyResult["matches"]
successtrue

QuerySettings

QuerySettings: object

Settings for a query

Type declaration

MemberTypeDescription
filesRichFile[]Synthetic files to apply the query to.
querystringThe GritQL pattern to apply.

query

query(settings, options): Promise< QueryResult | {message: string; success: false;} >

Apply a GritQL pattern to input files.

Parameters

ParameterType
settingsQuerySettings
optionsOmit< StepInputOptions, "paths" >

Returns

Promise< QueryResult | {message: string; success: false;} >

readFiles

ReadFilesResult

ReadFilesResult: object

The result of reading multiple files.

Type declaration

MemberType
successboolean

readFiles

readFiles(arg, options): Promise< ReadFilesResult | {message: string; success: false;} >

Reads multiple files from the current workspace.

Parameters

ParameterTypeDescription
argobject-
arg.pathsstring[]An array of relative paths to the files within the workspace
optionsStepInputOptions-

Returns

Promise< ReadFilesResult | {message: string; success: false;} >

readfile

ReadFileResult

ReadFileResult: object

The result of reading a file.

Type declaration

MemberType
successboolean

readFile

readFile(arg, options): Promise< ReadFileResult | {message: string; success: false;} >

Reads a file from the current workspace.

Parameters

ParameterTypeDescription
argobject-
arg.pathstringThe relative path to the file within the workspace
optionsStepInputOptions-

Returns

Promise< ReadFileResult | {message: string; success: false;} >

removeFiles

RemoveFilesResult

RemoveFilesResult: object

The result of removing a file.

Type declaration

MemberType
successboolean

RemoveFilesSettings

RemoveFilesSettings: object

Settings for removing files.

Type declaration

MemberTypeDescription
ephemeral?booleanIf true, omit the removals from workflow history
pathsFilePath[]-

removeFiles

removeFiles(arg, options): Promise< RemoveFilesResult | {message: string; success: false;} >

Remove files from the current workspace.

Parameters

ParameterType
argRemoveFilesSettings
optionsStepInputOptions

Returns

Promise< RemoveFilesResult | {message: string; success: false;} >

transform

TransformPair

A pair of before and after examples.

Example

TS
[{ input: 'console.log("hello world')', replacements: ['winston.log'] }]

Properties

PropertyTypeDescription
inputstringSample "before" input.
replacementsstring[]An array of replacements. A replacement should be provided for each match in the input.

TransformHistory

TransformHistory: object

Index signature

[key: FilePath]: TransformFileHistory


TransformSettings

TransformSettings: object

Settings for a particular transformation

Example

TS
const settings = {
  objective: 'Convert logging statements to winston.log',
  principles: ['Preserve equivalent log levels'],
  examples: [
    { input: 'console.log("hello world")', replacements: ['winston.log'] }
  ],
  query: `js"console.$_"`,
  model: 'fast',
};

Type declaration

MemberTypeDescription
examplesTransformPair[]Examples of the transform in action
formatter?"tagged" | "file" | "flex"Strategy used for formatting and chunking, default will intelligently choose the best strategy.<br /><br />Default<br /><br />'flex'
hideHistory?booleanIf set to true, skip the TransformHistory of original and modified snippets.
model?"fast" | "slow"The underlying model to use.<br /><br />Default<br /><br />'fast'
objectivestringThe natural language objective of the transform, e.g. "use winston instead of console.log"
principlesstring[]The principles that the transform should follow, e.g. "Preserve equivalent log levels"
querystringThe GritQL query to use for finding matches

transform

transform(arg, options): Promise< {fileHistory: TransformHistory; message: string; paths: string[]; success: true; warnings: boolean;} | {message: string; success: false;} >

Transform files using AI

Parameters

ParameterType
argTransformSettings
optionsStepInputOptions

Returns

Promise< {fileHistory: TransformHistory; message: string; paths: string[]; success: true; warnings: boolean;} | {message: string; success: false;} >

writeFiles

WriteFilesResult

WriteFilesResult: object

The result of writing a set of files.

Type declaration

MemberType
successboolean

WriteFilesSettings

WriteFilesSettings: object

Settings for writing files.

Type declaration

MemberTypeDescription
ephemeral?booleanIf true, omit the write from workflow history
filesRichFile[]-

writeFiles

writeFiles(arg, options): Promise< WriteFilesResult | {message: string; success: false;} >

Write files to the current workspace.

Parameters

ParameterType
argWriteFilesSettings
optionsStepInputOptions

Returns

Promise< WriteFilesResult | {message: string; success: false;} >


Generated using TypeDoc and typedoc-plugin-markdown