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,87 @@
|
|
|
1
|
+
import { derivePackage } from "../models.js";
|
|
2
|
+
/**
|
|
3
|
+
* The interface-satisfaction extractor (FR-002; research R6; data-model.md
|
|
4
|
+
* Section 7) — the pure half of US1's `interface` signal, and one of the
|
|
5
|
+
* five extractors the adapter fans out per (function record, canonical
|
|
6
|
+
* effect type) pair (FR-008).
|
|
7
|
+
*
|
|
8
|
+
* The rule is one row of pinned weight arithmetic, not tuning: a
|
|
9
|
+
* class-member record whose enclosing class's heritage declares an
|
|
10
|
+
* interface member carrying the record's name emits exactly one +30
|
|
11
|
+
* `interface` signal; every other record emits nothing. A weight that
|
|
12
|
+
* drifts from data-model.md Section 7 is a bug — the same posture as the
|
|
13
|
+
* caller bucket table (caller.ts) and the confidence formula (FR-009).
|
|
14
|
+
*
|
|
15
|
+
* Evidence seam (research R12): the rule is a pure function of the snapshot
|
|
16
|
+
* and the pair's effect type — no compiler interaction, no I/O, no
|
|
17
|
+
* `ProgramContext`. Every compiler-shaped decision — heritage resolution
|
|
18
|
+
* through the checker, the InterfaceDeclaration-kind gate, the
|
|
19
|
+
* declared-member table keyed by the compiler's escaped-name spelling, the
|
|
20
|
+
* `toString` apparent-member hazard — lives entirely in evidence.ts's
|
|
21
|
+
* `RecordEvidence.interfaceMember` (T019), pinned over program-mode fixture
|
|
22
|
+
* trees by tests/signals/evidence.test.ts (T011); the one runtime import
|
|
23
|
+
* here is `derivePackage`, the pure string helper that renders the record's
|
|
24
|
+
* dotted module path. The seam is what makes the rule exhaustively
|
|
25
|
+
* table-testable with hand-built snapshots (tests/signals/interface.test.ts,
|
|
26
|
+
* T012) — no tree, no tsconfig, no checker for the weights, exactly like
|
|
27
|
+
* the sibling pure rules (visibility, caller, naming, jsdoc).
|
|
28
|
+
*
|
|
29
|
+
* Effect-type blindness: interface evidence agrees with every effect type
|
|
30
|
+
* equally — a declared interface contract obligates the method as a whole,
|
|
31
|
+
* not one effect category — so unlike naming and documentation evidence
|
|
32
|
+
* (FR-005/FR-006) there is no routing gate, and `effectType` rides along as
|
|
33
|
+
* identity only.
|
|
34
|
+
*
|
|
35
|
+
* Parse-only degradation (FR-002; spec assumption 10): without a checker
|
|
36
|
+
* the seam answers `interfaceMember: false` for every record, so no
|
|
37
|
+
* interface signal exists at all — undeterminable is absence of evidence,
|
|
38
|
+
* never an error (Constitution Principle II), and degradation reduces
|
|
39
|
+
* precision, never availability.
|
|
40
|
+
*
|
|
41
|
+
* Determinism (Constitution Principle I; research R1): the emitted
|
|
42
|
+
* `reasoning` is a fixed template naming the matched member and the rule —
|
|
43
|
+
* a pure function of the matched rule and its token, stable per analyzer
|
|
44
|
+
* version and pinned by the test suite exactly like effect `description`
|
|
45
|
+
* strings.
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* Maps one (function record, canonical effect type) pair's evidence snapshot
|
|
49
|
+
* to FR-002's `interface` signal.
|
|
50
|
+
*
|
|
51
|
+
* The identity fields pass through verbatim — `function` is the record's
|
|
52
|
+
* unqualified name and `package` its `derivePackage` value — and the rule
|
|
53
|
+
* is effect-type-blind (see the module header): the same snapshot yields
|
|
54
|
+
* the same source, weight, and reasoning for any canonical effect type.
|
|
55
|
+
*
|
|
56
|
+
* @param evidence The record's evidence snapshot; the rule reads only
|
|
57
|
+
* `interfaceMember` and the record's identity fields, never the live
|
|
58
|
+
* compiler views.
|
|
59
|
+
* @param effectType The pair's canonical effect type — the signal's
|
|
60
|
+
* `side_effect_type` identity field.
|
|
61
|
+
* @returns The +30 `interface` signal when `evidence.interfaceMember` is
|
|
62
|
+
* true — a class-member record a heritage interface declares — or
|
|
63
|
+
* `undefined` otherwise, including every parse-only snapshot: neutral
|
|
64
|
+
* absence, never an error (Constitution Principle II).
|
|
65
|
+
*/
|
|
66
|
+
export function interfaceSignal(evidence, effectType) {
|
|
67
|
+
// FR-002's no-signal rows collapse onto one falsy arm at the seam: a
|
|
68
|
+
// non-class member, an undeclared member, a class base through either
|
|
69
|
+
// heritage token, an invalid extends-an-interface clause, and the
|
|
70
|
+
// parse-only degradation all arrive as `interfaceMember: false`. The
|
|
71
|
+
// class-membership invariant rides with it — evidence.ts only ever sets
|
|
72
|
+
// the flag for a record with an enclosing class-like — so the rule never
|
|
73
|
+
// re-derives a distinction the seam already made.
|
|
74
|
+
if (!evidence.interfaceMember) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
const { record } = evidence;
|
|
78
|
+
return {
|
|
79
|
+
function: record.name,
|
|
80
|
+
package: derivePackage(record.relPath),
|
|
81
|
+
side_effect_type: effectType,
|
|
82
|
+
source: "interface",
|
|
83
|
+
weight: 30,
|
|
84
|
+
reasoning: `member '${record.name}' is declared in an interface of the enclosing class's heritage`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=interface.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
|
6
|
+
* snapshot to FR-006's `docstring` signal.
|
|
7
|
+
*
|
|
8
|
+
* The identity fields pass through verbatim — `function` is the record's
|
|
9
|
+
* unqualified name and `package` its `derivePackage` value — and the
|
|
10
|
+
* rule reads no snapshot field beyond the two documentation components
|
|
11
|
+
* (see the module header): the same comment yields the same signal for
|
|
12
|
+
* a given effect type regardless of the record's name and every other
|
|
13
|
+
* evidence component.
|
|
14
|
+
*
|
|
15
|
+
* @param evidence The record's evidence snapshot; the rule reads only
|
|
16
|
+
* `docText`, `docTags`, and the record's identity fields.
|
|
17
|
+
* @param effectType The pair's canonical effect type — the signal's
|
|
18
|
+
* `side_effect_type` identity field and the routing gate's key.
|
|
19
|
+
* @returns The strongest agreeing tier's routed signal — +15 direct tag,
|
|
20
|
+
* +5 indirect verb, or −15 incidental verb — with the first routed
|
|
21
|
+
* token in the pinned list order naming the match; `undefined` when no
|
|
22
|
+
* tier has routed evidence (the undocumented record, vocabulary outside
|
|
23
|
+
* the closed lists, the unrouted gate rows, and the explicitly-empty
|
|
24
|
+
* routing rows all land here): at most one signal per (function,
|
|
25
|
+
* effect-type) pair, structurally, and never an exception.
|
|
26
|
+
*/
|
|
27
|
+
export declare function docstringSignal(evidence: RecordEvidence, effectType: SideEffectType): Signal | undefined;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { derivePackage } from "../models.js";
|
|
2
|
+
import { DIRECT_TAGS, INCIDENTAL_VERBS, INDIRECT_VERBS, ROUTING_TABLE, } from "./routing.js";
|
|
3
|
+
/**
|
|
4
|
+
* The documentation extractor (FR-006; research R4; Clarifications Q1/Q2;
|
|
5
|
+
* data-model.md Sections 6–7) — the pure half of US1's `docstring`
|
|
6
|
+
* signal, and one of the five extractors the adapter fans out per
|
|
7
|
+
* (function record, canonical effect type) pair (FR-008).
|
|
8
|
+
*
|
|
9
|
+
* The rule is pinned tier selection, not tuning: three closed
|
|
10
|
+
* vocabularies, each routed per effect type through the FR-007 table —
|
|
11
|
+
* a `@returns` tag routed to the value family or a `@throws` tag routed
|
|
12
|
+
* to the error family emits +15 (the direct tier: documentation
|
|
13
|
+
* structurally naming the effect's contract, Clarification Q1); one of
|
|
14
|
+
* the nine indirect verbs matched in the flattened doc text and routed
|
|
15
|
+
* emits +5; one of the four incidental verbs matched and routed emits
|
|
16
|
+
* −15 (research R2: incidental vocabulary routes only to the output
|
|
17
|
+
* family, which is what makes negative documentation evidence possible
|
|
18
|
+
* at all). A weight that drifts from data-model.md Section 7 is a bug —
|
|
19
|
+
* the same posture as the sibling pure rules (interface, visibility,
|
|
20
|
+
* caller, naming).
|
|
21
|
+
*
|
|
22
|
+
* At most ONE signal per pair, resolved to the strongest agreeing tier
|
|
23
|
+
* present (direct > indirect > incidental) — the single `Signal |
|
|
24
|
+
* undefined` return makes it structural, and it is what keeps one
|
|
25
|
+
* extractor from ever emitting mixed polarities: the writeBanner-style
|
|
26
|
+
* contradiction can only arise ACROSS sources, which is FR-011's model.
|
|
27
|
+
* Resolution operates on ROUTED evidence only — a tag or verb present
|
|
28
|
+
* but not routed to the pair's effect type neither emits nor suppresses;
|
|
29
|
+
* the tier simply has no match and resolution falls through to the
|
|
30
|
+
* weaker tier. Within a tier the FIRST token in the pinned closed-list
|
|
31
|
+
* order names the match in the reasoning (the deterministic tie-break,
|
|
32
|
+
* research R4) — never document order, so "Stores the data, then writes
|
|
33
|
+
* it." names 'writes' and "Traces and prints the flow." names 'prints'
|
|
34
|
+
* (Constitution Principle I). No effect type routes both a direct tag
|
|
35
|
+
* and an incidental verb over today's table (the suite's tripwire), so
|
|
36
|
+
* the direct-over-incidental step is arithmetically inert — implemented
|
|
37
|
+
* anyway, the pinned-guard stance.
|
|
38
|
+
*
|
|
39
|
+
* The direct tier matches the compiler's own tag list: `getJSDocTags`
|
|
40
|
+
* yields BARE names ('returns'), while the closed list and the routing
|
|
41
|
+
* table's `docTags` column keep the FR-006 '@'-prefixed spelling, so the
|
|
42
|
+
* matcher normalizes bare to '@'-prefixed — routing.ts's documented
|
|
43
|
+
* contract. The tag's comment text is deliberately unread: the tag's
|
|
44
|
+
* PRESENCE is the structural evidence, and a comment-less tag still
|
|
45
|
+
* fires. Tags outside the closed vocabulary (@param, @deprecated) are
|
|
46
|
+
* not evidence at all.
|
|
47
|
+
*
|
|
48
|
+
* The verb tiers match the flattened doc text case-insensitively with
|
|
49
|
+
* word-boundary delimitation on both ends: boundaries are word
|
|
50
|
+
* characters, not spaces, so a verb at either string edge or beside
|
|
51
|
+
* punctuation matches (`writes` alone; "It writes, then flushes."),
|
|
52
|
+
* while `Logs` matches `logs`, `debugging` does NOT match `debugs`, and
|
|
53
|
+
* a verb inside a longer word never fires (`Resets` is not `sets`) —
|
|
54
|
+
* the quickstart logMessage comment is the canonical fixture for the
|
|
55
|
+
* pair. The incidental tier consults `RoutingBranch.docIncidental`,
|
|
56
|
+
* routing.ts's shared incidental prefixes+verbs column: this extractor
|
|
57
|
+
* matches the four VERBS against it, never the naming prefixes — the
|
|
58
|
+
* token sets are disjoint, so iterating the closed vocabulary (not the
|
|
59
|
+
* column) keeps 'log' and 'debug' as standalone words inert here.
|
|
60
|
+
*
|
|
61
|
+
* The emitted source string is `docstring` — the protocol's established
|
|
62
|
+
* documentation-source value, NEVER 'jsdoc' (Clarification Q2: Gaze's
|
|
63
|
+
* mergeClassifications copies the source verbatim into ComputeScore, so
|
|
64
|
+
* a divergent string would leave the platform vocabulary; this module's
|
|
65
|
+
* path, jsdoc.ts, is internal naming only).
|
|
66
|
+
*
|
|
67
|
+
* Evidence seam (research R12): the rule is a pure function of the
|
|
68
|
+
* snapshot and the pair's effect type — no compiler interaction, no
|
|
69
|
+
* I/O, no `ProgramContext`. It reads only the two documentation
|
|
70
|
+
* components (`docText`, `docTags`) and the record's identity fields
|
|
71
|
+
* (`name` is the signal's `function`; `relPath` feeds `derivePackage`),
|
|
72
|
+
* which is what lets the adapter compute one snapshot per record for
|
|
73
|
+
* all five extractors while this rule stays blind to every other
|
|
74
|
+
* component. Unlike the checker-resolved components, documentation
|
|
75
|
+
* evidence is syntactic (data-model.md Section 5.1 marks both fields
|
|
76
|
+
* mode "both"), so this rule has NO parse-only degradation at all —
|
|
77
|
+
* the same availability as naming.
|
|
78
|
+
*
|
|
79
|
+
* Effect-type sensitivity — the routing gate (FR-007): documentation
|
|
80
|
+
* evidence agrees with effect types selectively, so the gate decides
|
|
81
|
+
* per pair — the same "Writes the file to disk." yields +5 on a
|
|
82
|
+
* `FileSystemWrite` effect and nothing on a `ReturnValue` effect. The
|
|
83
|
+
* lookup is total by construction (routing.ts's compile-time
|
|
84
|
+
* exhaustiveness), and an effect type with no agreeing vocabulary — the
|
|
85
|
+
* explicitly-empty rows — emits nothing, never an exception.
|
|
86
|
+
*
|
|
87
|
+
* Determinism (Constitution Principle I; research R1): the emitted
|
|
88
|
+
* `reasoning` is one of three fixed templates naming the matched tier
|
|
89
|
+
* and its token in the CANONICAL closed-list spelling ('@returns',
|
|
90
|
+
* 'writes', 'logs' — never the comment's own casing, so "Logs the
|
|
91
|
+
* message" and "logs the message" carry identical reasoning), stable
|
|
92
|
+
* per analyzer version and pinned by the test suite exactly like
|
|
93
|
+
* effect `description` strings.
|
|
94
|
+
*/
|
|
95
|
+
/**
|
|
96
|
+
* Escapes regular-expression metacharacters in a literal token before it
|
|
97
|
+
* is interpolated into a pattern. Today's closed verb lists are plain
|
|
98
|
+
* alphabetic words, so the escape is inert — but a future verb carrying
|
|
99
|
+
* a metacharacter must match as a literal, never as syntax: the
|
|
100
|
+
* pinned-guard stance, exactly like naming's longest-prefix selection.
|
|
101
|
+
*
|
|
102
|
+
* @param literal The canonical closed-list token.
|
|
103
|
+
* @returns The token with every regex metacharacter backslash-escaped.
|
|
104
|
+
*/
|
|
105
|
+
function escapeRegExp(literal) {
|
|
106
|
+
return literal.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The compiled whole-word pattern for each of the 13 closed verbs (9
|
|
110
|
+
* indirect + 4 incidental), folded once at module load rather than per
|
|
111
|
+
* pair — the same discipline as naming's folded prefixes. Case-
|
|
112
|
+
* insensitive and word-boundary delimited on both ends (see the module
|
|
113
|
+
* header for the boundary semantics).
|
|
114
|
+
*/
|
|
115
|
+
const VERB_PATTERNS = new Map([...INDIRECT_VERBS, ...INCIDENTAL_VERBS].map((verb) => [
|
|
116
|
+
verb,
|
|
117
|
+
new RegExp(`\\b${escapeRegExp(verb)}\\b`, "i"),
|
|
118
|
+
]));
|
|
119
|
+
/**
|
|
120
|
+
* Whether the snapshot's tag list carries the canonical direct tag —
|
|
121
|
+
* the compiler-shaped bare name normalized to the closed list's
|
|
122
|
+
* '@'-prefixed spelling (see the module header). The tag's comment text
|
|
123
|
+
* is deliberately unread: presence is the evidence.
|
|
124
|
+
*
|
|
125
|
+
* @param evidence The record's evidence snapshot; reads `docTags` only.
|
|
126
|
+
* @param tag The canonical '@'-prefixed closed-list tag.
|
|
127
|
+
* @returns Whether any snapshot tag normalizes to the canonical one.
|
|
128
|
+
*/
|
|
129
|
+
function hasDirectTag(evidence, tag) {
|
|
130
|
+
return evidence.docTags.some((docTag) => `@${docTag.tag.toLowerCase()}` === tag);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Whether the flattened doc text carries the canonical verb as a whole
|
|
134
|
+
* word. The map lookup is total by construction — the tier vocabularies
|
|
135
|
+
* ARE the map's keys — so the fallback branch is a type-level formality,
|
|
136
|
+
* never a behavioral path.
|
|
137
|
+
*
|
|
138
|
+
* @param evidence The record's evidence snapshot; reads `docText` only.
|
|
139
|
+
* @param verb The canonical closed-list verb.
|
|
140
|
+
* @returns Whether the text carries the verb as a whole word.
|
|
141
|
+
*/
|
|
142
|
+
function matchesVerb(evidence, verb) {
|
|
143
|
+
return VERB_PATTERNS.get(verb)?.test(evidence.docText) ?? false;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The three documentation tiers in STRONGEST-TIER RESOLUTION ORDER — the
|
|
147
|
+
* array order IS the rule: the first tier with a token that both matches
|
|
148
|
+
* the pair's evidence and is routed for the pair's effect type emits the
|
|
149
|
+
* pair's one signal (direct > indirect > incidental). Drawn from
|
|
150
|
+
* routing.ts's exported closed lists so the conformance suite's
|
|
151
|
+
* closed-list pins and this selection table cannot drift apart.
|
|
152
|
+
*/
|
|
153
|
+
const DOC_TIERS = [
|
|
154
|
+
{
|
|
155
|
+
label: "direct",
|
|
156
|
+
noun: "tag",
|
|
157
|
+
weight: 15,
|
|
158
|
+
vocabulary: DIRECT_TAGS,
|
|
159
|
+
routedIn: (branch) => branch.docTags,
|
|
160
|
+
matches: hasDirectTag,
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
label: "indirect",
|
|
164
|
+
noun: "verb",
|
|
165
|
+
weight: 5,
|
|
166
|
+
vocabulary: INDIRECT_VERBS,
|
|
167
|
+
routedIn: (branch) => branch.docIndirect,
|
|
168
|
+
matches: matchesVerb,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
label: "incidental",
|
|
172
|
+
noun: "verb",
|
|
173
|
+
weight: -15,
|
|
174
|
+
vocabulary: INCIDENTAL_VERBS,
|
|
175
|
+
routedIn: (branch) => branch.docIncidental,
|
|
176
|
+
matches: matchesVerb,
|
|
177
|
+
},
|
|
178
|
+
];
|
|
179
|
+
/**
|
|
180
|
+
* Maps one (function record, canonical effect type) pair's evidence
|
|
181
|
+
* snapshot to FR-006's `docstring` signal.
|
|
182
|
+
*
|
|
183
|
+
* The identity fields pass through verbatim — `function` is the record's
|
|
184
|
+
* unqualified name and `package` its `derivePackage` value — and the
|
|
185
|
+
* rule reads no snapshot field beyond the two documentation components
|
|
186
|
+
* (see the module header): the same comment yields the same signal for
|
|
187
|
+
* a given effect type regardless of the record's name and every other
|
|
188
|
+
* evidence component.
|
|
189
|
+
*
|
|
190
|
+
* @param evidence The record's evidence snapshot; the rule reads only
|
|
191
|
+
* `docText`, `docTags`, and the record's identity fields.
|
|
192
|
+
* @param effectType The pair's canonical effect type — the signal's
|
|
193
|
+
* `side_effect_type` identity field and the routing gate's key.
|
|
194
|
+
* @returns The strongest agreeing tier's routed signal — +15 direct tag,
|
|
195
|
+
* +5 indirect verb, or −15 incidental verb — with the first routed
|
|
196
|
+
* token in the pinned list order naming the match; `undefined` when no
|
|
197
|
+
* tier has routed evidence (the undocumented record, vocabulary outside
|
|
198
|
+
* the closed lists, the unrouted gate rows, and the explicitly-empty
|
|
199
|
+
* routing rows all land here): at most one signal per (function,
|
|
200
|
+
* effect-type) pair, structurally, and never an exception.
|
|
201
|
+
*/
|
|
202
|
+
export function docstringSignal(evidence, effectType) {
|
|
203
|
+
const { record } = evidence;
|
|
204
|
+
// The routing gate is total by construction (routing.ts's compile-time
|
|
205
|
+
// exhaustiveness), so the typed-canonical lookup has no fallback path.
|
|
206
|
+
const branch = ROUTING_TABLE[effectType];
|
|
207
|
+
// Strongest agreeing tier first, then first ROUTED token in the pinned
|
|
208
|
+
// list order — never document order (Constitution Principle I). The
|
|
209
|
+
// routing check sits INSIDE the vocabulary loop on purpose: a
|
|
210
|
+
// matching-but-unrouted token is skipped, not selected, which is what
|
|
211
|
+
// makes resolution operate on agreeing evidence only (a present but
|
|
212
|
+
// unrouted tag or verb neither emits nor suppresses).
|
|
213
|
+
for (const tier of DOC_TIERS) {
|
|
214
|
+
const routed = tier.routedIn(branch);
|
|
215
|
+
for (const token of tier.vocabulary) {
|
|
216
|
+
if (routed.includes(token) && tier.matches(evidence, token)) {
|
|
217
|
+
return {
|
|
218
|
+
function: record.name,
|
|
219
|
+
package: derivePackage(record.relPath),
|
|
220
|
+
side_effect_type: effectType,
|
|
221
|
+
source: "docstring",
|
|
222
|
+
weight: tier.weight,
|
|
223
|
+
reasoning: `documented with the ${tier.label} ${tier.noun} '${token}'`,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// No tier has routed evidence — neutral absence, never an error
|
|
229
|
+
// (Constitution Principle II): the confidence arithmetic simply
|
|
230
|
+
// proceeds without a documentation term.
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=jsdoc.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
|
6
|
+
* snapshot to FR-005's `naming_convention` signal.
|
|
7
|
+
*
|
|
8
|
+
* The identity fields pass through verbatim — `function` is the record's
|
|
9
|
+
* unqualified name (which is also the matched evidence) and `package`
|
|
10
|
+
* its `derivePackage` value — and the rule reads no other snapshot field
|
|
11
|
+
* (see the module header): the same name yields the same signal for a
|
|
12
|
+
* given effect type regardless of every other evidence component.
|
|
13
|
+
*
|
|
14
|
+
* @param evidence The record's evidence snapshot; the rule reads only
|
|
15
|
+
* the record's identity fields, never the compiler views or the other
|
|
16
|
+
* components.
|
|
17
|
+
* @param effectType The pair's canonical effect type — the signal's
|
|
18
|
+
* `side_effect_type` identity field and the routing gate's key.
|
|
19
|
+
* @returns The +30 sentinel signal for an `Err`-prefixed name on a
|
|
20
|
+
* `SentinelError` effect; otherwise the routed prefix's +10/−10 signal
|
|
21
|
+
* when the longest applicable closed prefix agrees with the effect type
|
|
22
|
+
* through the routing table; `undefined` when no prefix applies or the
|
|
23
|
+
* selected prefix has no agreement — at most one signal per
|
|
24
|
+
* (function, effect-type) pair, structurally.
|
|
25
|
+
*/
|
|
26
|
+
export declare function namingSignal(evidence: RecordEvidence, effectType: SideEffectType): Signal | undefined;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { derivePackage } from "../models.js";
|
|
2
|
+
import { CONTRACTUAL_PREFIXES, INCIDENTAL_PREFIXES, ROUTING_TABLE, } from "./routing.js";
|
|
3
|
+
/**
|
|
4
|
+
* FR-005's contractual family — the 18 closed prefixes whose presence
|
|
5
|
+
* AGREES with an effect being contractual (+10 via `naming_convention`
|
|
6
|
+
* when the routing table lists the selected prefix for the pair's effect
|
|
7
|
+
* type). Drawn from routing.ts's exported list so the conformance
|
|
8
|
+
* suite's closed-list pin and this selection table cannot drift apart.
|
|
9
|
+
*/
|
|
10
|
+
const CONTRACTUAL_FAMILY = {
|
|
11
|
+
prefixes: CONTRACTUAL_PREFIXES,
|
|
12
|
+
weight: 10,
|
|
13
|
+
label: "contractual",
|
|
14
|
+
routedIn: (branch) => branch.naming,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* FR-005's incidental family — the 4 closed logging prefixes whose
|
|
18
|
+
* presence DISAGREES with an effect being contractual (−10 when routed;
|
|
19
|
+
* only the output family ever lists them, which is what makes negative
|
|
20
|
+
* naming evidence possible at all — research R2). The routing column is
|
|
21
|
+
* `docIncidental`, routing.ts's shared incidental prefixes+verbs list:
|
|
22
|
+
* the prefix and verb token sets are disjoint, so one column serves the
|
|
23
|
+
* naming and documentation extractors without ambiguity.
|
|
24
|
+
*/
|
|
25
|
+
const INCIDENTAL_FAMILY = {
|
|
26
|
+
prefixes: INCIDENTAL_PREFIXES,
|
|
27
|
+
weight: -10,
|
|
28
|
+
label: "incidental",
|
|
29
|
+
routedIn: (branch) => branch.docIncidental,
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The union of the 22 closed prefixes as one flat selection table (FR-005
|
|
33
|
+
* selects the longest applicable prefix over the UNION, not per family),
|
|
34
|
+
* built once at module load. Contractual entries precede incidental
|
|
35
|
+
* ones; since two prefixes of the same length can both match one name's
|
|
36
|
+
* leading characters only by being the same string — and the two closed
|
|
37
|
+
* lists are disjoint — the order is unobservable beyond determinism.
|
|
38
|
+
*/
|
|
39
|
+
const CLOSED_PREFIXES = [
|
|
40
|
+
CONTRACTUAL_FAMILY,
|
|
41
|
+
INCIDENTAL_FAMILY,
|
|
42
|
+
].flatMap((family) => family.prefixes.map((prefix) => ({ prefix, folded: prefix.toLowerCase(), family })));
|
|
43
|
+
/**
|
|
44
|
+
* The sentinel special case's stem (FR-005; spec assumption 6): a record
|
|
45
|
+
* name beginning with `Err` — the constant holds the folded form, the
|
|
46
|
+
* case-insensitive matching key — evaluated for a `SentinelError`
|
|
47
|
+
* effect emits +30 in place of the prefix rules. The stem is matched
|
|
48
|
+
* with the same leading-character imprecision as every prefix
|
|
49
|
+
* (`ErrorMapper` fires — assumption 5's sentinel-side mirror,
|
|
50
|
+
* fixture-pinned). The carrying record's name governs because signals
|
|
51
|
+
* are computed per pair from the record the effect lives on: sentinel
|
|
52
|
+
* effects attach to the file's first function record (spec 002 FR-013),
|
|
53
|
+
* so that record's name is the one this rule reads (spec edge case 3).
|
|
54
|
+
*/
|
|
55
|
+
const SENTINEL_STEM = "err";
|
|
56
|
+
/**
|
|
57
|
+
* The sentinel special case's pinned weight (data-model.md Section 7):
|
|
58
|
+
* +30, replacing the prefix rules' ±10 for that effect entirely.
|
|
59
|
+
*/
|
|
60
|
+
const SENTINEL_WEIGHT = 30;
|
|
61
|
+
/**
|
|
62
|
+
* Selects FR-005's longest applicable prefix for a record name: the one
|
|
63
|
+
* closed-list entry whose folded form matches the name's leading
|
|
64
|
+
* characters, case-insensitively, longest first. Over today's closed
|
|
65
|
+
* lists at most one prefix can apply at all (the no-overlap tripwire in
|
|
66
|
+
* tests/signals/naming.test.ts); the length comparison is the pinned
|
|
67
|
+
* longest-wins rule that governs if the lists ever grow (research R3) —
|
|
68
|
+
* never removed to simplify the code, the same pinned-guard discipline
|
|
69
|
+
* as visibility's inert +20 clamp.
|
|
70
|
+
*
|
|
71
|
+
* @param name The record's unqualified name.
|
|
72
|
+
* @returns The longest applicable closed prefix, or `undefined` when
|
|
73
|
+
* the name begins with none of the 22.
|
|
74
|
+
*/
|
|
75
|
+
function selectLongestPrefix(name) {
|
|
76
|
+
const folded = name.toLowerCase();
|
|
77
|
+
let selected;
|
|
78
|
+
for (const candidate of CLOSED_PREFIXES) {
|
|
79
|
+
if (folded.startsWith(candidate.folded) &&
|
|
80
|
+
(selected === undefined || candidate.prefix.length > selected.prefix.length)) {
|
|
81
|
+
selected = candidate;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return selected;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Maps one (function record, canonical effect type) pair's evidence
|
|
88
|
+
* snapshot to FR-005's `naming_convention` signal.
|
|
89
|
+
*
|
|
90
|
+
* The identity fields pass through verbatim — `function` is the record's
|
|
91
|
+
* unqualified name (which is also the matched evidence) and `package`
|
|
92
|
+
* its `derivePackage` value — and the rule reads no other snapshot field
|
|
93
|
+
* (see the module header): the same name yields the same signal for a
|
|
94
|
+
* given effect type regardless of every other evidence component.
|
|
95
|
+
*
|
|
96
|
+
* @param evidence The record's evidence snapshot; the rule reads only
|
|
97
|
+
* the record's identity fields, never the compiler views or the other
|
|
98
|
+
* components.
|
|
99
|
+
* @param effectType The pair's canonical effect type — the signal's
|
|
100
|
+
* `side_effect_type` identity field and the routing gate's key.
|
|
101
|
+
* @returns The +30 sentinel signal for an `Err`-prefixed name on a
|
|
102
|
+
* `SentinelError` effect; otherwise the routed prefix's +10/−10 signal
|
|
103
|
+
* when the longest applicable closed prefix agrees with the effect type
|
|
104
|
+
* through the routing table; `undefined` when no prefix applies or the
|
|
105
|
+
* selected prefix has no agreement — at most one signal per
|
|
106
|
+
* (function, effect-type) pair, structurally.
|
|
107
|
+
*/
|
|
108
|
+
export function namingSignal(evidence, effectType) {
|
|
109
|
+
const { record } = evidence;
|
|
110
|
+
// The sentinel special case first (FR-005 precedence): a SentinelError
|
|
111
|
+
// effect carried by an Err-prefixed name emits +30 IN PLACE of the
|
|
112
|
+
// prefix rules — returning here is what makes "in place of"
|
|
113
|
+
// structural, and the single return value is what makes
|
|
114
|
+
// at-most-one-signal-per-pair structural. Every other combination
|
|
115
|
+
// falls through to the prefix rules: an Err-prefixed name on any other
|
|
116
|
+
// effect (Err is in neither closed list — no closed prefix even begins
|
|
117
|
+
// with 'e' — so the fallback is structurally silent), and a
|
|
118
|
+
// SentinelError effect on a non-Err name (the row's naming list is
|
|
119
|
+
// empty, so the gate below stays silent).
|
|
120
|
+
if (effectType === "SentinelError" &&
|
|
121
|
+
record.name.toLowerCase().startsWith(SENTINEL_STEM)) {
|
|
122
|
+
return {
|
|
123
|
+
function: record.name,
|
|
124
|
+
package: derivePackage(record.relPath),
|
|
125
|
+
side_effect_type: effectType,
|
|
126
|
+
source: "naming_convention",
|
|
127
|
+
weight: SENTINEL_WEIGHT,
|
|
128
|
+
reasoning: "name starts with 'Err', the SentinelError special case",
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
// Longest-prefix selection over the union of the 22 closed prefixes,
|
|
132
|
+
// case-insensitive on the name's leading characters. No applicable
|
|
133
|
+
// prefix is neutral absence, never an error (Constitution Principle
|
|
134
|
+
// II) — the confidence arithmetic simply proceeds without a naming
|
|
135
|
+
// term.
|
|
136
|
+
const selected = selectLongestPrefix(record.name);
|
|
137
|
+
if (selected === undefined) {
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
const { family, prefix } = selected;
|
|
141
|
+
// The routing gate (FR-007): the matched prefix is evidence only for
|
|
142
|
+
// the effect types whose routing row lists it — a match without
|
|
143
|
+
// agreement emits nothing. The family picks the column (contractual
|
|
144
|
+
// agreement in `naming`, incidental in `docIncidental`), and the
|
|
145
|
+
// lookup is total by construction — routing.ts's compile-time
|
|
146
|
+
// exhaustiveness — so there is no fallback path and never an
|
|
147
|
+
// exception.
|
|
148
|
+
if (!family.routedIn(ROUTING_TABLE[effectType]).includes(prefix)) {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
function: record.name,
|
|
153
|
+
package: derivePackage(record.relPath),
|
|
154
|
+
side_effect_type: effectType,
|
|
155
|
+
source: "naming_convention",
|
|
156
|
+
weight: family.weight,
|
|
157
|
+
reasoning: `name starts with the ${family.label} prefix '${prefix}'`,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=naming.js.map
|