peaks-loop 4.1.21 → 4.1.23
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/.claude-plugin/marketplace.json +3 -6
- package/CHANGELOG.md +191 -0
- package/dist/cli/commands/mut-commands-helpers.d.ts +6 -6
- package/dist/cli/commands/mut-commands-helpers.js +44 -26
- package/dist/cli/commands/observability-commands-hotspots.d.ts +54 -0
- package/dist/cli/commands/observability-commands-hotspots.js +222 -0
- package/dist/cli/commands/observability-commands-near-miss.d.ts +28 -0
- package/dist/cli/commands/observability-commands-near-miss.js +105 -0
- package/dist/cli/commands/observability-commands-queries.d.ts +61 -18
- package/dist/cli/commands/observability-commands-queries.js +88 -47
- package/dist/cli/commands/observability-commands.js +79 -20
- package/dist/services/artifacts/artifact-prerequisites.d.ts +3 -0
- package/dist/services/artifacts/artifact-prerequisites.js +1 -1
- package/dist/services/artifacts/prerequisite-path-census.d.ts +42 -0
- package/dist/services/artifacts/prerequisite-path-census.js +79 -0
- package/dist/services/artifacts/prerequisite-transition-event.js +13 -1
- package/dist/services/artifacts/rd-gate-event.d.ts +106 -0
- package/dist/services/artifacts/rd-gate-event.js +211 -0
- package/dist/services/artifacts/rd-transition-gates.d.ts +6 -0
- package/dist/services/artifacts/rd-transition-gates.js +65 -24
- package/dist/services/distribution/json-layout.d.ts +20 -0
- package/dist/services/distribution/json-layout.js +195 -0
- package/dist/services/distribution/plugin-manifest.d.ts +31 -2
- package/dist/services/distribution/plugin-manifest.js +40 -4
- package/dist/services/observability/aggregation-types.d.ts +21 -0
- package/dist/services/observability/aggregation.d.ts +12 -2
- package/dist/services/observability/aggregation.js +26 -2
- package/dist/services/observability/compliance-judge.d.ts +77 -0
- package/dist/services/observability/compliance-judge.js +143 -0
- package/dist/services/observability/compliance-spec.d.ts +96 -0
- package/dist/services/observability/compliance-spec.js +29 -0
- package/dist/services/observability/compliance-specs/peaks-race-code.spec.d.ts +37 -0
- package/dist/services/observability/compliance-specs/peaks-race-code.spec.js +66 -0
- package/dist/services/observability/compliance-specs/peaks-rd.spec.d.ts +50 -0
- package/dist/services/observability/compliance-specs/peaks-rd.spec.js +111 -0
- package/dist/services/observability/hotspot-attribution-summary.d.ts +84 -0
- package/dist/services/observability/hotspot-attribution-summary.js +74 -0
- package/dist/services/observability/hotspot-rows.d.ts +47 -0
- package/dist/services/observability/hotspot-rows.js +89 -0
- package/dist/services/observability/hotspot-shared.d.ts +212 -0
- package/dist/services/observability/hotspot-shared.js +122 -0
- package/dist/services/observability/hotspot-sources.d.ts +55 -0
- package/dist/services/observability/hotspot-sources.js +142 -0
- package/dist/services/observability/hotspots.d.ts +47 -0
- package/dist/services/observability/hotspots.js +47 -0
- package/dist/services/observability/near-miss-attempts.d.ts +175 -0
- package/dist/services/observability/near-miss-attempts.js +223 -0
- package/dist/services/observability/near-miss-coverage.d.ts +109 -0
- package/dist/services/observability/near-miss-coverage.js +108 -0
- package/dist/services/observability/near-miss-denominator.d.ts +81 -0
- package/dist/services/observability/near-miss-denominator.js +75 -0
- package/dist/services/observability/near-miss-difference.d.ts +98 -0
- package/dist/services/observability/near-miss-difference.js +132 -0
- package/dist/services/observability/near-miss-facts.d.ts +165 -0
- package/dist/services/observability/near-miss-facts.js +101 -0
- package/dist/services/observability/near-miss-gate-events.d.ts +75 -0
- package/dist/services/observability/near-miss-gate-events.js +106 -0
- package/dist/services/observability/near-miss-gates.d.ts +108 -0
- package/dist/services/observability/near-miss-gates.js +135 -0
- package/dist/services/observability/near-miss-records.d.ts +93 -0
- package/dist/services/observability/near-miss-records.js +87 -0
- package/dist/services/observability/near-miss.d.ts +148 -0
- package/dist/services/observability/near-miss.js +196 -0
- package/dist/services/observability/observability-schema.d.ts +17 -2
- package/dist/services/observability/observability-schema.js +21 -1
- package/dist/services/observability/owner-skill-map.d.ts +92 -0
- package/dist/services/observability/owner-skill-map.js +144 -0
- package/dist/services/observability/report-formatter-hotspots.d.ts +32 -0
- package/dist/services/observability/report-formatter-hotspots.js +76 -0
- package/dist/services/observability/report-formatter-near-miss.d.ts +48 -0
- package/dist/services/observability/report-formatter-near-miss.js +234 -0
- package/dist/services/observability/report-formatter.d.ts +49 -3
- package/dist/services/observability/report-formatter.js +55 -14
- package/dist/services/observability/retro-attribution.d.ts +129 -0
- package/dist/services/observability/retro-attribution.js +134 -0
- package/dist/services/observability/session-metric-rows.d.ts +153 -0
- package/dist/services/observability/session-metric-rows.js +184 -0
- package/package.json +5 -5
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `src/services/artifacts/prerequisite-path-census.ts`
|
|
3
|
+
*
|
|
4
|
+
* Every path shape that can reach the prerequisite missing list, as one
|
|
5
|
+
* de-duplicated list.
|
|
6
|
+
*
|
|
7
|
+
* WHY THIS EXISTS. The owner-skill map has to cover the paths the gates
|
|
8
|
+
* actually demand, and the gates read ONE table. Reading that table through
|
|
9
|
+
* a census function means the coverage check and the gate can never
|
|
10
|
+
* disagree about which paths exist — a second hand-written list would drift
|
|
11
|
+
* from the table on the first table change.
|
|
12
|
+
*
|
|
13
|
+
* THE THREE SOURCES OF A MISSING PATH. `checkPrerequisites` builds its
|
|
14
|
+
* missing list from three places, and a census that reads only the first
|
|
15
|
+
* would leave the other two uncovered:
|
|
16
|
+
*
|
|
17
|
+
* 1. the table loop — the canonical `relativePath`, plus the legacy tiers
|
|
18
|
+
* (`legacyRelativePath` / `legacyRelativePaths`) the resolver probes
|
|
19
|
+
* before it calls a file absent;
|
|
20
|
+
* 2. the judged-declaration refusals — the security artifact's own
|
|
21
|
+
* location, which the resolver reports verbatim;
|
|
22
|
+
* 3. the handoff capsule's gate-evidence declaration — a key that names a
|
|
23
|
+
* file that is not on disk, reported under the KEY's name, and the
|
|
24
|
+
* unreadable-capsule shape beside it.
|
|
25
|
+
*
|
|
26
|
+
* The `<rid>` placeholder is left in place on the table paths: this is the
|
|
27
|
+
* table's own shape, and the owner lookup is a prefix match, so the
|
|
28
|
+
* placeholder is irrelevant to it.
|
|
29
|
+
*
|
|
30
|
+
* THE KEY SET IS READ, NOT COPIED. `GATE_EVIDENCE_KEYS` is the one
|
|
31
|
+
* definition of the gate-evidence vocabulary, and a second copy of it here
|
|
32
|
+
* would be the same drift hole this census exists to close. The failure
|
|
33
|
+
* statuses are held in a `Record` keyed by the reader's own status type, so
|
|
34
|
+
* a status added to that type fails the build here until this census
|
|
35
|
+
* accounts for it.
|
|
36
|
+
*/
|
|
37
|
+
import { PREREQUISITES_BY_TYPE } from './artifact-prerequisites.js';
|
|
38
|
+
import { GATE_EVIDENCE_KEYS } from '../prd/handoff-types.js';
|
|
39
|
+
/**
|
|
40
|
+
* The failure statuses, keyed so that the type checks BOTH ways: a status
|
|
41
|
+
* added to the reader's union fails the build here until this record names
|
|
42
|
+
* it, and a status dropped from that union fails here as an excess key.
|
|
43
|
+
*/
|
|
44
|
+
const GATE_EVIDENCE_FAILURE_STATUSES = {
|
|
45
|
+
'read-error': true,
|
|
46
|
+
'frontmatter-malformed': true,
|
|
47
|
+
'field-not-map': true,
|
|
48
|
+
'value-not-string': true
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Every `relativePath` any request type demands, every legacy tier the
|
|
52
|
+
* resolver probes for one, and every gate-evidence shape a declaration can
|
|
53
|
+
* report — de-duplicated and sorted.
|
|
54
|
+
*/
|
|
55
|
+
export function allPrerequisitePaths() {
|
|
56
|
+
const paths = new Set();
|
|
57
|
+
for (const table of Object.values(PREREQUISITES_BY_TYPE)) {
|
|
58
|
+
for (const requirements of Object.values(table)) {
|
|
59
|
+
if (requirements === undefined)
|
|
60
|
+
continue;
|
|
61
|
+
for (const requirement of requirements) {
|
|
62
|
+
paths.add(requirement.relativePath);
|
|
63
|
+
if (requirement.legacyRelativePath !== undefined) {
|
|
64
|
+
paths.add(requirement.legacyRelativePath);
|
|
65
|
+
}
|
|
66
|
+
for (const legacy of requirement.legacyRelativePaths ?? []) {
|
|
67
|
+
paths.add(legacy);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const key of GATE_EVIDENCE_KEYS) {
|
|
73
|
+
paths.add(`gateEvidence.${key}`);
|
|
74
|
+
}
|
|
75
|
+
for (const status of Object.keys(GATE_EVIDENCE_FAILURE_STATUSES)) {
|
|
76
|
+
paths.add(`gateEvidence(${status})`);
|
|
77
|
+
}
|
|
78
|
+
return [...paths].sort();
|
|
79
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { emitObservabilityEvent } from '../observability/observability-service.js';
|
|
2
|
+
import { ownerSkillForPath } from '../observability/owner-skill-map.js';
|
|
2
3
|
/**
|
|
3
4
|
* Slice C of v2.11.1 — observability hook #7/7. Fire-and-forget per PRD Q4. The
|
|
4
5
|
* synchronous emit never throws and never blocks the prereq check's return
|
|
@@ -21,7 +22,18 @@ export function emitPrereqTransitionEvent(opts) {
|
|
|
21
22
|
artifactRole: opts.role,
|
|
22
23
|
to: opts.newState,
|
|
23
24
|
prereqOk: opts.result.ok,
|
|
24
|
-
missingCount: opts.result.missing.length
|
|
25
|
+
missingCount: opts.result.missing.length,
|
|
26
|
+
// The LIST, not only its length: the count says how many artifacts were
|
|
27
|
+
// missing, and the list says which ones and which skill owns each, so a
|
|
28
|
+
// reader can name the skill that failed to deliver. Ownership is per
|
|
29
|
+
// missing item; an aggregate owner is the reader's job, not the
|
|
30
|
+
// writer's.
|
|
31
|
+
missing: opts.result.missing.map((m) => ({
|
|
32
|
+
path: m.path,
|
|
33
|
+
description: m.description,
|
|
34
|
+
kind: m.kind,
|
|
35
|
+
ownerSkill: ownerSkillForPath(m.path)
|
|
36
|
+
}))
|
|
25
37
|
}
|
|
26
38
|
}, { projectRoot: opts.projectRoot });
|
|
27
39
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { RequestType } from './artifact-prerequisites.js';
|
|
2
|
+
import type { RdGatePhase, RdGateViolationKind } from './rd-transition-gates.js';
|
|
3
|
+
/** The gates the RD transition layer decides, by their stable ids. */
|
|
4
|
+
export type RdGateId = 'file-size-ratchet' | 'declared-type-corroboration' | 'claim-table';
|
|
5
|
+
/**
|
|
6
|
+
* Every gate id, as a list.
|
|
7
|
+
*
|
|
8
|
+
* A consumer that has to RECOGNISE a gate id cannot re-type the union: a
|
|
9
|
+
* second copy of the vocabulary is a list that rots, and it rots silently —
|
|
10
|
+
* a gate id added upstream would not be in the copy, so a gate that PASSED
|
|
11
|
+
* would be read as "not a gate we know" and never counted as evaluated.
|
|
12
|
+
*/
|
|
13
|
+
export declare const RD_GATE_IDS: readonly RdGateId[];
|
|
14
|
+
/** What the gate decided about the transition. */
|
|
15
|
+
export type RdGateOutcome = 'pass' | 'block' | 'bypass';
|
|
16
|
+
/**
|
|
17
|
+
* Every gate outcome, as a list.
|
|
18
|
+
*
|
|
19
|
+
* A consumer that has to RECOGNISE an outcome cannot re-type the union: a
|
|
20
|
+
* second copy of the vocabulary is a list that rots, and it rots SILENTLY —
|
|
21
|
+
* an outcome added upstream would not be in the copy, so the reader would
|
|
22
|
+
* treat a `pass` as "not a pass" and report a slice that evaluated every gate
|
|
23
|
+
* as one that skipped one.
|
|
24
|
+
*/
|
|
25
|
+
export declare const RD_GATE_OUTCOMES: readonly RdGateOutcome[];
|
|
26
|
+
/**
|
|
27
|
+
* Whether a value is one of the gate outcomes this build knows.
|
|
28
|
+
*
|
|
29
|
+
* An outcome this build does not know is UNREADABLE, not "not evaluated" —
|
|
30
|
+
* the two are different facts, and only the second one is a finding.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isRdGateOutcome(value: unknown): value is RdGateOutcome;
|
|
33
|
+
/** The ids of the gates the bypass note names, in the note's order. */
|
|
34
|
+
export declare function notedGateIds(phase: RdGatePhase): readonly RdGateId[];
|
|
35
|
+
/**
|
|
36
|
+
* The gates that are live for a transition, by its phase and by whether the
|
|
37
|
+
* declared type is tooling-only.
|
|
38
|
+
*/
|
|
39
|
+
export declare function liveGateIds(phase: RdGatePhase, judged: boolean): readonly RdGateId[];
|
|
40
|
+
/** The prose the bypass note uses for one gate id. */
|
|
41
|
+
export declare function gateLabel(gateId: RdGateId): string;
|
|
42
|
+
/**
|
|
43
|
+
* Why ONE gate did not run, when the transition was bypassed.
|
|
44
|
+
*
|
|
45
|
+
* PER GATE, not the shared note: the note the artifact carries names the
|
|
46
|
+
* skipped gates in prose, and it does not name every gate that stood down —
|
|
47
|
+
* so it cannot be the reason for all of them. The note stays the prose; this
|
|
48
|
+
* is the machine-facing explanation.
|
|
49
|
+
*/
|
|
50
|
+
export declare function bypassReason(gateId: RdGateId, phase: RdGatePhase): string;
|
|
51
|
+
/**
|
|
52
|
+
* Why the claim table could not be evaluated. The causes are DIFFERENT facts
|
|
53
|
+
* — no artifact at all, or a table some rid never filled in — and a consumer
|
|
54
|
+
* has to be able to tell them apart. (The third cause, a diff that could not
|
|
55
|
+
* be obtained, is a `block` with its own `violationKind`.)
|
|
56
|
+
*/
|
|
57
|
+
export declare function claimTableReason(artifactCount: number, missingCount: number): string;
|
|
58
|
+
/** The transition a gate decision belongs to. */
|
|
59
|
+
export type RdGateContext = {
|
|
60
|
+
readonly projectRoot: string;
|
|
61
|
+
readonly sessionId: string;
|
|
62
|
+
readonly sliceRid: string;
|
|
63
|
+
readonly phase: RdGatePhase;
|
|
64
|
+
/**
|
|
65
|
+
* The declared type of the slice, as the transition judged it. It travels
|
|
66
|
+
* with the event because the LIVE SET depends on it: a consumer that wants
|
|
67
|
+
* to know whether a gate was applicable has to read it HERE, not from the
|
|
68
|
+
* request artifact — `peaks request retag` rewrites the artifact's type
|
|
69
|
+
* line with no state guard, so the artifact carries the CURRENT type, not
|
|
70
|
+
* the type the transition ran under. A metric that has to re-read mutable
|
|
71
|
+
* session state is not reproducible from the events alone.
|
|
72
|
+
*/
|
|
73
|
+
readonly declaredType: RequestType;
|
|
74
|
+
};
|
|
75
|
+
/** The decision half of a gate event: what the gate decided, and why. */
|
|
76
|
+
export type RdGateDecision = {
|
|
77
|
+
readonly violationKind?: RdGateViolationKind | undefined;
|
|
78
|
+
readonly reason?: string | undefined;
|
|
79
|
+
};
|
|
80
|
+
/** The recorder for ONE transition: it fills in the transition's identity. */
|
|
81
|
+
export type RdGateRecorder = (gateId: RdGateId, outcome: RdGateOutcome, decision?: RdGateDecision) => void;
|
|
82
|
+
/** Bind the transition's identity, once. */
|
|
83
|
+
export declare function rdGateRecorder(context: RdGateContext): RdGateRecorder;
|
|
84
|
+
/**
|
|
85
|
+
* Record ONE gate decision in the session's observability stream.
|
|
86
|
+
*
|
|
87
|
+
* The detail carries the DECLARED TYPE, not a derived "was this slice
|
|
88
|
+
* tooling-only" boolean: the type is the more informative datum, and a consumer
|
|
89
|
+
* that has to re-read the request artifact to learn whether a gate was live
|
|
90
|
+
* cannot reproduce the answer from the events alone.
|
|
91
|
+
*
|
|
92
|
+
* The optional fields carry `| undefined` on purpose: this repository
|
|
93
|
+
* compiles with `exactOptionalPropertyTypes`, so a caller that forwards a
|
|
94
|
+
* possibly-absent value could not pass it to a plain optional property.
|
|
95
|
+
*/
|
|
96
|
+
export declare function emitRdGateEvent(opts: {
|
|
97
|
+
readonly projectRoot: string;
|
|
98
|
+
readonly sessionId: string;
|
|
99
|
+
readonly sliceRid: string;
|
|
100
|
+
readonly gateId: RdGateId;
|
|
101
|
+
readonly phase: RdGatePhase;
|
|
102
|
+
readonly declaredType: RequestType;
|
|
103
|
+
readonly outcome: RdGateOutcome;
|
|
104
|
+
readonly violationKind?: RdGateViolationKind | undefined;
|
|
105
|
+
readonly reason?: string | undefined;
|
|
106
|
+
}): void;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The gate layer's event vocabulary: the stable ids the RD transition gates
|
|
3
|
+
* are known by, and the ONE function that writes a gate decision into the
|
|
4
|
+
* observability stream.
|
|
5
|
+
*
|
|
6
|
+
* WHY THE IDS ARE STABLE STRINGS. A gate decision is only useful if a reader
|
|
7
|
+
* can ask "which gate blocked?" — across sessions, and across versions of
|
|
8
|
+
* this repository. A reader that has to recognise the CODE that produced the
|
|
9
|
+
* event cannot ask that question at all, which is how the gate layer stayed
|
|
10
|
+
* invisible until now.
|
|
11
|
+
*
|
|
12
|
+
* WHY THE EMITTER LIVES HERE AND NOT IN THE OBSERVABILITY SERVICE. The service
|
|
13
|
+
* module is at its file-size cap, and this file owns the gate vocabulary: the
|
|
14
|
+
* ids, the outcomes, and the prose the bypass note uses for them. The service
|
|
15
|
+
* keeps the schema-and-write half it has always owned.
|
|
16
|
+
*
|
|
17
|
+
* THE RECORDER IS CURRIED. One transition has ONE identity — the project, the
|
|
18
|
+
* session, the slice and the phase — and every decision it makes shares it.
|
|
19
|
+
* The recorder binds that identity once, so a decision costs one line at the
|
|
20
|
+
* call site and cannot forget which slice it belongs to.
|
|
21
|
+
*
|
|
22
|
+
* FIRE-AND-FORGET BY CONTRACT. The gate's verdict must not change because an
|
|
23
|
+
* event could not be written, so nothing here throws.
|
|
24
|
+
*/
|
|
25
|
+
import { emitObservabilityEvent } from '../observability/observability-service.js';
|
|
26
|
+
import { OBSERVABILITY_SCHEMA_VERSION } from '../observability/observability-schema.js';
|
|
27
|
+
/**
|
|
28
|
+
* Every gate id, as a list.
|
|
29
|
+
*
|
|
30
|
+
* A consumer that has to RECOGNISE a gate id cannot re-type the union: a
|
|
31
|
+
* second copy of the vocabulary is a list that rots, and it rots silently —
|
|
32
|
+
* a gate id added upstream would not be in the copy, so a gate that PASSED
|
|
33
|
+
* would be read as "not a gate we know" and never counted as evaluated.
|
|
34
|
+
*/
|
|
35
|
+
export const RD_GATE_IDS = [
|
|
36
|
+
'file-size-ratchet',
|
|
37
|
+
'declared-type-corroboration',
|
|
38
|
+
'claim-table'
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* Every gate outcome, as a list.
|
|
42
|
+
*
|
|
43
|
+
* A consumer that has to RECOGNISE an outcome cannot re-type the union: a
|
|
44
|
+
* second copy of the vocabulary is a list that rots, and it rots SILENTLY —
|
|
45
|
+
* an outcome added upstream would not be in the copy, so the reader would
|
|
46
|
+
* treat a `pass` as "not a pass" and report a slice that evaluated every gate
|
|
47
|
+
* as one that skipped one.
|
|
48
|
+
*/
|
|
49
|
+
export const RD_GATE_OUTCOMES = ['pass', 'block', 'bypass'];
|
|
50
|
+
/**
|
|
51
|
+
* Whether a value is one of the gate outcomes this build knows.
|
|
52
|
+
*
|
|
53
|
+
* An outcome this build does not know is UNREADABLE, not "not evaluated" —
|
|
54
|
+
* the two are different facts, and only the second one is a finding.
|
|
55
|
+
*/
|
|
56
|
+
export function isRdGateOutcome(value) {
|
|
57
|
+
return typeof value === 'string' && RD_GATE_OUTCOMES.includes(value);
|
|
58
|
+
}
|
|
59
|
+
/** The prose each gate id carries in the bypass note. */
|
|
60
|
+
const GATE_LABELS = {
|
|
61
|
+
'file-size-ratchet': 'file-size ratchet',
|
|
62
|
+
'declared-type-corroboration': 'declared-type corroboration',
|
|
63
|
+
'claim-table': 'claim table'
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* The gates the bypass NOTE names, per phase. This is NOT the live set: the
|
|
67
|
+
* note names the gates a reader is TOLD about, while `liveGateIds` is the set
|
|
68
|
+
* of checks that were actually APPLICABLE — a gate that was live and skipped
|
|
69
|
+
* has to be recorded even when the note does not name it.
|
|
70
|
+
*
|
|
71
|
+
* The note and this list are two readings of ONE table: the note's prose is
|
|
72
|
+
* built from these ids, so the text that names the skipped gates cannot drift
|
|
73
|
+
* from the prose the artifact carries.
|
|
74
|
+
*/
|
|
75
|
+
const NOTED_GATE_IDS = {
|
|
76
|
+
implemented: ['file-size-ratchet', 'declared-type-corroboration'],
|
|
77
|
+
'qa-handoff': ['declared-type-corroboration'],
|
|
78
|
+
'handed-off': ['declared-type-corroboration']
|
|
79
|
+
};
|
|
80
|
+
/** The ids of the gates the bypass note names, in the note's order. */
|
|
81
|
+
export function notedGateIds(phase) {
|
|
82
|
+
return NOTED_GATE_IDS[phase];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The gates that are LIVE for a transition: the checks that WOULD run if the
|
|
86
|
+
* transition were not bypassed.
|
|
87
|
+
*
|
|
88
|
+
* A live gate that produced no verdict was SKIPPED; a gate that is not live
|
|
89
|
+
* was never applicable to that transition. The two must be tellable apart, or
|
|
90
|
+
* a skipped gate is indistinguishable from a gate that does not exist for the
|
|
91
|
+
* slice — the invisible state this stream exists to remove.
|
|
92
|
+
*
|
|
93
|
+
* DERIVED FROM THE SOURCE, not from the note. `runRdTransitionGates` runs the
|
|
94
|
+
* size ratchet at `implemented` and, for a declared type that is NOT
|
|
95
|
+
* tooling-only, runs NOTHING else — the type rule is a no-op there and the
|
|
96
|
+
* claim table is never read. For a tooling-only declared type the type rule
|
|
97
|
+
* and the claim table run at every phase, and the size ratchet joins them at
|
|
98
|
+
* `implemented`.
|
|
99
|
+
*/
|
|
100
|
+
const LIVE_GATE_IDS = {
|
|
101
|
+
implemented: {
|
|
102
|
+
tooling: ['file-size-ratchet', 'declared-type-corroboration', 'claim-table'],
|
|
103
|
+
product: ['file-size-ratchet']
|
|
104
|
+
},
|
|
105
|
+
'qa-handoff': {
|
|
106
|
+
tooling: ['declared-type-corroboration', 'claim-table'],
|
|
107
|
+
product: []
|
|
108
|
+
},
|
|
109
|
+
'handed-off': {
|
|
110
|
+
tooling: ['declared-type-corroboration', 'claim-table'],
|
|
111
|
+
product: []
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* The gates that are live for a transition, by its phase and by whether the
|
|
116
|
+
* declared type is tooling-only.
|
|
117
|
+
*/
|
|
118
|
+
export function liveGateIds(phase, judged) {
|
|
119
|
+
return LIVE_GATE_IDS[phase][judged ? 'tooling' : 'product'];
|
|
120
|
+
}
|
|
121
|
+
/** The prose the bypass note uses for one gate id. */
|
|
122
|
+
export function gateLabel(gateId) {
|
|
123
|
+
return GATE_LABELS[gateId];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* What each gate was NOT able to check, when the transition was bypassed.
|
|
127
|
+
*/
|
|
128
|
+
const BYPASS_DETAIL = {
|
|
129
|
+
'file-size-ratchet': ', so no file was measured against the cap',
|
|
130
|
+
'declared-type-corroboration': ', so the declared type was never judged against the change set',
|
|
131
|
+
'claim-table': ', so no rid claim was checked against the working tree'
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Why ONE gate did not run, when the transition was bypassed.
|
|
135
|
+
*
|
|
136
|
+
* PER GATE, not the shared note: the note the artifact carries names the
|
|
137
|
+
* skipped gates in prose, and it does not name every gate that stood down —
|
|
138
|
+
* so it cannot be the reason for all of them. The note stays the prose; this
|
|
139
|
+
* is the machine-facing explanation.
|
|
140
|
+
*/
|
|
141
|
+
export function bypassReason(gateId, phase) {
|
|
142
|
+
return (`the ${gateLabel(gateId)} was not evaluated: --allow-incomplete bypassed the rd ` +
|
|
143
|
+
`${phase} gates${BYPASS_DETAIL[gateId]}`);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Why the claim table could not be evaluated. The causes are DIFFERENT facts
|
|
147
|
+
* — no artifact at all, or a table some rid never filled in — and a consumer
|
|
148
|
+
* has to be able to tell them apart. (The third cause, a diff that could not
|
|
149
|
+
* be obtained, is a `block` with its own `violationKind`.)
|
|
150
|
+
*/
|
|
151
|
+
export function claimTableReason(artifactCount, missingCount) {
|
|
152
|
+
if (artifactCount === 0) {
|
|
153
|
+
return ('the claim table could not be evaluated: the session has no RD artifact, so no rid ' +
|
|
154
|
+
'declares the paths it touched and an unclaimed source change cannot be ruled out');
|
|
155
|
+
}
|
|
156
|
+
return (`the claim table could not be evaluated: ${missingCount} of ${artifactCount} RD artifacts ` +
|
|
157
|
+
'declare no "## Changed paths" section, and an incomplete table cannot prove that no ' +
|
|
158
|
+
'source change is unclaimed');
|
|
159
|
+
}
|
|
160
|
+
/** Bind the transition's identity, once. */
|
|
161
|
+
export function rdGateRecorder(context) {
|
|
162
|
+
return (gateId, outcome, decision) => {
|
|
163
|
+
emitRdGateEvent({
|
|
164
|
+
...context,
|
|
165
|
+
gateId,
|
|
166
|
+
outcome,
|
|
167
|
+
violationKind: decision?.violationKind,
|
|
168
|
+
reason: decision?.reason
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Record ONE gate decision in the session's observability stream.
|
|
174
|
+
*
|
|
175
|
+
* The detail carries the DECLARED TYPE, not a derived "was this slice
|
|
176
|
+
* tooling-only" boolean: the type is the more informative datum, and a consumer
|
|
177
|
+
* that has to re-read the request artifact to learn whether a gate was live
|
|
178
|
+
* cannot reproduce the answer from the events alone.
|
|
179
|
+
*
|
|
180
|
+
* The optional fields carry `| undefined` on purpose: this repository
|
|
181
|
+
* compiles with `exactOptionalPropertyTypes`, so a caller that forwards a
|
|
182
|
+
* possibly-absent value could not pass it to a plain optional property.
|
|
183
|
+
*/
|
|
184
|
+
export function emitRdGateEvent(opts) {
|
|
185
|
+
const detail = {
|
|
186
|
+
gateId: opts.gateId,
|
|
187
|
+
phase: opts.phase,
|
|
188
|
+
declaredType: opts.declaredType,
|
|
189
|
+
outcome: opts.outcome
|
|
190
|
+
};
|
|
191
|
+
if (opts.violationKind !== undefined)
|
|
192
|
+
detail['violationKind'] = opts.violationKind;
|
|
193
|
+
if (opts.reason !== undefined)
|
|
194
|
+
detail['reason'] = opts.reason;
|
|
195
|
+
try {
|
|
196
|
+
emitObservabilityEvent({
|
|
197
|
+
schemaVersion: OBSERVABILITY_SCHEMA_VERSION,
|
|
198
|
+
ts: new Date().toISOString(),
|
|
199
|
+
sessionId: opts.sessionId,
|
|
200
|
+
category: 'gate',
|
|
201
|
+
sliceRid: opts.sliceRid,
|
|
202
|
+
detail
|
|
203
|
+
}, { projectRoot: opts.projectRoot });
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
// Fire-and-forget: the gate's verdict must not change because the event
|
|
207
|
+
// could not be written. `error` is held so the block is not an empty
|
|
208
|
+
// catch — swallowing it IS the contract, not an oversight.
|
|
209
|
+
void error;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
@@ -24,6 +24,12 @@
|
|
|
24
24
|
* table cannot prove "nobody claimed it", and guessing there would blame one
|
|
25
25
|
* slice for another's change. When it does not run, the returned note says so:
|
|
26
26
|
* a silently skipped check is indistinguishable from a passing one.
|
|
27
|
+
*
|
|
28
|
+
* EVERY DECISION IS RECORDED. Each gate that runs emits one `gate` event
|
|
29
|
+
* carrying its stable id, the phase, the declared type and what it decided
|
|
30
|
+
* (`pass` / `block` / `bypass`), so the layer that decides can be read back
|
|
31
|
+
* instead of inferred from the absence of an error. A refusal is recorded
|
|
32
|
+
* BEFORE it is thrown.
|
|
27
33
|
*/
|
|
28
34
|
import type { RequestType } from './artifact-prerequisites.js';
|
|
29
35
|
import { type RequestArtifactState } from './request-artifact-state-helpers.js';
|
|
@@ -6,6 +6,7 @@ import { isArtifactWorkspaceFile } from '../scan/type-sanity-service.js';
|
|
|
6
6
|
import { listSessionRdArtifactIds, readRidChangeClaims } from '../scan/rid-change-claims.js';
|
|
7
7
|
import { slugifyDescription } from '../../shared/incrementing-number.js';
|
|
8
8
|
import { normalizePath } from '../../shared/path-utils.js';
|
|
9
|
+
import { bypassReason, claimTableReason, gateLabel, liveGateIds, notedGateIds, rdGateRecorder } from './rd-gate-event.js';
|
|
9
10
|
/**
|
|
10
11
|
* True for the three states the RD gates judge. A type PREDICATE, so a caller
|
|
11
12
|
* that filters on it keeps the narrowed state — the old inline `||` chain did
|
|
@@ -28,19 +29,36 @@ export class TypeCorroborationViolationError extends Error {
|
|
|
28
29
|
/** Written into the artifact when `--allow-incomplete` skips a gate that COULD
|
|
29
30
|
* have judged this type: a silent bypass is indistinguishable from a pass. */
|
|
30
31
|
export function rdGatesBypassNote(phase) {
|
|
31
|
-
const gates = phase
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const gates = notedGateIds(phase)
|
|
33
|
+
.map((gateId) => gateLabel(gateId))
|
|
34
|
+
.join(', ');
|
|
34
35
|
return (`bypassed the rd ${phase} gates (${gates}) via --allow-incomplete; ` +
|
|
35
36
|
'none of them was evaluated');
|
|
36
37
|
}
|
|
38
|
+
/** The gates a bypassed transition skipped, each with its own event: every
|
|
39
|
+
* gate that was LIVE for the transition and did not run. The live set is not
|
|
40
|
+
* the note's list — see `liveGateIds`. */
|
|
41
|
+
function reportBypass(record, phase, judged) {
|
|
42
|
+
for (const gateId of liveGateIds(phase, judged)) {
|
|
43
|
+
record(gateId, 'bypass', { reason: bypassReason(gateId, phase) });
|
|
44
|
+
}
|
|
45
|
+
return judged ? rdGatesBypassNote(phase) : null;
|
|
46
|
+
}
|
|
37
47
|
/** The shared read, or the fail-closed verdict built from the same message. */
|
|
38
|
-
function readOrRefuse(projectRoot, declaredType) {
|
|
48
|
+
function readOrRefuse(record, projectRoot, declaredType) {
|
|
39
49
|
try {
|
|
40
50
|
return readGitChangeSet(projectRoot, 'HEAD');
|
|
41
51
|
}
|
|
42
52
|
catch {
|
|
43
|
-
|
|
53
|
+
const verdict = diffUnavailableVerdict(declaredType);
|
|
54
|
+
// BEFORE the throw: after it the event would never fire, and "the diff
|
|
55
|
+
// could not be read" is one of the facts this stream exists to keep. IT IS
|
|
56
|
+
// THE CLAIM TABLE'S BLOCK, because the criterion is which gate could not be
|
|
57
|
+
// EVALUATED: the working-tree diff is the precondition the claim table
|
|
58
|
+
// needs. The verdict function living in the type-corroboration module is
|
|
59
|
+
// incidental.
|
|
60
|
+
record('claim-table', 'block', { violationKind: 'diff-unavailable', reason: verdict.message });
|
|
61
|
+
throw new TypeCorroborationViolationError(declaredType, verdict);
|
|
44
62
|
}
|
|
45
63
|
}
|
|
46
64
|
/** The note written when the anti-lie fallback could not run. */
|
|
@@ -85,15 +103,21 @@ function judgeDeclaredType(options) {
|
|
|
85
103
|
if (tableComplete) {
|
|
86
104
|
const unclaimed = unclaimedSourcePaths(options.worktreePaths, claims);
|
|
87
105
|
if (unclaimed.length > 0) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
106
|
+
const message = unclaimedMessage(options.declaredType, unclaimed);
|
|
107
|
+
options.record('claim-table', 'block', {
|
|
108
|
+
violationKind: 'source-unclaimed',
|
|
109
|
+
reason: message
|
|
110
|
+
});
|
|
111
|
+
return { ok: false, kind: 'source-unclaimed', message };
|
|
93
112
|
}
|
|
113
|
+
options.record('claim-table', 'pass');
|
|
94
114
|
}
|
|
95
115
|
else {
|
|
96
116
|
note = fallbackDisabledNote(options.sessionId, missing.length, artifactIds.length);
|
|
117
|
+
// The fallback STOOD DOWN — it did not pass. A bypass says so; a pass
|
|
118
|
+
// would claim a check that never ran, and the reason says WHICH stand-down.
|
|
119
|
+
const standDown = claimTableReason(artifactIds.length, missing.length);
|
|
120
|
+
options.record('claim-table', 'bypass', { reason: standDown });
|
|
97
121
|
}
|
|
98
122
|
// (B) The rid's own declaration; the whole working tree when it declared none.
|
|
99
123
|
const scope = own ?? options.worktreePaths;
|
|
@@ -107,27 +131,49 @@ function judgeDeclaredType(options) {
|
|
|
107
131
|
// anti-lie fallback stood down, a reader of the refusal alone must not be
|
|
108
132
|
// left thinking it was in force.
|
|
109
133
|
const message = note === null ? verdict.message : `${verdict.message} ${note}`;
|
|
134
|
+
const refusal = { violationKind: verdict.kind, reason: message };
|
|
135
|
+
options.record('declared-type-corroboration', 'block', refusal);
|
|
110
136
|
return { ok: false, kind: verdict.kind, message };
|
|
111
137
|
}
|
|
138
|
+
options.record('declared-type-corroboration', 'pass');
|
|
112
139
|
return { ok: true, note };
|
|
113
140
|
}
|
|
141
|
+
/** The size ratchet, and the event that records what it decided. The refusal
|
|
142
|
+
* is recorded BEFORE the throw — after it the event would never fire. */
|
|
143
|
+
function runSizeRatchet(record, projectRoot, changedFiles) {
|
|
144
|
+
const size = changedFiles === undefined
|
|
145
|
+
? scanFileSize({ projectRoot })
|
|
146
|
+
: scanFileSize({ projectRoot, changedFiles });
|
|
147
|
+
if (!size.ok) {
|
|
148
|
+
const error = new FileSizeViolationError(size.violations);
|
|
149
|
+
record('file-size-ratchet', 'block', { reason: error.message });
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
record('file-size-ratchet', 'pass');
|
|
153
|
+
}
|
|
114
154
|
export function runRdTransitionGates(options) {
|
|
155
|
+
const record = rdGateRecorder({
|
|
156
|
+
projectRoot: options.projectRoot,
|
|
157
|
+
sessionId: options.sessionId,
|
|
158
|
+
sliceRid: options.requestId,
|
|
159
|
+
phase: options.phase,
|
|
160
|
+
declaredType: options.declaredType
|
|
161
|
+
});
|
|
115
162
|
const judged = isToolingOnlyDeclaredType(options.declaredType);
|
|
116
|
-
if (options.allowIncomplete)
|
|
117
|
-
return
|
|
163
|
+
if (options.allowIncomplete) {
|
|
164
|
+
return reportBypass(record, options.phase, judged);
|
|
165
|
+
}
|
|
118
166
|
if (!judged) {
|
|
119
167
|
// The size ratchet still runs at implemented; the type rule is a no-op here.
|
|
120
|
-
if (options.phase === 'implemented')
|
|
121
|
-
|
|
122
|
-
if (!size.ok)
|
|
123
|
-
throw new FileSizeViolationError(size.violations);
|
|
124
|
-
}
|
|
168
|
+
if (options.phase === 'implemented')
|
|
169
|
+
runSizeRatchet(record, options.projectRoot);
|
|
125
170
|
return null;
|
|
126
171
|
}
|
|
127
172
|
// ONE enumeration for the whole transition: the type rule judges the rid's own
|
|
128
173
|
// paths against the same working-tree read the size ratchet measures.
|
|
129
|
-
const changeSet = readOrRefuse(options.projectRoot, options.declaredType);
|
|
174
|
+
const changeSet = readOrRefuse(record, options.projectRoot, options.declaredType);
|
|
130
175
|
const verdict = judgeDeclaredType({
|
|
176
|
+
record,
|
|
131
177
|
projectRoot: options.projectRoot,
|
|
132
178
|
declaredType: options.declaredType,
|
|
133
179
|
requestId: options.requestId,
|
|
@@ -137,12 +183,7 @@ export function runRdTransitionGates(options) {
|
|
|
137
183
|
if (!verdict.ok)
|
|
138
184
|
throw new TypeCorroborationViolationError(options.declaredType, verdict);
|
|
139
185
|
if (options.phase === 'implemented') {
|
|
140
|
-
|
|
141
|
-
projectRoot: options.projectRoot,
|
|
142
|
-
changedFiles: changeSet.changedFiles
|
|
143
|
-
});
|
|
144
|
-
if (!size.ok)
|
|
145
|
-
throw new FileSizeViolationError(size.violations);
|
|
186
|
+
runSizeRatchet(record, options.projectRoot, changeSet.changedFiles);
|
|
146
187
|
}
|
|
147
188
|
return verdict.note;
|
|
148
189
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** The two knobs of prettier's JSON layout a render can depend on. */
|
|
2
|
+
export interface JsonLayoutOptions {
|
|
3
|
+
/** prettier's `printWidth` — the column budget one printed line may use. */
|
|
4
|
+
readonly printWidth: number;
|
|
5
|
+
/** prettier's `tabWidth` — how many spaces one indentation level is. */
|
|
6
|
+
readonly tabWidth: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* prettier's own defaults, used when the repository's config says nothing about a
|
|
10
|
+
* knob. They are prettier's, not this repository's: the config file is the one
|
|
11
|
+
* source of truth for the numbers, and a second copy of them here would be a
|
|
12
|
+
* second decision.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEFAULT_JSON_LAYOUT: JsonLayoutOptions;
|
|
15
|
+
/**
|
|
16
|
+
* Render a JSON value in the layout prettier produces for JSON, newline-terminated.
|
|
17
|
+
*
|
|
18
|
+
* The output is a prettier FIXED POINT: formatting it again returns it unchanged.
|
|
19
|
+
*/
|
|
20
|
+
export declare function renderJsonDocument(value: unknown, options?: JsonLayoutOptions): string;
|