@avinashgaurav/manti 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +226 -2
- package/action/run.js +82 -0
- package/action.yml +46 -0
- package/bin/manti.js +123 -0
- package/package.json +50 -4
- package/src/ai.js +109 -0
- package/src/checks.js +534 -0
- package/src/dates.js +69 -0
- package/src/evalchecks.js +182 -0
- package/src/fix.js +137 -0
- package/src/index.js +99 -0
- package/src/morechecks.js +308 -0
- package/src/notecheck.js +130 -0
- package/src/numbers.js +141 -0
- package/src/text.js +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Avinash Gaurav
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,227 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/manti.svg" width="150" alt="Manti, a mantis shrimp with big gradient eyes">
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<h1 align="center">Manti</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center"><b>The fact-checker for AI-written docs. Catch what the AI made up, before your boss does.</b></p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://avinashgaurav.github.io/manti/">Try it in your browser</a> ·
|
|
11
|
+
<a href="#usage">CLI</a> ·
|
|
12
|
+
<a href="#in-a-pull-request-github-action">GitHub Action</a> ·
|
|
13
|
+
<a href="#use-it-in-claude-code">Claude Code</a> ·
|
|
14
|
+
<a href="#how-accurate-is-it">How accurate</a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
You give an AI your notes and it gives back a PRD, an exec update or a launch plan. Somewhere in there is a "23% lift" you never said, a "studies show" with no study, a quote nobody said, a VP who is really a PM, or a launch date that falls on the wrong weekday, or "Azure is included" when your notes say it is out of scope. Manti reads the draft against what you actually gave the AI, runs 25 checks, shows where the points went across six areas, and fixes what it can.
|
|
18
|
+
|
|
19
|
+
It is a plain script, not another AI: fast, free, private, and the same answer every time. An optional AI double-check is there for reworded claims, with your own key. (Manti is a mantis shrimp. They have the best eyes in the sea.)
|
|
20
|
+
|
|
21
|
+
[](https://avinashgaurav.github.io/manti/)
|
|
22
|
+
|
|
23
|
+
**On the website** ([avinashgaurav.github.io/manti](https://avinashgaurav.github.io/manti/)) you paste text or drop a Word, PDF or markdown file; everything runs in the page and nothing is uploaded. You get each flag explained under its line, "Fix my draft" with a reason for every change, a summary to paste into Slack, and a share link that carries the draft inside the link itself. Try the PRD, exec update or launch plan examples to see it work.
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
$ npx @avinashgaurav/manti draft.md --source notes.md
|
|
27
|
+
|
|
28
|
+
draft.md against notes.md
|
|
29
|
+
Score 14/100 (F) 6 errors, 7 warnings, 5 notes
|
|
30
|
+
Accuracy 68 · Maths 80 · Sources 84 · Dates 87 · Completeness 96 · Clarity 99
|
|
31
|
+
|
|
32
|
+
L1 note missing-section This looks like a PRD but has no section on goals or success metrics.
|
|
33
|
+
L4 error unsourced-number 68% is not in your input, not computed from it, and not labelled as an assumption or target.
|
|
34
|
+
L4 error fake-source Cites "Studies show" but your input gives no such source. Name it and link it, or cut it.
|
|
35
|
+
L5 warning invented-name "Globex" does not appear in your input. If it is a person, customer, tool or competitor, check it is real and relevant.
|
|
36
|
+
...
|
|
37
|
+
|
|
38
|
+
$ npx @avinashgaurav/manti draft.md --source notes.md --fix > fixed.md
|
|
39
|
+
Fixed 5 things. 10 left for you ...
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## What it checks
|
|
43
|
+
|
|
44
|
+
| Scorecard | Check | Catches | Needs notes |
|
|
45
|
+
| --- | --- | --- | --- |
|
|
46
|
+
| Accuracy | `unsourced-number` | Figures not in your notes, not computed from them, and not labelled as an estimate or target | Yes |
|
|
47
|
+
| | `invented-name` | People, customers, tools or competitors your notes never mention | Yes |
|
|
48
|
+
| | `invented-quote` | Words in quote marks that nobody in your notes said | Yes |
|
|
49
|
+
| | `period-mismatch` | A per-month figure in your notes written as per year here, or the other way round | Yes |
|
|
50
|
+
| | `contradiction` | The same metric with two values in one doc | No |
|
|
51
|
+
| | `scale-mismatch` | Right digits, wrong size or unit: 1.2M in your notes, 12M here; 200 ms written as 200 s | Yes |
|
|
52
|
+
| | `rounding-drift` | Rounding that changes the story: 38.6% in your notes becomes "nearly 50%" | Yes |
|
|
53
|
+
| | `direction-flip` | "Rose" when the numbers fell, or when your notes say it went down | Partly |
|
|
54
|
+
| | `role-change` | Priya the PM in your notes becomes Priya the VP | Yes |
|
|
55
|
+
| | `notes-conflict` | The opposite of a status in your notes: "Azure is included" when it is out of scope, "approved" when it is being evaluated, "completed" when it is pending, a revenue figure when none was quantified | Yes |
|
|
56
|
+
| | `count-mismatch` | "10 existing customers" when your notes say 5, including numbers written as words ("five") | Yes |
|
|
57
|
+
| Maths | `math-error` | Percent changes, "X of Y (Z%)" and `a + b = c` that don't add up | No |
|
|
58
|
+
| | `table-total` | A Total row that doesn't match the rows above it | No |
|
|
59
|
+
| | `percent-points` | "Up 5%" when 20% to 25% is 5 points (a 25% rise) | No |
|
|
60
|
+
| Sources | `fake-source` | "Studies show", "according to Gartner", norms stated as fact, links not in your notes | Partly |
|
|
61
|
+
| | `overclaim` | "Guaranteed", "risk-free", "definitely": forecasts written as certainties | No |
|
|
62
|
+
| | `broken-link` | Empty links, example.com, "htps://", reference links never defined | No |
|
|
63
|
+
| Dates | `date-error` | Impossible dates, wrong weekdays, past dates written as plans, dates not in your notes | Partly |
|
|
64
|
+
| | `relative-date` | "Last quarter", "next month" in a doc that never says when it was written | No |
|
|
65
|
+
| Completeness | `missing-section` | A PRD with no risks or goals, a launch plan with no owner or rollback, an update with no ask | No |
|
|
66
|
+
| | `missing-owner` | Next steps or action items with no owner or no date | No |
|
|
67
|
+
| | `leftover` | `[TBD]`, `[link]`, "insert X here", `{{template}}` text | No |
|
|
68
|
+
| | `missing-fact` | Key figures in your notes that never made it into the draft | Yes |
|
|
69
|
+
| Clarity | `vague-claim` | "Significantly", "industry-leading", "best-in-class" with no number behind them | No |
|
|
70
|
+
| | `readability` | Jargon ("utilize", "move the needle"), 40-word sentences, a reading grade too high for busy readers | No |
|
|
71
|
+
|
|
72
|
+
A number counts as sourced if it is in your notes, or a reader could compute it from them (sums, differences, ratios, percentages, percent changes, monthly to yearly), including step by step through numbers the doc already derived. A sentence that says "assumption", "estimate", "target", "TBD" or similar is treated as labelled.
|
|
73
|
+
|
|
74
|
+
**Score:** the overall score starts at 100 and loses 10 per error, 3 per warning and 1 per note. Each of the six scorecard areas is scored the same way on its own checks.
|
|
75
|
+
|
|
76
|
+
**Fix:** `--fix` (or "Fix my draft" on the website) rewrites only what it can do without guessing: it corrects wrong maths, wrong weekdays, per-month vs per-year mix-ups and table totals; drops "studies show" style sources and marks the figure behind them "(estimate)"; labels unsourced figures "(estimate)"; softens certainty words; cuts hype adverbs; puts back the right scale, unit, rounded figure or job title from your notes; writes "5 points" for a points change; swaps jargon for plain words; and turns impossible dates into `[date]`. Invented quotes, names, owners, missing sections, links, contradictions, direction flips and relative dates are left for you, and listed. Fix never hides a problem: it marks a claim rather than quietly rewording it.
|
|
77
|
+
|
|
78
|
+
<a id="usage"></a>
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npx @avinashgaurav/manti draft.md --source notes.md # check a draft against your notes
|
|
83
|
+
npx @avinashgaurav/manti draft.md -s thread.txt -s data.csv # several sources
|
|
84
|
+
cat draft.md | npx @avinashgaurav/manti - -s notes.md # from stdin
|
|
85
|
+
npx @avinashgaurav/manti draft.md # no source: maths, dates, sources, leftovers, vague claims only
|
|
86
|
+
npx @avinashgaurav/manti draft.md -s notes.md --json # machine-readable
|
|
87
|
+
npx @avinashgaurav/manti draft.md -s notes.md --fail-under 80 # exit 1 below 80, for CI
|
|
88
|
+
npx @avinashgaurav/manti draft.md -s notes.md --fix > fixed.md # safe fixes; what's left goes to stderr
|
|
89
|
+
npx @avinashgaurav/manti draft.md -s notes.md --allow Acme,Northwind # names that are fine
|
|
90
|
+
ANTHROPIC_API_KEY=... npx @avinashgaurav/manti draft.md -s notes.md --ai # add the optional AI double-check
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
From code (`npm i @avinashgaurav/manti`):
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
import { factcheck, fixAll } from "@avinashgaurav/manti";
|
|
97
|
+
const { score, dimensions, findings } = factcheck(draft, { source: notes });
|
|
98
|
+
const { text } = fixAll(draft, (t) => factcheck(t, { source: notes }).findings);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Node 18 or later. No dependencies.
|
|
102
|
+
|
|
103
|
+
## In a pull request (GitHub Action)
|
|
104
|
+
|
|
105
|
+
Put docs in your repo and Manti checks each one a PR adds or changes: every finding shows on its line in the PR, a score table goes in the job summary, and the job fails below `fail-under`. Notes are picked up from a sibling `<name>.notes.md` or `<name>.source.md`, or set with `source`.
|
|
106
|
+
|
|
107
|
+
```yaml
|
|
108
|
+
# .github/workflows/manti.yml
|
|
109
|
+
name: manti
|
|
110
|
+
on: pull_request
|
|
111
|
+
permissions:
|
|
112
|
+
contents: read
|
|
113
|
+
jobs:
|
|
114
|
+
docs:
|
|
115
|
+
runs-on: ubuntu-latest
|
|
116
|
+
steps:
|
|
117
|
+
- uses: actions/checkout@v4
|
|
118
|
+
with:
|
|
119
|
+
fetch-depth: 0
|
|
120
|
+
- uses: avinashgaurav/manti@v1
|
|
121
|
+
with:
|
|
122
|
+
fail-under: 70 # 0 to only annotate
|
|
123
|
+
# files: "docs/**/*.md" # default: the .md files changed in the PR
|
|
124
|
+
# source: notes/q3.md # default: <name>.notes.md next to each doc
|
|
125
|
+
# allow: Acme,Northwind
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
No AI and no secrets: it runs the same checks as the CLI, on the runner, using the runner's Node (GitHub-hosted runners have it; on a self-hosted runner, add `actions/setup-node` first).
|
|
129
|
+
|
|
130
|
+
## AI double-check (optional)
|
|
131
|
+
|
|
132
|
+
The rules catch what can be checked exactly. A claim that was reworded ("revenue grew because of the new pricing" when your notes give no cause) needs a reader. `--ai` (or the AI switch on the website) sends the draft and your notes to Claude with **your own** Anthropic key and adds what it finds as `ai-claim` findings under Accuracy.
|
|
133
|
+
|
|
134
|
+
- Off by default. Without it, nothing leaves your machine.
|
|
135
|
+
- Every AI finding must quote your draft word for word; anything it can't point to is dropped, so it can't invent problems on lines that don't exist.
|
|
136
|
+
- AI suggestions are shown, never applied by Fix.
|
|
137
|
+
- Uses `claude-opus-5-5` by default (`--ai-model` to change). On the website the key stays in your browser and is sent only to `api.anthropic.com`.
|
|
138
|
+
|
|
139
|
+
## Use it in Claude Code
|
|
140
|
+
|
|
141
|
+
The repo is also a Claude Code plugin with one skill. After Claude drafts a document from your notes, it runs the checker on its own draft, fixes every error (sources it, labels it or cuts it) and tells you what it changed. Ask it to fact-check someone else's doc and it reports the findings instead of rewriting.
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
/plugin marketplace add avinashgaurav/manti
|
|
145
|
+
/plugin install manti@manti
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Tested with `claude plugin eval` (`evals/`), 3 runs each, with and without the plugin, judged by Sonnet, on 1 December 2026:
|
|
149
|
+
|
|
150
|
+
| Case | With the skill | Without |
|
|
151
|
+
| --- | --- | --- |
|
|
152
|
+
| Draft a CFO update from notes; final draft has no figure that isn't in the notes, computed from them, or labelled | **3 / 3** | 1 / 3 |
|
|
153
|
+
| Fact-check a draft with 5 planted errors; all 5 found | 3 / 3 | 3 / 3 |
|
|
154
|
+
|
|
155
|
+
Read with care: 2 cases, written by me. The first run of the drafting case scored 0 / 3 with the skill, because Claude kept a header date that was not in the notes; I changed the skill to replace such dates with `[date]` and reran that case. Without the skill, Claude already finds obvious planted errors when asked; the skill's gain is in checking its own drafts.
|
|
156
|
+
|
|
157
|
+
## How accurate is it?
|
|
158
|
+
|
|
159
|
+
Three tests, each with its limits. Short version: Manti is strong on sources, placeholders, maths, dates and anything with a number in it. It also catches claims that flip a status in your notes ("approved" when they say "being evaluated"). Claims with no number and no matching status line ("this improves cash flow") are what the optional AI double-check is for.
|
|
160
|
+
|
|
161
|
+
| Test | What it measures | Result |
|
|
162
|
+
| --- | --- | --- |
|
|
163
|
+
| Planted errors (`npm run bench`) | 799 mistakes planted one at a time into 12 hand-written docs | **745 caught on the right line (93%)**, 707 (88%) by the exact check built for that mistake; 2 notes on the 12 clean docs; Fix broke nothing |
|
|
164
|
+
| Outside test cases (`bench/external.js`) | 34 docs written by ChatGPT and Gemini, with their own answer keys | **85 of 111 caught (77%)**, 6 false alarms on 10 clean docs (half of them right). This is the fairer number: none of these docs were used to write the checks before they were scored. |
|
|
165
|
+
| An AI judge (below) | Real Claude-written PM docs graded by Sonnet for invented figures | **19 of the 25** the judge failed (29 of 36 across all 173 drafts on disk) |
|
|
166
|
+
|
|
167
|
+
### Planted errors, per check
|
|
168
|
+
|
|
169
|
+
`node bench/run.js` plants one known error at a time into 12 hand-written, faithful drafts (PRD, exec update, launch plan, board memo, incident review, pricing note, OKRs and more) and records, per check, whether it fires on that line, what it flags on the clean drafts, and whether Fix repairs it without touching anything else. On 2 December 2026: 745 of 799 planted errors caught on the planted line (707 by the exact check), 2 notes on the 12 clean drafts, and Fix broke nothing. By area: Sources 100%, Clarity 100%, Maths 98%, Completeness 97%, Dates 90%, Accuracy 84%. Many of these phrasings were added after earlier runs of this same benchmark missed them, so read it as "these phrasings are handled", and use the outside cases for an unbiased rate. Per-check results, every miss and the caveats are in [bench/RESULTS.md](bench/RESULTS.md).
|
|
170
|
+
|
|
171
|
+
### Outside test cases
|
|
172
|
+
|
|
173
|
+
The planted-error docs were written by the same person who wrote the checks, so they flatter it. To get away from that, ChatGPT and Gemini were each asked to write 8 realistic notes-and-draft pairs with their own mistakes planted, 2 of them clean, plus an answer key. `node bench/external.js <files>` scores any set in that format (the prompt is in [bench/external-prompt.md](bench/external-prompt.md); the case files themselves are kept out of the repo).
|
|
174
|
+
|
|
175
|
+
Two rounds, 34 docs, 111 planted mistakes:
|
|
176
|
+
|
|
177
|
+
| Round | Caught | False alarms on clean docs |
|
|
178
|
+
| --- | --- | --- |
|
|
179
|
+
| First run of the checks | 54 of 111 (49%) | 15 |
|
|
180
|
+
| After fixing what it found | **85 of 111 (77%)** | 6, and 3 of those were right (the "clean" draft really did invent a date, or add something its notes put out of scope) |
|
|
181
|
+
|
|
182
|
+
What moved the number: two new checks (`notes-conflict` for status flips, `count-mismatch` for counts that differ, including "five" vs "three"), a check of claimed % changes against the table row they name, "nearly half" style fractions, a quote given to the wrong person, and a dozen smaller fixes. Every fix has a test, and each round was re-run against the planted-error benchmark so nothing that worked before broke.
|
|
183
|
+
|
|
184
|
+
What is still missed (30 of 111): claims with no number and no status line to contradict ("this improves cash flow", "SEV-2", "within 20 minutes"), totals that happen to be computable from other numbers in the notes, and one-off phrasings. The answer keys from both models were also wrong in places, so this number is approximate.
|
|
185
|
+
|
|
186
|
+
### Agreement with an AI judge
|
|
187
|
+
|
|
188
|
+
I ran it on 96 real drafts from the [pm-os plugin evals](https://github.com/avinashgaurav/pm-os/tree/main/plugin): 8 kinds of PM document, written by Claude with and without a "don't invent figures" skill, each graded by a Sonnet judge on the same rule ("every figure comes from the prompt or is labelled; no outside benchmarks or invented links"). The prompt was used as `--source`.
|
|
189
|
+
|
|
190
|
+
| Counting as "flagged" | Judge failed, we flagged | Judge failed, we missed | Judge passed, we flagged | Judge passed, we didn't |
|
|
191
|
+
| --- | --- | --- | --- | --- |
|
|
192
|
+
| Errors and warnings | **19 / 25** | 6 | 30 / 71 | 41 |
|
|
193
|
+
| Errors only | 3 / 25 | 22 | 1 / 71 | 70 |
|
|
194
|
+
|
|
195
|
+
Rerun on 2 December 2026 after the benchmark fixes (it was 32 / 71 and 2 / 25, 2 / 71 before). Both rows use the two checks that match the judge's rule, `unsourced-number` and `fake-source`.
|
|
196
|
+
|
|
197
|
+
What that means:
|
|
198
|
+
|
|
199
|
+
- **Errors and warnings catch most of what the judge catches** (19 of 25), at the cost of flagging about 42% of drafts the judge passed. Most of those extra flags are durations and counts ("within 14 days", "25, 50 and 100 seats") that the judge sometimes accepts and sometimes rejects; the judge itself is not consistent on them.
|
|
200
|
+
- **Errors alone are rare and usually right**, but most judge failures are warning-level: an invented duration, a count, a norm stated as fact.
|
|
201
|
+
- **It is a reviewer's aid, not a verdict.** It cannot tell a reasonable planning choice from a made-up fact; it tells you where to look.
|
|
202
|
+
- Small, one-off comparison, and I tuned the rules while looking at these drafts. Reproduce it with `node scripts/validate-against-judge.js <eval-result.json ...>`.
|
|
203
|
+
|
|
204
|
+
## Limits
|
|
205
|
+
|
|
206
|
+
- English. The command line reads markdown or plain text; the website also reads Word (.docx) and PDF files, in your browser.
|
|
207
|
+
- From PDFs, tables and bullet lists come through as plain lines, so the table-total and owner checks only work on Word, markdown or text.
|
|
208
|
+
- It matches numbers, not meaning: a sourced number used for the wrong thing passes.
|
|
209
|
+
- Name detection is a heuristic on capitalised words; use `--allow` for your own company and product names.
|
|
210
|
+
- Claims without numbers ("customers love it", "the budget is approved") need a reader: use the optional AI double-check.
|
|
211
|
+
- Numbers written as words and fractions like "nearly half" are read only where they can be compared with your notes.
|
|
212
|
+
- A made-up figure that happens to be computable from other numbers in your notes can pass.
|
|
213
|
+
- The judge comparison above covers `unsourced-number` and `fake-source` only (`ALL=1` runs every check, but the judge's rule is about figures and sources). The other checks are measured by the planted-error benchmark in `bench/`.
|
|
214
|
+
|
|
215
|
+
## Roadmap
|
|
216
|
+
|
|
217
|
+
1. ~~Script checks, scorecard, CLI~~
|
|
218
|
+
2. ~~Paste-and-check web page~~ (`index.html`; runs in the browser, nothing is sent anywhere)
|
|
219
|
+
2b. ~~Six more checks, a six-part scorecard and safe auto-fix~~ (0.2.0)
|
|
220
|
+
2c. ~~Eleven more checks (25 in all), a GitHub Action, and an optional AI double-check~~ (0.3.0)
|
|
221
|
+
3. ~~Claude Code skill: check drafts as they are written~~
|
|
222
|
+
4. Chrome extension: check a doc where you write it
|
|
223
|
+
5. Eval mode: test your own AI-writing prompts against cases, with and without a change
|
|
224
|
+
|
|
225
|
+
## License
|
|
226
|
+
|
|
227
|
+
MIT
|
package/action/run.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Runs inside the GitHub Action: find the docs, check each one, annotate the PR, write a summary, set the exit code.
|
|
2
|
+
import { readFileSync, existsSync, appendFileSync, readdirSync, lstatSync } from "node:fs";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { join, dirname, basename, extname, relative } from "node:path";
|
|
5
|
+
import { factcheck } from "../src/index.js";
|
|
6
|
+
|
|
7
|
+
const env = process.env;
|
|
8
|
+
const list = (s) => (s ?? "").split(/[\s,]+/).map((x) => x.trim()).filter(Boolean);
|
|
9
|
+
const failUnder = Number(env.MANTI_FAIL_UNDER ?? 70);
|
|
10
|
+
const only = list(env.MANTI_ONLY);
|
|
11
|
+
const allowNames = list(env.MANTI_ALLOW);
|
|
12
|
+
|
|
13
|
+
/** Changed .md files in this PR, or every .md file when not in a PR. */
|
|
14
|
+
function changedDocs() {
|
|
15
|
+
const base = env.GITHUB_BASE_REF;
|
|
16
|
+
if (base) {
|
|
17
|
+
try {
|
|
18
|
+
execFileSync("git", ["fetch", "--no-tags", "--depth=1", "origin", base], { stdio: "ignore" });
|
|
19
|
+
const out = execFileSync("git", ["diff", "--name-only", "--diff-filter=AMR", `origin/${base}`, "HEAD", "--", "*.md", "*.markdown"], { encoding: "utf8" });
|
|
20
|
+
return list(out).filter(isDraft);
|
|
21
|
+
} catch {
|
|
22
|
+
console.log("::warning title=Manti::Could not diff against the base branch; checking every .md file. Use actions/checkout with fetch-depth: 0.");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return walk(".").filter(isDraft);
|
|
26
|
+
}
|
|
27
|
+
const isDraft = (f) => existsSync(f) && !lstatSync(f).isSymbolicLink() && !/\.(notes|source)\.(md|markdown)$/i.test(f) && !/(^|\/)(node_modules|\.git|CHANGELOG\.md$)/.test(f);
|
|
28
|
+
function walk(dir) {
|
|
29
|
+
const out = [];
|
|
30
|
+
for (const name of readdirSync(dir)) {
|
|
31
|
+
if (name === "node_modules" || name.startsWith(".")) continue;
|
|
32
|
+
const p = join(dir, name);
|
|
33
|
+
const st = lstatSync(p);
|
|
34
|
+
if (st.isSymbolicLink()) continue; // never follow links out of the repo
|
|
35
|
+
if (st.isDirectory()) out.push(...walk(p));
|
|
36
|
+
else if (/\.(md|markdown)$/i.test(name)) out.push(relative(".", p));
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
/** Tiny glob: *, ** and ? only. */
|
|
41
|
+
function expand(patterns) {
|
|
42
|
+
const all = walk(".");
|
|
43
|
+
return [...new Set(patterns.flatMap((p) => {
|
|
44
|
+
if (!/[*?]/.test(p)) return existsSync(p) ? [p] : [];
|
|
45
|
+
const re = new RegExp("^" + p.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\/?/g, "\u0000").replace(/\*/g, "[^/]*").replace(/\?/g, ".").replace(/\u0000/g, ".*") + "$");
|
|
46
|
+
return all.filter((f) => re.test(f));
|
|
47
|
+
}))];
|
|
48
|
+
}
|
|
49
|
+
function sourceFor(file) {
|
|
50
|
+
if (env.MANTI_SOURCE) return list(env.MANTI_SOURCE).flatMap((p) => expand([p])).map((p) => readFileSync(p, "utf8")).join("\n\n");
|
|
51
|
+
const stem = join(dirname(file), basename(file, extname(file)));
|
|
52
|
+
for (const s of [`${stem}.notes.md`, `${stem}.source.md`]) if (existsSync(s)) return readFileSync(s, "utf8");
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
const esc = (s) => String(s).replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
|
|
56
|
+
const escProp = (s) => esc(s).replace(/:/g, "%3A").replace(/,/g, "%2C");
|
|
57
|
+
|
|
58
|
+
const files = env.MANTI_FILES ? expand(list(env.MANTI_FILES)) : changedDocs();
|
|
59
|
+
const rows = [];
|
|
60
|
+
let lowest = 100;
|
|
61
|
+
for (const file of files) {
|
|
62
|
+
const source = sourceFor(file);
|
|
63
|
+
const r = factcheck(readFileSync(file, "utf8"), { source, only: only.length ? only : undefined, allowNames });
|
|
64
|
+
lowest = Math.min(lowest, r.score);
|
|
65
|
+
for (const x of r.findings) {
|
|
66
|
+
const level = x.severity === "error" ? "error" : x.severity === "warning" ? "warning" : "notice";
|
|
67
|
+
console.log(`::${level} file=${escProp(file)},line=${x.line},title=${escProp(`Manti: ${x.check}`)}::${esc(x.message)}`);
|
|
68
|
+
}
|
|
69
|
+
rows.push({ file, r, withSource: !!source });
|
|
70
|
+
console.log(`${esc(file)}: ${r.score}/100 (${r.grade}), ${r.counts.error} errors, ${r.counts.warning} warnings, ${r.counts.note} notes${source ? "" : " (no notes found, source checks skipped)"}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!files.length) console.log("Manti: no docs to check.");
|
|
74
|
+
if (env.GITHUB_STEP_SUMMARY) {
|
|
75
|
+
const lines = ["## Manti", "", files.length ? "| Doc | Score | Errors | Warnings | Notes | Checked against notes |" : "No docs to check.", files.length ? "|---|---|---|---|---|---|" : ""];
|
|
76
|
+
for (const { file, r, withSource } of rows) lines.push(`| \`${file}\` | **${r.score}** (${r.grade}) | ${r.counts.error} | ${r.counts.warning} | ${r.counts.note} | ${withSource ? "yes" : "no"} |`);
|
|
77
|
+
if (failUnder > 0 && files.length) lines.push("", lowest < failUnder ? `Failed: the lowest score is ${lowest}, below ${failUnder}.` : `Passed: every doc scores ${failUnder} or more.`);
|
|
78
|
+
lines.push("", "Fix most of it with `npx @avinashgaurav/manti <doc> -s <notes> --fix`, or paste it into https://avinashgaurav.github.io/manti/.");
|
|
79
|
+
appendFileSync(env.GITHUB_STEP_SUMMARY, lines.join("\n") + "\n");
|
|
80
|
+
}
|
|
81
|
+
if (env.GITHUB_OUTPUT) appendFileSync(env.GITHUB_OUTPUT, `lowest-score=${lowest}\n`);
|
|
82
|
+
process.exit(failUnder > 0 && files.length && lowest < failUnder ? 1 : 0);
|
package/action.yml
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
name: "Manti: fact-check AI-written docs"
|
|
2
|
+
description: "Checks the docs changed in a pull request for made-up numbers, wrong maths, fake sources, bad dates and missing pieces. No AI, nothing leaves the runner."
|
|
3
|
+
author: "Avinash Gaurav"
|
|
4
|
+
branding:
|
|
5
|
+
icon: "check-circle"
|
|
6
|
+
color: "orange"
|
|
7
|
+
|
|
8
|
+
inputs:
|
|
9
|
+
files:
|
|
10
|
+
description: "Docs to check (space- or newline-separated globs). Default: the .md files changed in this pull request."
|
|
11
|
+
required: false
|
|
12
|
+
default: ""
|
|
13
|
+
source:
|
|
14
|
+
description: "Notes to check every doc against. Without it, each doc uses a sibling <name>.notes.md or <name>.source.md if there is one."
|
|
15
|
+
required: false
|
|
16
|
+
default: ""
|
|
17
|
+
fail-under:
|
|
18
|
+
description: "Fail the job if any doc scores below this (0 to 100). Use 0 to never fail."
|
|
19
|
+
required: false
|
|
20
|
+
default: "70"
|
|
21
|
+
only:
|
|
22
|
+
description: "Run only these checks (comma-separated)."
|
|
23
|
+
required: false
|
|
24
|
+
default: ""
|
|
25
|
+
allow:
|
|
26
|
+
description: "Names that are fine even if not in your notes (comma-separated): your company, your product."
|
|
27
|
+
required: false
|
|
28
|
+
default: ""
|
|
29
|
+
|
|
30
|
+
outputs:
|
|
31
|
+
lowest-score:
|
|
32
|
+
description: "The lowest score across the checked docs."
|
|
33
|
+
value: ${{ steps.manti.outputs.lowest-score }}
|
|
34
|
+
|
|
35
|
+
runs:
|
|
36
|
+
using: "composite"
|
|
37
|
+
steps:
|
|
38
|
+
- id: manti
|
|
39
|
+
shell: bash
|
|
40
|
+
env:
|
|
41
|
+
MANTI_FILES: ${{ inputs.files }}
|
|
42
|
+
MANTI_SOURCE: ${{ inputs.source }}
|
|
43
|
+
MANTI_FAIL_UNDER: ${{ inputs.fail-under }}
|
|
44
|
+
MANTI_ONLY: ${{ inputs.only }}
|
|
45
|
+
MANTI_ALLOW: ${{ inputs.allow }}
|
|
46
|
+
run: node "$GITHUB_ACTION_PATH/action/run.js"
|
package/bin/manti.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { factcheck, fixAll, CHECKS, aiCheck, AI_MODEL } from "../src/index.js";
|
|
4
|
+
|
|
5
|
+
const HELP = `manti: the fact-checker for AI-written docs. 25 checks against the notes you gave the AI.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
manti <draft.md> [--source notes.md ...] [options]
|
|
9
|
+
cat draft.md | manti - --source notes.md
|
|
10
|
+
|
|
11
|
+
Options:
|
|
12
|
+
-s, --source <file> What you gave the AI (notes, data, thread). Repeatable.
|
|
13
|
+
Without it, only the checks that need no input run.
|
|
14
|
+
--today <YYYY-MM-DD> Date for past-date checks (default: today).
|
|
15
|
+
--only <a,b> Run only these checks: ${Object.keys(CHECKS).join(", ")}.
|
|
16
|
+
--allow <a,b> Names that are fine even if not in your input (your company, product).
|
|
17
|
+
--fail-under <score> Exit 1 if the score is below this (for CI).
|
|
18
|
+
--fix Print a fixed copy of the draft (maths, weekdays, periods, totals corrected;
|
|
19
|
+
unsourced figures labelled; generic "studies show" sources dropped). What's left goes
|
|
20
|
+
to stderr. With --json, prints { text, changes, left }.
|
|
21
|
+
--ai Also run an AI double-check with your own key (ANTHROPIC_API_KEY). Catches reworded
|
|
22
|
+
claims the rules miss. Sends the draft and notes to Anthropic. Needs --source.
|
|
23
|
+
--ai-model <id> Model for --ai (default: ${AI_MODEL}).
|
|
24
|
+
--json Print the full result as JSON.
|
|
25
|
+
-h, --help Show this help.
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
function parse(argv) {
|
|
29
|
+
const o = { sources: [], only: [], allow: [], json: false, failUnder: null, today: undefined, file: null };
|
|
30
|
+
for (let i = 0; i < argv.length; i++) {
|
|
31
|
+
const a = argv[i];
|
|
32
|
+
const next = () => {
|
|
33
|
+
if (i + 1 >= argv.length) die(`${a} needs a value`);
|
|
34
|
+
return argv[++i];
|
|
35
|
+
};
|
|
36
|
+
if (a === "-h" || a === "--help") o.help = true;
|
|
37
|
+
else if (a === "-s" || a === "--source") o.sources.push(next());
|
|
38
|
+
else if (a === "--today") o.today = next();
|
|
39
|
+
else if (a === "--only") o.only.push(...next().split(","));
|
|
40
|
+
else if (a === "--allow") o.allow.push(...next().split(","));
|
|
41
|
+
else if (a === "--fail-under") o.failUnder = Number(next());
|
|
42
|
+
else if (a === "--json") o.json = true;
|
|
43
|
+
else if (a === "--fix") o.fix = true;
|
|
44
|
+
else if (a === "--ai") o.ai = true;
|
|
45
|
+
else if (a === "--ai-model") o.aiModel = next();
|
|
46
|
+
else if (a.startsWith("-") && a !== "-") die(`Unknown option ${a}`);
|
|
47
|
+
else if (!o.file) o.file = a;
|
|
48
|
+
else die(`Unexpected argument ${a}`);
|
|
49
|
+
}
|
|
50
|
+
return o;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function die(msg) {
|
|
54
|
+
process.stderr.write(`manti: ${msg}\n\n${HELP}`);
|
|
55
|
+
process.exit(2);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function read(path) {
|
|
59
|
+
try {
|
|
60
|
+
return readFileSync(path === "-" ? 0 : path, "utf8");
|
|
61
|
+
} catch (e) {
|
|
62
|
+
die(`cannot read ${path}: ${e.code ?? e.message}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const opts = parse(process.argv.slice(2));
|
|
67
|
+
if (opts.help || !opts.file) {
|
|
68
|
+
process.stdout.write(HELP);
|
|
69
|
+
process.exit(opts.help ? 0 : 2);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const doc = read(opts.file);
|
|
73
|
+
const source = opts.sources.map(read).join("\n\n");
|
|
74
|
+
let extra = [];
|
|
75
|
+
if (opts.ai) {
|
|
76
|
+
if (!source.trim()) die("--ai needs --source: the AI checks the draft against your notes");
|
|
77
|
+
if (!process.env.ANTHROPIC_API_KEY) die("--ai needs ANTHROPIC_API_KEY set to your own Anthropic key");
|
|
78
|
+
try {
|
|
79
|
+
extra = await aiCheck(doc, source, { apiKey: process.env.ANTHROPIC_API_KEY, model: opts.aiModel });
|
|
80
|
+
} catch (e) {
|
|
81
|
+
process.stderr.write(`manti: AI double-check skipped: ${e.message}\n`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
let result;
|
|
85
|
+
try {
|
|
86
|
+
result = factcheck(doc, { source, today: opts.today, only: opts.only, allowNames: opts.allow, extra });
|
|
87
|
+
} catch (e) {
|
|
88
|
+
die(e.message);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (opts.fix) {
|
|
92
|
+
const recheck = (t) => factcheck(t, { source, today: opts.today, only: opts.only, allowNames: opts.allow }).findings;
|
|
93
|
+
const { text, changes, left } = fixAll(doc, recheck, 3, { source });
|
|
94
|
+
if (opts.json) {
|
|
95
|
+
process.stdout.write(JSON.stringify({ text, changes, left }, null, 2) + "\n");
|
|
96
|
+
process.exit(0);
|
|
97
|
+
}
|
|
98
|
+
process.stdout.write(text.endsWith("\n") ? text : text + "\n");
|
|
99
|
+
process.stderr.write(`\nFixed ${changes.length} thing${changes.length === 1 ? "" : "s"}. ${left.length} left for you:\n`);
|
|
100
|
+
for (const x of left) process.stderr.write(` L${String(x.line).padEnd(4)} ${x.severity.padEnd(7)} ${x.message}\n`);
|
|
101
|
+
const after = factcheck(text, { source, today: opts.today, only: opts.only, allowNames: opts.allow });
|
|
102
|
+
process.exit(opts.failUnder != null && after.score < opts.failUnder ? 1 : 0);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (opts.json) {
|
|
106
|
+
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
107
|
+
} else {
|
|
108
|
+
const tty = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
109
|
+
const c = (code, s) => (tty ? `\x1b[${code}m${s}\x1b[0m` : s);
|
|
110
|
+
const sev = { error: c(31, "error "), warning: c(33, "warning"), note: c(36, "note ") };
|
|
111
|
+
const src = opts.sources.length ? `against ${opts.sources.join(", ")}` : c(2, "(no --source: number, name and date-source checks skipped)");
|
|
112
|
+
const { error, warning, note } = result.counts;
|
|
113
|
+
process.stdout.write(`\n${c(1, opts.file === "-" ? "stdin" : opts.file)} ${src}\n`);
|
|
114
|
+
process.stdout.write(`${c(1, `Score ${result.score}/100 (${result.grade})`)} ${error} errors, ${warning} warnings, ${note} notes\n`);
|
|
115
|
+
process.stdout.write(c(2, result.dimensions.filter((d) => d.ran).map((d) => `${d.label} ${d.score}`).join(" · ")) + "\n\n");
|
|
116
|
+
for (const x of result.findings) {
|
|
117
|
+
process.stdout.write(` L${String(x.line).padEnd(4)} ${sev[x.severity]} ${c(2, x.check.padEnd(16))} ${x.message}\n`);
|
|
118
|
+
}
|
|
119
|
+
if (!result.findings.length) process.stdout.write(" No problems found.\n");
|
|
120
|
+
process.stdout.write("\n");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (opts.failUnder != null && result.score < opts.failUnder) process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avinashgaurav/manti",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Manti, the fact-checker for AI-written docs. 25 checks for made-up numbers, fake sources and quotes, wrong maths and scale, broken dates and missing pieces, against the notes you gave the AI. Fixes what it can. GitHub Action and optional AI double-check included.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"manti": "bin/manti.js",
|
|
8
|
+
"factcheck-docs": "bin/manti.js"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": { "access": "public" },
|
|
11
|
+
"main": "src/index.js",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./src/index.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"bin",
|
|
17
|
+
"src",
|
|
18
|
+
"action",
|
|
19
|
+
"action.yml",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "node --test test/*.test.js",
|
|
28
|
+
"bench": "node bench/run.js"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"ai",
|
|
32
|
+
"chatgpt",
|
|
33
|
+
"claude",
|
|
34
|
+
"docs",
|
|
35
|
+
"eval",
|
|
36
|
+
"evals",
|
|
37
|
+
"fact-check",
|
|
38
|
+
"hallucination",
|
|
39
|
+
"llm",
|
|
40
|
+
"manti",
|
|
41
|
+
"prd",
|
|
42
|
+
"product-management",
|
|
43
|
+
"scorecard"
|
|
44
|
+
],
|
|
45
|
+
"author": "Avinash Gaurav (https://github.com/avinashgaurav)",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+https://github.com/avinashgaurav/manti.git"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://avinashgaurav.github.io/manti/"
|
|
52
|
+
}
|