@polycode-projects/the-mechanical-code-talker 5.0.40 → 5.0.42
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polycode-projects/the-mechanical-code-talker",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.42",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "The Mechanical Code Talker (tmct) — a tolerant, offline, $0 chat surface that guides you toward precision queries about a software repository. ELIZA/PARRY-style but domain-obsessed with code. No model calls; indexes a repo on request (tmct index) or reads any producer's graph.",
|
package/src/domain/ask.mjs
CHANGED
|
@@ -545,6 +545,49 @@ function parseSetPhrase(text, nlp, depth) {
|
|
|
545
545
|
* the gerund form, "who touched the module importing X" falls through to the legacy
|
|
546
546
|
* strategy pipeline, which misreads the leading verb "touched" as the flat ASK shape's
|
|
547
547
|
* subject term instead of resolving to a real entity. */
|
|
548
|
+
/** Split a relative clause's words at a trailing branch of bare qualifier
|
|
549
|
+
* adjectives, which restricts the MATRIX head rather than the embedded one.
|
|
550
|
+
*
|
|
551
|
+
* "modules importing the module that defines fnAlpha but not tested" excludes
|
|
552
|
+
* the tested IMPORTERS, not a tested definer — the same sentence with the
|
|
553
|
+
* adjective fronted ("untested modules that import the module that defines
|
|
554
|
+
* fnAlpha") is the reading it pairs with, and the explicit-pronoun order
|
|
555
|
+
* ("modules that import … and tested") already splits its branches at the
|
|
556
|
+
* matrix head before this production is reached. Left inside the relative
|
|
557
|
+
* clause, the filter narrowed the definer instead, which is a set of one that
|
|
558
|
+
* usually survives it, so the exclusion silently did nothing.
|
|
559
|
+
*
|
|
560
|
+
* Only adjectives lift. A trailing branch with a verb of its own is a second
|
|
561
|
+
* predicate on the embedded head and stays where it was written. Returns
|
|
562
|
+
* {rest, lifted} with `lifted` as ready-made boolean atoms, or null when the
|
|
563
|
+
* clause carries no such branch. */
|
|
564
|
+
function liftTrailingQualifierBranches(words) {
|
|
565
|
+
const lc = words.map((x) => x.toLowerCase());
|
|
566
|
+
const conns = Object.keys(BOOLEAN_CONNECTIVES).sort((a, z) => z.split(" ").length - a.split(" ").length);
|
|
567
|
+
const lifted = [];
|
|
568
|
+
let end = words.length;
|
|
569
|
+
for (;;) {
|
|
570
|
+
let found = null;
|
|
571
|
+
for (let i = end - 1; i >= 1 && !found; i -= 1) {
|
|
572
|
+
for (const c of conns) {
|
|
573
|
+
const cw = c.split(" ");
|
|
574
|
+
if (i + cw.length <= end && lc.slice(i, i + cw.length).join(" ") === c) {
|
|
575
|
+
found = { at: i, len: cw.length, op: BOOLEAN_CONNECTIVES[c] };
|
|
576
|
+
break;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
if (!found) break;
|
|
581
|
+
const tail = words.slice(found.at + found.len, end);
|
|
582
|
+
const { blc } = dropLeadCopula(tail, tail.map((x) => x.toLowerCase()));
|
|
583
|
+
if (!blc.length || !blc.every((x) => QUALIFIERS[x])) break;
|
|
584
|
+
lifted.unshift({ op: found.op, kind: "qual", filters: blc });
|
|
585
|
+
end = found.at;
|
|
586
|
+
}
|
|
587
|
+
if (!lifted.length || !end) return null;
|
|
588
|
+
return { rest: words.slice(0, end), lifted };
|
|
589
|
+
}
|
|
590
|
+
|
|
548
591
|
function parseNested(w, lc, nlp, depth) {
|
|
549
592
|
for (let r = 1; r < lc.length; r += 1) {
|
|
550
593
|
const isPronoun = RELATIVE_PRONOUNS.includes(lc[r]);
|
|
@@ -568,10 +611,18 @@ function parseNested(w, lc, nlp, depth) {
|
|
|
568
611
|
// so the inner may itself be nested/boolean/qualified (depth ≥2). An explicit
|
|
569
612
|
// relative pronoun is consumed (skip past it, start at r+1); a gerund marker IS
|
|
570
613
|
// the predicate's own verb, so it stays in the inner text (start AT r).
|
|
571
|
-
const
|
|
614
|
+
const innerWords = w.slice(isPronoun ? r + 1 : r);
|
|
615
|
+
const highAttached = liftTrailingQualifierBranches(innerWords);
|
|
616
|
+
const innerText = `which ${lc[r - 1]} ${(highAttached ? highAttached.rest : innerWords).join(" ")}`;
|
|
572
617
|
const inner = parseSetPhrase(innerText, nlp, depth + 1);
|
|
573
618
|
if (!inner || inner.node === "miss") return inner ? { node: "miss", reason: inner.reason || "inner clause didn't parse" } : { node: "miss", reason: "inner clause didn't parse" };
|
|
574
|
-
|
|
619
|
+
const set = { node: outer.shape === "reverse" ? "reverseSet" : "forwardSet", kind: outer.kind, entityType: outer.entityType, inner };
|
|
620
|
+
if (!highAttached) return set;
|
|
621
|
+
return {
|
|
622
|
+
node: "boolean",
|
|
623
|
+
entityType: outer.entityType,
|
|
624
|
+
atoms: [{ op: "seed", kind: "set", ast: set }, ...highAttached.lifted],
|
|
625
|
+
};
|
|
575
626
|
}
|
|
576
627
|
return null;
|
|
577
628
|
}
|
|
@@ -1238,6 +1289,24 @@ function parseFindPredicateHead(w, lc) {
|
|
|
1238
1289
|
return { entityType: noun.entityType, term, relIdx: r };
|
|
1239
1290
|
}
|
|
1240
1291
|
|
|
1292
|
+
// An identity filter inside a boolean predicate: "…covered by X AND NAMED Y"
|
|
1293
|
+
// keeps the members of the branch's own set whose name is Y. Without it the
|
|
1294
|
+
// branch has no verb of its own, so it inherits the previous branch's verb and
|
|
1295
|
+
// reads the name as that verb's object — which either fails to parse or answers
|
|
1296
|
+
// about the wrong entity. Exact names only; the {node:"named"} leaf it builds
|
|
1297
|
+
// runs no fuzzy tier, and a name the index has no entity for refuses.
|
|
1298
|
+
// "called" also spells the passive of the `calls` verb, so it reads as a name
|
|
1299
|
+
// only where a copula has already declared a predicate adjective ("and IS
|
|
1300
|
+
// called X"); "named" carries no such second reading and needs no copula.
|
|
1301
|
+
function nameFilterAtom(entityType, bw, blc, afterCopula) {
|
|
1302
|
+
if (!blc.length) return null;
|
|
1303
|
+
if (blc[0] !== "named" && !(blc[0] === "called" && afterCopula)) return null;
|
|
1304
|
+
if (blc[1] === "by") return null;
|
|
1305
|
+
const term = bw.slice(1).join(" ").trim();
|
|
1306
|
+
if (!term) return null;
|
|
1307
|
+
return { node: "named", entityType: entityType || null, term };
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1241
1310
|
/** Build boolean/qualifier atoms for a predicate whose first (seed) atom the
|
|
1242
1311
|
* caller already determined externally. Every atom's op defaults to
|
|
1243
1312
|
* "intersection" except where an explicit and/or/but-not connective says
|
|
@@ -1252,6 +1321,8 @@ function buildPredicateAtoms(entityType, subjPrefix, predLc, predWords, nlp, dep
|
|
|
1252
1321
|
const op = b === 0 ? "intersection" : ops[b - 1];
|
|
1253
1322
|
const qc = dropLeadCopula(bw, blc);
|
|
1254
1323
|
if (qc.blc.length && qc.blc.every((x) => QUALIFIERS[x])) { atoms.push({ op, kind: "qual", filters: qc.blc }); continue; }
|
|
1324
|
+
const namedAtom = nameFilterAtom(entityType, qc.bw, qc.blc, qc.blc.length !== blc.length);
|
|
1325
|
+
if (namedAtom) { atoms.push({ op, kind: "set", ast: namedAtom }); continue; }
|
|
1255
1326
|
if (blc[0] === "of" || blc[0] === "in") {
|
|
1256
1327
|
const owned = membershipAtom(entityType, bw.slice(1), nlp, depth);
|
|
1257
1328
|
if (owned.node === "miss") return { miss: owned.reason };
|
|
@@ -1393,6 +1464,8 @@ function parseRelationalOrQualified(w, lc, nlp, depth) {
|
|
|
1393
1464
|
const op = b === 0 ? "seed" : ops[b - 1];
|
|
1394
1465
|
const qc = dropLeadCopula(bw, blc);
|
|
1395
1466
|
if (qc.blc.length && qc.blc.every((x) => QUALIFIERS[x])) { atoms.push({ op, kind: "qual", filters: qc.blc }); continue; }
|
|
1467
|
+
const namedAtom = nameFilterAtom(entityType, qc.bw, qc.blc, qc.blc.length !== blc.length);
|
|
1468
|
+
if (namedAtom) { atoms.push({ op, kind: "set", ast: namedAtom }); continue; }
|
|
1396
1469
|
if (blc[0] === "of" || blc[0] === "in") {
|
|
1397
1470
|
const owned = membershipAtom(entityType, bw.slice(1), nlp, depth + 1);
|
|
1398
1471
|
if (owned.node === "miss") return owned;
|
|
@@ -1687,6 +1760,24 @@ function moduleIdOf(graph, ind) {
|
|
|
1687
1760
|
return qualSets(graph).moduleOfSymbol.get(ind.id) || null;
|
|
1688
1761
|
}
|
|
1689
1762
|
|
|
1763
|
+
/** The module a coverage question is really about for this individual.
|
|
1764
|
+
*
|
|
1765
|
+
* `tests` edges run module to module, so a symbol is covered exactly when the
|
|
1766
|
+
* module it lives in is. Which module that is comes from the defines edge
|
|
1767
|
+
* first and the recorded source site second — a method belongs to its class,
|
|
1768
|
+
* not to the module's top-level scope, so it carries a site and no defines
|
|
1769
|
+
* edge of its own, and reading only the edge left every method outside the
|
|
1770
|
+
* tested set and therefore inside every complement.
|
|
1771
|
+
*
|
|
1772
|
+
* Null means the index places this individual in no module at all, which is a
|
|
1773
|
+
* different thing from "not tested" — see qualHolds. */
|
|
1774
|
+
function coveragePivotModuleId(graph, ind) {
|
|
1775
|
+
const direct = moduleIdOf(graph, ind);
|
|
1776
|
+
if (direct) return direct;
|
|
1777
|
+
const path = moduleLabelOf(ind);
|
|
1778
|
+
return path ? modulesByPath(graph).get(normPath(path))?.id || null : null;
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1690
1781
|
/** Meta fallback to real entities: after a SchemaClass/SchemaPredicate miss,
|
|
1691
1782
|
* an exact case-insensitive unique label match against real code-entity
|
|
1692
1783
|
* classes, so "what is a Record" answers even though Record isn't a graph
|
|
@@ -1790,7 +1881,7 @@ function qualHolds(graph, ind, spec) {
|
|
|
1790
1881
|
return ex.has(String(ind.label).toLowerCase()) || ex.has(String(ind.id).toLowerCase());
|
|
1791
1882
|
}
|
|
1792
1883
|
case "tested": {
|
|
1793
|
-
const mid =
|
|
1884
|
+
const mid = coveragePivotModuleId(graph, ind);
|
|
1794
1885
|
const sets = qualSets(graph);
|
|
1795
1886
|
// A TEST module is neither tested nor untested. Coverage is a claim about
|
|
1796
1887
|
// SOURCE modules, so asking whether a test covers itself is a category
|
|
@@ -1800,10 +1891,13 @@ function qualHolds(graph, ind, spec) {
|
|
|
1800
1891
|
// path shape (a test-named module that happens to test nothing).
|
|
1801
1892
|
const mind = mid ? graph.byId?.get?.(mid) : null;
|
|
1802
1893
|
if (mid && (sets.testModules.has(mid) || (mind && isTestPath(String(mind.label).toLowerCase())))) return false;
|
|
1803
|
-
//
|
|
1804
|
-
//
|
|
1805
|
-
//
|
|
1806
|
-
|
|
1894
|
+
// Nothing this index can place in a module is outside the coverage
|
|
1895
|
+
// question altogether, at BOTH polarities — a Commit is neither tested
|
|
1896
|
+
// nor untested. Reading a missing pivot as "not tested" put every such
|
|
1897
|
+
// individual in the complement, which is how the negation's universe
|
|
1898
|
+
// grew past the set the question was about.
|
|
1899
|
+
if (!mid) return false;
|
|
1900
|
+
return sets.testedModules.has(mid) === spec.value;
|
|
1807
1901
|
}
|
|
1808
1902
|
default: return false;
|
|
1809
1903
|
}
|
|
@@ -1955,9 +2049,48 @@ function packageIndividuals(graph) {
|
|
|
1955
2049
|
.map(([dir]) => ({ id: `pkg:${dir}`, label: dir, class: "Package" }));
|
|
1956
2050
|
}
|
|
1957
2051
|
|
|
2052
|
+
/** Individuals whose own name IS `term`: an exact label or id, or — for a module
|
|
2053
|
+
* — the same path once normalized. No substring, prose or fuzzy tier: a name
|
|
2054
|
+
* filter that near-matched would hand back a confident answer about a
|
|
2055
|
+
* neighbouring entity, which is the shape the miss-over-guess contract forbids.
|
|
2056
|
+
* `entityType` null means any kind. */
|
|
2057
|
+
function individualsNamed(graph, term, entityType) {
|
|
2058
|
+
const t = String(term || "").trim().toLowerCase();
|
|
2059
|
+
if (!t) return [];
|
|
2060
|
+
const asPath = normPath(t);
|
|
2061
|
+
return graph.individuals.filter((ind) => {
|
|
2062
|
+
if (entityType && ind.class !== entityType) return false;
|
|
2063
|
+
const label = String(ind.label || "").toLowerCase();
|
|
2064
|
+
if (label === t || String(ind.id || "").toLowerCase() === t) return true;
|
|
2065
|
+
return ind.class === "Module" && normPath(label) === asPath;
|
|
2066
|
+
});
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
/** The first `named <X>` filter anywhere in a compiled AST whose name the graph
|
|
2070
|
+
* holds no entity for, with whatever else does carry that name. A name the
|
|
2071
|
+
* index cannot place is a refusal, not an empty intersection: the surrounding
|
|
2072
|
+
* question would otherwise answer "no classes" about a module that does not
|
|
2073
|
+
* exist. Walks the whole AST, so the filter refuses at any nesting depth.
|
|
2074
|
+
* Deterministic — individuals are scanned in graph order. */
|
|
2075
|
+
function unknownNameFilter(graph, node) {
|
|
2076
|
+
if (!node || typeof node !== "object") return null;
|
|
2077
|
+
if (Array.isArray(node)) {
|
|
2078
|
+
for (const child of node) { const hit = unknownNameFilter(graph, child); if (hit) return hit; }
|
|
2079
|
+
return null;
|
|
2080
|
+
}
|
|
2081
|
+
if (node.node === "named") {
|
|
2082
|
+
if (individualsNamed(graph, node.term, node.entityType).length) return null;
|
|
2083
|
+
return { term: node.term, entityType: node.entityType || null, elsewhere: individualsNamed(graph, node.term, null)[0] || null };
|
|
2084
|
+
}
|
|
2085
|
+
for (const value of Object.values(node)) { const hit = unknownNameFilter(graph, value); if (hit) return hit; }
|
|
2086
|
+
return null;
|
|
2087
|
+
}
|
|
2088
|
+
|
|
1958
2089
|
/** Compile a set-producing AST into an array of individuals. */
|
|
1959
2090
|
function evalSet(graph, ast, opts) {
|
|
1960
2091
|
switch (ast.node) {
|
|
2092
|
+
// Identity filter: the entity a boolean branch's "named <X>" picks out.
|
|
2093
|
+
case "named": return individualsNamed(graph, ast.term, ast.entityType);
|
|
1961
2094
|
case "clause": return traverse(graph, ast.clause, opts).matches || [];
|
|
1962
2095
|
case "allOfClass":
|
|
1963
2096
|
if (ast.entityType === "Package") return packageIndividuals(graph);
|
|
@@ -2079,6 +2212,17 @@ function evalSet(graph, ast, opts) {
|
|
|
2079
2212
|
* for them: "not exported" really is everything that is not exported. */
|
|
2080
2213
|
const oppositeQualifierSpec = (spec) => (spec && typeof spec.value === "boolean" ? { ...spec, value: !spec.value } : null);
|
|
2081
2214
|
|
|
2215
|
+
/** The adjective for a qualifier's opposite, where the vocabulary carries one
|
|
2216
|
+
* ("untested" -> "tested"). A receipt that has to state the negation reads
|
|
2217
|
+
* "but it is tested" from this, instead of stacking a bare "not" onto an
|
|
2218
|
+
* already-negative adjective. Null where the qualifier has no opposite word. */
|
|
2219
|
+
function oppositeQualifierWord(word) {
|
|
2220
|
+
const spec = QUALIFIERS[word];
|
|
2221
|
+
const opposite = oppositeQualifierSpec(spec);
|
|
2222
|
+
if (!opposite) return null;
|
|
2223
|
+
return Object.keys(QUALIFIERS).find((k) => QUALIFIERS[k].via === opposite.via && QUALIFIERS[k].value === opposite.value) || null;
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2082
2226
|
function evalBoolean(graph, ast, opts) {
|
|
2083
2227
|
let acc = [];
|
|
2084
2228
|
for (const atom of ast.atoms) {
|
|
@@ -2460,6 +2604,8 @@ function commitTouchObjectIds(graph, base, opts) {
|
|
|
2460
2604
|
* simple path — {matches, …} plus compositeKind/compositeMiss flags render() reads. */
|
|
2461
2605
|
function evalComposite(graph, ast, opts = {}) {
|
|
2462
2606
|
if (ast.node === "miss") return { compositeMiss: true, reason: ast.reason || null, matches: [] };
|
|
2607
|
+
const unknownName = unknownNameFilter(graph, ast);
|
|
2608
|
+
if (unknownName) return { compositeMiss: true, unknownName, matches: [] };
|
|
2463
2609
|
if (ast.node === "exists") return evalExists(graph, ast);
|
|
2464
2610
|
if (ast.node === "qualCheck") return evalQualCheck(graph, ast, opts);
|
|
2465
2611
|
if (ast.node === "universal") return evalUniversal(graph, ast, opts);
|
|
@@ -2528,14 +2674,32 @@ function evalComposite(graph, ast, opts = {}) {
|
|
|
2528
2674
|
function qualifierEmptiedSet(graph, ast, opts) {
|
|
2529
2675
|
if (ast.node !== "boolean" || ast.atoms?.length !== 2) return null;
|
|
2530
2676
|
const [seed, filter] = ast.atoms;
|
|
2531
|
-
if (seed.op !== "seed" || filter.
|
|
2677
|
+
if (seed.op !== "seed" || filter.kind !== "qual") return null;
|
|
2678
|
+
const excluded = filter.op === "difference";
|
|
2679
|
+
if (!excluded && filter.op !== "intersection") return null;
|
|
2532
2680
|
const clause = seed.ast?.node === "clause" ? seed.ast.clause : null;
|
|
2533
2681
|
if (!clause?.kind || !clause.object || clause.modifier === "transitive") return null;
|
|
2534
2682
|
const held = evalSet(graph, seed.ast, opts);
|
|
2535
2683
|
if (!held.length) return null;
|
|
2684
|
+
const allHold = (words) => held.every((ind) => words.every((f) => qualHolds(graph, ind, QUALIFIERS[f])));
|
|
2685
|
+
// A difference reports what the exclusion took away, so it may only name the
|
|
2686
|
+
// qualifier where the clause's members really do satisfy it. A member the
|
|
2687
|
+
// qualifier does not apply to at either polarity leaves by the same door, and
|
|
2688
|
+
// saying it was tested would be a guess about a coverage fact nothing records.
|
|
2689
|
+
if (excluded && !allHold(filter.filters)) return null;
|
|
2690
|
+
// An intersection's members failed the filter, which is all that is proven,
|
|
2691
|
+
// so the receipt negates it. A filter that is already a negative adjective
|
|
2692
|
+
// would stack into "but it is not untested", so where the vocabulary carries
|
|
2693
|
+
// the positive word AND every member satisfies it, the receipt says that
|
|
2694
|
+
// instead.
|
|
2695
|
+
const opposites = excluded || !filter.filters.every((f) => QUALIFIERS[f].value === false)
|
|
2696
|
+
? [] : filter.filters.map(oppositeQualifierWord);
|
|
2697
|
+
const statable = opposites.length > 0 && opposites.every(Boolean) && allHold(opposites);
|
|
2536
2698
|
return {
|
|
2537
2699
|
count: held.length, entityType: clause.entityType || ast.entityType || null,
|
|
2538
|
-
kind: clause.kind, object: clause.object,
|
|
2700
|
+
kind: clause.kind, object: clause.object,
|
|
2701
|
+
filters: statable ? opposites : filter.filters,
|
|
2702
|
+
negated: !excluded && !statable,
|
|
2539
2703
|
};
|
|
2540
2704
|
}
|
|
2541
2705
|
|
|
@@ -2571,14 +2735,54 @@ function filtersOnCoverage(node) {
|
|
|
2571
2735
|
return Object.values(node).some(filtersOnCoverage);
|
|
2572
2736
|
}
|
|
2573
2737
|
|
|
2574
|
-
/** An empty coverage-filtered set over symbols
|
|
2575
|
-
*
|
|
2576
|
-
*
|
|
2738
|
+
/** An empty coverage-filtered set over symbols has a grain behind it worth
|
|
2739
|
+
* saying: `tests` edges are recorded module to module, so a symbol counts as
|
|
2740
|
+
* covered exactly when the module it lives in does. Say that instead of the
|
|
2577
2741
|
* generic rephrase nudge, which would send the reader somewhere unrelated. */
|
|
2578
2742
|
function coverageGrainNote(parsed, entityType) {
|
|
2579
2743
|
if (!["Function", "Method"].includes(entityType)) return null;
|
|
2580
2744
|
if (!filtersOnCoverage(parsed)) return null;
|
|
2581
|
-
|
|
2745
|
+
const noun = nounFor(entityType, 1);
|
|
2746
|
+
return `This index records tests edges module to module, so a ${noun} counts as covered exactly when the module it lives in is tested — ask about that module to see the coverage itself.`;
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
/** The two shapes that filter a whole kind by a qualifier and nothing else:
|
|
2750
|
+
* the plain "which functions are exported", and the boolean the negative
|
|
2751
|
+
* polarity compiles to. Both carry the same two facts — which kind, which
|
|
2752
|
+
* adjective — and the third says which way the question ran. */
|
|
2753
|
+
function wholeKindQualifierFilter(parsed) {
|
|
2754
|
+
if (parsed?.node === "qualifier" && parsed.inner?.node === "allOfClass" && parsed.filters?.length) {
|
|
2755
|
+
return { entityType: parsed.inner.entityType || parsed.entityType, filters: parsed.filters, negated: false };
|
|
2756
|
+
}
|
|
2757
|
+
if (parsed?.node !== "boolean" || parsed.atoms?.length !== 2) return null;
|
|
2758
|
+
const [seed, filter] = parsed.atoms;
|
|
2759
|
+
if (seed.op !== "seed" || seed.ast?.node !== "allOfClass") return null;
|
|
2760
|
+
if (filter.kind !== "qual" || !filter.filters?.length) return null;
|
|
2761
|
+
if (filter.op !== "difference" && filter.op !== "intersection") return null;
|
|
2762
|
+
return {
|
|
2763
|
+
entityType: seed.ast.entityType || parsed.entityType,
|
|
2764
|
+
filters: filter.filters,
|
|
2765
|
+
negated: filter.op === "difference",
|
|
2766
|
+
};
|
|
2767
|
+
}
|
|
2768
|
+
|
|
2769
|
+
/** The branch to point at when a qualifier emptied a set drawn from a whole
|
|
2770
|
+
* kind. "which functions are not exported" takes every function the index
|
|
2771
|
+
* holds and removes the exported ones, so the qualifier is the only thing
|
|
2772
|
+
* that can have emptied it, and the exported functions are the branch worth
|
|
2773
|
+
* offering. The polarity flips to the side the question did not ask about,
|
|
2774
|
+
* and both phrasings are ones the parser accepts, so the nudge can never name
|
|
2775
|
+
* a shape that misses.
|
|
2776
|
+
*
|
|
2777
|
+
* Only an unrestricted set qualifies. Once a clause narrows it first, that
|
|
2778
|
+
* clause may be what emptied it, and naming the qualifier's branch would
|
|
2779
|
+
* point past the real gap. */
|
|
2780
|
+
function qualifierBranchNote(parsed) {
|
|
2781
|
+
const filtered = wholeKindQualifierFilter(parsed);
|
|
2782
|
+
if (!filtered) return null;
|
|
2783
|
+
const kindPlural = nounFor(filtered.entityType || "Module", 2);
|
|
2784
|
+
const polarity = filtered.negated ? "" : "not ";
|
|
2785
|
+
return `Try "which ${kindPlural} are ${polarity}${listJoin(filtered.filters)}" for that branch on its own.`;
|
|
2582
2786
|
}
|
|
2583
2787
|
|
|
2584
2788
|
function renderComposite(parsed, result, graph) {
|
|
@@ -2586,6 +2790,14 @@ function renderComposite(parsed, result, graph) {
|
|
|
2586
2790
|
if (result.reason === "no-prev") {
|
|
2587
2791
|
return { content: `"those"/"them" needs a previous answer to refer to — ask a listing question first, then follow up.`, miss: true, ambiguous: false };
|
|
2588
2792
|
}
|
|
2793
|
+
if (result.unknownName) {
|
|
2794
|
+
const { term, entityType, elsewhere } = result.unknownName;
|
|
2795
|
+
const wanted = entityType ? nounFor(entityType, 1) : "entity";
|
|
2796
|
+
const clash = elsewhere
|
|
2797
|
+
? ` "${term}" names ${articleFor(nounFor(elsewhere.class, 1))} ${nounFor(elsewhere.class, 1)} here, not ${articleFor(wanted)} ${wanted}.`
|
|
2798
|
+
: "";
|
|
2799
|
+
return { content: `no ${wanted} named "${term}" in this index.${clash}`, miss: true, ambiguous: false };
|
|
2800
|
+
}
|
|
2589
2801
|
return { content: `couldn't compile this compositional question${result.reason ? ` (${result.reason})` : ""}. ${compositionalHint()}.`, miss: true, ambiguous: false };
|
|
2590
2802
|
}
|
|
2591
2803
|
if (result.compositeKind === "exists") {
|
|
@@ -2815,24 +3027,27 @@ function renderComposite(parsed, result, graph) {
|
|
|
2815
3027
|
}
|
|
2816
3028
|
// set-producing
|
|
2817
3029
|
if (!result.matches.length) {
|
|
2818
|
-
// A grain the graph records nothing at cannot be reported as a filter that
|
|
2819
|
-
// rejected anything — that note keeps precedence over the narrowing below.
|
|
2820
|
-
const grainNote = coverageGrainNote(parsed, result.entityType);
|
|
2821
3030
|
// The qualifier, not the clause, is what emptied this set — so name the
|
|
2822
3031
|
// entities the clause did hold and point at that branch on its own,
|
|
2823
3032
|
// instead of a blanket "nothing matches" beside an unrelated recovery.
|
|
2824
|
-
const narrowed =
|
|
3033
|
+
const narrowed = result.narrowedFrom;
|
|
2825
3034
|
if (narrowed) {
|
|
2826
3035
|
const kindPlural = nounFor(narrowed.entityType || "Module", 2);
|
|
3036
|
+
const filters = listJoin(narrowed.filters);
|
|
3037
|
+
const clause = narrowed.negated
|
|
3038
|
+
? { one: `but it is not ${filters}`, many: `but none of them is ${filters}` }
|
|
3039
|
+
: { one: `but it is ${filters}`, many: `but all of them are ${filters}` };
|
|
2827
3040
|
const held = narrowed.count === 1
|
|
2828
|
-
? `1 ${nounFor(narrowed.entityType || "Module", 1)} ${
|
|
2829
|
-
: `${narrowed.count} ${kindPlural} ${bareVerbFor(narrowed.kind)} ${narrowed.object},
|
|
3041
|
+
? `1 ${nounFor(narrowed.entityType || "Module", 1)} ${thirdPersonVerbFor(narrowed.kind)} ${narrowed.object}, ${clause.one}`
|
|
3042
|
+
: `${narrowed.count} ${kindPlural} ${bareVerbFor(narrowed.kind)} ${narrowed.object}, ${clause.many}`;
|
|
2830
3043
|
return {
|
|
2831
3044
|
content: `${held}. Try "which ${kindPlural} ${bareVerbFor(narrowed.kind)} ${narrowed.object}" for that branch on its own.`,
|
|
2832
3045
|
miss: true, ambiguous: false, matches: [],
|
|
2833
3046
|
};
|
|
2834
3047
|
}
|
|
2835
|
-
const hint =
|
|
3048
|
+
const hint = coverageGrainNote(parsed, result.entityType)
|
|
3049
|
+
|| qualifierBranchNote(parsed)
|
|
3050
|
+
|| touchesRephraseHint(graph);
|
|
2836
3051
|
return { content: `nothing in the index matches that${result.entityType ? ` (${nounFor(result.entityType, 2)})` : ""}. ${hint}`, miss: true, ambiguous: false, matches: [] };
|
|
2837
3052
|
}
|
|
2838
3053
|
return { content: `${compositeList(result.matches)}.`, miss: false, ambiguous: false, matches: result.matches };
|
|
@@ -4002,6 +4217,15 @@ function bareVerbFor(kind) {
|
|
|
4002
4217
|
return RELATIONS[kind]?.bare || kind;
|
|
4003
4218
|
}
|
|
4004
4219
|
|
|
4220
|
+
/** The 3rd-person singular of a relation's bare form, keeping any preposition
|
|
4221
|
+
* the phrase carries: "inherit from" -> "inherits from". A one-member set
|
|
4222
|
+
* otherwise read "1 class inherits Base" beside the plural's "classes inherit
|
|
4223
|
+
* from Base" in the very next sentence. */
|
|
4224
|
+
function thirdPersonVerbFor(kind) {
|
|
4225
|
+
const [head, ...rest] = String(bareVerbFor(kind)).split(" ");
|
|
4226
|
+
return [`${head}s`, ...rest].join(" ");
|
|
4227
|
+
}
|
|
4228
|
+
|
|
4005
4229
|
/** The passive participle of a relation ("uses" -> "used", "imports" ->
|
|
4006
4230
|
* "imported"), for the confirming "X is <participle> by Y" frame. The bare
|
|
4007
4231
|
* forms in this vocabulary are all regular, so a single +d/+ed rule covers
|
|
@@ -150,7 +150,13 @@ function parseInline(text) {
|
|
|
150
150
|
// CHOICE_MAX_OPTIONS (an eight-option "A) ... H) ...") is still recognized
|
|
151
151
|
// as enumerated and declines on the option count, rather than the marker
|
|
152
152
|
// regex itself silently stopping short and truncating the list.
|
|
153
|
-
|
|
153
|
+
//
|
|
154
|
+
// A marker stands alone: whitespace or the start of the text before it, and
|
|
155
|
+
// whitespace or the end of the text after it. Without both edges the letter
|
|
156
|
+
// and dot inside a dotted path ("app/lib/a.mjs … app/lib/b.mjs") read as an
|
|
157
|
+
// A, B label run, and an ordinary set question gets answered as a closed
|
|
158
|
+
// multiple choice over the fragments either side of the slash.
|
|
159
|
+
const LABEL_MARKER_RE = /(?<=^|\s)\(?([A-Za-z])[.):](?=\s|$)/g;
|
|
154
160
|
|
|
155
161
|
/** The longest run of label markers found in strict A, B, C, ... sequence.
|
|
156
162
|
* A marker that does not match the next expected letter is skipped rather
|
|
@@ -162,7 +168,7 @@ function findAcceptedLabelSequence(text) {
|
|
|
162
168
|
LABEL_MARKER_RE.lastIndex = 0;
|
|
163
169
|
let m;
|
|
164
170
|
while ((m = LABEL_MARKER_RE.exec(text))) {
|
|
165
|
-
const letter =
|
|
171
|
+
const letter = m[1].toUpperCase();
|
|
166
172
|
if (letter === String.fromCharCode(65 + expected)) {
|
|
167
173
|
accepted.push({ letter, start: m.index, end: LABEL_MARKER_RE.lastIndex });
|
|
168
174
|
expected += 1;
|