@sema-agent/wiki-gate 0.0.0-stage → 7.67.1

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.
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Versions, severities and the age rules — the readings every gate entry grades a finding by.
3
+ */
4
+ /** A finding's severity: a warning prints, a failure sets the exit code. */
5
+ export type Severity = "warn" | "fail";
6
+ /** A `V` sentence this many minor versions behind the version under check is reported (never failed). */
7
+ export declare const V_AGE_MINORS = 3;
8
+ /** A `U` sentence whose acceptance cell is this many releases behind the repository is reported (never failed). */
9
+ export declare const U_AGE_RELEASES = 3;
10
+ /** `[major, minor, patch]` of an `X.Y.Z` version; undefined for anything else. */
11
+ export declare function parseVersion(v: unknown): [number, number, number] | undefined;
12
+ /** -1 / 0 / 1; a version that is not X.Y.Z throws (a severity judged on NaN would read every finding as a warning). */
13
+ export declare function compareVersions(a: string, b: string): -1 | 0 | 1;
14
+ /**
15
+ * Where a severity is judged: the version under check, the strict reading, and the version findings fail from — the
16
+ * repository's own, for the genre under check.
17
+ */
18
+ export interface SeverityContext {
19
+ readonly version: string;
20
+ readonly strict?: boolean;
21
+ readonly redFrom: string;
22
+ }
23
+ /** A finding's severity. `finding.fixed` is a severity the version does not move. */
24
+ export declare function severityOf(finding: {
25
+ readonly fixed?: Severity;
26
+ }, { version, strict, redFrom }: SeverityContext): Severity;
27
+ /** One `run:` ref read: who ran it, against which package at which version, and when. */
28
+ export interface RunRef {
29
+ readonly who: string;
30
+ readonly pkg: string;
31
+ readonly version: string;
32
+ readonly date: string;
33
+ }
34
+ /** `who@pkg@ver@date` — the package may be scoped (`dgx@@sema-agent/server@7.145.0@2026-11-05`). */
35
+ export declare function parseRun(body: string): RunRef | undefined;
36
+ /** The repository a gate checks: its package name, the version its releases carry, and the word its pages name it by. */
37
+ export interface RepoIdentity {
38
+ readonly name: string;
39
+ readonly version: string;
40
+ }
41
+ /**
42
+ * How old a `V` sentence is, against the version of the package it names that this check reads — never against the
43
+ * page's own `verified:` line, which moves only when the page is restamped. It takes {@link parseRun}'s answer as it
44
+ * is; a run that answer could not read is a caller's fault and throws (the anchors gate never asks about one).
45
+ */
46
+ export declare function vAgeFinding(run: RunRef | undefined, repo: RepoIdentity): {
47
+ message: string;
48
+ fixed: Severity;
49
+ } | undefined;
50
+ /**
51
+ * How many releases separate two versions of one repository, as that repository releases: undefined when it cannot
52
+ * say. This reading counts minor versions inside one major (a repository that releases by patch hands in its own).
53
+ */
54
+ export type ReleaseDistance = (from: string, to: string) => number | undefined;
55
+ /** The distance by minor versions inside one major; another major is a distance this reading cannot say. */
56
+ export declare const minorReleaseDistance: ReleaseDistance;
57
+ /**
58
+ * How old a `U` sentence is: its acceptance cell's version against the repository's, by the repository's release
59
+ * distance. Never failed — a person, not a machine, re-runs a black-box cell.
60
+ */
61
+ export declare function uAgeFinding(cellVersion: string, repo: RepoIdentity, distance: ReleaseDistance): {
62
+ message: string;
63
+ fixed: Severity;
64
+ } | undefined;
@@ -0,0 +1,53 @@
1
+ export const V_AGE_MINORS = 3;
2
+ export const U_AGE_RELEASES = 3;
3
+ export function parseVersion(v) {
4
+ const m = /^(\d+)\.(\d+)\.(\d+)$/.exec(String(v));
5
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : undefined;
6
+ }
7
+ export function compareVersions(a, b) {
8
+ const pa = parseVersion(a);
9
+ const pb = parseVersion(b);
10
+ if (pa === undefined || pb === undefined)
11
+ throw new Error(`a version must read X.Y.Z, got ${JSON.stringify(pa === undefined ? a : b)}`);
12
+ for (let i = 0; i < 3; i++)
13
+ if (pa[i] !== pb[i])
14
+ return pa[i] < pb[i] ? -1 : 1;
15
+ return 0;
16
+ }
17
+ export function severityOf(finding, { version, strict = false, redFrom }) {
18
+ if (finding.fixed !== undefined)
19
+ return finding.fixed;
20
+ return strict || compareVersions(version, redFrom) >= 0 ? "fail" : "warn";
21
+ }
22
+ export function parseRun(body) {
23
+ const m = /^([a-z0-9-]+)@(@?[a-z0-9][a-z0-9./_-]*)@(\d+\.\d+\.\d+)@(\d{4}-\d{2}-\d{2})$/.exec(body);
24
+ return m ? { who: m[1], pkg: m[2], version: m[3], date: m[4] } : undefined;
25
+ }
26
+ export function vAgeFinding(run, repo) {
27
+ if (run === undefined)
28
+ throw new TypeError("vAgeFinding: no run to judge (parseRun read none)");
29
+ if (run.pkg !== repo.name)
30
+ return { message: `the run names ${run.pkg}, of which this check reads no version: its age cannot be judged`, fixed: "warn" };
31
+ const [maj, min] = parseVersion(run.version);
32
+ const [nowMaj, nowMin] = parseVersion(repo.version);
33
+ if (maj !== nowMaj)
34
+ return { message: `the run is at ${run.version}, another major than ${repo.version}`, fixed: "fail" };
35
+ if (nowMin - min >= V_AGE_MINORS)
36
+ return { message: `the run is at ${run.version}, ${nowMin - min} minor versions behind ${repo.version}`, fixed: "warn" };
37
+ return undefined;
38
+ }
39
+ export const minorReleaseDistance = (from, to) => {
40
+ const a = parseVersion(from);
41
+ const b = parseVersion(to);
42
+ if (a === undefined || b === undefined || a[0] !== b[0])
43
+ return undefined;
44
+ return b[1] - a[1];
45
+ };
46
+ export function uAgeFinding(cellVersion, repo, distance) {
47
+ const d = distance(cellVersion, repo.version);
48
+ if (d === undefined)
49
+ return { message: `the acceptance cell is at ${cellVersion}, a distance from ${repo.version} this repository's release reading cannot say: its age cannot be judged`, fixed: "warn" };
50
+ if (d >= U_AGE_RELEASES)
51
+ return { message: `the acceptance cell is at ${cellVersion}, ${d} releases behind ${repo.version}`, fixed: "warn" };
52
+ return undefined;
53
+ }
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@sema-agent/wiki-gate",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "7.67.1",
4
+ "private": false,
5
+ "description": "The sema wiki gates as a library: one reader module with three gate entries (anchors, freshness, coverage) and the stamp, over a repository you name. The repository's own readers and generators are handed in; the rules are the package's.",
6
+ "type": "module",
7
+ "license": "BUSL-1.1",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/sema-agent/sema-core.git",
11
+ "directory": "packages/wiki-gate"
12
+ },
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "sideEffects": false,
25
+ "engines": {
26
+ "node": ">=20.18.1"
27
+ },
28
+ "dependencies": {
29
+ "typescript": "5.7.2"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "scripts": {
35
+ "build": "tsc -p tsconfig.json && tsc -p tsconfig.json --emitDeclarationOnly --removeComments false"
36
+ },
37
+ "gitHead": "f37485960eb53ae879d3f16fa176ecc0ea1506c8"
38
+ }