@veda-hq/pariksha 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +25 -2
- package/dist/boundary.js +44 -0
- package/dist/cli.js +99 -0
- package/package.json +41 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The Veda Authors
|
|
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,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @veda-hq/pariksha
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
परीक्षा, examination. Repository checks: doc drift, rule enforcement,
|
|
4
|
+
test-quality ratchets. Part of [Veda](https://github.com/veda-hq/veda).
|
|
5
|
+
|
|
6
|
+
## v0.1: `pariksha boundary`
|
|
7
|
+
|
|
8
|
+
Refuses any file git tracks, by its path or its text, that names a word on
|
|
9
|
+
the repository's deny list.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npx @veda-hq/pariksha@0.1.0 boundary [--root <dir>] [--deny <file>]
|
|
13
|
+
npx @veda-hq/pariksha@0.1.0 hash <word>
|
|
14
|
+
npx @veda-hq/pariksha@0.1.0 --version
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- The deny list (default `.veda/deny.sha256`, relative to the root) holds one
|
|
18
|
+
SHA-256 hash of a lowercase word per line; blank lines and `#` comments are
|
|
19
|
+
ignored. `pariksha hash <word>` prints the line for a word.
|
|
20
|
+
- Words are runs of ASCII letters and digits, compared case-insensitively:
|
|
21
|
+
`foo-bar`, `foo_bar` and `@Foo/bar` all contain the word `foo`.
|
|
22
|
+
- Binary files (any NUL byte) are skipped. Untracked files are not read.
|
|
23
|
+
- Exit codes: 0 clean, 1 a denied word was found (each is listed with its file
|
|
24
|
+
and line; line 0 is the file's path), 2 a usage or deny-list error.
|
|
25
|
+
|
|
26
|
+
Node 24 or later. MIT.
|
package/dist/boundary.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// The boundary check: no tracked file names a denied name. The deny list holds
|
|
2
|
+
// SHA-256 hashes of lowercase words, so a repository can refuse a name without
|
|
3
|
+
// writing it down.
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
export const hash = (word) => createHash('sha256').update(word.toLowerCase()).digest('hex');
|
|
6
|
+
/** The deny list's hashes: one per line; blank lines and # comments ignored. */
|
|
7
|
+
export const parseDenyList = (text) => {
|
|
8
|
+
const hashes = new Set();
|
|
9
|
+
for (const raw of text.split('\n')) {
|
|
10
|
+
const line = raw.replace(/#.*/, '').trim().toLowerCase();
|
|
11
|
+
if (line === '')
|
|
12
|
+
continue;
|
|
13
|
+
if (!/^[0-9a-f]{64}$/.test(line))
|
|
14
|
+
throw new Error(`not a SHA-256 hash: "${line}"`);
|
|
15
|
+
hashes.add(line);
|
|
16
|
+
}
|
|
17
|
+
return hashes;
|
|
18
|
+
};
|
|
19
|
+
/** A file is text unless it holds a NUL byte. */
|
|
20
|
+
export const isText = (bytes) => !bytes.includes(0);
|
|
21
|
+
/** Every word of every file whose hash is denied, by file and line. */
|
|
22
|
+
export const findDenied = (files, deny) => {
|
|
23
|
+
const hits = [];
|
|
24
|
+
const seen = new Map();
|
|
25
|
+
const denied = (word) => {
|
|
26
|
+
let d = seen.get(word);
|
|
27
|
+
if (d === undefined) {
|
|
28
|
+
d = deny.has(hash(word));
|
|
29
|
+
seen.set(word, d);
|
|
30
|
+
}
|
|
31
|
+
return d;
|
|
32
|
+
};
|
|
33
|
+
for (const file of files) {
|
|
34
|
+
// A path names things too: a file called after a denied name is refused.
|
|
35
|
+
const lines = [file.path, ...file.text.split('\n')];
|
|
36
|
+
lines.forEach((text, i) => {
|
|
37
|
+
for (const word of text.toLowerCase().match(/[a-z0-9]+/g) ?? []) {
|
|
38
|
+
if (denied(word))
|
|
39
|
+
hits.push({ file: file.path, line: i, word });
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return hits;
|
|
44
|
+
};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// pariksha: repository checks. v0.1 has one, `boundary`.
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
5
|
+
import { join, resolve } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { findDenied, hash, isText, parseDenyList } from './boundary.js';
|
|
8
|
+
export const DENY_FILE = '.veda/deny.sha256';
|
|
9
|
+
const USAGE = [
|
|
10
|
+
'usage: pariksha boundary [--root <dir>] [--deny <file>]',
|
|
11
|
+
' pariksha hash <word>',
|
|
12
|
+
' pariksha --version',
|
|
13
|
+
].join('\n');
|
|
14
|
+
export const ownVersion = () => {
|
|
15
|
+
const pkg = join(import.meta.dirname, '..', 'package.json');
|
|
16
|
+
return JSON.parse(readFileSync(pkg, 'utf8')).version;
|
|
17
|
+
};
|
|
18
|
+
/** The files git tracks under root, text ones only. */
|
|
19
|
+
export const trackedFiles = (root) => {
|
|
20
|
+
const names = execFileSync('git', ['ls-files', '-z'], { cwd: root, encoding: 'utf8' }).split('\0').filter(Boolean);
|
|
21
|
+
const files = [];
|
|
22
|
+
for (const path of names) {
|
|
23
|
+
const full = join(root, path);
|
|
24
|
+
if (!existsSync(full))
|
|
25
|
+
continue; // deleted in the working tree, not yet committed
|
|
26
|
+
const bytes = readFileSync(full);
|
|
27
|
+
if (isText(bytes))
|
|
28
|
+
files.push({ path, text: bytes.toString('utf8') });
|
|
29
|
+
}
|
|
30
|
+
return files;
|
|
31
|
+
};
|
|
32
|
+
const flags = (rest) => {
|
|
33
|
+
const out = new Map();
|
|
34
|
+
for (let i = 0; i < rest.length; i += 2) {
|
|
35
|
+
const name = rest[i];
|
|
36
|
+
const value = rest[i + 1];
|
|
37
|
+
if ((name !== '--root' && name !== '--deny') || !value || out.has(name))
|
|
38
|
+
return undefined;
|
|
39
|
+
out.set(name, value);
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
};
|
|
43
|
+
const boundary = (rest, io) => {
|
|
44
|
+
const f = flags(rest);
|
|
45
|
+
if (!f) {
|
|
46
|
+
io.err(USAGE);
|
|
47
|
+
return 2;
|
|
48
|
+
}
|
|
49
|
+
const root = resolve(f.get('--root') ?? '.');
|
|
50
|
+
const denyPath = resolve(root, f.get('--deny') ?? DENY_FILE);
|
|
51
|
+
if (!existsSync(denyPath)) {
|
|
52
|
+
io.err(`pariksha boundary: no deny list at ${denyPath}`);
|
|
53
|
+
return 2;
|
|
54
|
+
}
|
|
55
|
+
let deny;
|
|
56
|
+
try {
|
|
57
|
+
deny = parseDenyList(readFileSync(denyPath, 'utf8'));
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
io.err(`pariksha boundary: ${denyPath}: ${e.message}`);
|
|
61
|
+
return 2;
|
|
62
|
+
}
|
|
63
|
+
const files = trackedFiles(root);
|
|
64
|
+
const hits = findDenied(files, deny);
|
|
65
|
+
if (hits.length > 0) {
|
|
66
|
+
for (const h of hits) {
|
|
67
|
+
const at = h.line === 0 ? `${h.file} (its path)` : `${h.file}:${h.line}`;
|
|
68
|
+
io.err(`pariksha boundary: ${at}: "${h.word}" is on the deny list`);
|
|
69
|
+
}
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
io.out(`pariksha boundary: ${files.length} files, none names a denied word (${deny.size} on the list)`);
|
|
73
|
+
return 0;
|
|
74
|
+
};
|
|
75
|
+
export const run = (args, io, version = ownVersion()) => {
|
|
76
|
+
const [command, ...rest] = args;
|
|
77
|
+
if (command === '--version' && rest.length === 0) {
|
|
78
|
+
io.out(version);
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
if (command === 'hash' && rest.length === 1 && rest[0]) {
|
|
82
|
+
io.out(hash(rest[0]));
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
if (command === 'boundary')
|
|
86
|
+
return boundary(rest, io);
|
|
87
|
+
io.err(USAGE);
|
|
88
|
+
return 2;
|
|
89
|
+
};
|
|
90
|
+
const isMain = () => {
|
|
91
|
+
const entry = process.argv[1];
|
|
92
|
+
return entry !== undefined && realpathSync(entry) === fileURLToPath(import.meta.url);
|
|
93
|
+
};
|
|
94
|
+
if (isMain()) {
|
|
95
|
+
process.exitCode = run(process.argv.slice(2), {
|
|
96
|
+
out: (line) => console.info(line),
|
|
97
|
+
err: (line) => console.error(line),
|
|
98
|
+
});
|
|
99
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veda-hq/pariksha",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Repository checks: doc drift, rule enforcement, test-quality ratchets. v0.1: the boundary check, which refuses any tracked file naming a denied word.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"repository checks",
|
|
7
|
+
"lint",
|
|
8
|
+
"boundary",
|
|
9
|
+
"ci",
|
|
10
|
+
"coding agents"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=24.15"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/veda-hq/veda.git",
|
|
20
|
+
"directory": "packages/pariksha"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/veda-hq/veda/tree/main/packages/pariksha#readme",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"provenance": true
|
|
26
|
+
},
|
|
27
|
+
"bin": {
|
|
28
|
+
"pariksha": "dist/cli.js"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "24.19.2",
|
|
35
|
+
"typescript": "7.0.2"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc -p tsconfig.build.json",
|
|
39
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
40
|
+
"test": "node --test --experimental-test-coverage --test-coverage-lines=95 --test-coverage-functions=95 --test-coverage-branches=90 --test-coverage-exclude=src/**/*.test.ts src/**/*.test.ts",
|
|
41
|
+
"smoke": "node dist/cli.js --version && node dist/cli.js boundary --root ../..",
|
|
42
|
+
"check": "pnpm typecheck && pnpm test && pnpm build && pnpm smoke"
|
|
43
|
+
}
|
|
6
44
|
}
|