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
Property | Type |
---|---|
file_path | string |
range | object |
range.end | object |
range.end.charOffset | number |
range.start | object |
range.start.charOffset | number |
Extraction
Values extracted from inside a file, with positional information.
Properties
Property | Type | Description |
---|---|---|
content | string | The literal string content found at the given range in the file. |
file_path | string | - |
range | Range | - |
variable | string | - |
ApplySettings
ApplySettings:
object
Settings for applying a GritQL pattern.
Type declaration
Member | Type | Description |
---|---|---|
extract ? | string [] | Metavariables you want to extract the value of.<br /><br />Example<br /><br />['$name', '$my_function'] |
maxResults ? | number | The maximum number of files with matches to return.<br />If set, Grit will stop searching after this many files are returned. |
query | string | The 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
Parameter | Type |
---|---|
arg | ApplySettings |
options | StepInputOptions |
Returns
Promise
< {files
: string
[]; matches
: ApplyMatch
[]; outputs
: Extraction
[]; success
: true
;} | {message
: string
; success
: false
;} >
check
CheckItem
A standardized name/level identifier for a check criterion, such as a GritQL pattern.
Properties
Property | Type |
---|---|
level | EnforcementLevel |
name | string |
CheckSettings
Properties
Property | Type | Description |
---|---|---|
level ? | EnforcementLevel | The minimum level of enforcement to check.<br /><br />Default<br /><br />'warn' |
CheckResult
CheckResult:
object
Type declaration
Member | Type | Description |
---|---|---|
__typename | "CheckResult" | - |
checks | CheckItem [] | Criteria that were validated by the check. |
data | undefined | Record < string , any > | - |
message | undefined | string | - |
outcome | undefined | "failure" | "success" | "skipped" | - |
rewriteMessages | RewriteLike [] | - |
success | boolean | - |
check
check(
arg
,options
):Promise
<CheckResult
| {message
:string
;success
:false
;} >
Run all enforced GritQL patterns on a repository.
Parameters
Parameter | Type |
---|---|
arg | CheckSettings |
options | StepInputOptions |
Returns
Promise
< CheckResult
| {message
: string
; success
: false
;} >
getcontext
WorkflowContextResult
The result of getting the current workflow context.
Extends
Properties
Property | Type | Description |
---|---|---|
__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. |
paths | string [] | The current paths targeted by the workflow. |
success | true | - |
getContext
getContext(
arg
,options
):Promise
<WorkflowContextResult
| {message
:string
;success
:false
;} >
Get info about the current execution context.
Parameters
Parameter | Type |
---|---|
arg | object |
options | StepInputOptions |
Returns
Promise
< WorkflowContextResult
| {message
: string
; success
: false
;} >
llm
ChatMessage
ChatMessage:
object
Type declaration
Member | Type |
---|---|
content | string |
role | "user" | "system" | "assistant" |
LLMQuery
LLMQuery:
object
Settings for an LLM call
Type declaration
Member | Type |
---|---|
messages | ChatMessage [] |
model | SupportedModel |
LLMResult
LLMResult:
object
Result of running an LLM call
Type declaration
Member | Type |
---|---|
parsed ? | any |
result | string |
success | true |
llm
llm(
settings
,options
):Promise
<LLMResult
| {message
:string
;success
:false
;} >
Retrieve a result from an LLM call
Parameters
Parameter | Type |
---|---|
settings | LLMQuery |
options | Omit < StepInputOptions , "paths" > |
Returns
Promise
< LLMResult
| {message
: string
; success
: false
;} >
query
QueryResult
QueryResult:
object
Result of running a query on synthetic files
Type declaration
Member | Type |
---|---|
matches | ApplyResult ["matches" ] |
success | true |
QuerySettings
QuerySettings:
object
Settings for a query
Type declaration
Member | Type | Description |
---|---|---|
files | RichFile [] | Synthetic files to apply the query to. |
query | string | The GritQL pattern to apply. |
query
query(
settings
,options
):Promise
<QueryResult
| {message
:string
;success
:false
;} >
Apply a GritQL pattern to input files.
Parameters
Parameter | Type |
---|---|
settings | QuerySettings |
options | Omit < StepInputOptions , "paths" > |
Returns
Promise
< QueryResult
| {message
: string
; success
: false
;} >
readFiles
ReadFilesResult
ReadFilesResult:
object
The result of reading multiple files.
Type declaration
Member | Type |
---|---|
success | boolean |
readFiles
readFiles(
arg
,options
):Promise
<ReadFilesResult
| {message
:string
;success
:false
;} >
Reads multiple files from the current workspace.
Parameters
Parameter | Type | Description |
---|---|---|
arg | object | - |
arg.paths | string [] | An array of relative paths to the files within the workspace |
options | StepInputOptions | - |
Returns
Promise
< ReadFilesResult
| {message
: string
; success
: false
;} >
readfile
ReadFileResult
ReadFileResult:
object
The result of reading a file.
Type declaration
Member | Type |
---|---|
success | boolean |
readFile
readFile(
arg
,options
):Promise
<ReadFileResult
| {message
:string
;success
:false
;} >
Reads a file from the current workspace.
Parameters
Parameter | Type | Description |
---|---|---|
arg | object | - |
arg.path | string | The relative path to the file within the workspace |
options | StepInputOptions | - |
Returns
Promise
< ReadFileResult
| {message
: string
; success
: false
;} >
removeFiles
RemoveFilesResult
RemoveFilesResult:
object
The result of removing a file.
Type declaration
Member | Type |
---|---|
success | boolean |
RemoveFilesSettings
RemoveFilesSettings:
object
Settings for removing files.
Type declaration
Member | Type | Description |
---|---|---|
ephemeral ? | boolean | If true, omit the removals from workflow history |
paths | FilePath [] | - |
removeFiles
removeFiles(
arg
,options
):Promise
<RemoveFilesResult
| {message
:string
;success
:false
;} >
Remove files from the current workspace.
Parameters
Parameter | Type |
---|---|
arg | RemoveFilesSettings |
options | StepInputOptions |
Returns
Promise
< RemoveFilesResult
| {message
: string
; success
: false
;} >
transform
TransformPair
A pair of before and after examples.
Example
[{ input: 'console.log("hello world')', replacements: ['winston.log'] }]
Properties
Property | Type | Description |
---|---|---|
input | string | Sample "before" input. |
replacements | string [] | 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
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
Member | Type | Description |
---|---|---|
examples | TransformPair [] | 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 ? | boolean | If 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' |
objective | string | The natural language objective of the transform, e.g. "use winston instead of console.log" |
principles | string [] | The principles that the transform should follow, e.g. "Preserve equivalent log levels" |
query | string | The 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
Parameter | Type |
---|---|
arg | TransformSettings |
options | StepInputOptions |
Returns
Promise
< {fileHistory
: TransformHistory
; message
: string
; paths
: string
[]; success
: true
; warnings
: boolean
;} | {message
: string
; success
: false
;} >
writeFile
writeFile
writeFile(
arg
,options
):Promise
<WriteFileResult
| {message
:string
;success
:false
;} >
Write a file to the current workspace.
Parameters
Parameter | Type |
---|---|
arg | RichFile |
options | StepInputOptions |
Returns
Promise
< WriteFileResult
| {message
: string
; success
: false
;} >
writeFiles
WriteFileResult
WriteFileResult:
object
Write a single file result
Type declaration
Member | Type |
---|---|
success | boolean |
WriteFileSettings
WriteFileSettings:
object
Settings for writing files.
Type declaration
Member | Type |
---|---|
content | string |
path | string |
WriteFilesResult
WriteFilesResult:
object
The result of writing a set of files.
Type declaration
Member | Type |
---|---|
success | boolean |
WriteFilesSettings
WriteFilesSettings:
object
Settings for writing files.
Type declaration
Member | Type | Description |
---|---|---|
ephemeral ? | boolean | If true, omit the write from workflow history |
files | RichFile [] | - |
writeFiles
writeFiles(
arg
,options
):Promise
<WriteFilesResult
| {message
:string
;success
:false
;} >
Write files to the current workspace.
Parameters
Parameter | Type |
---|---|
arg | WriteFilesSettings |
options | StepInputOptions |
Returns
Promise
< WriteFilesResult
| {message
: string
; success
: false
;} >
Generated using TypeDoc and typedoc-plugin-markdown