reading-stone 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +11 -0
- package/README.md +301 -2
- package/dist/analysis.d.ts +341 -0
- package/dist/analysis.js +392 -0
- package/dist/cognitive.d.ts +163 -0
- package/dist/cognitive.js +380 -0
- package/dist/complexity.d.ts +102 -0
- package/dist/complexity.js +163 -0
- package/dist/coverage.d.ts +78 -0
- package/dist/coverage.js +635 -0
- package/dist/detector.d.ts +41 -0
- package/dist/detector.js +2134 -0
- package/dist/discovery.d.ts +330 -0
- package/dist/discovery.js +930 -0
- package/dist/doc-coverage.d.ts +155 -0
- package/dist/doc-coverage.js +543 -0
- package/dist/extract.d.ts +209 -0
- package/dist/extract.js +498 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +63 -0
- package/dist/internal.d.ts +75 -0
- package/dist/internal.js +63 -0
- package/dist/main.d.ts +8 -0
- package/dist/main.js +39 -0
- package/dist/models.d.ts +185 -0
- package/dist/models.js +170 -0
- package/dist/program.d.ts +207 -0
- package/dist/program.js +662 -0
- package/dist/protocol.d.ts +88 -0
- package/dist/protocol.js +74 -0
- package/dist/quality/assertions.d.ts +81 -0
- package/dist/quality/assertions.js +425 -0
- package/dist/quality/collect.d.ts +66 -0
- package/dist/quality/collect.js +412 -0
- package/dist/quality/inference.d.ts +86 -0
- package/dist/quality/inference.js +603 -0
- package/dist/quality/matchers.d.ts +129 -0
- package/dist/quality/matchers.js +220 -0
- package/dist/quality/pairing.d.ts +133 -0
- package/dist/quality/pairing.js +770 -0
- package/dist/quality/pipeline.d.ts +59 -0
- package/dist/quality/pipeline.js +202 -0
- package/dist/quality/types.d.ts +127 -0
- package/dist/quality/types.js +92 -0
- package/dist/safeio.d.ts +107 -0
- package/dist/safeio.js +314 -0
- package/dist/server.d.ts +19 -0
- package/dist/server.js +451 -0
- package/dist/signals/adapter.d.ts +103 -0
- package/dist/signals/adapter.js +323 -0
- package/dist/signals/caller-index.d.ts +117 -0
- package/dist/signals/caller-index.js +147 -0
- package/dist/signals/caller.d.ts +76 -0
- package/dist/signals/caller.js +108 -0
- package/dist/signals/evidence.d.ts +233 -0
- package/dist/signals/evidence.js +578 -0
- package/dist/signals/interface.d.ts +68 -0
- package/dist/signals/interface.js +87 -0
- package/dist/signals/jsdoc.d.ts +27 -0
- package/dist/signals/jsdoc.js +233 -0
- package/dist/signals/naming.d.ts +26 -0
- package/dist/signals/naming.js +160 -0
- package/dist/signals/routing.d.ts +163 -0
- package/dist/signals/routing.js +416 -0
- package/dist/signals/types.d.ts +146 -0
- package/dist/signals/types.js +99 -0
- package/dist/signals/visibility.d.ts +23 -0
- package/dist/signals/visibility.js +82 -0
- package/dist/taxonomy.d.ts +89 -0
- package/dist/taxonomy.js +217 -0
- package/package.json +61 -4
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { type SideEffectType } from "../taxonomy.js";
|
|
2
|
+
/**
|
|
3
|
+
* The classification-signal wire record (FR-001; research R1; data-model.md
|
|
4
|
+
* Section 2) — the raw evidence unit the `classify_signals` method emits and
|
|
5
|
+
* Gaze's `mergeClassifications` → `ComputeScore` pipeline sums back into the
|
|
6
|
+
* reported confidence (the FR-011 sum-invariant): one signal attributes a
|
|
7
|
+
* single piece of classification evidence to one (function record, canonical
|
|
8
|
+
* effect type) pair.
|
|
9
|
+
*
|
|
10
|
+
* The record is deliberately label-free (FR-001): raw signals never carry a
|
|
11
|
+
* classification — `contractual`/`incidental`/`ambiguous` verdicts live on
|
|
12
|
+
* `analyze` effects' `Classification` values only (src/models.ts). A signal
|
|
13
|
+
* says why an effect leans one way; the label is the pipeline's conclusion.
|
|
14
|
+
*
|
|
15
|
+
* Serialization enforces the same Constitution Principle I rules as
|
|
16
|
+
* models.ts, rather than trusting call-site discipline:
|
|
17
|
+
*
|
|
18
|
+
* - Fail loud: a `source` outside the six closed values, a
|
|
19
|
+
* `side_effect_type` that is neither canonical nor alias, a non-integer
|
|
20
|
+
* `weight`, or a present-but-empty `reasoning` throws instead of emitting
|
|
21
|
+
* invalid protocol data. A malformed signal is an analyzer bug; silently
|
|
22
|
+
* shipping it would corrupt every score Gaze computes from the feed.
|
|
23
|
+
* - Omit-unset-optionals: `reasoning` absent or explicitly `undefined` is
|
|
24
|
+
* omitted from the serialized object — never emitted as `null`.
|
|
25
|
+
*
|
|
26
|
+
* No protocol method consumes these records yet — by design: the extractors,
|
|
27
|
+
* the adapter, and the `classify_signals` handler land in later tasks of
|
|
28
|
+
* this feature (US1/US2). Defining the shape once here is what keeps every
|
|
29
|
+
* extractor protocol-shaped instead of inventing per-module ad-hoc
|
|
30
|
+
* structures.
|
|
31
|
+
*
|
|
32
|
+
* Naming follows the wire/identifier split models.ts documents: wire-format
|
|
33
|
+
* fields are snake_case per the protocol payload contract
|
|
34
|
+
* (`side_effect_type`), and the identity field is `function` — the
|
|
35
|
+
* unqualified record name, never `name` (FR-001). Entities are immutable
|
|
36
|
+
* value records — `readonly` fields, never mutated after construction
|
|
37
|
+
* (convention pack AP-004).
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* One of exactly six closed source values (FR-001) — the rule family a
|
|
41
|
+
* signal's evidence came from: `interface` (a declared interface member),
|
|
42
|
+
* `visibility` (exportedness components), `caller_count` (distinct calling
|
|
43
|
+
* modules), `naming_convention` (name prefixes and the `Err` sentinel
|
|
44
|
+
* special case), `docstring` (JSDoc tags and prose verbs — the protocol's
|
|
45
|
+
* established documentation-source string, never `jsdoc`; Clarification
|
|
46
|
+
* Q2), and `contradiction` (the synthesized mixed-polarity penalty,
|
|
47
|
+
* FR-011). No other source value may appear on the wire.
|
|
48
|
+
*/
|
|
49
|
+
export type SignalSource = "interface" | "visibility" | "caller_count" | "naming_convention" | "docstring" | "contradiction";
|
|
50
|
+
/**
|
|
51
|
+
* A single raw classification signal on one (function record, canonical
|
|
52
|
+
* effect type) pair (FR-001).
|
|
53
|
+
*
|
|
54
|
+
* `side_effect_type` must be canonical: extractor code resolves any alias
|
|
55
|
+
* spelling through `resolveSideEffectType` before constructing a `Signal`,
|
|
56
|
+
* and `serializeSignal` enforces canonical membership again as defense in
|
|
57
|
+
* depth — aliases never reach the wire.
|
|
58
|
+
*
|
|
59
|
+
* `reasoning` follows the omit-unset-optionals rule: absent (or explicitly
|
|
60
|
+
* `undefined`) at construction, omitted from serialization — never `null`.
|
|
61
|
+
* Unlike models.ts's pass-through optionals it is content-validated when
|
|
62
|
+
* present, because FR-001 pins non-emptiness as wire contract rather than
|
|
63
|
+
* a construction-time convention.
|
|
64
|
+
*/
|
|
65
|
+
export interface Signal {
|
|
66
|
+
/**
|
|
67
|
+
* The unqualified function record name — the wire identity field, never
|
|
68
|
+
* `name` (FR-001; spec assumption 9).
|
|
69
|
+
*/
|
|
70
|
+
readonly function: string;
|
|
71
|
+
/** Dotted module path derived by `derivePackage` from the record's file. */
|
|
72
|
+
readonly package: string;
|
|
73
|
+
/** The canonical side-effect type — the only vocabulary reportable on the wire. */
|
|
74
|
+
readonly side_effect_type: SideEffectType;
|
|
75
|
+
/**
|
|
76
|
+
* The rule that produced this signal; membership in the closed source
|
|
77
|
+
* set is validated at serialization.
|
|
78
|
+
*/
|
|
79
|
+
readonly source: SignalSource;
|
|
80
|
+
/**
|
|
81
|
+
* Signed integer weight from the closed weight set (data-model.md
|
|
82
|
+
* Section 7). Integer-ness is serializer-checked; the closed set itself
|
|
83
|
+
* is enforced by the extractors' pinned rules rather than a runtime
|
|
84
|
+
* membership test — visibility's clamped component sums (e.g. +14) make
|
|
85
|
+
* the set arithmetic, not enumerable.
|
|
86
|
+
*/
|
|
87
|
+
readonly weight: number;
|
|
88
|
+
/**
|
|
89
|
+
* Deterministic fixed-template explanation naming the matched rule and
|
|
90
|
+
* token; non-empty when present (spec assumption 8).
|
|
91
|
+
*/
|
|
92
|
+
readonly reasoning?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The `classify_signals` result shape (FR-014; data-model.md Section 2): a
|
|
96
|
+
* single `signals` key holding the wire records — exactly one key, with an
|
|
97
|
+
* empty analysis a `{"signals": []}` success rather than an error.
|
|
98
|
+
* `analyze` never emits `Signal` values: its effects carry classifications
|
|
99
|
+
* only (FR-012).
|
|
100
|
+
*
|
|
101
|
+
* Ordering is the emitter's responsibility (the adapter, FR-014):
|
|
102
|
+
* `(package, function, side_effect_type, source)` codepoint comparison — a
|
|
103
|
+
* total order with no tie-break rule, because pair keying keeps the
|
|
104
|
+
* ordering key duplicate-free.
|
|
105
|
+
*
|
|
106
|
+
* The pin is load-bearing end to end: the `classify_signals` entry
|
|
107
|
+
* (src/analysis.ts) returns `ClassifySignalsResult["signals"]` and the
|
|
108
|
+
* server handler constructs its wrapper against this interface, so the
|
|
109
|
+
* wire shape is compile-time enforced rather than merely declared
|
|
110
|
+
* (FR-014).
|
|
111
|
+
*/
|
|
112
|
+
export interface ClassifySignalsResult {
|
|
113
|
+
/** The raw signals in `(package, function, side_effect_type, source)` order. */
|
|
114
|
+
readonly signals: readonly Signal[];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Serializes a `Signal` to its wire shape (FR-001): required `function`,
|
|
118
|
+
* `package`, `side_effect_type`, `source`, and `weight` are always
|
|
119
|
+
* emitted; `reasoning` appears only when set — omitted, never `null`, when
|
|
120
|
+
* absent or explicitly `undefined`.
|
|
121
|
+
*
|
|
122
|
+
* The return is typed `Signal` — the validated wire-shaped value, its
|
|
123
|
+
* alias (if any) resolved to the canonical type — so the
|
|
124
|
+
* `classify_signals` entry's payload and the server handler's
|
|
125
|
+
* `ClassifySignalsResult` wrapper are compile-time pinned to this shape
|
|
126
|
+
* (FR-014's wire contract, enforced rather than asserted).
|
|
127
|
+
*
|
|
128
|
+
* Validation fails loud (Constitution Principle I). `side_effect_type` is
|
|
129
|
+
* checked through the same resolver detection code uses: a canonical name
|
|
130
|
+
* passes through, an alias spelling that slipped past construction
|
|
131
|
+
* resolves to its canonical target (aliases never reach the wire), and a
|
|
132
|
+
* string that is neither canonical nor alias throws. `source` must be one
|
|
133
|
+
* of the six closed values, `weight` a signed integer, and a present
|
|
134
|
+
* `reasoning` a non-empty string — the one optional field whose content is
|
|
135
|
+
* validated, because FR-001 pins non-emptiness as wire contract rather
|
|
136
|
+
* than a construction-time convention.
|
|
137
|
+
*
|
|
138
|
+
* @param signal The signal to serialize.
|
|
139
|
+
* @returns The validated wire-shaped `Signal`: `function`, `package`,
|
|
140
|
+
* `side_effect_type`, `source`, and `weight`, plus `reasoning` when set.
|
|
141
|
+
* @throws Error when `function` or `package` is not a string,
|
|
142
|
+
* `side_effect_type` is neither a canonical side-effect type nor an alias,
|
|
143
|
+
* `source` is outside the closed set, `weight` is not an integer, or
|
|
144
|
+
* `reasoning` is present but not a non-empty string.
|
|
145
|
+
*/
|
|
146
|
+
export declare function serializeSignal(signal: Signal): Signal;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { resolveSideEffectType } from "../taxonomy.js";
|
|
2
|
+
/**
|
|
3
|
+
* The six closed source values (FR-001) — the serializer's membership set.
|
|
4
|
+
* A `Set` (like models.ts's `CLASSIFICATION_LABELS` and taxonomy's
|
|
5
|
+
* `CANONICAL_NAMES`) so lookups consult own data only, never the prototype
|
|
6
|
+
* chain. Constructed with the `SignalSource` element type so a misspelled
|
|
7
|
+
* member is a compile error — the same compile-time check taxonomy gets by
|
|
8
|
+
* building its set from the `SideEffectType[]` literal.
|
|
9
|
+
*/
|
|
10
|
+
const SIGNAL_SOURCES = new Set([
|
|
11
|
+
"interface",
|
|
12
|
+
"visibility",
|
|
13
|
+
"caller_count",
|
|
14
|
+
"naming_convention",
|
|
15
|
+
"docstring",
|
|
16
|
+
"contradiction",
|
|
17
|
+
]);
|
|
18
|
+
/**
|
|
19
|
+
* Fail-loud guard for a required string field: throws when `value` is not
|
|
20
|
+
* a string (Constitution Principle I — invalid record content never
|
|
21
|
+
* reaches the wire). The field is named in the message for actionable
|
|
22
|
+
* diagnostics.
|
|
23
|
+
*
|
|
24
|
+
* A module-private twin of models.ts's guard rather than a shared export:
|
|
25
|
+
* the serializers keep their validation helpers private (the house
|
|
26
|
+
* pattern), and T004's scope is this one new file — promoting the guard to
|
|
27
|
+
* a shared module is a cross-cutting refactor the plan does not ask for.
|
|
28
|
+
*
|
|
29
|
+
* @param value The field value to type-check.
|
|
30
|
+
* @param field Human-readable field description for the error message.
|
|
31
|
+
*/
|
|
32
|
+
function requireString(value, field) {
|
|
33
|
+
if (typeof value !== "string") {
|
|
34
|
+
throw new Error(`Invalid ${field}: expected a string, got ${typeof value}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Serializes a `Signal` to its wire shape (FR-001): required `function`,
|
|
39
|
+
* `package`, `side_effect_type`, `source`, and `weight` are always
|
|
40
|
+
* emitted; `reasoning` appears only when set — omitted, never `null`, when
|
|
41
|
+
* absent or explicitly `undefined`.
|
|
42
|
+
*
|
|
43
|
+
* The return is typed `Signal` — the validated wire-shaped value, its
|
|
44
|
+
* alias (if any) resolved to the canonical type — so the
|
|
45
|
+
* `classify_signals` entry's payload and the server handler's
|
|
46
|
+
* `ClassifySignalsResult` wrapper are compile-time pinned to this shape
|
|
47
|
+
* (FR-014's wire contract, enforced rather than asserted).
|
|
48
|
+
*
|
|
49
|
+
* Validation fails loud (Constitution Principle I). `side_effect_type` is
|
|
50
|
+
* checked through the same resolver detection code uses: a canonical name
|
|
51
|
+
* passes through, an alias spelling that slipped past construction
|
|
52
|
+
* resolves to its canonical target (aliases never reach the wire), and a
|
|
53
|
+
* string that is neither canonical nor alias throws. `source` must be one
|
|
54
|
+
* of the six closed values, `weight` a signed integer, and a present
|
|
55
|
+
* `reasoning` a non-empty string — the one optional field whose content is
|
|
56
|
+
* validated, because FR-001 pins non-emptiness as wire contract rather
|
|
57
|
+
* than a construction-time convention.
|
|
58
|
+
*
|
|
59
|
+
* @param signal The signal to serialize.
|
|
60
|
+
* @returns The validated wire-shaped `Signal`: `function`, `package`,
|
|
61
|
+
* `side_effect_type`, `source`, and `weight`, plus `reasoning` when set.
|
|
62
|
+
* @throws Error when `function` or `package` is not a string,
|
|
63
|
+
* `side_effect_type` is neither a canonical side-effect type nor an alias,
|
|
64
|
+
* `source` is outside the closed set, `weight` is not an integer, or
|
|
65
|
+
* `reasoning` is present but not a non-empty string.
|
|
66
|
+
*/
|
|
67
|
+
export function serializeSignal(signal) {
|
|
68
|
+
requireString(signal.function, "signal function");
|
|
69
|
+
requireString(signal.package, "signal package");
|
|
70
|
+
const type = resolveSideEffectType(signal.side_effect_type);
|
|
71
|
+
if (type === undefined) {
|
|
72
|
+
throw new Error(`Invalid side effect type: ${signal.side_effect_type}`);
|
|
73
|
+
}
|
|
74
|
+
if (!SIGNAL_SOURCES.has(signal.source)) {
|
|
75
|
+
throw new Error(`Invalid signal source: ${signal.source}`);
|
|
76
|
+
}
|
|
77
|
+
if (!Number.isInteger(signal.weight)) {
|
|
78
|
+
throw new Error(`Invalid signal weight: ${signal.weight} (must be an integer)`);
|
|
79
|
+
}
|
|
80
|
+
const serialized = {
|
|
81
|
+
function: signal.function,
|
|
82
|
+
package: signal.package,
|
|
83
|
+
side_effect_type: type,
|
|
84
|
+
source: signal.source,
|
|
85
|
+
weight: signal.weight,
|
|
86
|
+
};
|
|
87
|
+
if (signal.reasoning !== undefined) {
|
|
88
|
+
requireString(signal.reasoning, "signal reasoning");
|
|
89
|
+
if (signal.reasoning.length === 0) {
|
|
90
|
+
throw new Error("Invalid signal reasoning: must be a non-empty string when present");
|
|
91
|
+
}
|
|
92
|
+
// Spread rather than mutate: Signal is an immutable value record
|
|
93
|
+
// (AP-004), so the optional field joins as a new value — the same
|
|
94
|
+
// key order the wire has always had, `reasoning` last.
|
|
95
|
+
return { ...serialized, reasoning: signal.reasoning };
|
|
96
|
+
}
|
|
97
|
+
return serialized;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SideEffectType } from "../taxonomy.js";
|
|
2
|
+
import type { RecordEvidence } from "./evidence.js";
|
|
3
|
+
import type { Signal } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Maps one (function record, canonical effect type) pair's evidence snapshot
|
|
6
|
+
* to FR-003's `visibility` signal.
|
|
7
|
+
*
|
|
8
|
+
* The identity fields pass through verbatim — `function` is the record's
|
|
9
|
+
* unqualified name and `package` its `derivePackage` value — and the rule is
|
|
10
|
+
* effect-type-blind (see the module header): the same snapshot yields the
|
|
11
|
+
* same source, weight, and reasoning for any canonical effect type.
|
|
12
|
+
*
|
|
13
|
+
* @param evidence The record's evidence snapshot; the rule reads only the
|
|
14
|
+
* three visibility components and the record's identity fields, never the
|
|
15
|
+
* live compiler views.
|
|
16
|
+
* @param effectType The pair's canonical effect type — the signal's
|
|
17
|
+
* `side_effect_type` identity field.
|
|
18
|
+
* @returns The `visibility` signal carrying the clamped component sum (+8,
|
|
19
|
+
* +6, +6, or their intermediate sums up to +20) when at least one component
|
|
20
|
+
* applies, or `undefined` when zero do — positive-only visibility (spec
|
|
21
|
+
* assumption 4), never a negative signal and never a 0-weight wire row.
|
|
22
|
+
*/
|
|
23
|
+
export declare function visibilitySignal(evidence: RecordEvidence, effectType: SideEffectType): Signal | undefined;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { derivePackage } from "../models.js";
|
|
2
|
+
/**
|
|
3
|
+
* FR-003's three components, transcribed from data-model.md Section 7. The
|
|
4
|
+
* row order is the pinned reasoning order (function → return type → receiver)
|
|
5
|
+
* and the weights are the pinned contributions — one table is the single
|
|
6
|
+
* source of truth for both, so the arithmetic and the reasoning template
|
|
7
|
+
* cannot drift apart (DRY). Alternatives considered: independent if-chains
|
|
8
|
+
* for the sum and the labels were rejected because a future fourth component
|
|
9
|
+
* (or a re-tuned weight) would need two coordinated edits, where the table
|
|
10
|
+
* makes that extension a one-row change the +20 clamp guards loudly.
|
|
11
|
+
*/
|
|
12
|
+
const VISIBILITY_COMPONENTS = [
|
|
13
|
+
{
|
|
14
|
+
applies: (evidence) => evidence.exportedFunction,
|
|
15
|
+
weight: 8,
|
|
16
|
+
label: "exported function",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
applies: (evidence) => evidence.exportedReturnType,
|
|
20
|
+
weight: 6,
|
|
21
|
+
label: "exported return type",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
applies: (evidence) => evidence.exportedReceiver,
|
|
25
|
+
weight: 6,
|
|
26
|
+
label: "exported receiver",
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
/**
|
|
30
|
+
* FR-003's pinned maximum: the summed component weight is clamped to +20.
|
|
31
|
+
* Arithmetically inert today — 8+6+6 = 20 exactly — and retained anyway as
|
|
32
|
+
* the pinned guard: research R5's rejected alternative is dropping the inert
|
|
33
|
+
* clamp, and removing a pinned guard to simplify code is a gate-weakening
|
|
34
|
+
* move. A future fourth component or re-tuned weight that pushes the raw sum
|
|
35
|
+
* past 20 fails the clamp row loud (tests/signals/visibility.test.ts).
|
|
36
|
+
*/
|
|
37
|
+
const MAX_VISIBILITY_WEIGHT = 20;
|
|
38
|
+
/**
|
|
39
|
+
* Maps one (function record, canonical effect type) pair's evidence snapshot
|
|
40
|
+
* to FR-003's `visibility` signal.
|
|
41
|
+
*
|
|
42
|
+
* The identity fields pass through verbatim — `function` is the record's
|
|
43
|
+
* unqualified name and `package` its `derivePackage` value — and the rule is
|
|
44
|
+
* effect-type-blind (see the module header): the same snapshot yields the
|
|
45
|
+
* same source, weight, and reasoning for any canonical effect type.
|
|
46
|
+
*
|
|
47
|
+
* @param evidence The record's evidence snapshot; the rule reads only the
|
|
48
|
+
* three visibility components and the record's identity fields, never the
|
|
49
|
+
* live compiler views.
|
|
50
|
+
* @param effectType The pair's canonical effect type — the signal's
|
|
51
|
+
* `side_effect_type` identity field.
|
|
52
|
+
* @returns The `visibility` signal carrying the clamped component sum (+8,
|
|
53
|
+
* +6, +6, or their intermediate sums up to +20) when at least one component
|
|
54
|
+
* applies, or `undefined` when zero do — positive-only visibility (spec
|
|
55
|
+
* assumption 4), never a negative signal and never a 0-weight wire row.
|
|
56
|
+
*/
|
|
57
|
+
export function visibilitySignal(evidence, effectType) {
|
|
58
|
+
// Applicability is decided per component (they are independent, FR-003);
|
|
59
|
+
// the filtered rows preserve the table's pinned order, which is also the
|
|
60
|
+
// reasoning's fixed component order.
|
|
61
|
+
const applicable = VISIBILITY_COMPONENTS.filter((component) => component.applies(evidence));
|
|
62
|
+
// Positive-only (spec assumption 4): zero applicable components emit no
|
|
63
|
+
// signal at all — the confidence arithmetic simply proceeds without a
|
|
64
|
+
// visibility term.
|
|
65
|
+
if (applicable.length === 0) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
// FR-003: the emitted weight is the sum of the applicable components,
|
|
69
|
+
// clamped to the +20 maximum (the pinned guard — MAX_VISIBILITY_WEIGHT).
|
|
70
|
+
const weight = Math.min(applicable.reduce((total, component) => total + component.weight, 0), MAX_VISIBILITY_WEIGHT);
|
|
71
|
+
const labels = applicable.map((component) => component.label);
|
|
72
|
+
const { record } = evidence;
|
|
73
|
+
return {
|
|
74
|
+
function: record.name,
|
|
75
|
+
package: derivePackage(record.relPath),
|
|
76
|
+
side_effect_type: effectType,
|
|
77
|
+
source: "visibility",
|
|
78
|
+
weight,
|
|
79
|
+
reasoning: `exported API surface: ${labels.join(", ")}`,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=visibility.js.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The canonical side-effect taxonomy (FR-011, FR-012; research R1) — the
|
|
3
|
+
* protocol v1.2.0 vocabulary every reported effect must use.
|
|
4
|
+
*
|
|
5
|
+
* Constitution Principle I (Protocol Fidelity) requires response data to
|
|
6
|
+
* use Gaze's universal side effect taxonomy; inventing local type names
|
|
7
|
+
* that diverge from it is prohibited. This module is that vocabulary for
|
|
8
|
+
* Reading Stone: the 48 canonical `SideEffectType` names with fixed tier
|
|
9
|
+
* membership (P0=6, P1=11, P2=16, P3=9, P4=6), the `Tier` scale, and the
|
|
10
|
+
* 11 language-neutral aliases (FR-012) — all transcribed verbatim, exact
|
|
11
|
+
* casing and spelling, from the feature's authoritative data model
|
|
12
|
+
* (specs/001-discovery-shared-analysis/data-model.md).
|
|
13
|
+
*
|
|
14
|
+
* Tier membership is fixed data, deliberately NOT configurable (FR-011):
|
|
15
|
+
* an analyzer must never widen, narrow, or re-tier the platform's
|
|
16
|
+
* taxonomy on its own authority.
|
|
17
|
+
*
|
|
18
|
+
* Compile-time exhaustiveness is the module's core safety mechanism
|
|
19
|
+
* (research R1): `TIER_MAP` and `ALIAS_MAP` are `Record`s keyed by the
|
|
20
|
+
* full literal unions, so the compiler rejects a missing key, an extra
|
|
21
|
+
* key, or an out-of-union value — a taxonomy edit that drops, adds, or
|
|
22
|
+
* misspells a member cannot build.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* The priority level of a side-effect type: P0 fixes the detection
|
|
26
|
+
* requirement level (P0 effects must be detected with zero false
|
|
27
|
+
* negatives), P4 is the loosest. Fixed by protocol v1.2.0; see `TIER_MAP`
|
|
28
|
+
* for each type's assignment.
|
|
29
|
+
*/
|
|
30
|
+
export type Tier = "P0" | "P1" | "P2" | "P3" | "P4";
|
|
31
|
+
/**
|
|
32
|
+
* One of exactly 48 canonical side-effect type names — the only
|
|
33
|
+
* vocabulary a reported effect may use (Constitution Principle I).
|
|
34
|
+
* Members are listed tier by tier, P0 through P4, in data-model.md table
|
|
35
|
+
* order; each member's tier assignment lives in `TIER_MAP`.
|
|
36
|
+
*/
|
|
37
|
+
export type SideEffectType = "ReturnValue" | "ErrorReturn" | "SentinelError" | "ReceiverMutation" | "PointerArgMutation" | "ErrorSignal" | "SliceMutation" | "MapMutation" | "GlobalMutation" | "WriterOutput" | "HTTPResponseWrite" | "ChannelSend" | "ChannelClose" | "DeferredReturnMutation" | "GeneratorYield" | "ContainerMutation" | "StreamOutput" | "FileSystemWrite" | "FileSystemDelete" | "FileSystemMeta" | "DatabaseWrite" | "DatabaseTransaction" | "GoroutineSpawn" | "Panic" | "CallbackInvocation" | "LogWrite" | "ContextCancellation" | "AsyncGeneratorYield" | "MetaprogrammingMutation" | "DescriptorEffect" | "ResourceManagement" | "ImportSideEffect" | "MonkeyPatch" | "StdoutWrite" | "StderrWrite" | "EnvVarMutation" | "MutexOp" | "WaitGroupOp" | "AtomicOp" | "TimeDependency" | "ProcessExit" | "RecoverBehavior" | "ReflectionMutation" | "UnsafeMutation" | "CgoCall" | "FinalizerRegistration" | "SyncPoolOp" | "ClosureCaptureMutation";
|
|
38
|
+
/**
|
|
39
|
+
* Tier membership for every canonical type (FR-011) — fixed, NOT
|
|
40
|
+
* configurable. Keyed by the full `SideEffectType` union, so the compiler
|
|
41
|
+
* rejects any missing or extra entry (compile-time exhaustiveness); the
|
|
42
|
+
* value type is `Tier`, so a misspelled tier is rejected too. Entries are
|
|
43
|
+
* grouped P0→P4 in data-model.md table order: P0=6, P1=11, P2=16, P3=9,
|
|
44
|
+
* P4=6 — 48 in total.
|
|
45
|
+
*/
|
|
46
|
+
export declare const TIER_MAP: Readonly<Record<SideEffectType, Tier>>;
|
|
47
|
+
/**
|
|
48
|
+
* All 48 canonical type names, grouped by tier P0→P4 and in
|
|
49
|
+
* data-model.md table order within each tier. The literal's element type
|
|
50
|
+
* is `SideEffectType`, so only union members may appear — misspellings
|
|
51
|
+
* are rejected at compile time. The sibling conformance suite
|
|
52
|
+
* (tests/taxonomy.test.ts, T014) asserts the 48-member count and tier
|
|
53
|
+
* sizes against data-model.md.
|
|
54
|
+
*/
|
|
55
|
+
export declare const SIDE_EFFECT_TYPES: readonly SideEffectType[];
|
|
56
|
+
/**
|
|
57
|
+
* One of exactly 11 language-neutral aliases (FR-012): alternate
|
|
58
|
+
* spellings detection code may match in source, each resolving to exactly
|
|
59
|
+
* one canonical `SideEffectType` via `ALIAS_MAP`. Aliases are never
|
|
60
|
+
* emitted — detection code resolves them to canonical names through
|
|
61
|
+
* `resolveSideEffectType` before constructing records.
|
|
62
|
+
*/
|
|
63
|
+
export type SideEffectAlias = "AsyncTaskSpawn" | "AsyncMessageSend" | "AsyncChannelClose" | "BarrierOp" | "PanicRecovery" | "FFICall" | "ObjectPoolOp" | "DeferredMutation" | "ArgumentMutation" | "ProcessTermination" | "SentinelErrorDecl";
|
|
64
|
+
/**
|
|
65
|
+
* Alias resolution (FR-012): each of the 11 aliases maps to exactly one
|
|
66
|
+
* canonical `SideEffectType`. Keyed by the full `SideEffectAlias` union
|
|
67
|
+
* (compile-time exhaustiveness) with canonical-only values. Transcribed
|
|
68
|
+
* verbatim from the data-model.md alias table.
|
|
69
|
+
*/
|
|
70
|
+
export declare const ALIAS_MAP: Readonly<Record<SideEffectAlias, SideEffectType>>;
|
|
71
|
+
/**
|
|
72
|
+
* Resolves a side-effect name to its canonical `SideEffectType`
|
|
73
|
+
* (FR-012 resolution rule): a canonical name maps to itself, an alias
|
|
74
|
+
* maps to its canonical target, and any other string maps to
|
|
75
|
+
* `undefined`.
|
|
76
|
+
*
|
|
77
|
+
* Detection code constructs canonical-typed records through this
|
|
78
|
+
* resolver regardless of which spelling it matched, so aliases never
|
|
79
|
+
* leak into reported effects. Matching is exact and case-sensitive —
|
|
80
|
+
* protocol names carry exact casing, and a near-miss string must resolve
|
|
81
|
+
* to `undefined`, not to a guessed canonical type (silent misresolution
|
|
82
|
+
* would violate Constitution Principle I).
|
|
83
|
+
*
|
|
84
|
+
* @param name The side-effect name to resolve: a canonical name, an
|
|
85
|
+
* alias, or any other string.
|
|
86
|
+
* @returns The canonical `SideEffectType` for canonical names and
|
|
87
|
+
* aliases; `undefined` for anything else.
|
|
88
|
+
*/
|
|
89
|
+
export declare function resolveSideEffectType(name: string): SideEffectType | undefined;
|
package/dist/taxonomy.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The canonical side-effect taxonomy (FR-011, FR-012; research R1) — the
|
|
3
|
+
* protocol v1.2.0 vocabulary every reported effect must use.
|
|
4
|
+
*
|
|
5
|
+
* Constitution Principle I (Protocol Fidelity) requires response data to
|
|
6
|
+
* use Gaze's universal side effect taxonomy; inventing local type names
|
|
7
|
+
* that diverge from it is prohibited. This module is that vocabulary for
|
|
8
|
+
* Reading Stone: the 48 canonical `SideEffectType` names with fixed tier
|
|
9
|
+
* membership (P0=6, P1=11, P2=16, P3=9, P4=6), the `Tier` scale, and the
|
|
10
|
+
* 11 language-neutral aliases (FR-012) — all transcribed verbatim, exact
|
|
11
|
+
* casing and spelling, from the feature's authoritative data model
|
|
12
|
+
* (specs/001-discovery-shared-analysis/data-model.md).
|
|
13
|
+
*
|
|
14
|
+
* Tier membership is fixed data, deliberately NOT configurable (FR-011):
|
|
15
|
+
* an analyzer must never widen, narrow, or re-tier the platform's
|
|
16
|
+
* taxonomy on its own authority.
|
|
17
|
+
*
|
|
18
|
+
* Compile-time exhaustiveness is the module's core safety mechanism
|
|
19
|
+
* (research R1): `TIER_MAP` and `ALIAS_MAP` are `Record`s keyed by the
|
|
20
|
+
* full literal unions, so the compiler rejects a missing key, an extra
|
|
21
|
+
* key, or an out-of-union value — a taxonomy edit that drops, adds, or
|
|
22
|
+
* misspells a member cannot build.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Tier membership for every canonical type (FR-011) — fixed, NOT
|
|
26
|
+
* configurable. Keyed by the full `SideEffectType` union, so the compiler
|
|
27
|
+
* rejects any missing or extra entry (compile-time exhaustiveness); the
|
|
28
|
+
* value type is `Tier`, so a misspelled tier is rejected too. Entries are
|
|
29
|
+
* grouped P0→P4 in data-model.md table order: P0=6, P1=11, P2=16, P3=9,
|
|
30
|
+
* P4=6 — 48 in total.
|
|
31
|
+
*/
|
|
32
|
+
export const TIER_MAP = {
|
|
33
|
+
// P0
|
|
34
|
+
ReturnValue: "P0",
|
|
35
|
+
ErrorReturn: "P0",
|
|
36
|
+
SentinelError: "P0",
|
|
37
|
+
ReceiverMutation: "P0",
|
|
38
|
+
PointerArgMutation: "P0",
|
|
39
|
+
ErrorSignal: "P0",
|
|
40
|
+
// P1
|
|
41
|
+
SliceMutation: "P1",
|
|
42
|
+
MapMutation: "P1",
|
|
43
|
+
GlobalMutation: "P1",
|
|
44
|
+
WriterOutput: "P1",
|
|
45
|
+
HTTPResponseWrite: "P1",
|
|
46
|
+
ChannelSend: "P1",
|
|
47
|
+
ChannelClose: "P1",
|
|
48
|
+
DeferredReturnMutation: "P1",
|
|
49
|
+
GeneratorYield: "P1",
|
|
50
|
+
ContainerMutation: "P1",
|
|
51
|
+
StreamOutput: "P1",
|
|
52
|
+
// P2
|
|
53
|
+
FileSystemWrite: "P2",
|
|
54
|
+
FileSystemDelete: "P2",
|
|
55
|
+
FileSystemMeta: "P2",
|
|
56
|
+
DatabaseWrite: "P2",
|
|
57
|
+
DatabaseTransaction: "P2",
|
|
58
|
+
GoroutineSpawn: "P2",
|
|
59
|
+
Panic: "P2",
|
|
60
|
+
CallbackInvocation: "P2",
|
|
61
|
+
LogWrite: "P2",
|
|
62
|
+
ContextCancellation: "P2",
|
|
63
|
+
AsyncGeneratorYield: "P2",
|
|
64
|
+
MetaprogrammingMutation: "P2",
|
|
65
|
+
DescriptorEffect: "P2",
|
|
66
|
+
ResourceManagement: "P2",
|
|
67
|
+
ImportSideEffect: "P2",
|
|
68
|
+
MonkeyPatch: "P2",
|
|
69
|
+
// P3
|
|
70
|
+
StdoutWrite: "P3",
|
|
71
|
+
StderrWrite: "P3",
|
|
72
|
+
EnvVarMutation: "P3",
|
|
73
|
+
MutexOp: "P3",
|
|
74
|
+
WaitGroupOp: "P3",
|
|
75
|
+
AtomicOp: "P3",
|
|
76
|
+
TimeDependency: "P3",
|
|
77
|
+
ProcessExit: "P3",
|
|
78
|
+
RecoverBehavior: "P3",
|
|
79
|
+
// P4
|
|
80
|
+
ReflectionMutation: "P4",
|
|
81
|
+
UnsafeMutation: "P4",
|
|
82
|
+
CgoCall: "P4",
|
|
83
|
+
FinalizerRegistration: "P4",
|
|
84
|
+
SyncPoolOp: "P4",
|
|
85
|
+
ClosureCaptureMutation: "P4",
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* All 48 canonical type names, grouped by tier P0→P4 and in
|
|
89
|
+
* data-model.md table order within each tier. The literal's element type
|
|
90
|
+
* is `SideEffectType`, so only union members may appear — misspellings
|
|
91
|
+
* are rejected at compile time. The sibling conformance suite
|
|
92
|
+
* (tests/taxonomy.test.ts, T014) asserts the 48-member count and tier
|
|
93
|
+
* sizes against data-model.md.
|
|
94
|
+
*/
|
|
95
|
+
export const SIDE_EFFECT_TYPES = [
|
|
96
|
+
// P0
|
|
97
|
+
"ReturnValue",
|
|
98
|
+
"ErrorReturn",
|
|
99
|
+
"SentinelError",
|
|
100
|
+
"ReceiverMutation",
|
|
101
|
+
"PointerArgMutation",
|
|
102
|
+
"ErrorSignal",
|
|
103
|
+
// P1
|
|
104
|
+
"SliceMutation",
|
|
105
|
+
"MapMutation",
|
|
106
|
+
"GlobalMutation",
|
|
107
|
+
"WriterOutput",
|
|
108
|
+
"HTTPResponseWrite",
|
|
109
|
+
"ChannelSend",
|
|
110
|
+
"ChannelClose",
|
|
111
|
+
"DeferredReturnMutation",
|
|
112
|
+
"GeneratorYield",
|
|
113
|
+
"ContainerMutation",
|
|
114
|
+
"StreamOutput",
|
|
115
|
+
// P2
|
|
116
|
+
"FileSystemWrite",
|
|
117
|
+
"FileSystemDelete",
|
|
118
|
+
"FileSystemMeta",
|
|
119
|
+
"DatabaseWrite",
|
|
120
|
+
"DatabaseTransaction",
|
|
121
|
+
"GoroutineSpawn",
|
|
122
|
+
"Panic",
|
|
123
|
+
"CallbackInvocation",
|
|
124
|
+
"LogWrite",
|
|
125
|
+
"ContextCancellation",
|
|
126
|
+
"AsyncGeneratorYield",
|
|
127
|
+
"MetaprogrammingMutation",
|
|
128
|
+
"DescriptorEffect",
|
|
129
|
+
"ResourceManagement",
|
|
130
|
+
"ImportSideEffect",
|
|
131
|
+
"MonkeyPatch",
|
|
132
|
+
// P3
|
|
133
|
+
"StdoutWrite",
|
|
134
|
+
"StderrWrite",
|
|
135
|
+
"EnvVarMutation",
|
|
136
|
+
"MutexOp",
|
|
137
|
+
"WaitGroupOp",
|
|
138
|
+
"AtomicOp",
|
|
139
|
+
"TimeDependency",
|
|
140
|
+
"ProcessExit",
|
|
141
|
+
"RecoverBehavior",
|
|
142
|
+
// P4
|
|
143
|
+
"ReflectionMutation",
|
|
144
|
+
"UnsafeMutation",
|
|
145
|
+
"CgoCall",
|
|
146
|
+
"FinalizerRegistration",
|
|
147
|
+
"SyncPoolOp",
|
|
148
|
+
"ClosureCaptureMutation",
|
|
149
|
+
];
|
|
150
|
+
/**
|
|
151
|
+
* Alias resolution (FR-012): each of the 11 aliases maps to exactly one
|
|
152
|
+
* canonical `SideEffectType`. Keyed by the full `SideEffectAlias` union
|
|
153
|
+
* (compile-time exhaustiveness) with canonical-only values. Transcribed
|
|
154
|
+
* verbatim from the data-model.md alias table.
|
|
155
|
+
*/
|
|
156
|
+
export const ALIAS_MAP = {
|
|
157
|
+
AsyncTaskSpawn: "GoroutineSpawn",
|
|
158
|
+
AsyncMessageSend: "ChannelSend",
|
|
159
|
+
AsyncChannelClose: "ChannelClose",
|
|
160
|
+
BarrierOp: "WaitGroupOp",
|
|
161
|
+
PanicRecovery: "RecoverBehavior",
|
|
162
|
+
FFICall: "CgoCall",
|
|
163
|
+
ObjectPoolOp: "SyncPoolOp",
|
|
164
|
+
DeferredMutation: "DeferredReturnMutation",
|
|
165
|
+
ArgumentMutation: "PointerArgMutation",
|
|
166
|
+
ProcessTermination: "Panic",
|
|
167
|
+
SentinelErrorDecl: "SentinelError",
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Canonical-name membership set derived from `SIDE_EFFECT_TYPES` — an O(1),
|
|
171
|
+
* prototype-safe backing store for the type guard below. Deliberately NOT
|
|
172
|
+
* the `in` operator: `in` consults the prototype chain, so
|
|
173
|
+
* `"toString" in TIER_MAP` is `true` and would misresolve
|
|
174
|
+
* `Object.prototype` property names as canonical types.
|
|
175
|
+
*/
|
|
176
|
+
const CANONICAL_NAMES = new Set(SIDE_EFFECT_TYPES);
|
|
177
|
+
/**
|
|
178
|
+
* Type guard: reports whether `name` is one of the 48 canonical
|
|
179
|
+
* `SideEffectType` names. Sound because `CANONICAL_NAMES` holds exactly
|
|
180
|
+
* the members of `SIDE_EFFECT_TYPES`, whose elements the compiler has
|
|
181
|
+
* already verified against the `SideEffectType` union.
|
|
182
|
+
*/
|
|
183
|
+
function isSideEffectType(name) {
|
|
184
|
+
return CANONICAL_NAMES.has(name);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Alias-name → canonical-type lookup derived from `ALIAS_MAP`, so the
|
|
188
|
+
* resolver reads as one total function over arbitrary strings. Like the
|
|
189
|
+
* set above, `Map` lookups are own-data only — no prototype chain is
|
|
190
|
+
* consulted — keeping resolution exact for inputs like `"toString"`.
|
|
191
|
+
*/
|
|
192
|
+
const ALIAS_TARGETS = new Map(Object.entries(ALIAS_MAP));
|
|
193
|
+
/**
|
|
194
|
+
* Resolves a side-effect name to its canonical `SideEffectType`
|
|
195
|
+
* (FR-012 resolution rule): a canonical name maps to itself, an alias
|
|
196
|
+
* maps to its canonical target, and any other string maps to
|
|
197
|
+
* `undefined`.
|
|
198
|
+
*
|
|
199
|
+
* Detection code constructs canonical-typed records through this
|
|
200
|
+
* resolver regardless of which spelling it matched, so aliases never
|
|
201
|
+
* leak into reported effects. Matching is exact and case-sensitive —
|
|
202
|
+
* protocol names carry exact casing, and a near-miss string must resolve
|
|
203
|
+
* to `undefined`, not to a guessed canonical type (silent misresolution
|
|
204
|
+
* would violate Constitution Principle I).
|
|
205
|
+
*
|
|
206
|
+
* @param name The side-effect name to resolve: a canonical name, an
|
|
207
|
+
* alias, or any other string.
|
|
208
|
+
* @returns The canonical `SideEffectType` for canonical names and
|
|
209
|
+
* aliases; `undefined` for anything else.
|
|
210
|
+
*/
|
|
211
|
+
export function resolveSideEffectType(name) {
|
|
212
|
+
if (isSideEffectType(name)) {
|
|
213
|
+
return name;
|
|
214
|
+
}
|
|
215
|
+
return ALIAS_TARGETS.get(name);
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=taxonomy.js.map
|