FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
docs/scripts/check-documentation.py at main · agentsfleet/docs · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
agentsfleet
/
docs
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
docs
/
scripts
/
check-documentation.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
342 lines (313 loc) · 12.7 KB
Breadcrumbs
docs
/
scripts
/
check-documentation.py
Copy path
File metadata and controls
executable file
·
342 lines (313 loc) · 12.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#!/usr/bin/env python3
"""Check published MDX pages against the agentsfleet documentation rules."""
from
__future__
import
annotations
import
re
import
sys
from
pathlib
import
Path
PAGE_FIELDS
=
{
"type"
,
"audience"
,
"verified"
,
"executable"
,
}
FIELD_VALUES
=
{
"type"
: {
"tutorial"
,
"how-to"
,
"reference"
,
"explanation"
,
"troubleshooting"
},
"audience"
: {
"user"
,
"operator"
,
"contributor"
},
"executable"
: {
"true"
,
"false"
},
}
PAGE_SECTIONS
=
{
"tutorial"
: [
"What you will build"
,
"Before you begin"
,
"Steps"
,
"Verify it works"
,
"What you learned"
,
"Related pages"
,
],
"how-to"
: [
"What this does"
,
"Before you begin"
,
"Steps"
,
"Verify it works"
,
"Common problems"
,
"Remove or undo"
,
"Related pages"
,
],
"reference"
: [
"Synopsis"
,
"Example with output"
,
"Options"
,
"Errors"
,
"Related pages"
],
"explanation"
: [
"What it is"
,
"Why it exists"
,
"How it behaves"
,
"Limits"
,
"Related pages"
],
"troubleshooting"
: [
"Symptom"
,
"Why it happened"
,
"How to fix it"
,
"How to prevent it"
],
}
BANNED_PATTERNS
=
{
"utilise"
:
re
.
compile
(
r"\butilis(?:e|es|ed|ing)\b"
,
re
.
IGNORECASE
),
"facilitate"
:
re
.
compile
(
r"\bfacilitat(?:e|es|ed|ing)\b"
,
re
.
IGNORECASE
),
"leverage"
:
re
.
compile
(
r"\bleverag(?:e|es|ed|ing)\b"
,
re
.
IGNORECASE
),
"orchestrate"
:
re
.
compile
(
r"\borchestrat(?:e|es|ed|ing|ion)\b"
,
re
.
IGNORECASE
),
"instantiate"
:
re
.
compile
(
r"\binstantiat(?:e|es|ed|ing|ion)\b"
,
re
.
IGNORECASE
),
"terminate"
:
re
.
compile
(
r"\bterminat(?:e|es|ed|ing|ion|al)\b"
,
re
.
IGNORECASE
),
"provision"
:
re
.
compile
(
r"\bprovision(?:s|ed|ing)?\b"
,
re
.
IGNORECASE
),
"execute"
:
re
.
compile
(
r"\bexecut(?:e|es|ed|ing|ion)\b"
,
re
.
IGNORECASE
),
"persist"
:
re
.
compile
(
r"\bpersist(?:s|ed|ing|ent|ence)?\b"
,
re
.
IGNORECASE
),
"hydrate"
:
re
.
compile
(
r"\bhydrat(?:e|es|ed|ing|ion)\b"
,
re
.
IGNORECASE
),
"artifact"
:
re
.
compile
(
r"\bartifacts?\b"
,
re
.
IGNORECASE
),
**
{
word
:
re
.
compile
(
rf"\b
{
re
.
escape
(
word
)
}
\b"
,
re
.
IGNORECASE
)
for
word
in
(
"powerful"
,
"revolutionary"
,
"enterprise-grade"
,
"seamless"
,
"cutting-edge"
,
"robust"
,
"next-generation"
,
"world-class"
,
"intelligent"
,
)
},
}
MARKETING_WORDS
=
{
"powerful"
,
"revolutionary"
,
"enterprise-grade"
,
"seamless"
,
"cutting-edge"
,
"robust"
,
"next-generation"
,
"world-class"
,
"intelligent"
,
}
ACRONYM_ALLOWLIST
=
{
"API"
,
"CSS"
,
"DELETE"
,
"DNS"
,
"GET"
,
"HEAD"
,
"HTML"
,
"HTTP"
,
"IP"
,
"JSON"
,
"OPTIONS"
,
"OS"
,
"PATCH"
,
"POST"
,
"PUT"
,
"SQL"
,
"TCP"
,
"UDP"
,
"URL"
,
}
NON_PAGE_CODE_SNIPPETS
=
{
Path
(
"snippets/rates.mdx"
)}
ERROR_REFERENCE_PRIVATE_TERMS
=
{
"API_MAX_"
,
"DATABASE_URL"
,
"MEMORY_RUNTIME_URL"
,
"Postgres memory schema"
,
"REDIS_URL_API"
,
"SSE_MAX_"
,
"config_json"
,
"core.model_library"
,
"core.platform_provider_defaults"
,
"core.tenant_model_entries"
,
"err= field"
,
}
FRONTMATTER_BOUNDARY
=
"---"
FENCE_PATTERN
=
re
.
compile
(
r"^```([^\s]*)\s*$"
)
HEADING_PATTERN
=
re
.
compile
(
r"^(#{1,6})\s+(.+?)\s*$"
)
WORD_PATTERN
=
re
.
compile
(
r"\b[\w'-]+\b"
)
SENTENCE_PATTERN
=
re
.
compile
(
r"(?<=[.!?])(?:[\s]+|$)"
)
ACRONYM_PATTERN
=
re
.
compile
(
r"(?<![-_`])\b[A-Z][A-Z0-9]{1,5}\b(?![-_`])"
)
def
issue
(
rule
:
str
,
path
:
Path
,
line
:
int
,
message
:
str
)
->
str
:
return
f"
{
rule
}
{
path
}
:
{
line
}
:
{
message
}
"
def
split_frontmatter
(
text
:
str
)
->
tuple
[
dict
[
str
,
str
],
str
,
int
]:
lines
=
text
.
splitlines
()
if
not
lines
or
lines
[
0
]
!=
FRONTMATTER_BOUNDARY
:
return
{},
text
,
1
try
:
end
=
lines
.
index
(
FRONTMATTER_BOUNDARY
,
1
)
except
ValueError
:
return
{},
text
,
1
fields
:
dict
[
str
,
str
]
=
{}
for
line
in
lines
[
1
:
end
]:
if
":"
in
line
and
not
line
.
startswith
((
" "
,
"-"
)):
key
,
value
=
line
.
split
(
":"
,
1
)
fields
[
key
.
strip
()]
=
value
.
strip
().
strip
(
"
\"
'"
)
return
fields
,
"
\n
"
.
join
(
lines
[
end
+
1
:]),
end
+
2
def
visible_lines
(
body
:
str
)
->
list
[
tuple
[
int
,
str
]]:
result
:
list
[
tuple
[
int
,
str
]]
=
[]
in_fence
=
False
for
number
,
line
in
enumerate
(
body
.
splitlines
(),
1
):
if
FENCE_PATTERN
.
match
(
line
.
strip
()):
in_fence
=
not
in_fence
continue
if
in_fence
:
continue
stripped
=
line
.
lstrip
()
if
stripped
.
startswith
(
"{"
)
or
stripped
in
{
"*/"
,
"*/}"
}:
continue
heading
=
HEADING_PATTERN
.
match
(
line
)
if
heading
:
result
.
append
((
number
,
heading
.
group
(
2
)))
result
.
append
((
number
,
""
))
continue
if
stripped
.
startswith
(
"|"
):
cells
=
[
cell
.
strip
()
for
cell
in
stripped
.
strip
(
"|"
).
split
(
"|"
)]
if
cells
and
all
(
re
.
fullmatch
(
r":?-{3,}:?"
,
cell
)
for
cell
in
cells
):
continue
for
cell
in
cells
:
cleaned_cell
=
re
.
sub
(
r"`[^`]+`"
,
""
,
cell
)
cleaned_cell
=
re
.
sub
(
r"<[^>]+>"
,
""
,
cleaned_cell
)
cleaned_cell
=
re
.
sub
(
r"\[([^]]+)]\([^)]+\)"
,
r"\1"
,
cleaned_cell
)
cleaned_cell
=
re
.
sub
(
r"\*\*|__"
,
""
,
cleaned_cell
).
strip
()
if
cleaned_cell
:
result
.
append
((
number
,
cleaned_cell
))
result
.
append
((
number
,
""
))
continue
is_list_item
=
bool
(
re
.
match
(
r"^(?:[-*+]\s+|\d+[.)]\s+)"
,
stripped
))
cleaned
=
re
.
sub
(
r"^(?:[-*+]\s+|\d+[.)]\s+|>\s*)"
,
""
,
stripped
)
cleaned
=
re
.
sub
(
r"<[^>]+>"
,
""
,
cleaned
)
cleaned
=
re
.
sub
(
r"`[^`]+`"
,
""
,
cleaned
)
cleaned
=
re
.
sub
(
r"\[([^]]+)]\([^)]+\)"
,
r"\1"
,
cleaned
)
cleaned
=
re
.
sub
(
r"\*\*|__"
,
""
,
cleaned
).
strip
()
result
.
append
((
number
,
cleaned
))
if
is_list_item
:
result
.
append
((
number
,
""
))
return
result
def
lint_language
(
path
:
Path
,
body
:
str
,
line_offset
:
int
)
->
list
[
str
]:
errors
:
list
[
str
]
=
[]
visible
=
visible_lines
(
body
)
for
word
,
pattern
in
sorted
(
BANNED_PATTERNS
.
items
()):
for
number
,
line
in
visible
:
if
pattern
.
search
(
line
):
rule
=
"DOC-07"
if
word
in
MARKETING_WORDS
else
"DOC-05"
errors
.
append
(
issue
(
rule
,
path
,
number
+
line_offset
-
1
,
f"banned word '
{
word
}
'"
))
break
expanded
:
set
[
str
]
=
set
()
reported
:
set
[
str
]
=
set
()
for
number
,
line
in
visible
:
expanded_here
=
set
(
re
.
findall
(
r"\(([A-Z][A-Z0-9]{1,5})\)"
,
line
))
for
acronym
in
ACRONYM_PATTERN
.
findall
(
line
):
if
acronym
in
ACRONYM_ALLOWLIST
:
continue
if
acronym
in
expanded_here
:
expanded
.
add
(
acronym
)
continue
if
acronym
not
in
expanded
and
acronym
not
in
reported
:
errors
.
append
(
issue
(
"DOC-10"
,
path
,
number
+
line_offset
-
1
,
f"expand '
{
acronym
}
' once"
))
reported
.
add
(
acronym
)
paragraph
:
list
[
tuple
[
int
,
str
]]
=
[]
for
number
,
line
in
visible
+
[(
len
(
body
.
splitlines
())
+
1
,
""
)]:
if
line
:
paragraph
.
append
((
number
,
line
))
continue
if
not
paragraph
:
continue
paragraph_text
=
" "
.
join
(
value
for
_
,
value
in
paragraph
)
sentences
=
[
value
for
value
in
SENTENCE_PATTERN
.
split
(
paragraph_text
)
if
value
.
strip
()]
if
len
(
sentences
)
>
3
:
errors
.
append
(
issue
(
"DOC-03"
,
path
,
paragraph
[
0
][
0
]
+
line_offset
-
1
,
"paragraph has more than 3 sentences"
))
for
sentence
in
sentences
:
word_count
=
len
(
WORD_PATTERN
.
findall
(
sentence
))
if
word_count
>
25
:
errors
.
append
(
issue
(
"DOC-02"
,
path
,
paragraph
[
0
][
0
]
+
line_offset
-
1
,
f"sentence has
{
word_count
}
words"
))
paragraph
=
[]
return
errors
def
parse_headings
(
body
:
str
)
->
list
[
tuple
[
int
,
int
,
str
]]:
headings
:
list
[
tuple
[
int
,
int
,
str
]]
=
[]
in_fence
=
False
for
number
,
line
in
enumerate
(
body
.
splitlines
(),
1
):
if
FENCE_PATTERN
.
match
(
line
.
strip
()):
in_fence
=
not
in_fence
continue
match
=
None
if
in_fence
else
HEADING_PATTERN
.
match
(
line
)
if
match
:
headings
.
append
((
number
,
len
(
match
.
group
(
1
)),
match
.
group
(
2
).
strip
(
"`"
)))
return
headings
def
lint_fences
(
path
:
Path
,
body
:
str
,
line_offset
:
int
)
->
list
[
str
]:
errors
:
list
[
str
]
=
[]
fences
:
list
[
tuple
[
str
,
int
]]
=
[]
open_language
:
str
|
None
=
None
for
number
,
line
in
enumerate
(
body
.
splitlines
(),
1
):
match
=
FENCE_PATTERN
.
match
(
line
.
strip
())
if
not
match
:
continue
if
open_language
is
None
:
open_language
=
match
.
group
(
1
)
fences
.
append
((
open_language
,
number
))
else
:
open_language
=
None
for
index
, (
language
,
number
)
in
enumerate
(
fences
):
if
language
==
"bash"
and
(
index
+
1
>=
len
(
fences
)
or
fences
[
index
+
1
][
0
]
!=
"text"
):
errors
.
append
(
issue
(
"DOC-15"
,
path
,
number
+
line_offset
-
1
,
"bash command needs a following text output block"
))
return
errors
def
lint_page
(
path
:
Path
,
text
:
str
)
->
list
[
str
]:
fields
,
body
,
line_offset
=
split_frontmatter
(
text
)
errors
:
list
[
str
]
=
[]
if
not
fields
:
return
[
issue
(
"DOC-F1"
,
path
,
1
,
"missing front matter"
)]
for
field
in
sorted
(
PAGE_FIELDS
):
if
not
fields
.
get
(
field
):
errors
.
append
(
issue
(
"DOC-F1"
,
path
,
1
,
f"missing '
{
field
}
'"
))
for
field
,
values
in
FIELD_VALUES
.
items
():
if
fields
.
get
(
field
)
and
fields
[
field
]
not
in
values
:
errors
.
append
(
issue
(
"DOC-F1"
,
path
,
1
,
f"invalid '
{
field
}
' value"
))
if
fields
.
get
(
"verified"
)
and
not
re
.
fullmatch
(
r"\d{4}-\d{2}-\d{2}"
,
fields
[
"verified"
]):
errors
.
append
(
issue
(
"DOC-F2"
,
path
,
1
,
"verified must use YYYY-MM-DD"
))
ignores
=
[
line
for
line
in
text
.
splitlines
()
if
"lint-ignore:"
in
line
]
if
len
(
ignores
)
>
3
:
errors
.
append
(
issue
(
"DOC-35"
,
path
,
1
,
"more than 3 lint-ignore entries"
))
headings
=
parse_headings
(
body
)
h1_count
=
sum
(
level
==
1
for
_
,
level
,
_
in
headings
)
if
h1_count
!=
1
:
errors
.
append
(
issue
(
"DOC-25"
,
path
,
line_offset
,
f"expected 1 H1, found
{
h1_count
}
"
))
for
previous
,
current
in
zip
(
headings
,
headings
[
1
:]):
if
current
[
1
]
>
previous
[
1
]
+
1
:
errors
.
append
(
issue
(
"DOC-25"
,
path
,
current
[
0
]
+
line_offset
-
1
,
"heading level is skipped"
))
page_type
=
fields
.
get
(
"type"
)
required
=
PAGE_SECTIONS
.
get
(
page_type
, [])
level_two
=
[
title
for
_
,
level
,
title
in
headings
if
level
==
2
]
positions
=
[
level_two
.
index
(
title
)
if
title
in
level_two
else
-
1
for
title
in
required
]
missing
=
[
title
for
title
,
position
in
zip
(
required
,
positions
)
if
position
<
0
]
if
missing
:
errors
.
append
(
issue
(
"DOC-P1"
,
path
,
line_offset
,
f"missing sections:
{
', '
.
join
(
missing
)
}
"
))
elif
positions
!=
sorted
(
positions
):
errors
.
append
(
issue
(
"DOC-P1"
,
path
,
line_offset
,
"required sections are out of order"
))
lines
=
body
.
splitlines
()
for
number
,
line
in
enumerate
(
lines
,
1
):
if
line
.
startswith
(
"|"
)
and
re
.
search
(
r"\bOption\b"
,
line
,
re
.
IGNORECASE
)
and
"Default"
not
in
line
:
errors
.
append
(
issue
(
"DOC-19"
,
path
,
number
+
line_offset
-
1
,
"option table needs a Default column"
))
if
line
.
startswith
(
"|"
):
cells
=
[
cell
.
strip
().
lower
()
for
cell
in
line
.
strip
(
"|"
).
split
(
"|"
)]
if
any
(
cell
in
{
"action"
,
"instruction"
,
"procedure"
,
"step"
}
for
cell
in
cells
):
errors
.
append
(
issue
(
"DOC-27"
,
path
,
number
+
line_offset
-
1
,
"procedure must not use a table"
))
errors
.
extend
(
lint_language
(
path
,
body
,
line_offset
))
errors
.
extend
(
lint_fences
(
path
,
body
,
line_offset
))
if
path
==
Path
(
"api-reference/error-codes.mdx"
):
for
term
in
sorted
(
ERROR_REFERENCE_PRIVATE_TERMS
):
if
term
in
body
:
errors
.
append
(
issue
(
"DOC-22"
,
path
,
line_offset
,
f"customer error text exposes '
{
term
}
'"
))
return
errors
def
lint_tree
(
root
:
Path
)
->
list
[
str
]:
errors
:
list
[
str
]
=
[]
for
path
in
sorted
(
root
.
rglob
(
"*.mdx"
)):
relative
=
path
.
relative_to
(
root
)
text
=
path
.
read_text
(
encoding
=
"utf-8"
)
if
relative
==
Path
(
"changelog.mdx"
):
continue
if
relative
in
NON_PAGE_CODE_SNIPPETS
:
continue
if
relative
.
parts
[
0
]
==
"snippets"
:
errors
.
extend
(
lint_language
(
relative
,
text
,
1
))
continue
errors
.
extend
(
lint_page
(
relative
,
text
))
return
errors
def
main
()
->
int
:
root
=
Path
(
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
>
1
else
"."
).
resolve
()
errors
=
lint_tree
(
root
)
if
errors
:
print
(
"Documentation check failed:"
)
print
(
"
\n
"
.
join
(
f"
{
error
}
"
for
error
in
errors
))
return
1
print
(
"Documentation check passed"
)
return
0
if
__name__
==
"__main__"
:
raise
SystemExit
(
main
())
Back
|
FazBrowse Home
|
New Git URL