@unbrained/pm-lint 2026.10.13 → 2026.10.29
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 +9 -1
- package/README.md +122 -9
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -1
- package/dist/src/baseline-file.d.ts.map +1 -1
- package/dist/src/baseline-file.js +26 -10
- package/dist/src/baseline-file.js.map +1 -1
- package/dist/src/baseline.d.ts +3 -4
- package/dist/src/baseline.d.ts.map +1 -1
- package/dist/src/baseline.js +2 -2
- package/dist/src/baseline.js.map +1 -1
- package/dist/src/commands.js +1 -1
- package/dist/src/commands.js.map +1 -1
- package/dist/src/engine.d.ts +12 -3
- package/dist/src/engine.d.ts.map +1 -1
- package/dist/src/engine.js +28 -14
- package/dist/src/engine.js.map +1 -1
- 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/rule-pack-command.d.ts.map +1 -1
- package/dist/src/rule-pack-command.js +10 -4
- package/dist/src/rule-pack-command.js.map +1 -1
- package/dist/src/rule-pack-conflicts.d.ts +22 -0
- package/dist/src/rule-pack-conflicts.d.ts.map +1 -0
- package/dist/src/rule-pack-conflicts.js +75 -0
- package/dist/src/rule-pack-conflicts.js.map +1 -0
- package/dist/src/rule-pack-contract.d.ts +59 -0
- package/dist/src/rule-pack-contract.d.ts.map +1 -0
- package/dist/src/rule-pack-contract.js +161 -0
- package/dist/src/rule-pack-contract.js.map +1 -0
- package/dist/src/rule-pack.d.ts +4 -54
- package/dist/src/rule-pack.d.ts.map +1 -1
- package/dist/src/rule-pack.js +23 -136
- package/dist/src/rule-pack.js.map +1 -1
- package/dist/src/rules.d.ts +2 -0
- package/dist/src/rules.d.ts.map +1 -1
- package/dist/src/rules.js +4 -1
- package/dist/src/rules.js.map +1 -1
- 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/docs/conflicting-rule-packs.md +106 -0
- package/docs/incremental-example.md +64 -0
- package/docs/incremental-validation.md +99 -0
- package/examples/conflicting-rules.json +21 -0
- package/manifest.json +2 -2
- package/package.json +27 -14
package/dist/src/engine.js
CHANGED
|
@@ -3,6 +3,7 @@ import { analyzeDuplicateItems } from '@unbrained/pm-cli/sdk/query';
|
|
|
3
3
|
import { RULES } from './rules.js';
|
|
4
4
|
import { readLintSettings, resolveConfig } from './settings.js';
|
|
5
5
|
import { assertBaselinePolicy, isAcknowledged, parseBaseline, RULE_VERSION, sourceDigest } from './baseline.js';
|
|
6
|
+
import { DEFAULT_STATUSES, readLintStatuses } from './statuses.js';
|
|
6
7
|
/** Map severities to their stable CI ordering. */
|
|
7
8
|
export const SEVERITY_RANK = { info: 0, warn: 1, error: 2 };
|
|
8
9
|
/** Maximum characters of offending text one finding carries. */
|
|
@@ -12,14 +13,21 @@ export function excerptText(value) {
|
|
|
12
13
|
return value.trim().slice(0, EXCERPT_LIMIT);
|
|
13
14
|
}
|
|
14
15
|
/** Decide whether one item status falls inside a rule's lifecycle scope. */
|
|
15
|
-
export function inScope(scope, status) {
|
|
16
|
+
export function inScope(scope, status, registry = DEFAULT_STATUSES) {
|
|
16
17
|
if (scope === 'all')
|
|
17
18
|
return true;
|
|
18
19
|
if (scope === 'non_terminal' || scope === 'active')
|
|
19
|
-
return status
|
|
20
|
+
return !registry.terminal_statuses.has(status);
|
|
20
21
|
if (scope === 'terminal')
|
|
21
|
-
return status
|
|
22
|
-
|
|
22
|
+
return registry.terminal_statuses.has(status);
|
|
23
|
+
if (scope === 'closed')
|
|
24
|
+
return registry.terminal_done_statuses.has(status);
|
|
25
|
+
if (scope === 'canceled')
|
|
26
|
+
return registry.terminal_canceled_statuses.has(status);
|
|
27
|
+
if (scope === 'blocked')
|
|
28
|
+
return registry.blocked_statuses.has(status);
|
|
29
|
+
const open = registry.by_id.get(status)?.roles.includes('default_open') === true;
|
|
30
|
+
return scope === 'open' ? open : registry.active_statuses.has(status) && !open;
|
|
23
31
|
}
|
|
24
32
|
/** Parse a comma-separated status selection into nonempty status tokens. */
|
|
25
33
|
export function statusSelection(value) {
|
|
@@ -49,8 +57,8 @@ function selectItems(items, options) {
|
|
|
49
57
|
return items.filter(/** Filters restrict findings while rules retain the complete corpus. */ /** Filters restrict findings while rules retain the complete corpus. */ item => (options.type === undefined || item.type === options.type) && (statuses === undefined || statuses.includes(item.status)) && (ids === undefined || ids.has(item.id)) && (since === undefined || Date.parse(item.updated_at) >= since));
|
|
50
58
|
}
|
|
51
59
|
/** Reconcile the SDK duplicate scan with certified active counts before using its findings. */
|
|
52
|
-
export function duplicateItemIds(result, items) {
|
|
53
|
-
const active = items.filter(/** Match the SDK duplicate operation's explicit lifecycle selection. */ /** Match the SDK duplicate operation's explicit lifecycle selection. */ item =>
|
|
60
|
+
export function duplicateItemIds(result, items, registry = DEFAULT_STATUSES) {
|
|
61
|
+
const active = items.filter(/** Match the SDK duplicate operation's explicit lifecycle selection. */ /** Match the SDK duplicate operation's explicit lifecycle selection. */ item => registry.active_statuses.has(item.status) || registry.blocked_statuses.has(item.status));
|
|
54
62
|
if (result.cost.item_count !== active.length)
|
|
55
63
|
throw new Error('Duplicate source does not match the certified corpus');
|
|
56
64
|
if (result.count >= 1000)
|
|
@@ -68,18 +76,18 @@ export async function lintItems(client, pmRoot, options = {}, now = Date.now())
|
|
|
68
76
|
const baseline = options.baseline === undefined ? undefined : parseBaseline(options.baseline);
|
|
69
77
|
if (baseline !== undefined)
|
|
70
78
|
assertBaselinePolicy(config, resolveConfig(undefined), options);
|
|
71
|
-
return lintCorpus(await client.listAllComplete(), config, options, now);
|
|
79
|
+
return lintCorpus(await client.listAllComplete(), config, options, now, await readLintStatuses(pmRoot));
|
|
72
80
|
}
|
|
73
81
|
/** Evaluate an SDK-certified snapshot with the same rule engine used by ordinary lint. */
|
|
74
|
-
export function lintCorpus(source, config, options = {}, now = Date.now()) {
|
|
82
|
+
export function lintCorpus(source, config, options = {}, now = Date.now(), statuses = DEFAULT_STATUSES, evaluate = evaluateRule) {
|
|
75
83
|
const baseline = options.baseline === undefined ? undefined : parseBaseline(options.baseline);
|
|
76
84
|
const corpus = certifyCompleteListResult(source);
|
|
77
85
|
const selected = selectItems(corpus.items, options);
|
|
78
86
|
let duplicateIds = new Set();
|
|
79
87
|
if (config.rules.PML010.enabled) {
|
|
80
|
-
const active = corpus.items.filter(/** The SDK receives only the
|
|
88
|
+
const active = corpus.items.filter(/** The SDK receives only the registry's active lifecycle corpus. */ /** The SDK receives only the registry's active lifecycle corpus. */ item => statuses.active_statuses.has(item.status) || statuses.blocked_statuses.has(item.status));
|
|
81
89
|
const duplicates = analyzeDuplicateItems(active, { threshold: config.rules.PML010.parameters.threshold ?? 0.92, limit: 1000 });
|
|
82
|
-
duplicateIds = duplicateItemIds(duplicates, corpus.items);
|
|
90
|
+
duplicateIds = duplicateItemIds(duplicates, corpus.items, statuses);
|
|
83
91
|
}
|
|
84
92
|
const findings = [];
|
|
85
93
|
const summary = Object.fromEntries(RULES.map(/** Every rule reports a stable per-severity count, zero included. */ /** Every rule reports a stable per-severity count, zero included. */ rule => [rule.code, { info: 0, warn: 0, error: 0 }]));
|
|
@@ -89,12 +97,13 @@ export function lintCorpus(source, config, options = {}, now = Date.now()) {
|
|
|
89
97
|
if (!effective.enabled)
|
|
90
98
|
continue;
|
|
91
99
|
// An explicit --status selection overrides every rule's scope: the caller named the lifecycle to judge.
|
|
92
|
-
if (options.status === undefined && !inScope(effective.scope, item.status))
|
|
100
|
+
if (options.status === undefined && !inScope(effective.scope, item.status, statuses))
|
|
93
101
|
continue;
|
|
94
|
-
const context = { items: corpus.items, now, parameters: effective.parameters, duplicateIds };
|
|
95
|
-
|
|
102
|
+
const context = { items: corpus.items, now, parameters: effective.parameters, duplicateIds, statuses };
|
|
103
|
+
const verdict = evaluate(rule, item, context);
|
|
104
|
+
if (!verdict.matched)
|
|
96
105
|
continue;
|
|
97
|
-
const finding = { item_id: item.id, rule: rule.code, rule_version: RULE_VERSION, source_digest: sourceDigest(item), disposition: 'new', severity: effective.severity, field: rule.field, hint: rule.hint, title: item.title, excerpt:
|
|
106
|
+
const finding = { item_id: item.id, rule: rule.code, rule_version: RULE_VERSION, source_digest: sourceDigest(item), disposition: 'new', severity: effective.severity, field: rule.field, hint: rule.hint, title: item.title, excerpt: verdict.excerpt };
|
|
98
107
|
if (baseline !== undefined && isAcknowledged(finding, baseline))
|
|
99
108
|
finding.disposition = 'debt';
|
|
100
109
|
findings.push(finding);
|
|
@@ -107,4 +116,9 @@ export function lintCorpus(source, config, options = {}, now = Date.now()) {
|
|
|
107
116
|
const failed = findings.some(/** Baseline gates fail every new finding; ordinary lint retains severity policy. */ /** Baseline gates fail every new finding; ordinary lint retains severity policy. */ finding => baseline === undefined ? SEVERITY_RANK[finding.severity] >= SEVERITY_RANK[config.failOn] : finding.disposition === 'new');
|
|
108
117
|
return { findings, debt_count: debtCount, new_count: findings.length - debtCount, stale_count: staleCount, count: findings.length, scanned: selected.length, corpus_count: corpus.items.length, summary, complete_list: corpus.complete_list, fail_on: baseline === undefined ? config.failOn : 'info', exit_code: failed ? 1 : 0 };
|
|
109
118
|
}
|
|
119
|
+
/** Default full-scan evaluator; incremental scans replace only this predicate call. */
|
|
120
|
+
export function evaluateRule(rule, item, context) {
|
|
121
|
+
const matched = rule.check(item, context);
|
|
122
|
+
return { matched, excerpt: matched ? excerptText(rule.excerpt?.(item, context) ?? '') : '' };
|
|
123
|
+
}
|
|
110
124
|
//# sourceMappingURL=engine.js.map
|
package/dist/src/engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGhE,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGhE,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAChH,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAqBnE,kDAAkD;AAClD,MAAM,CAAC,MAA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M,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,KAAK,KAAK,CAAC,CAAC;IACvP,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,MAAM,GAAG,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,aAAa,EAAE,OAAO,EAAE,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACtU,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,YAAY,CAAC,IAAU,EAAE,IAAkB,EAAE,OAAoB;IAC/E,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC1C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAC/F,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CommandHandlerContext, ExtensionApi } from '@unbrained/pm-cli/sdk/authoring';
|
|
2
|
+
/** Render the complete findings and constant-sized reuse receipt without exposing checkpoint internals. */
|
|
3
|
+
export declare function runIncrementalCommand(ctx: CommandHandlerContext): Promise<Record<string, unknown>>;
|
|
4
|
+
/** Register explicit checkpoint management separately from the existing time-selection command. */
|
|
5
|
+
export declare function registerIncrementalCommand(api: ExtensionApi): void;
|
|
6
|
+
//# sourceMappingURL=incremental-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"incremental-command.d.ts","sourceRoot":"","sources":["../../src/incremental-command.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAI3F,2GAA2G;AAC3G,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAWxG;AAED,mGAAmG;AACnG,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI,CAKlE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineCommand } from '@unbrained/pm-cli/sdk';
|
|
2
|
+
import { IncrementalRefusal } from './incremental-contract.js';
|
|
3
|
+
import { filesystemLintSource, lintIncrementalFile } from './incremental-file.js';
|
|
4
|
+
/** Render the complete findings and constant-sized reuse receipt without exposing checkpoint internals. */
|
|
5
|
+
export async function runIncrementalCommand(ctx) {
|
|
6
|
+
try {
|
|
7
|
+
const path = ctx.options.state;
|
|
8
|
+
if (typeof path !== 'string')
|
|
9
|
+
throw new IncrementalRefusal('invalid_input', 'Exactly one state file is required.', 'Supply --state <file>; add --rebuild for the first scan or after an explicit rebuild refusal.');
|
|
10
|
+
const scan = await lintIncrementalFile(filesystemLintSource(ctx.pm_root), path, ctx.options.rebuild === undefined ? false : ctx.options.rebuild);
|
|
11
|
+
const { exit_code, ...result } = scan.result;
|
|
12
|
+
return { ok: true, ...result, incremental: scan.incremental, ...(exit_code === 0 ? {} : { exit_code }) };
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (!(error instanceof IncrementalRefusal))
|
|
16
|
+
throw error;
|
|
17
|
+
return { ok: false, refusal: { code: error.code, message: error.message, remedy: error.remedy }, exit_code: 2 };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** Register explicit checkpoint management separately from the existing time-selection command. */
|
|
21
|
+
export function registerIncrementalCommand(api) {
|
|
22
|
+
api.registerCommand(defineCommand({ name: 'lint incremental', description: 'Update a complete lint result using rule dependencies and SDK event cursors', read_output: { row_keys: ['findings'] }, flags: [
|
|
23
|
+
{ long: '--state', value_name: 'file', value_type: 'string', description: 'Required checkpoint file in an existing writable cache directory' },
|
|
24
|
+
{ long: '--rebuild', description: 'Explicitly rebuild after first use, cursor loss, rule version or policy drift' },
|
|
25
|
+
], examples: ['pm lint incremental --state lint.local.json --rebuild --json', 'pm lint incremental --state lint.local.json'], run: runIncrementalCommand }));
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=incremental-command.js.map
|
|
@@ -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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leCode } 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","s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 +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,MA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AAC;IAClD,sBAAsB,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAChG,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACpD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,EAAE,EAAE,EAAE,CAAC,SAAS,EAAE,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,CAA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AO,MAAM,CAAC;IAChB,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YAAC,MAAM,UAAU,EAAE,CAAC,SAAS,CAAC,CAAC;QAAC,CAAC;gBAAS,CAAC;YAAC,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QAAC,CAAC;IAC3E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ListMutationEventsOptions, MutationEventPage, PmClient } from '@unbrained/pm-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
|