liarliar 0.0.0 → 0.1.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/README.md +26 -1
- package/dist/check.d.ts +5 -0
- package/dist/check.js +38 -0
- package/dist/claims.d.ts +34 -0
- package/dist/claims.js +216 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +62 -0
- package/dist/code.d.ts +27 -0
- package/dist/code.js +231 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.js +33 -0
- package/dist/files.d.ts +3 -0
- package/dist/files.js +13 -0
- package/dist/generated.d.ts +12 -0
- package/dist/generated.js +63 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +6 -0
- package/dist/markdown.d.ts +20 -0
- package/dist/markdown.js +44 -0
- package/dist/names.d.ts +10 -0
- package/dist/names.js +38 -0
- package/dist/numbers.d.ts +22 -0
- package/dist/numbers.js +79 -0
- package/dist/owners.d.ts +8 -0
- package/dist/owners.js +82 -0
- package/dist/report.d.ts +6 -0
- package/dist/report.js +27 -0
- package/dist/resolve.d.ts +20 -0
- package/dist/resolve.js +42 -0
- package/dist/tables.d.ts +20 -0
- package/dist/tables.js +75 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.js +1 -0
- package/package.json +22 -4
package/dist/tables.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { resolve } from './resolve.js';
|
|
2
|
+
/**
|
|
3
|
+
* Claims in Markdown tables: a row that names code in its first cell and gives a value in a column headed
|
|
4
|
+
* "Default", "Without it" or "Value", as quoted code and nothing else (bar a note in brackets):
|
|
5
|
+
*
|
|
6
|
+
* | Variable | What | Default |
|
|
7
|
+
* | `MODEL_JUDGE` | The judge | `auto` |
|
|
8
|
+
* | `MIN_A`, `MIN_B` | Two floors | `2`, `5` |
|
|
9
|
+
*
|
|
10
|
+
* One value for the row, or one per name in order. An env variable is held to the defaults the code gives it;
|
|
11
|
+
* a constant to its value. A name the code doesn't know is left to the names check.
|
|
12
|
+
*/
|
|
13
|
+
export const VALUE_COLUMN = /default|without|value|fallback/i;
|
|
14
|
+
const cells = (line) => line.trim().replace(/^\||\|$/g, '').split(/(?<!\\)\|/).map((c) => c.trim());
|
|
15
|
+
const same = (said, value) => (typeof value === 'number' ? Number(said) === value : typeof value === 'string' || typeof value === 'boolean' ? said === String(value) : false);
|
|
16
|
+
export function checkTables(doc, index, column = VALUE_COLUMN) {
|
|
17
|
+
const findings = [];
|
|
18
|
+
let bound = 0;
|
|
19
|
+
let passed = 0;
|
|
20
|
+
const lines = doc.text.split('\n');
|
|
21
|
+
let header;
|
|
22
|
+
let offset = 0;
|
|
23
|
+
for (let i = 0; i < lines.length; offset += lines[i].length + 1, i++) {
|
|
24
|
+
const line = lines[i];
|
|
25
|
+
if (!line.trim().startsWith('|')) {
|
|
26
|
+
header = undefined;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (!header) {
|
|
30
|
+
header = cells(line);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (/^\|?\s*:?-{3,}/.test(line.trim()))
|
|
34
|
+
continue;
|
|
35
|
+
const row = cells(line);
|
|
36
|
+
const names = [...(row[0] ?? '').matchAll(/`([A-Z][A-Z0-9_]+(?:\.\w+)*)`/g)].map((m) => m[1]);
|
|
37
|
+
if (!names.length)
|
|
38
|
+
continue;
|
|
39
|
+
header.forEach((title, c) => {
|
|
40
|
+
if (c === 0 || !column.test(title))
|
|
41
|
+
return;
|
|
42
|
+
const cell = row[c] ?? '';
|
|
43
|
+
if (!/^`[^`]+`(?:,\s*`[^`]+`)*(?:\s*\(.*\))?$/.test(cell))
|
|
44
|
+
return;
|
|
45
|
+
const said = [...cell.matchAll(/`([^`]+)`/g)].map((m) => m[1]);
|
|
46
|
+
names.forEach((name, n) => {
|
|
47
|
+
const value = said.length === 1 ? said[0] : said[n];
|
|
48
|
+
if (value === undefined)
|
|
49
|
+
return;
|
|
50
|
+
const env = (index.env.get(name) ?? []).filter((d) => d.value !== undefined);
|
|
51
|
+
const resolved = env.length ? undefined : resolve(index, name);
|
|
52
|
+
const candidates = env.length ? env : resolved?.kind === 'value' ? [resolved.where] : [];
|
|
53
|
+
const values = env.length ? env.map((d) => d.value) : resolved?.kind === 'value' ? [resolved.value] : [];
|
|
54
|
+
if (!values.length)
|
|
55
|
+
return;
|
|
56
|
+
bound += 1;
|
|
57
|
+
if (values.some((v) => same(value, v))) {
|
|
58
|
+
passed += 1;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const code = [...new Set(values.map((v) => (typeof v === 'string' ? v : JSON.stringify(v))))].join(' or ');
|
|
62
|
+
const where = candidates.map((d) => `${d.file}:${d.line}`).join(', ');
|
|
63
|
+
findings.push({
|
|
64
|
+
check: 'claim',
|
|
65
|
+
severity: 'error',
|
|
66
|
+
file: doc.file,
|
|
67
|
+
line: doc.line(offset),
|
|
68
|
+
message: `The table gives \`${value}\` for \`${name}\`, but ${where} ${env.length ? 'falls back to' : 'makes it'} \`${code}\`.`,
|
|
69
|
+
fix: `Write \`${code}\` in that cell of ${doc.file}, or change the code.`,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return { findings, bound, passed };
|
|
75
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { CodeIndex } from './code.js';
|
|
2
|
+
export type Check = 'claim' | 'name' | 'owner' | 'generated';
|
|
3
|
+
export interface Finding {
|
|
4
|
+
check: Check;
|
|
5
|
+
/** error fails the check; warning is shown but passes; info is only listed with --all. */
|
|
6
|
+
severity: 'error' | 'warning' | 'info';
|
|
7
|
+
file: string;
|
|
8
|
+
line: number;
|
|
9
|
+
/** What is wrong, in one sentence. */
|
|
10
|
+
message: string;
|
|
11
|
+
/** What to do about it, in one sentence an agent can act on. */
|
|
12
|
+
fix: string;
|
|
13
|
+
}
|
|
14
|
+
export interface Context {
|
|
15
|
+
root: string;
|
|
16
|
+
index: CodeIndex;
|
|
17
|
+
}
|
|
18
|
+
/** Writes a generated region or file from the code. */
|
|
19
|
+
export type Generator = (context: Context) => string | Promise<string>;
|
|
20
|
+
export interface Config {
|
|
21
|
+
/** The repository's root; defaults to the config file's folder or the working directory. */
|
|
22
|
+
root?: string;
|
|
23
|
+
/** Markdown files whose claims are held to the code. */
|
|
24
|
+
docs: string[];
|
|
25
|
+
/** TypeScript and JavaScript files whose constants and env defaults are the truth. */
|
|
26
|
+
code: string[];
|
|
27
|
+
/** Other files (SQL, YAML, JSON, TOML, .env.example) whose words count as names the code still has. */
|
|
28
|
+
words?: string[];
|
|
29
|
+
/** Globs left out of every list above. node_modules is always left out. */
|
|
30
|
+
ignore?: string[];
|
|
31
|
+
names?: {
|
|
32
|
+
/** Names a doc may give that the code doesn't have: set by a vendor, a platform or CI. */
|
|
33
|
+
allow?: string[];
|
|
34
|
+
/** Words that, near a name, say it was deliberately dropped ("removed", "renamed"). */
|
|
35
|
+
gone?: RegExp;
|
|
36
|
+
};
|
|
37
|
+
tables?: {
|
|
38
|
+
/** Table columns whose quoted values are held to the code (default: headed Default, Without, Value or Fallback). */
|
|
39
|
+
column?: RegExp;
|
|
40
|
+
};
|
|
41
|
+
owners?: {
|
|
42
|
+
/** The docs that own code (default: config.docs). */
|
|
43
|
+
docs?: string[];
|
|
44
|
+
/** The code that must have an owning doc, and whose changes must change it. */
|
|
45
|
+
code: string[];
|
|
46
|
+
/** Other names a doc may use for a file, such as a route's URL path for its handler. */
|
|
47
|
+
aliases?: (file: string) => string[];
|
|
48
|
+
/** Files with nothing a doc would say: helpers, clients, formatting. */
|
|
49
|
+
except?: string[];
|
|
50
|
+
/** The commit trailer that excuses a commit from changing a doc (default "Docs-unchanged"). */
|
|
51
|
+
trailer?: string;
|
|
52
|
+
/** The branch changes are compared with (default "origin/main"). */
|
|
53
|
+
base?: string;
|
|
54
|
+
/** Fail when an owned file has no doc at all (default true). */
|
|
55
|
+
requireDoc?: boolean;
|
|
56
|
+
};
|
|
57
|
+
/** Regions inside docs, by name: <!-- liarliar:generate NAME --> … <!-- liarliar:end -->. */
|
|
58
|
+
generate?: Record<string, Generator>;
|
|
59
|
+
/** Whole files written from the code, by path. */
|
|
60
|
+
files?: Record<string, Generator>;
|
|
61
|
+
}
|
|
62
|
+
export interface Report {
|
|
63
|
+
findings: Finding[];
|
|
64
|
+
/** Claims found and how many were checked, for "how much of the docs is held to the code". */
|
|
65
|
+
claims: {
|
|
66
|
+
bound: number;
|
|
67
|
+
passed: number;
|
|
68
|
+
unbound: number;
|
|
69
|
+
};
|
|
70
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "liarliar",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Docs that can't lie about the code
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Docs that can't lie about the code, even with ten agents editing it.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Pidgeon <hi@pidgeon.fyi>",
|
|
7
7
|
"homepage": "https://pidgeon.fyi",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
8
|
+
"type": "module",
|
|
9
|
+
"engines": { "node": ">=22" },
|
|
10
|
+
"bin": { "liarliar": "dist/cli.js" },
|
|
11
|
+
"exports": { ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" } },
|
|
12
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc -p tsconfig.build.json",
|
|
15
|
+
"typecheck": "tsc --noEmit",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"check": "tsc --noEmit && vitest run",
|
|
18
|
+
"prepublishOnly": "pnpm build && pnpm check"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"jiti": "^2.7.0",
|
|
22
|
+
"typescript": "^5.9.3"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^26.6.11",
|
|
26
|
+
"vitest": "^5.1.2"
|
|
27
|
+
},
|
|
10
28
|
"publishConfig": { "access": "public" }
|
|
11
29
|
}
|