@unbrained/pm-lint 0.0.0-stage → 2026.10.28
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/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +446 -2
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/src/baseline-file.d.ts +7 -0
- package/dist/src/baseline-file.d.ts.map +1 -0
- package/dist/src/baseline-file.js +79 -0
- package/dist/src/baseline-file.js.map +1 -0
- package/dist/src/baseline.d.ts +39 -0
- package/dist/src/baseline.d.ts.map +1 -0
- package/dist/src/baseline.js +68 -0
- package/dist/src/baseline.js.map +1 -0
- package/dist/src/commands.d.ts +33 -0
- package/dist/src/commands.d.ts.map +1 -0
- package/dist/src/commands.js +94 -0
- package/dist/src/commands.js.map +1 -0
- package/dist/src/engine.d.ts +48 -0
- package/dist/src/engine.d.ts.map +1 -0
- package/dist/src/engine.js +124 -0
- package/dist/src/engine.js.map +1 -0
- package/dist/src/incremental-command.d.ts +6 -0
- package/dist/src/incremental-command.d.ts.map +1 -0
- package/dist/src/incremental-command.js +27 -0
- package/dist/src/incremental-command.js.map +1 -0
- package/dist/src/incremental-contract.d.ts +72 -0
- package/dist/src/incremental-contract.d.ts.map +1 -0
- package/dist/src/incremental-contract.js +142 -0
- package/dist/src/incremental-contract.js.map +1 -0
- package/dist/src/incremental-file.d.ts +13 -0
- package/dist/src/incremental-file.d.ts.map +1 -0
- package/dist/src/incremental-file.js +119 -0
- package/dist/src/incremental-file.js.map +1 -0
- package/dist/src/incremental.d.ts +41 -0
- package/dist/src/incremental.d.ts.map +1 -0
- package/dist/src/incremental.js +116 -0
- package/dist/src/incremental.js.map +1 -0
- package/dist/src/repair-command.d.ts +6 -0
- package/dist/src/repair-command.d.ts.map +1 -0
- package/dist/src/repair-command.js +26 -0
- package/dist/src/repair-command.js.map +1 -0
- package/dist/src/repair-snapshot.d.ts +5 -0
- package/dist/src/repair-snapshot.d.ts.map +1 -0
- package/dist/src/repair-snapshot.js +66 -0
- package/dist/src/repair-snapshot.js.map +1 -0
- package/dist/src/repairs.d.ts +64 -0
- package/dist/src/repairs.d.ts.map +1 -0
- package/dist/src/repairs.js +129 -0
- package/dist/src/repairs.js.map +1 -0
- package/dist/src/rule-pack-command.d.ts +8 -0
- package/dist/src/rule-pack-command.d.ts.map +1 -0
- package/dist/src/rule-pack-command.js +30 -0
- package/dist/src/rule-pack-command.js.map +1 -0
- package/dist/src/rule-pack.d.ts +79 -0
- package/dist/src/rule-pack.d.ts.map +1 -0
- package/dist/src/rule-pack.js +174 -0
- package/dist/src/rule-pack.js.map +1 -0
- package/dist/src/rules.d.ts +28 -0
- package/dist/src/rules.d.ts.map +1 -0
- package/dist/src/rules.js +153 -0
- package/dist/src/rules.js.map +1 -0
- package/dist/src/settings.d.ts +31 -0
- package/dist/src/settings.d.ts.map +1 -0
- package/dist/src/settings.js +109 -0
- package/dist/src/settings.js.map +1 -0
- package/dist/src/sidecar-publication.d.ts +39 -0
- package/dist/src/sidecar-publication.d.ts.map +1 -0
- package/dist/src/sidecar-publication.js +105 -0
- package/dist/src/sidecar-publication.js.map +1 -0
- package/dist/src/statuses.d.ts +8 -0
- package/dist/src/statuses.d.ts.map +1 -0
- package/dist/src/statuses.js +10 -0
- package/dist/src/statuses.js.map +1 -0
- package/dist/src/types.d.ts +44 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/witness-command.d.ts +6 -0
- package/dist/src/witness-command.d.ts.map +1 -0
- package/dist/src/witness-command.js +27 -0
- package/dist/src/witness-command.js.map +1 -0
- package/dist/src/witnesses.d.ts +74 -0
- package/dist/src/witnesses.d.ts.map +1 -0
- package/dist/src/witnesses.js +171 -0
- package/dist/src/witnesses.js.map +1 -0
- package/docs/incremental-example.md +64 -0
- package/docs/incremental-validation.md +99 -0
- package/docs/portable-rule-packs-validation.md +86 -0
- package/docs/repair-preview-example.md +43 -0
- package/docs/repair-preview-validation.md +42 -0
- package/examples/authoring-rules.json +30 -0
- package/manifest.json +13 -0
- package/package.json +150 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"incremental-command.js","sourceRoot":"","sources":["../../src/incremental-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAElF,2GAA2G;AAC3G,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,GAA0B;IACpE,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC;QAC/B,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,MAAM,IAAI,kBAAkB,CAAC,eAAe,EAAE,qCAAqC,EAAE,+FAA+F,CAAC,CAAC;QACpN,MAAM,IAAI,GAAG,MAAM,mBAAmB,CAAC,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,OAAkB,CAAC,CAAC;QAC5J,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QAC7C,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IAC3G,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,CAAC,KAAK,YAAY,kBAAkB,CAAC;YAAE,MAAM,KAAK,CAAC;QACxD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IAClH,CAAC;AACH,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,0BAA0B,CAAC,GAAiB;IAC1D,GAAG,CAAC,eAAe,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,WAAW,EAAE,6EAA6E,EAAE,WAAW,EAAE,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,KAAK,EAAE;YACxM,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,kEAAkE,EAAE;YAC9I,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,+EAA+E,EAAE;SACpH,EAAE,QAAQ,EAAE,CAAC,8DAA8D,EAAE,6CAA6C,CAAC,EAAE,GAAG,EAAE,qBAAqB,EAAE,CAAC,CAAC,CAAC;AAC/J,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ItemMetadata, MutationEventPage } from '@unbrained/pm-cli/sdk';
|
|
2
|
+
import type { RuleCode } from './types.ts';
|
|
3
|
+
/** Strict resource ceilings; exhaustion refuses rather than truncating a complete result. */
|
|
4
|
+
export declare const INCREMENTAL_LIMITS: {
|
|
5
|
+
readonly items: 50000;
|
|
6
|
+
readonly bytes: number;
|
|
7
|
+
readonly events: 1000000;
|
|
8
|
+
readonly time: 8640000000000000;
|
|
9
|
+
};
|
|
10
|
+
/** Dependencies of a predicate, separate from freshly rendered finding evidence. */
|
|
11
|
+
export interface RuleDependency {
|
|
12
|
+
fields: readonly (keyof ItemMetadata)[];
|
|
13
|
+
global: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Global predicates always run: clock, hierarchy, local references and SDK duplicate clusters. */
|
|
16
|
+
export declare const RULE_DEPENDENCIES: Readonly<Record<RuleCode, RuleDependency>>;
|
|
17
|
+
/** Saved predicate inputs, bounded display excerpts and a ten-bit violation set. */
|
|
18
|
+
export interface IncrementalItemState {
|
|
19
|
+
id: string;
|
|
20
|
+
source_digest: string;
|
|
21
|
+
inputs: string[];
|
|
22
|
+
excerpts: string[];
|
|
23
|
+
violations: number;
|
|
24
|
+
}
|
|
25
|
+
/** SDK cursor plus an anchor whose continued existence is checked through the SDK. */
|
|
26
|
+
export interface IncrementalCursor {
|
|
27
|
+
value: string;
|
|
28
|
+
item_id: string;
|
|
29
|
+
version: number;
|
|
30
|
+
ts: string;
|
|
31
|
+
}
|
|
32
|
+
/** Portable, checksummed checkpoint owned exclusively by this package. */
|
|
33
|
+
export interface IncrementalCheckpoint {
|
|
34
|
+
owner: 'pm-lint-incremental';
|
|
35
|
+
format: 1;
|
|
36
|
+
rule_version: string;
|
|
37
|
+
policy_digest: string;
|
|
38
|
+
source_id: string;
|
|
39
|
+
cursor: IncrementalCursor | null;
|
|
40
|
+
items: IncrementalItemState[];
|
|
41
|
+
digest: string;
|
|
42
|
+
}
|
|
43
|
+
/** Controls accepted at the SDK boundary; a rebuild must be explicit. */
|
|
44
|
+
export interface IncrementalRequest {
|
|
45
|
+
rebuild?: boolean;
|
|
46
|
+
checkpoint?: IncrementalCheckpoint;
|
|
47
|
+
now?: number;
|
|
48
|
+
}
|
|
49
|
+
/** Machine categories with concrete recovery instructions on every refusal. */
|
|
50
|
+
export type IncrementalRefusalCode = 'invalid_input' | 'rebuild_required' | 'foreign_state' | 'rule_drift' | 'policy_drift' | 'cursor_lost' | 'source_changed' | 'limit_exceeded' | 'state_busy' | 'state_io';
|
|
51
|
+
/** Typed, privacy-conscious refusal shared by SDK and CLI. */
|
|
52
|
+
export declare class IncrementalRefusal extends Error {
|
|
53
|
+
/** Stable machine-readable category. */
|
|
54
|
+
readonly code: IncrementalRefusalCode;
|
|
55
|
+
/** Concrete next action without private source details. */
|
|
56
|
+
readonly remedy: string;
|
|
57
|
+
/** Keep diagnostics independent of untrusted content and local paths. */
|
|
58
|
+
constructor(code: IncrementalRefusalCode, message: string, remedy?: string);
|
|
59
|
+
}
|
|
60
|
+
/** Check exact finite integer domains before any successful numeric output. */
|
|
61
|
+
export declare function incrementalInteger(value: unknown, max: number): number;
|
|
62
|
+
/** Apply the same hard limits to validated input, source receipts and checkpoint producers. */
|
|
63
|
+
export declare function assertIncrementalLimit(value: number, max: number): void;
|
|
64
|
+
/** Validate continuation progress independently of the SDK transport; fuzzable with real page data. */
|
|
65
|
+
export declare function assertIncrementalPage(page: MutationEventPage, seen: ReadonlySet<string>): void;
|
|
66
|
+
/** Validate every emitted numeric leaf, including future receipt fields and per-rule totals. */
|
|
67
|
+
export declare function validateIncrementalNumbers(value: unknown): void;
|
|
68
|
+
/** Validate and detach an imported checkpoint using the same schema as every producer. */
|
|
69
|
+
export declare function parseIncrementalCheckpoint(value: unknown): IncrementalCheckpoint;
|
|
70
|
+
/** Parse the only incremental request schema before accessing any SDK source. */
|
|
71
|
+
export declare function parseIncrementalRequest(value: unknown): IncrementalRequest;
|
|
72
|
+
//# sourceMappingURL=incremental-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"incremental-contract.d.ts","sourceRoot":"","sources":["../../src/incremental-contract.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,6FAA6F;AAC7F,eAAO,MAAM,kBAAkB;aAAK,KAAK,EAAE,KAAK;aAAE,KAAK;aAAoB,MAAM,EAAE,OAAO;aAAE,IAAI,EAAE,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Aa,GAAG,gBAAgB,GAAG,gBAAgB,GAAG,YAAY,GAAG,UAAU,CAAC;AAE9M,8DAA8D;AAC9D,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IACtC,2DAA2D;IAC3D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,yEAAyE;IACzE,YAAY,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAyF,EAKzJ;CACF;AAqBD,+EAA+E;AAC/E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAGtE;AACD,+FAA+F;AAC/F,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAEvE;AACD,uGAAuG;AACvG,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,CAG9F;AACD,gGAAgG;AAChG,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAK/D;AAQD,0FAA0F;AAC1F,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,qBAAqB,CA8BhF;AAED,iFAAiF;AACjF,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,kBAAkB,CAU1E"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { sourceDigest } from './baseline.js';
|
|
2
|
+
import { RULES } from './rules.js';
|
|
3
|
+
/** Strict resource ceilings; exhaustion refuses rather than truncating a complete result. */
|
|
4
|
+
export const INCREMENTAL_LIMITS = { items: 50000, bytes: 64 * 1024 * 1024, events: 1000000, time: 8640000000000000 };
|
|
5
|
+
/** Global predicates always run: clock, hierarchy, local references and SDK duplicate clusters. */
|
|
6
|
+
export const RULE_DEPENDENCIES = {
|
|
7
|
+
PML001: { fields: ['title'], global: false },
|
|
8
|
+
PML002: { fields: ['type', 'acceptance_criteria'], global: false },
|
|
9
|
+
PML003: { fields: ['title', 'acceptance_criteria'], global: false },
|
|
10
|
+
PML004: { fields: ['title', 'resolution', 'actual_result', 'close_reason', 'closed_at', 'comments'], global: false },
|
|
11
|
+
PML005: { fields: [], global: true },
|
|
12
|
+
PML006: { fields: ['type', 'files', 'tests'], global: false },
|
|
13
|
+
PML007: { fields: [], global: true },
|
|
14
|
+
PML008: { fields: ['title', 'description', 'notes'], global: false },
|
|
15
|
+
PML009: { fields: [], global: true },
|
|
16
|
+
PML010: { fields: [], global: true },
|
|
17
|
+
};
|
|
18
|
+
/** Typed, privacy-conscious refusal shared by SDK and CLI. */
|
|
19
|
+
export class IncrementalRefusal extends Error {
|
|
20
|
+
/** Stable machine-readable category. */
|
|
21
|
+
code;
|
|
22
|
+
/** Concrete next action without private source details. */
|
|
23
|
+
remedy;
|
|
24
|
+
/** Keep diagnostics independent of untrusted content and local paths. */
|
|
25
|
+
constructor(code, message, remedy = 'Run lint incremental --state <file> --rebuild to create a fresh complete checkpoint.') {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = 'IncrementalRefusal';
|
|
28
|
+
this.code = code;
|
|
29
|
+
this.remedy = remedy;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** One strict schema primitive for versioned request and checkpoint records. */
|
|
33
|
+
function record(value, required, optional = []) {
|
|
34
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value) || (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) || required.some(/** Required keys cannot be inherited or omitted. */ /** Required keys cannot be inherited or omitted. */ key => !Object.hasOwn(value, key)) || Object.keys(value).some(/** Refuse misspelled or unsupported controls. */ /** Refuse misspelled or unsupported controls. */ key => !required.includes(key) && !optional.includes(key)))
|
|
35
|
+
invalid();
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
/** A schema failure never silently creates an empty successful checkpoint. */
|
|
39
|
+
function invalid() {
|
|
40
|
+
throw new IncrementalRefusal('invalid_input', 'Invalid incremental request or checkpoint schema.', 'Correct the documented request fields; for damaged state, preserve it and choose a new state file with --rebuild.');
|
|
41
|
+
}
|
|
42
|
+
/** Require dense bounded arrays, including when callers bypass JSON transport. */
|
|
43
|
+
function array(value, max) {
|
|
44
|
+
if (!Array.isArray(value) || value.length > max || Object.keys(value).length !== value.length || Array.from({ length: value.length }, /** Sparse positions must be owned values. */ (_, i) => !Object.hasOwn(value, i)).some(Boolean))
|
|
45
|
+
invalid();
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
/** Keep literal identifiers readable across old tracker formats without imposing a new ID alphabet. */
|
|
49
|
+
function text(value, max) {
|
|
50
|
+
if (typeof value !== 'string' || value.length === 0 || value.length > max)
|
|
51
|
+
invalid();
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
/** Check exact finite integer domains before any successful numeric output. */
|
|
55
|
+
export function incrementalInteger(value, max) {
|
|
56
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0 || value > max)
|
|
57
|
+
invalid();
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
/** Apply the same hard limits to validated input, source receipts and checkpoint producers. */
|
|
61
|
+
export function assertIncrementalLimit(value, max) {
|
|
62
|
+
if (value > max)
|
|
63
|
+
throw new IncrementalRefusal('limit_exceeded', 'Incremental scan exceeds a documented resource ceiling.', 'Use a tracker and history within the documented item, event and checkpoint byte ceilings; never truncate a scan.');
|
|
64
|
+
}
|
|
65
|
+
/** Validate continuation progress independently of the SDK transport; fuzzable with real page data. */
|
|
66
|
+
export function assertIncrementalPage(page, seen) {
|
|
67
|
+
incrementalInteger(page.count, 1000);
|
|
68
|
+
if (page.count !== page.events.length || (page.has_more && page.count === 0) || (page.count > 0 && (page.next_cursor === undefined || seen.has(page.next_cursor))))
|
|
69
|
+
throw new IncrementalRefusal('cursor_lost', 'SDK pagination did not supply a complete progressing page.');
|
|
70
|
+
}
|
|
71
|
+
/** Validate every emitted numeric leaf, including future receipt fields and per-rule totals. */
|
|
72
|
+
export function validateIncrementalNumbers(value) {
|
|
73
|
+
if (typeof value === 'number')
|
|
74
|
+
incrementalInteger(value, Number.MAX_SAFE_INTEGER);
|
|
75
|
+
else if (typeof value === 'object' && value !== null) {
|
|
76
|
+
for (const child of Object.values(value))
|
|
77
|
+
validateIncrementalNumbers(child);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Validate producer digests without accepting truncated evidence. */
|
|
81
|
+
function digest(value) {
|
|
82
|
+
const hash = text(value, 64);
|
|
83
|
+
if (!/^[a-f0-9]{64}$/.test(hash))
|
|
84
|
+
invalid();
|
|
85
|
+
return hash;
|
|
86
|
+
}
|
|
87
|
+
/** Validate and detach an imported checkpoint using the same schema as every producer. */
|
|
88
|
+
export function parseIncrementalCheckpoint(value) {
|
|
89
|
+
const row = record(value, ['owner', 'format', 'rule_version', 'policy_digest', 'source_id', 'cursor', 'items', 'digest']);
|
|
90
|
+
if (row.owner !== 'pm-lint-incremental')
|
|
91
|
+
throw new IncrementalRefusal('foreign_state', 'Checkpoint belongs to another producer; it was skipped.', 'Choose a separate checkpoint file; foreign records are never overwritten.');
|
|
92
|
+
if (row.format !== 1)
|
|
93
|
+
invalid();
|
|
94
|
+
let cursor = null;
|
|
95
|
+
if (row.cursor !== null) {
|
|
96
|
+
const entry = record(row.cursor, ['value', 'item_id', 'version', 'ts']);
|
|
97
|
+
cursor = { value: text(entry.value, 4096), item_id: text(entry.item_id, 4096), version: incrementalInteger(entry.version, Number.MAX_SAFE_INTEGER), ts: text(entry.ts, 64) };
|
|
98
|
+
if (cursor.version === 0 || !Number.isFinite(Date.parse(cursor.ts)))
|
|
99
|
+
invalid();
|
|
100
|
+
}
|
|
101
|
+
const seen = new Set();
|
|
102
|
+
const items = array(row.items, INCREMENTAL_LIMITS.items).map(/** Rebuild each row from validated primitives; never normalize native item data. */ /** Rebuild each row from validated primitives; never normalize native item data. */ value => {
|
|
103
|
+
const item = record(value, ['id', 'source_digest', 'inputs', 'excerpts', 'violations']);
|
|
104
|
+
const id = text(item.id, 4096);
|
|
105
|
+
if (seen.has(id))
|
|
106
|
+
invalid();
|
|
107
|
+
seen.add(id);
|
|
108
|
+
const inputs = array(item.inputs, RULES.length).map(/** Empty input digests identify declared global checks. */ /** Empty input digests identify declared global checks. */ value => value === '' ? '' : digest(value));
|
|
109
|
+
if (inputs.length !== RULES.length)
|
|
110
|
+
invalid();
|
|
111
|
+
const excerpts = array(item.excerpts, RULES.length).map(/** Blank excerpts represent absence findings or clean pairs. */ /** Blank excerpts represent absence findings or clean pairs. */ value => {
|
|
112
|
+
if (typeof value !== 'string' || value.length > 160)
|
|
113
|
+
invalid();
|
|
114
|
+
return value;
|
|
115
|
+
});
|
|
116
|
+
if (excerpts.length !== RULES.length)
|
|
117
|
+
invalid();
|
|
118
|
+
return { id, source_digest: digest(item.source_digest), inputs, excerpts, violations: incrementalInteger(item.violations, (1 << RULES.length) - 1) };
|
|
119
|
+
});
|
|
120
|
+
const checkpoint = { owner: row.owner, format: row.format, rule_version: text(row.rule_version, 128), policy_digest: digest(row.policy_digest), source_id: digest(row.source_id), cursor, items, digest: digest(row.digest) };
|
|
121
|
+
const { digest: checksum, ...payload } = checkpoint;
|
|
122
|
+
if (sourceDigest(payload) !== checksum)
|
|
123
|
+
invalid();
|
|
124
|
+
assertIncrementalLimit(Buffer.byteLength(JSON.stringify(checkpoint)), INCREMENTAL_LIMITS.bytes);
|
|
125
|
+
return checkpoint;
|
|
126
|
+
}
|
|
127
|
+
/** Parse the only incremental request schema before accessing any SDK source. */
|
|
128
|
+
export function parseIncrementalRequest(value) {
|
|
129
|
+
const input = record(value, [], ['rebuild', 'checkpoint', 'now']);
|
|
130
|
+
const request = {};
|
|
131
|
+
if (input.rebuild !== undefined) {
|
|
132
|
+
if (typeof input.rebuild !== 'boolean')
|
|
133
|
+
invalid();
|
|
134
|
+
request.rebuild = input.rebuild;
|
|
135
|
+
}
|
|
136
|
+
if (input.now !== undefined)
|
|
137
|
+
request.now = incrementalInteger(input.now, INCREMENTAL_LIMITS.time);
|
|
138
|
+
if (input.checkpoint !== undefined)
|
|
139
|
+
request.checkpoint = parseIncrementalCheckpoint(input.checkpoint);
|
|
140
|
+
return request;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=incremental-contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"incremental-contract.js","sourceRoot":"","sources":["../../src/incremental-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAInC,6FAA6F;AAC7F,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAW,CAAC;AAK9H,mGAAmG;AACnG,MAAM,CAAC,MAAM,iBAAiB,GAA+C;IAC3E,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE;IAC5C,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,qBAAqB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE;IAClE,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,qBAAqB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE;IACnE,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE;IACpH,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;IACpC,M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YAAY,EAAE,KAAK,CAAC,CAAC,CAAC;IAClE,MAAM,OAAO,GAAuB,EAAE,CAAC;IACvC,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAChC,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,SAAS;YAAE,OAAO,EAAE,CAAC;QAClD,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAClC,CAAC;IACD,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS;QAAE,OAAO,CAAC,GAAG,GAAG,kBAAkB,CAAC,KAAK,CAAC,GAAG,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAClG,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS;QAAE,OAAO,CAAC,UAAU,GAAG,0BAA0B,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACtG,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IncrementalCheckpoint } from './incremental-contract.ts';
|
|
2
|
+
import type { IncrementalBoundary, IncrementalLintResult, IncrementalLintSource } from './incremental.ts';
|
|
3
|
+
/** File-wrapper boundaries let integration tests inject real peer transitions at every await. */
|
|
4
|
+
export type IncrementalFileBoundary = IncrementalBoundary | 'locked' | 'loaded' | 'publish' | 'published' | 'release';
|
|
5
|
+
/** Bind core SDK capabilities to one explicit local tracker; never resolve a host from argv or symlinks. */
|
|
6
|
+
export declare function filesystemLintSource(pmRoot: string): IncrementalLintSource;
|
|
7
|
+
/** Read one bounded regular checkpoint without following foreign symbolic links or waiting on pipes. */
|
|
8
|
+
export declare function readIncrementalCheckpoint(path: string): Promise<IncrementalCheckpoint | undefined>;
|
|
9
|
+
/** Decode exactly the observed regular-file size before passing bytes to the single checkpoint schema. */
|
|
10
|
+
export declare function decodeIncrementalCheckpoint(bytes: Uint8Array, expectedSize: number): IncrementalCheckpoint;
|
|
11
|
+
/** Serialize checkpoint writers with a core token-owned lease and fence the final atomic publication. */
|
|
12
|
+
export declare function lintIncrementalFile(source: IncrementalLintSource, statePath: string, rebuild?: boolean, onBoundary?: (boundary: IncrementalFileBoundary) => Promise<void>): Promise<IncrementalLintResult>;
|
|
13
|
+
//# sourceMappingURL=incremental-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"incremental-file.d.ts","sourceRoot":"","sources":["../../src/incremental-file.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAK1G,iGAAiG;AACjG,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC;AAEtH,4GAA4G;AAC5G,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB,CAU1E;AAED,wGAAwG;AACxG,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAaxG;AAED,0GAA0G;AAC1G,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,GAAG,qBAAqB,CAO1G;AAED,yGAAyG;AACzG,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,UAAQ,EAAE,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,uBAAuB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAwC9M"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { open, realpath } from 'node:fs/promises';
|
|
3
|
+
import { basename, dirname, resolve } from 'node:path';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { acquireLockLease, certifyCompleteListResult, listMutationEvents, PmClient } from '@unbrained/pm-cli/sdk';
|
|
6
|
+
import { sourceDigest } from './baseline.js';
|
|
7
|
+
import { INCREMENTAL_LIMITS, IncrementalRefusal, parseIncrementalCheckpoint, parseIncrementalRequest } from './incremental-contract.js';
|
|
8
|
+
import { lintIncremental } from './incremental.js';
|
|
9
|
+
import { readLintSettings, resolveConfig } from './settings.js';
|
|
10
|
+
import { readLintStatuses } from './statuses.js';
|
|
11
|
+
import { prepareSidecarPublication, readSidecarSnapshot, SidecarConflict } from './sidecar-publication.js';
|
|
12
|
+
/** Bind core SDK capabilities to one explicit local tracker; never resolve a host from argv or symlinks. */
|
|
13
|
+
export function filesystemLintSource(pmRoot) {
|
|
14
|
+
const root = resolve(pmRoot);
|
|
15
|
+
return {
|
|
16
|
+
identity: root,
|
|
17
|
+
client: PmClient.forActiveExtensionHost({ pmRoot: root, cwd: dirname(root) }),
|
|
18
|
+
/** The SDK owns event ordering, indexing, cursors and backend diagnostics. */
|
|
19
|
+
events: options => listMutationEvents({ ...options, pmRoot: root }),
|
|
20
|
+
/** Load settings and lifecycle roles through the supported SDK readers. */
|
|
21
|
+
policy: async () => ({ config: resolveConfig(await readLintSettings(root)), statuses: await readLintStatuses(root) }),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Read one bounded regular checkpoint without following foreign symbolic links or waiting on pipes. */
|
|
25
|
+
export async function readIncrementalCheckpoint(path) {
|
|
26
|
+
let handle;
|
|
27
|
+
try {
|
|
28
|
+
handle = await open(path, constants.O_RDONLY | constants.O_NONBLOCK | constants.O_NOFOLLOW);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error.code === 'ENOENT')
|
|
32
|
+
return undefined;
|
|
33
|
+
throw new IncrementalRefusal('state_io', 'Cannot open the checkpoint.', 'Use a readable regular checkpoint file; symbolic links and special files are unsupported.');
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const info = await handle.stat();
|
|
37
|
+
if (!info.isFile() || info.size > INCREMENTAL_LIMITS.bytes)
|
|
38
|
+
throw new IncrementalRefusal('state_io', 'Checkpoint is not a bounded regular file.', 'Use a regular checkpoint within the documented byte ceiling.');
|
|
39
|
+
const bytes = Buffer.alloc(info.size + 1);
|
|
40
|
+
const { bytesRead } = await handle.read(bytes, 0, bytes.length, 0);
|
|
41
|
+
return decodeIncrementalCheckpoint(bytes.subarray(0, bytesRead), info.size);
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
await handle.close();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Decode exactly the observed regular-file size before passing bytes to the single checkpoint schema. */
|
|
48
|
+
export function decodeIncrementalCheckpoint(bytes, expectedSize) {
|
|
49
|
+
if (bytes.byteLength !== expectedSize)
|
|
50
|
+
throw new IncrementalRefusal('state_io', 'Checkpoint changed while being read.', 'Retry after the current writer finishes.');
|
|
51
|
+
let value;
|
|
52
|
+
try {
|
|
53
|
+
value = JSON.parse(Buffer.from(bytes).toString('utf8'));
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
throw new IncrementalRefusal('invalid_input', 'Checkpoint JSON is malformed.', 'Preserve the damaged file for inspection and choose a new state file for an explicit rebuild.');
|
|
57
|
+
}
|
|
58
|
+
return parseIncrementalCheckpoint(value);
|
|
59
|
+
}
|
|
60
|
+
/** Serialize checkpoint writers with a core token-owned lease and fence the final atomic publication. */
|
|
61
|
+
export async function lintIncrementalFile(source, statePath, rebuild = false, onBoundary) {
|
|
62
|
+
parseIncrementalRequest({ rebuild });
|
|
63
|
+
if (typeof statePath !== 'string' || statePath.trim() === '')
|
|
64
|
+
throw new IncrementalRefusal('invalid_input', 'A state file is required.', 'Supply --state <file> in an existing writable cache directory.');
|
|
65
|
+
let path;
|
|
66
|
+
let lease;
|
|
67
|
+
try {
|
|
68
|
+
// Canonicalize the parent so cooperating writers using directory aliases share one lease.
|
|
69
|
+
path = resolve(await realpath(dirname(resolve(statePath))), basename(resolve(statePath)));
|
|
70
|
+
lease = await acquireLockLease(dirname(path), `lint-${sourceDigest(path)}`, 3600, randomUUID(), false, true, 0, { maxWaitMs: 0 });
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
throw new IncrementalRefusal('state_busy', 'Checkpoint lease is unavailable.', 'Retry after the peer writer finishes; verify the state directory exists and is writable.');
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
await onBoundary?.('locked');
|
|
77
|
+
let observed;
|
|
78
|
+
try {
|
|
79
|
+
observed = readSidecarSnapshot(path, INCREMENTAL_LIMITS.bytes);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
throw new IncrementalRefusal('state_io', 'Cannot read the checkpoint generation.', 'Use a readable regular checkpoint within the documented byte ceiling.');
|
|
83
|
+
}
|
|
84
|
+
const previous = observed === undefined ? undefined : decodeIncrementalCheckpoint(observed.bytes, observed.bytes.length);
|
|
85
|
+
await onBoundary?.('loaded');
|
|
86
|
+
const result = await lintIncremental(source, { rebuild, ...(previous === undefined ? {} : { checkpoint: previous }) }, onBoundary);
|
|
87
|
+
await onBoundary?.('publish');
|
|
88
|
+
const current = certifyCompleteListResult(await source.client.listAllComplete());
|
|
89
|
+
const revisions = current.items.map(/** Revalidate every source revision through the SDK before publishing derived state. */ /** Revalidate every source revision through the SDK before publishing derived state. */ item => [item.id, sourceDigest(item)]).sort();
|
|
90
|
+
const expected = result.checkpoint.items.map(/** Source order is irrelevant to the complete snapshot. */ /** Source order is irrelevant to the complete snapshot. */ item => [item.id, item.source_digest]).sort();
|
|
91
|
+
const policy = await source.policy();
|
|
92
|
+
if (sourceDigest(revisions) !== sourceDigest(expected) || sourceDigest({ config: policy.config, statuses: policy.statuses.definitions }) !== result.checkpoint.policy_digest)
|
|
93
|
+
throw new IncrementalRefusal('source_changed', 'Current SDK revisions no longer match the evaluated snapshot.', 'Retry against current SDK state; no stale checkpoint was published.');
|
|
94
|
+
let publication;
|
|
95
|
+
try {
|
|
96
|
+
publication = await prepareSidecarPublication(path, `${JSON.stringify(result.checkpoint)}\n`, observed, INCREMENTAL_LIMITS.bytes);
|
|
97
|
+
await lease.fence(/** Core fences ownership; the final target check and replacement do not yield. */ async () => { publication.commit(); });
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
if (error instanceof SidecarConflict)
|
|
101
|
+
throw new IncrementalRefusal('source_changed', error.message, 'Retry from the current checkpoint; foreign and peer state was preserved.');
|
|
102
|
+
throw new IncrementalRefusal('state_io', 'Checkpoint publication failed.', 'Verify storage and lease ownership, then retry from the current checkpoint.');
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
publication?.dispose();
|
|
106
|
+
}
|
|
107
|
+
await onBoundary?.('published');
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
try {
|
|
112
|
+
await onBoundary?.('release');
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
await lease.release();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=incremental-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"incremental-file.js","sourceRoot":"","sources":["../../src/incremental-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAClH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,kBAAkB,E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cli/sdk';
|
|
2
|
+
import type { LintResult } from './engine.ts';
|
|
3
|
+
import type { IncrementalCheckpoint, IncrementalRequest } from './incremental-contract.ts';
|
|
4
|
+
import type { LintStatusRegistry } from './statuses.ts';
|
|
5
|
+
import type { LintConfig, RuleCode } from './types.ts';
|
|
6
|
+
/** Native SDK capabilities supplied by a filesystem, remote or hosted adapter. */
|
|
7
|
+
export interface IncrementalLintSource {
|
|
8
|
+
/** Stable backend/workspace identity; persisted only as a digest. */
|
|
9
|
+
identity: string;
|
|
10
|
+
client: Pick<PmClient, 'listAllComplete'>;
|
|
11
|
+
events: (options: Pick<ListMutationEventsOptions, 'since' | 'limit' | 'item'>) => Promise<MutationEventPage>;
|
|
12
|
+
policy: () => Promise<{
|
|
13
|
+
config: LintConfig;
|
|
14
|
+
statuses: LintStatusRegistry;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
/** Observable boundaries for deterministic integration interleavings, never SDK mocks. */
|
|
18
|
+
export type IncrementalBoundary = 'policy' | 'anchor' | 'events' | 'corpus' | 'evaluated' | 'verified';
|
|
19
|
+
/** Evaluation counts measure actual predicate calls; all unchanged findings remain in result. */
|
|
20
|
+
export interface IncrementalLintResult {
|
|
21
|
+
result: LintResult;
|
|
22
|
+
checkpoint: IncrementalCheckpoint;
|
|
23
|
+
incremental: {
|
|
24
|
+
mode: 'rebuild' | 'update';
|
|
25
|
+
changed_items: number;
|
|
26
|
+
evaluated: number;
|
|
27
|
+
reused: number;
|
|
28
|
+
events: number;
|
|
29
|
+
event_pages: number;
|
|
30
|
+
by_rule: Record<RuleCode, {
|
|
31
|
+
evaluated: number;
|
|
32
|
+
reused: number;
|
|
33
|
+
global: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Hash both explicit version and dependency declarations so metadata drift cannot reuse stale outcomes. */
|
|
38
|
+
export declare function incrementalRuleVersion(): string;
|
|
39
|
+
/** Update a complete lint result, using only SDK reads and detached caller-owned checkpoint state. */
|
|
40
|
+
export declare function lintIncremental(source: IncrementalLintSource, input?: IncrementalRequest, onBoundary?: (boundary: IncrementalBoundary) => Promise<void>): Promise<IncrementalLintResult>;
|
|
41
|
+
//# sourceMappingURL=incremental.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"incremental.d.ts","sourceRoot":"","sources":["../../src/incremental.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGpG,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,aAAa,CAAC;AAE7D,OAAO,KAAK,EAAE,qBAAqB,EAA2C,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpI,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEvD,kFAAkF;AAClF,MAAM,WAAW,qBAAqB;IACpC,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;IAC1C,MAAM,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,yBAAyB,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC7G,MAAM,EAAE,MAAM,OAAO,CAAC;QAAE,MAAM,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE,kBAAkB,CAAA;KAAE,CAAC,CAAC;CAC7E;AACD,0FAA0F;AAC1F,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAC;AACvG,iGAAiG;AACjG,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,EAAE,qBAAqB,CAAC;IAClC,WAAW,EAAE;QACX,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;QAC3B,aAAa,EAAE,MAAM,CAAC;QACtB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC,QAAQ,EAAE;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,OAAO,CAAA;SAAE,CAAC,CAAC;KACnF,CAAC;CACH;AA2CD,4GAA4G;AAC5G,wBAAgB,sBAAsB,IAAI,MAAM,CAE/C;AAED,sGAAsG;AACtG,wBAAsB,eAAe,CAAC,MAAM,EAAE,qBAAqB,EAAE,KAAK,GAAE,kBAAuB,EAAE,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAmDlM"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { certifyCompleteListResult } from '@unbrained/pm-cli/sdk';
|
|
2
|
+
import { RULE_VERSION, sourceDigest } from './baseline.js';
|
|
3
|
+
import { evaluateRule, lintCorpus } from './engine.js';
|
|
4
|
+
import { assertIncrementalLimit, assertIncrementalPage, INCREMENTAL_LIMITS, IncrementalRefusal, parseIncrementalCheckpoint, parseIncrementalRequest, RULE_DEPENDENCIES, validateIncrementalNumbers } from './incremental-contract.js';
|
|
5
|
+
import { RULES } from './rules.js';
|
|
6
|
+
/** Drain core event pagination to a recoverable boundary; never infer continuation from time. */
|
|
7
|
+
async function drain(source, start, stats, item) {
|
|
8
|
+
let cursor = start;
|
|
9
|
+
let since = item === undefined ? start?.value : start.ts;
|
|
10
|
+
const ids = new Set();
|
|
11
|
+
const anchors = new Set();
|
|
12
|
+
const seen = new Set();
|
|
13
|
+
for (;;) {
|
|
14
|
+
const page = await readPage(source, { since, limit: 1000, ...(item === undefined ? {} : { item }) });
|
|
15
|
+
assertIncrementalPage(page, seen);
|
|
16
|
+
stats.event_pages += 1;
|
|
17
|
+
stats.events += page.count;
|
|
18
|
+
assertIncrementalLimit(stats.events, INCREMENTAL_LIMITS.events);
|
|
19
|
+
for (const event of page.events) {
|
|
20
|
+
ids.add(event.item_id);
|
|
21
|
+
anchors.add(`${event.item_id}:${event.version}:${event.ts}`);
|
|
22
|
+
}
|
|
23
|
+
if (page.count > 0) {
|
|
24
|
+
const last = page.events[page.events.length - 1];
|
|
25
|
+
seen.add(page.next_cursor);
|
|
26
|
+
cursor = { value: page.next_cursor, item_id: last.item_id, version: last.version, ts: last.ts };
|
|
27
|
+
since = page.next_cursor;
|
|
28
|
+
}
|
|
29
|
+
if (!page.has_more)
|
|
30
|
+
return { cursor, ids, anchors };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** Map native SDK cursor/read failures before applying package-owned progress and budget checks. */
|
|
34
|
+
async function readPage(source, options) {
|
|
35
|
+
try {
|
|
36
|
+
return await source.events(options);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
throw new IncrementalRefusal('cursor_lost', 'SDK event continuation is unavailable.');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Revalidate the saved SDK anchor; core cursors alone do not certify retained history. */
|
|
43
|
+
async function verifyAnchor(source, cursor, stats) {
|
|
44
|
+
if (cursor === null)
|
|
45
|
+
return;
|
|
46
|
+
const page = await drain(source, cursor, stats, cursor.item_id);
|
|
47
|
+
if (!page.anchors.has(`${cursor.item_id}:${cursor.version}:${cursor.ts}`))
|
|
48
|
+
throw new IncrementalRefusal('cursor_lost', 'The saved event anchor is no longer readable.');
|
|
49
|
+
}
|
|
50
|
+
/** Hash both explicit version and dependency declarations so metadata drift cannot reuse stale outcomes. */
|
|
51
|
+
export function incrementalRuleVersion() {
|
|
52
|
+
return sourceDigest({ version: RULE_VERSION, dependencies: RULE_DEPENDENCIES });
|
|
53
|
+
}
|
|
54
|
+
/** Update a complete lint result, using only SDK reads and detached caller-owned checkpoint state. */
|
|
55
|
+
export async function lintIncremental(source, input = {}, onBoundary) {
|
|
56
|
+
const request = parseIncrementalRequest(input);
|
|
57
|
+
const previous = request.checkpoint;
|
|
58
|
+
if (!request.rebuild && previous === undefined)
|
|
59
|
+
throw new IncrementalRefusal('rebuild_required', 'No checkpoint exists; an explicit rebuild is required.');
|
|
60
|
+
const identity = sourceDigest(source.identity);
|
|
61
|
+
if (previous !== undefined && previous.source_id !== identity)
|
|
62
|
+
throw new IncrementalRefusal('foreign_state', 'Checkpoint belongs to a different source; it was skipped.', 'Use a separate checkpoint for this source; foreign state is never overwritten.');
|
|
63
|
+
const { config, statuses } = await source.policy();
|
|
64
|
+
const policy = sourceDigest({ config, statuses: statuses.definitions });
|
|
65
|
+
await onBoundary?.('policy');
|
|
66
|
+
if (!request.rebuild && previous.rule_version !== incrementalRuleVersion())
|
|
67
|
+
throw new IncrementalRefusal('rule_drift', 'Rule version or dependency declarations changed.');
|
|
68
|
+
if (!request.rebuild && previous.policy_digest !== policy)
|
|
69
|
+
throw new IncrementalRefusal('policy_drift', 'Lint settings or configured status roles changed.');
|
|
70
|
+
const stats = { mode: request.rebuild ? 'rebuild' : 'update', changed_items: 0, evaluated: 0, reused: 0, events: 0, event_pages: 0, by_rule: Object.fromEntries(RULES.map(/** Keep all ten rule counts, including disabled or out-of-scope rules. */ /** Keep all ten rule counts, including disabled or out-of-scope rules. */ rule => [rule.code, { evaluated: 0, reused: 0, global: RULE_DEPENDENCIES[rule.code].global }])) };
|
|
71
|
+
if (!request.rebuild)
|
|
72
|
+
await verifyAnchor(source, previous.cursor, stats);
|
|
73
|
+
await onBoundary?.('anchor');
|
|
74
|
+
const events = await drain(source, request.rebuild ? null : previous.cursor, stats);
|
|
75
|
+
await onBoundary?.('events');
|
|
76
|
+
const corpus = certifyCompleteListResult(await source.client.listAllComplete());
|
|
77
|
+
await onBoundary?.('corpus');
|
|
78
|
+
assertIncrementalLimit(corpus.items.length, INCREMENTAL_LIMITS.items);
|
|
79
|
+
const old = new Map((request.rebuild ? [] : previous.items).map(/** Compare current SDK state, including changes to fields no predicate consumes. */ /** Compare current SDK state, including changes to fields no predicate consumes. */ item => [item.id, item]));
|
|
80
|
+
const current = new Map();
|
|
81
|
+
for (const item of corpus.items) {
|
|
82
|
+
current.set(item.id, { id: item.id, source_digest: sourceDigest(item), inputs: RULES.map(/** Status participates in every pair because it determines applicability. */ /** Status participates in every pair because it determines applicability. */ rule => RULE_DEPENDENCIES[rule.code].global ? '' : sourceDigest([item.status, ...RULE_DEPENDENCIES[rule.code].fields.map(/** Native SDK values define dependency equality. */ /** Native SDK values define dependency equality. */ field => item[field])])), excerpts: RULES.map(/** Clean and out-of-scope pairs carry no saved text. */ () => ''), violations: 0 });
|
|
83
|
+
}
|
|
84
|
+
for (const id of new Set([...old.keys(), ...current.keys()])) {
|
|
85
|
+
if (old.get(id)?.source_digest === current.get(id)?.source_digest)
|
|
86
|
+
continue;
|
|
87
|
+
stats.changed_items += 1;
|
|
88
|
+
if (!request.rebuild && !events.ids.has(id))
|
|
89
|
+
throw new IncrementalRefusal('cursor_lost', 'Current SDK state changed without a corresponding retained event.');
|
|
90
|
+
}
|
|
91
|
+
const evaluate = /** Reuse only an unchanged declared input; render findings from current SDK metadata. */ (rule, item, context) => {
|
|
92
|
+
const index = RULES.indexOf(rule);
|
|
93
|
+
const next = current.get(item.id);
|
|
94
|
+
const prior = old.get(item.id);
|
|
95
|
+
const cached = !RULE_DEPENDENCIES[rule.code].global && prior !== undefined && prior.inputs[index] === next.inputs[index];
|
|
96
|
+
const verdict = cached ? { matched: (prior.violations & (1 << index)) !== 0, excerpt: prior.excerpts[index] } : evaluateRule(rule, item, context);
|
|
97
|
+
stats.by_rule[rule.code][cached ? 'reused' : 'evaluated'] += 1;
|
|
98
|
+
stats[cached ? 'reused' : 'evaluated'] += 1;
|
|
99
|
+
if (verdict.matched)
|
|
100
|
+
next.violations |= 1 << index;
|
|
101
|
+
next.excerpts[index] = verdict.excerpt;
|
|
102
|
+
return verdict;
|
|
103
|
+
};
|
|
104
|
+
const result = lintCorpus(corpus, config, {}, request.now ?? Date.now(), statuses, evaluate);
|
|
105
|
+
await onBoundary?.('evaluated');
|
|
106
|
+
const tail = await drain(source, events.cursor, stats);
|
|
107
|
+
const latestPolicy = await source.policy();
|
|
108
|
+
if (tail.ids.size > 0 || sourceDigest({ config: latestPolicy.config, statuses: latestPolicy.statuses.definitions }) !== policy)
|
|
109
|
+
throw new IncrementalRefusal('source_changed', 'Source or policy changed during the scan.', 'Retry the scan against current SDK state; no checkpoint was advanced.');
|
|
110
|
+
await onBoundary?.('verified');
|
|
111
|
+
validateIncrementalNumbers({ result, stats });
|
|
112
|
+
const payload = { owner: 'pm-lint-incremental', format: 1, rule_version: incrementalRuleVersion(), policy_digest: policy, source_id: identity, cursor: events.cursor, items: [...current.values()] };
|
|
113
|
+
const checkpoint = parseIncrementalCheckpoint({ ...payload, digest: sourceDigest(payload) });
|
|
114
|
+
return { result, checkpoint, incremental: stats };
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=incremental.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"incremental.js","sourceRoot":"","sources":["../../src/incremental.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAEtO,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAA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E,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7F,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CommandHandlerContext, ExtensionApi } from '@unbrained/pm-cli/sdk/authoring';
|
|
2
|
+
/** Render compact preview context and typed refusals using the host's TOON or JSON transport. */
|
|
3
|
+
export declare function runRepairCommand(ctx: CommandHandlerContext): Promise<Record<string, unknown>>;
|
|
4
|
+
/** Register a single-item observational preview; successful questions do not signal a lint gate failure. */
|
|
5
|
+
export declare function registerRepairCommand(api: ExtensionApi): void;
|
|
6
|
+
//# sourceMappingURL=repair-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repair-command.d.ts","sourceRoot":"","sources":["../../src/repair-command.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAG3F,iGAAiG;AACjG,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAQnG;AAED,4GAA4G;AAC5G,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI,CAK7D"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineCommand } from '@unbrained/pm-cli/sdk';
|
|
2
|
+
import { previewAuthoringRepairs, RepairRefusal } from './repairs.js';
|
|
3
|
+
/** Render compact preview context and typed refusals using the host's TOON or JSON transport. */
|
|
4
|
+
export async function runRepairCommand(ctx) {
|
|
5
|
+
try {
|
|
6
|
+
const request = { id: scalar(ctx.options.id), revision: scalar(ctx.options.revision) };
|
|
7
|
+
return { ok: true, ...await previewAuthoringRepairs(ctx.pm_root, request) };
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
if (!(error instanceof RepairRefusal))
|
|
11
|
+
throw error;
|
|
12
|
+
return { ok: false, refusal: { code: error.code, message: error.message, remedy: error.remedy }, writes: 0, exit_code: 2 };
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Register a single-item observational preview; successful questions do not signal a lint gate failure. */
|
|
16
|
+
export function registerRepairCommand(api) {
|
|
17
|
+
api.registerCommand(defineCommand({ name: 'lint repair', description: 'Preview revision-bound mechanical repairs and explicit author questions without writes', flags: [
|
|
18
|
+
{ long: '--id', value_name: 'id', value_type: 'string', description: 'Required canonical item id; previews one target' },
|
|
19
|
+
{ long: '--revision', value_name: 'sha256', value_type: 'string', description: 'Refuse unless the target still matches this observed revision' },
|
|
20
|
+
], examples: ['pm lint repair --id pm-example-abcd --json', 'pm lint repair --id pm-example-abcd --revision <sha256>'], run: runRepairCommand }));
|
|
21
|
+
}
|
|
22
|
+
/** Unwrap exactly one host flag occurrence; preserve invalid runtime values for request validation. */
|
|
23
|
+
function scalar(value) {
|
|
24
|
+
return (Array.isArray(value) && value.length === 1 ? value[0] : value);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=repair-command.js.map
|