Skip to content

Commit bd20826

Browse files
authored
Merge pull request #8 from hawkeyexl/llm
Add instruction validation and model management
2 parents db69b6d + 4cdabd4 commit bd20826

16 files changed

+3602
-541
lines changed

README.md

Lines changed: 180 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,18 @@ A tool to validate Markdown document structure against specified templates, ensu
3030
npx doc-structure-lint --file-path path/to/doc.md --template path/to/template.yaml
3131
```
3232

33+
Doc Structure Lint uses a _local_ language model to evaluate some parts of your templates and content. This model only takes about 2 GB of storage, and it's only downloaded once. When you run the tool for the first time, it may take a few minutes to download the language model. If you don't want to download the model during installation, set the `DOC_STRUCTURE_LINT_PRELOAD` environment variable to `0`. However, if you specify an `instructions` property in your template, the model will be downloaded regardless of the `DOC_STRUCTURE_LINT_PRELOAD` variable value.
34+
35+
```bash
36+
export DOC_STRUCTURE_LINT_PRELOAD=0 && npx doc-structure-lint --file-path path/to/doc.md --template path/to/template.yaml
37+
```
38+
3339
### Options
3440

3541
- `--file-path` or `-f`: Path to the Markdown document to validate
3642
- `--template-path` or `-p`: Path to the YAML template file (default: `./template.yaml`)
3743
- `--template` or `-t`: Name of the template to use
44+
- `--json`: Output results in JSON format
3845

3946
## Usage (as a package)
4047

@@ -47,56 +54,207 @@ npm install doc-structure-lint
4754
### API Usage
4855

4956
```javascript
50-
import { lintDocument } from 'doc-structure-lint';
57+
import { lintDocument } from "doc-structure-lint";
5158

5259
async function validateDocument() {
53-
const result = await lintDocument({
54-
file: "path/to/doc.md",
55-
templatePath: "path/to/template.yaml",
56-
template: "Template name",
57-
});
60+
const result = await lintDocument({
61+
file: "path/to/doc.md",
62+
templatePath: "path/to/template.yaml",
63+
template: "Template name",
64+
});
5865
}
5966
```
6067

6168
## Template Format
6269

63-
Templates are defined in YAML and can specify:
70+
Templates are defined in YAML and specify the structure and content requirements for your documents. Each template can contain multiple sections with various validation rules.
71+
72+
Template definitions also support referencing with the `$ref` key, allowing you to reuse common section definitions across multiple templates.
73+
74+
### Basic Structure
75+
76+
```yaml
77+
templates:
78+
template-name: # Must be alphanumeric, can include hyphens and underscores
79+
sections: # Required - contains section definitions
80+
section-name: # Must be alphanumeric, can include hyphens and underscores
81+
# Section properties go here
82+
```
83+
84+
### Section Properties
85+
86+
```yml
87+
description: Description of the section's purpose
88+
instructions: # List of instructions that a section must follow, evaluated by a local language model. Doesn't evaluate content from subsections.
89+
- Instruction 1
90+
- Instruction 2
91+
required: true # Whether the section must be present (default: true)
92+
heading:
93+
const: Exact heading text # Exact heading text match
94+
pattern: ^Regex pattern$ # Regex pattern for heading text
95+
sections: # Nested subsection definitions
96+
nested-section:
97+
# Nested section properties
98+
additionalSections: false # Allow undefined subsections (default: false)
99+
```
100+
101+
### Content Validation Rules
102+
103+
#### Paragraphs
104+
105+
```yaml
106+
paragraphs:
107+
min: 0 # Minimum number of paragraphs
108+
max: 10 # Maximum number of paragraphs
109+
patterns: # Array of regex patterns applied sequentially
110+
- "^Start with.*"
111+
- ".*end with this$"
112+
```
113+
114+
#### Code Blocks
115+
116+
```yaml
117+
code_blocks:
118+
min: 0 # Minimum number of code blocks
119+
max: 5 # Maximum number of code blocks
120+
```
121+
122+
#### Lists
123+
124+
```yaml
125+
lists:
126+
min: 0 # Minimum number of lists
127+
max: 5 # Maximum number of lists
128+
items: # Requirements for list items
129+
min: 1 # Minimum items per list
130+
max: 10 # Maximum items per list
131+
paragraphs: # Paragraph requirements within items
132+
min: 0
133+
max: 2
134+
code_blocks: # Code block requirements within items
135+
min: 0
136+
max: 1
137+
lists: # Nested list requirements
138+
min: 0
139+
max: 2
140+
```
141+
142+
#### Content Sequence
143+
144+
Use `sequence` to specify a strict order of content elements:
145+
146+
```yaml
147+
sequence:
148+
- paragraphs:
149+
min: 1 # Must start with at least one paragraph
150+
max: 3 # But a maximum of three paragraphs
151+
- code_blocks:
152+
max: 1 # Followed by at most one code block
153+
- lists:
154+
min: 1 # Then at least one list
155+
- paragraphs:
156+
min: 1 # And ending with at least one paragraph
157+
```
158+
159+
### Example Template
160+
161+
The following definition includes templates for a "How To" guide and an "API Operation" reference. Note that the `parameters` component is used in multiple sections with the `$ref` key.
64162

65163
```yaml
66164
templates:
67-
how-to-guide: # Template name
165+
how-to:
68166
sections:
69-
introduction: # Section name
70-
paragraphs: # Paragraph count requirements for the whole section
167+
title:
168+
instructions:
169+
- Must mention the intent of the document
170+
paragraphs:
171+
min: 1
172+
sections:
173+
overview:
174+
heading:
175+
const: Overview
176+
paragraphs:
177+
min: 1
178+
before you start:
179+
heading:
180+
const: Before you start
181+
paragraphs:
182+
min: 1
183+
task:
184+
paragraphs:
185+
min: 1
186+
additionalSections: true
187+
sections:
188+
Sub-task:
189+
paragraphs:
190+
min: 1
191+
see also:
192+
heading:
193+
const: See also
194+
paragraphs:
195+
min: 1
196+
api-operation:
197+
sections:
198+
overview:
199+
heading:
200+
const: "Overview"
201+
paragraphs:
71202
min: 1
72203
max: 3
73-
prerequisites:
74-
sequence: # Specific sequence of elements in the section
75-
- paragraphs:
76-
min: 1
77-
- lists:
78-
min: 1
79-
items:
80-
min: 2
81-
usage:
204+
request-parameters:
205+
$ref: "#/components/parameters"
206+
response-parameters:
207+
$ref: "#/components/parameters"
208+
examples:
209+
required: true
82210
code_blocks:
83211
min: 1
84212
sections:
85-
advanced_features: # Subsection name
213+
success:
214+
heading:
215+
const: "Success Response"
216+
sequence:
217+
- paragraphs:
218+
min: 1
219+
- code_blocks:
220+
min: 1
221+
error:
86222
required: false
87-
troubleshooting:
223+
heading:
224+
const: "Error Response"
225+
226+
components:
227+
parameters:
228+
required: false
229+
heading:
230+
pattern: "^Parameters|Request Parameters$"
231+
lists:
232+
min: 1
233+
items:
234+
min: 1
88235
```
89236

90-
> **Note:** Comprehensive rules reference coming soon.
237+
To use this template, save it to a file (like the default `templates.yaml`) and specify the template name that matches the key you set in your definition:
238+
239+
```bash how-to
240+
npx doc-structure-lint --file-path path/to/doc.md --template-path path/to/templates.yaml --template how-to
241+
```
242+
243+
```bash api-operation
244+
npx doc-structure-lint --file-path path/to/operation.md --template-path path/to/templates.yaml --template api-operation
245+
```
91246

92247
## Development
93248

94249
1. Clone the repository
95250
2. Install dependencies:
251+
96252
```bash
97253
npm install
98254
```
255+
99256
3. Run tests:
257+
100258
```bash
101259
npm test
102260
```

0 commit comments

Comments
 (0)