Skip to content

Commit eabe0fd

Browse files
committed
Add TLAi linter.
1 parent 3880110 commit eabe0fd

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

.github/workflows/tlaplus.yml

+36
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,39 @@ jobs:
108108
path: |
109109
tla/consistency/*_TTrace_*.tla
110110
tla/*.json
111+
112+
tlai-linter:
113+
runs-on: ubuntu-latest
114+
115+
env:
116+
## https://microsoft.github.io/genaiscript/reference/token/
117+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
118+
OPENAI_API_BASE: ${{ secrets.OPENAI_API_BASE }}
119+
OPENAI_API_TYPE: ${{ secrets.OPENAI_API_TYPE }}
120+
121+
steps:
122+
- name: Clone repo
123+
uses: actions/checkout@v4
124+
with:
125+
## All history for git diff below to succeed.
126+
fetch-depth: 0
127+
128+
- name: Setup NodeJS
129+
## https://github.com/actions/setup-node
130+
uses: actions/setup-node@v4
131+
with:
132+
node-version: "20"
133+
134+
- name: Run GenAIscript on the TLA+ specs that are added in this pull request.
135+
## Identify git diff: $(git diff --name-only HEAD^ | grep '.tla')
136+
## Install genaiscript runtime: https://microsoft.github.io/genaiscript/reference/cli/
137+
## Output LLM response in SARIF format: https://microsoft.github.io/genaiscript/reference/scripts/annotations/ (redirect other output to /dev/null for GH not to also show the annotations)
138+
run: npx --yes genaiscript run scripts/TLAi-linter.genai.js $(git diff --name-only HEAD^ | grep '.tla') --max-tokens 2000 --out-annotations results.sarif > /dev/null
139+
140+
- name: Upload SARIF file
141+
## https://sarifweb.azurewebsites.net
142+
## https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/uploading-a-sarif-file-to-github
143+
if: success() || failure()
144+
uses: github/codeql-action/upload-sarif@v3
145+
with:
146+
sarif_file: results.sarif

scripts/TLAi-linter.genai.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// learn more at https://aka.ms/genaiscript
2+
script({
3+
title: "TLAi-linter",
4+
description:
5+
"Check if the prose comments and their TLA+ declarations and definitions are syntactically and semantically consistent",
6+
});
7+
8+
// use def to emit LLM variables
9+
def(
10+
"TLA+",
11+
env.files.filter((f) => f.filename.endsWith(".tla")),
12+
{ lineNumbers: true },
13+
);
14+
15+
// use $ to output formatted text to the prompt
16+
$`You are an expert at TLA+/TLAPLUS. Your task is to check if the prose comments and their TLA+ declarations and definitions are syntactically and semantically consistent!!!
17+
Explain any consistencies and inconsistencies you may find. Report inconsistent and consistent pairs in a single ANNOTATION section.
18+
19+
## TLA+ Syntax Hints
20+
- A formula [A]_v is called a temporal formula, and is shorthand for the formula A \/ v' = v. In other words, the formula is true if A is true or if the value of v remains unchanged. Usually, v is a tuple of the spec's variables.
21+
- The symbol \`#\` is alternative syntax used for inequality in TLA+; the other symbol is \`/=\".
22+
23+
## TLA+ Semantics Hints
24+
- Do NOT add any invariants or properties to the behavior specification Spec or any of its subformulas. This would change THEOREM Spec => Inv into THEOREM Spec /\ Inv => Inv, which is vacuously true.
25+
- TLA+ specs are always stuttering insensitive, i.e., the next-state relation is always [A]_v. In other words, one cannot write a stuttering sensitive specification.
26+
27+
## TLA+ Convention Hints
28+
- The type correctness invariant is typically called TypeOK.
29+
- Users can employ TLA labels as a means to conceptually associate a comment with a sub-formula like a specific disjunct or conjunct of a TLA formula. Even though these labels have no other function, they facilitate referencing particular parts of the formula from a comment.
30+
31+
## Formal and informal math Hints
32+
- Take into account that humans may write informal math that is syntactically different from the formal math, yet semantically equivalent. For example, humans may write \`N > 3T\` instead of \`N > 3 * T\`.
33+
`;

0 commit comments

Comments
 (0)