@polycode-projects/the-mechanical-code-talker 5.0.37 → 5.0.39

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/README.md CHANGED
@@ -1496,7 +1496,7 @@ The `<where-marker>` slot takes any of *defined*, *declared*, *located*, *implem
1496
1496
  - **uses** — *uses*, *use*, *makes use of*, *make use of*, and more
1497
1497
  - **calls** — *invokes*, *invoke*, *calls*, *call*, and more
1498
1498
  - **defines** — *defines*, *define*, *declares*, *declare*, and more
1499
- - **contains** — *contains*, *contain*, *lives in*, *live in*, and more
1499
+ - **contains** — *contains*, *contain*, *containing*, *belongs to*, and more
1500
1500
  - **tests** — *tests*, *test*, *covers*, *cover*, and more
1501
1501
  - **inherits** — *inherits from*, *inherit from*, *inherits*, *inherit*, and more
1502
1502
  - **touches** — *touched*, *touches*, *changed*, *change*, and more
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polycode-projects/the-mechanical-code-talker",
3
- "version": "5.0.37",
3
+ "version": "5.0.39",
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.",
@@ -28,6 +28,29 @@ const INHERITS_REVERSE_VERB_LIST = [
28
28
  "superclass", "superclasses",
29
29
  ];
30
30
 
31
+ // The `contains` phrasings a MEMBER uses about its own container: "Widget.render
32
+ // belongs to Widget" states the same stored edge as "Widget contains
33
+ // Widget.render", read from the other end. They sit in RELATIONS.contains.verbs
34
+ // (below) so VERB_TO_KIND resolves them to the right relation, and in
35
+ // CONVERSE_VERBS (below that) so the strategies that build a parse flip the
36
+ // direction instead of traversing the mirror of the question asked.
37
+ const CONTAINS_CONVERSE_VERB_LIST = [
38
+ "belongs to", "belong to",
39
+ "is part of", "are part of",
40
+ "is defined in", "are defined in",
41
+ ];
42
+
43
+ // The PLACEMENT phrasings of the same relation ("live in", "sit inside") state
44
+ // where their subject is, and a taught locative fact stores exactly that
45
+ // subject ("ann lives in paris" -> ann mgx:life-in paris, ask-world-relation's
46
+ // own lane). So these read forward, and a converse entry would invert every
47
+ // taught placement answer. "define" is no placement verb, which is why
48
+ // "is defined in" sits in the converse list above instead.
49
+ const CONTAINS_PLACEMENT_VERB_LIST = [
50
+ "lives in", "live in",
51
+ "sits in", "sit in", "sits inside", "sit inside",
52
+ ];
53
+
31
54
  export const RELATIONS = {
32
55
  imports: {
33
56
  bare: "import",
@@ -87,10 +110,12 @@ export const RELATIONS = {
87
110
  bare: "contain",
88
111
  comment: "Class -> Method/Attribute: subject's membership includes object.",
89
112
  verbs: [
90
- "contains", "contain", "lives in", "live in", "is defined in", "are defined in",
91
- "is part of", "are part of", "sits in", "sit in", "sits inside", "sit inside",
113
+ "contains", "contain",
92
114
  // gerund (g-drop normalization)
93
115
  "containing",
116
+ // the member's-side phrasings, flipped at parse time (CONVERSE_VERBS)
117
+ ...CONTAINS_CONVERSE_VERB_LIST,
118
+ ...CONTAINS_PLACEMENT_VERB_LIST,
94
119
  ],
95
120
  },
96
121
  tests: {
@@ -292,6 +317,31 @@ export const INHERITS_REVERSE_VERBS = Object.freeze([
292
317
  "is the superclass of", "are the superclass of", "is the parent class of",
293
318
  ]);
294
319
 
320
+ /** Every verb phrase that names its relation from the OBJECT's side. The stored
321
+ * edge runs one way; these phrases state it backwards, so a parse built from
322
+ * the phrase alone answers the mirror of the question asked. A strategy that
323
+ * has just built a parse hands it to `readConverse` below. Closed table: a
324
+ * phrase is here only because it is already in RELATIONS' own verb lists. */
325
+ export const CONVERSE_VERBS = Object.freeze(new Set([
326
+ ...INHERITS_REVERSE_VERBS,
327
+ ...CONTAINS_CONVERSE_VERB_LIST,
328
+ ]));
329
+
330
+ /** Turn a parse built from a converse verb phrase into the reading the phrase
331
+ * actually has. The two named roles swap ("does X belong to Y" asks whether Y
332
+ * contains X); a set question changes direction and keeps its asked kind
333
+ * filter ("which methods are part of Widget" lists what Widget contains, not
334
+ * the methods containing Widget). Any other shape, and any forward-reading
335
+ * verb, comes back untouched — a verb with no converse entry keeps whatever
336
+ * reading it already had, including an honest miss. */
337
+ export function readConverse(parsed, verbPhrase) {
338
+ if (!parsed || !CONVERSE_VERBS.has(verbPhrase)) return parsed;
339
+ if (parsed.shape === "ask") return { ...parsed, subject: parsed.object, object: parsed.subject };
340
+ if (parsed.shape === "reverse") return { ...parsed, shape: "forward" };
341
+ if (parsed.shape === "forward") return { ...parsed, shape: "reverse" };
342
+ return parsed;
343
+ }
344
+
295
345
  // ---- where/when/mentions markers: these questions carry no relation verb,
296
346
  // so ask.mjs routes them by marker word instead of VERB_TO_KIND. ----
297
347
 
@@ -516,6 +516,8 @@ function parseSetPhrase(text, nlp, depth) {
516
516
  if (negated) return negated;
517
517
  const w = splitWords(text);
518
518
  const lc = w.map((x) => x.toLowerCase());
519
+ const window = parseCommitFilter(w, lc);
520
+ if (window) return window;
519
521
  const definitionSite = parseDefinitionSiteMembership(w, lc, nlp, depth);
520
522
  if (definitionSite) return definitionSite;
521
523
  const nested = parseNested(w, lc, nlp, depth);
@@ -695,16 +697,33 @@ function parseTemporal(w, lc, nlp, depth = 0) {
695
697
  // when-shape above (which dates one named entity's touch history). "in"/
696
698
  // "during" are deliberately excluded — "what changed in <commit>" means that
697
699
  // commit's own touch-set instead.
700
+ //
701
+ // An entity kind may head the question ("which MODULES changed on 2026-06-28"),
702
+ // which asks the same window and then reads what those commits touched at that
703
+ // grain. Without it the sentence fell through to the flat shapes, which read the
704
+ // date as an entity name and offered a confident ambiguity list about the index's
705
+ // modules — the miss-over-guess contract's worst shape, over a window the graph
706
+ // can bound exactly.
698
707
  const COMMIT_FILTER_OPS = new Set(["since", "before", "after", "on"]);
708
+ const COMMIT_FILTER_LEADS = new Set(["what", "which"]);
699
709
  function parseCommitFilter(w, lc) {
700
- if (lc[0] !== "what" || lc[1] !== "changed") return null;
701
- let i = 2;
710
+ if (!COMMIT_FILTER_LEADS.has(lc[0])) return null;
711
+ let i = 1;
712
+ let entityType = null;
713
+ if (lc[i] !== "changed") {
714
+ const noun = entityNoun(lc[i]);
715
+ if (!noun || noun.placeholder) return null;
716
+ entityType = noun.entityType;
717
+ i += 1;
718
+ }
719
+ if (lc[i] !== "changed") return null;
720
+ i += 1;
702
721
  if (lc[i] === "ever") i += 1;
703
722
  if (!COMMIT_FILTER_OPS.has(lc[i])) return null;
704
723
  const op = lc[i];
705
724
  const pivotRaw = w.slice(i + 1).join(" ").trim();
706
- if (!pivotRaw) return { node: "miss", reason: `"what changed ${op}" needs a date or commit afterward` };
707
- return { node: "commitFilter", op, pivotRaw };
725
+ if (!pivotRaw) return { node: "miss", reason: `"changed ${op}" needs a date or commit afterward` };
726
+ return { node: "commitFilter", op, pivotRaw, entityType };
708
727
  }
709
728
 
710
729
  // "<kind> in|of <owner>" where the OWNER is itself a relative clause ("functions
@@ -1480,7 +1499,14 @@ function siteDefiningModules(graph, objectIds) {
1480
1499
  return uniqueById(out);
1481
1500
  }
1482
1501
 
1483
- const definesHop = (kind, entityType) => entityType === "Module" && kindsFor(kind).includes("defines");
1502
+ // Both stored membership relations answer "which module is this in": `defines`
1503
+ // runs Module -> symbol, `contains` runs Class -> member, and a member's own
1504
+ // recorded source site stands in for either edge when the index never wrote one.
1505
+ // So a converse-verb question at module grain ("which module does Button live
1506
+ // in") reaches the same site fallback the defines hop already uses.
1507
+ const MODULE_MEMBERSHIP_KINDS = new Set(["defines", "contains"]);
1508
+ const moduleMembershipHop = (kind, entityType) => entityType === "Module"
1509
+ && kindsFor(kind).some((k) => MODULE_MEMBERSHIP_KINDS.has(k));
1484
1510
 
1485
1511
  const askSiteMembersCache = new WeakMap();
1486
1512
 
@@ -1531,7 +1557,7 @@ function reverseOverSet(graph, kind, entityType, objectIds) {
1531
1557
  const subjects = uniqueById(edges.map((e) => graph.byId.get(e.subject)).filter(Boolean));
1532
1558
  if (!entityType || entityType === "Change") return subjects;
1533
1559
  const direct = subjects.filter((s) => s.class === entityType);
1534
- if (definesHop(kind, entityType)) {
1560
+ if (moduleMembershipHop(kind, entityType)) {
1535
1561
  // Per-object, not per-set: "the module that defines {Widget, Button}" is the
1536
1562
  // union of each symbol's defining module, so a set where one member carries
1537
1563
  // the edge and another only a site must answer with both.
@@ -1548,22 +1574,55 @@ function reverseOverSet(graph, kind, entityType, objectIds) {
1548
1574
 
1549
1575
  const GIT_PROV_REF_RE = /^git:(.+)$/i;
1550
1576
 
1551
- /** How many distinct commits are attested to have touched a SET of entities —
1552
- * the same "touched by N commit(s)" convention renderDescribe's attestation
1553
- * line already uses (codegraph.mjs's turnRefCount), not the narrower "touches
1554
- * edge count" reverseOverSet(kind="touches") returns. A commit can be recorded
1555
- * in an entity's own `derived_from` provenance with no full Commit individual
1556
- * of its own (the ingester's touches-edge and provenance-ref writes can drift,
1557
- * e.g. a truncated commit walk) — reverseOverSet alone then undercounts, or
1558
- * misses entirely when NO touches edge survived. Deduped by short sha so a
1559
- * provenance ref naming a commit that DOES have a touches-edge individual
1560
- * isn't double-counted. */
1577
+ /** The shas a `git:<sha>` provenance ref is still allowed to attest a touch for.
1578
+ *
1579
+ * A ref in an entity's `derived_from` names a commit. It does not say the commit
1580
+ * touched that entity, and it carries no date, so it can only be counted where
1581
+ * the graph has nothing better. Three cases, and the window is what separates
1582
+ * them:
1583
+ *
1584
+ * - the graph holds the Commit AND records what it touched — that recorded touch
1585
+ * set is the index's own statement of the commit's reach, so it decides on its
1586
+ * own and the ref adds nothing;
1587
+ * - the graph holds the Commit but records no touch edge for it anywhere (a
1588
+ * truncated commit walk drops them) — the index is silent on its reach, so the
1589
+ * ref is the only attestation left and it counts;
1590
+ * - the graph holds no Commit for the sha — the index can neither name nor date
1591
+ * it, so it sits outside the history this graph can count over and stays
1592
+ * uncounted rather than being guessed into the total.
1593
+ *
1594
+ * Returns the labels from case two, lowercased and sorted, so the count is a
1595
+ * pure function of the fact set whatever order the individuals arrived in. */
1596
+ function provenanceAttestableShas(graph) {
1597
+ const withTouchSet = new Set();
1598
+ for (const kind of ["touches", "touchesSymbol"]) {
1599
+ for (const e of edgesOfKind(graph, kind)) {
1600
+ const commit = graph.byId.get(e.subject);
1601
+ if (commit?.class === "Commit") withTouchSet.add(String(commit.label || "").toLowerCase());
1602
+ }
1603
+ }
1604
+ return graph.individuals
1605
+ .filter((i) => i.class === "Commit")
1606
+ .map((i) => String(i.label || "").toLowerCase())
1607
+ .filter((label) => label && !withTouchSet.has(label))
1608
+ .sort();
1609
+ }
1610
+
1611
+ /** How many distinct commits inside this index's own recorded history are
1612
+ * attested to have touched a SET of entities. The touch edges reaching the set
1613
+ * are the spine; a `git:<sha>` provenance ref adds a commit only under
1614
+ * provenanceAttestableShas's rule above, so a count can never name a larger
1615
+ * number than "which commits touched X" can list. */
1561
1616
  function commitTouchCount(graph, objectIds) {
1562
1617
  const shas = new Set(reverseOverSet(graph, "touches", "Commit", objectIds).map((c) => String(c.label || "").toLowerCase()));
1618
+ const attestable = provenanceAttestableShas(graph);
1563
1619
  for (const id of objectIds) {
1564
1620
  for (const ref of graph.byId.get(id)?.derived_from || []) {
1565
1621
  const m = GIT_PROV_REF_RE.exec(String(ref || ""));
1566
- if (m) shas.add(m[1].toLowerCase());
1622
+ if (!m) continue;
1623
+ const sha = m[1].toLowerCase();
1624
+ const known = attestable.find((label) => label.startsWith(sha) || sha.startsWith(label));
1625
+ if (known) shas.add(known);
1567
1626
  }
1568
1627
  }
1569
1628
  return shas.size;
@@ -1925,6 +1984,10 @@ function evalSet(graph, ast, opts) {
1925
1984
  const positive = new Set(forwardOverSet(graph, ast.kind, new Set([r.match.id])).map((x) => x.id));
1926
1985
  return graph.individuals.filter((i) => i.class === universeType && !positive.has(i.id));
1927
1986
  }
1987
+ // A date-or-commit window as a set atom, so "how many modules changed on
1988
+ // <date>" composes through the ordinary count path. An unresolved pivot is
1989
+ // caught by the count branch before it can read as a bare zero.
1990
+ case "commitFilter": return evalCommitFilter(graph, ast).matches;
1928
1991
  case "reverseSet": {
1929
1992
  const ids = new Set(evalSet(graph, ast.inner, opts).map((i) => i.id));
1930
1993
  return reverseOverSet(graph, ast.kind, ast.entityType, ids);
@@ -2141,7 +2204,7 @@ const COMMIT_FILTER_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
2141
2204
  * here, beside the fully typed result, before render() flattens it all to a
2142
2205
  * sentence; the session layer is what registers them into its record. */
2143
2206
  function evalCommitFilter(graph, ast) {
2144
- const { op, pivotRaw } = ast;
2207
+ const { op, pivotRaw, entityType = null } = ast;
2145
2208
  const dateOf = (c) => String((c.attributes || []).find((a) => a.key === "date")?.value || "").slice(0, 10);
2146
2209
  let pivotDate = null;
2147
2210
  let pivotId = null;
@@ -2156,8 +2219,11 @@ function evalCommitFilter(graph, ast) {
2156
2219
  pivotDate = dateOf(match);
2157
2220
  }
2158
2221
  }
2159
- if (!pivotDate) return { compositeKind: "commitFilter", op, pivotRaw, pivotResolved: false, matches: [] };
2160
- const matches = graph.individuals
2222
+ if (!pivotDate) return { compositeKind: "commitFilter", op, pivotRaw, entityType, pivotResolved: false, matches: [] };
2223
+ // Two dates on the same day tie under a lexical compare, so the id breaks the
2224
+ // tie: the window's answer must not depend on which order the individuals
2225
+ // arrived in.
2226
+ const inWindow = graph.individuals
2161
2227
  .filter((i) => i.class === "Commit" && i.id !== pivotId && dateOf(i))
2162
2228
  .filter((c) => {
2163
2229
  const d = dateOf(c);
@@ -2166,12 +2232,19 @@ function evalCommitFilter(graph, ast) {
2166
2232
  if (op === "after") return d > pivotDate;
2167
2233
  return d === pivotDate; // "on"
2168
2234
  })
2169
- .sort((a, b) => dateOf(b).localeCompare(dateOf(a)));
2235
+ .sort((a, b) => dateOf(b).localeCompare(dateOf(a)) || String(a.id).localeCompare(String(b.id)));
2236
+ // A kind-headed window reads what the qualifying commits touched at that
2237
+ // grain; the bare shape answers with the commits themselves.
2238
+ const touched = entityType && entityType !== "Commit" && entityType !== "Change"
2239
+ ? uniqueById(inWindow.flatMap((c) => commitTouches(graph, c, entityType).matches))
2240
+ : null;
2241
+ const matches = touched || inWindow;
2170
2242
  const referents = [];
2171
2243
  if (matches.length) {
2244
+ const setClass = touched ? entityType : "Commit";
2172
2245
  referents.push({
2173
- kind: "set", class: "Commit",
2174
- label: `${matches.length} commit${matches.length === 1 ? "" : "s"} ${op} ${pivotRaw}`,
2246
+ kind: "set", class: setClass,
2247
+ label: `${matches.length} ${nounFor(setClass, matches.length)} ${op} ${pivotRaw}`,
2175
2248
  ids: matches.map((c) => c.id),
2176
2249
  attrs: { count: matches.length, op, ...(pivotId ? { pivot: pivotId } : {}) },
2177
2250
  lane: "commitFilter",
@@ -2184,7 +2257,10 @@ function evalCommitFilter(graph, ast) {
2184
2257
  lane: "commitFilter",
2185
2258
  });
2186
2259
  }
2187
- return { compositeKind: "commitFilter", op, pivotRaw, pivotDate, pivotResolved: true, matches, referents };
2260
+ return {
2261
+ compositeKind: "commitFilter", op, pivotRaw, pivotDate, pivotResolved: true,
2262
+ entityType, windowCount: inWindow.length, matches, referents,
2263
+ };
2188
2264
  }
2189
2265
 
2190
2266
  /** Temporal over a nested set: the commits that touched any member of the
@@ -2388,6 +2464,13 @@ function evalComposite(graph, ast, opts = {}) {
2388
2464
  if (ast.node === "qualCheck") return evalQualCheck(graph, ast, opts);
2389
2465
  if (ast.node === "universal") return evalUniversal(graph, ast, opts);
2390
2466
  if (ast.node === "count") {
2467
+ // A window the pivot can't bound refuses, so the count never reads as a
2468
+ // grounded zero over a window nobody could place.
2469
+ if (ast.base.node === "commitFilter") {
2470
+ const window = evalCommitFilter(graph, ast.base);
2471
+ if (!window.pivotResolved) return window;
2472
+ return { compositeKind: "count", count: window.matches.length, entityType: ast.entityType, matches: [] };
2473
+ }
2391
2474
  // "how many commits touched <X>" — count against provenance attestation
2392
2475
  // (commitTouchCount), not the bare touches-edge set evalSet(base) would
2393
2476
  // give: see commitTouchCount's own doc for why the two can disagree.
@@ -2634,9 +2717,18 @@ function renderComposite(parsed, result, graph) {
2634
2717
  miss: true, ambiguous: false, matches: [],
2635
2718
  };
2636
2719
  }
2637
- if (!result.matches.length) {
2720
+ if (!result.windowCount) {
2638
2721
  return { content: `no commits recorded ${result.op} ${result.pivotRaw}.`, miss: true, ambiguous: false, matches: [] };
2639
2722
  }
2723
+ // A kind-headed window that no commit reached at that grain is an honest
2724
+ // empty naming both the kind and the window, never the commit list.
2725
+ if (result.entityType && result.entityType !== "Commit" && result.entityType !== "Change") {
2726
+ const kindNoun = nounFor(result.entityType, result.matches.length || 2);
2727
+ if (!result.matches.length) {
2728
+ return { content: `no ${kindNoun} changed ${result.op} ${result.pivotRaw}.`, miss: true, ambiguous: false, matches: [] };
2729
+ }
2730
+ return { content: `${compositeList(result.matches)}.`, miss: false, ambiguous: false, matches: result.matches };
2731
+ }
2640
2732
  const dateOf = (c) => String((c.attributes || []).find((a) => a.key === "date")?.value || "");
2641
2733
  const shown = result.matches.slice(0, HISTORY_CAP).map((c) => {
2642
2734
  const day = dateOf(c).slice(0, 10);
@@ -3749,7 +3841,7 @@ export function traverse(graph, parsed, { contextId = null, prev = null, pinnedO
3749
3841
  matches = subjects;
3750
3842
  } else {
3751
3843
  const direct = subjects.filter((s) => s.class === entityType);
3752
- const sited = direct.length || !definesHop(kind, entityType) ? [] : siteDefiningModules(graph, new Set([gObjMatch.id]));
3844
+ const sited = direct.length || !moduleMembershipHop(kind, entityType) ? [] : siteDefiningModules(graph, new Set([gObjMatch.id]));
3753
3845
  if (direct.length) {
3754
3846
  matches = direct;
3755
3847
  } else if (sited.length) {
@@ -250,8 +250,12 @@ export function renderDescribe(graph, ind, { candidates = [] } = {}) {
250
250
  const lines = [];
251
251
  lines.push(`${ind.label} — ${classHeading(ind.class)} (id: ${ind.id})`);
252
252
 
253
+ // Counts the entity's own provenance refs, which is not the same as the number
254
+ // of commits that touched it: a `turn:` ref is no commit at all, and a `git:`
255
+ // ref may name a commit this index never ingested. The touches edges below say
256
+ // what touched it; saying "touched by N commit(s)" here contradicted them.
253
257
  const refs = (ind.derived_from || []).filter(isProvRef);
254
- if (refs.length) lines.push(`attestation: touched by ${refs.length} commit(s)`);
258
+ if (refs.length) lines.push(`attestation: ${refs.length} provenance ref(s)`);
255
259
 
256
260
  for (const a of ind.attributes || []) {
257
261
  lines.push(`attribute: ${a.key} = ${a.value}${a.prop ? ` [${a.prop}]` : ""}`);
@@ -7,7 +7,7 @@
7
7
  import {
8
8
  VERB_TO_KIND, ENTITY_TO_TYPE, MODIFIER_TO_KIND,
9
9
  META_MEANING_VERBS, WHERE_MARKERS, MENTION_MARKERS,
10
- INHERITS_REVERSE_VERBS, stripTrailingScopeFiller, stripTrailingDiscourseTag,
10
+ readConverse, stripTrailingScopeFiller, stripTrailingDiscourseTag,
11
11
  ARTICLE_RELATION_CONTINUATIONS, HAS_FAMILY_VERBS,
12
12
  } from "../../ask-vocab.mjs";
13
13
  import { escapeRegex } from "../normalize.mjs";
@@ -23,9 +23,9 @@ const META_ALT = META_MEANING_VERBS.slice().sort((a, b) => b.length - a.length).
23
23
  const isHasFamilyDefines = (kind, verb) => kind === "defines" && HAS_FAMILY_VERBS.has(verb);
24
24
 
25
25
  const TEMPLATES = [
26
- // T1 ASK: "does X import Y" -> Yes/No. REVERSE VERB SWAP: a semantically-reverse
27
- // verb ("superclass of") means the opposite of its forward counterpart, so
28
- // INHERITS_REVERSE_VERBS (ask-vocab.mjs) swaps subject/object here at parse time.
26
+ // T1 ASK: "does X import Y" -> Yes/No. A converse verb ("superclass of",
27
+ // "belongs to") states the relation from its object's side, so readConverse
28
+ // (ask-vocab.mjs) swaps subject/object here at parse time.
29
29
  {
30
30
  name: "ask",
31
31
  re: new RegExp(`^(?:does|do|did)\\s+(.+?)\\s+(${VERB_ALT})\\s+(.+?)\\??$`, "i"),
@@ -33,13 +33,15 @@ const TEMPLATES = [
33
33
  const verb = m[2].toLowerCase();
34
34
  const kind = VERB_TO_KIND[verb];
35
35
  if (isHasFamilyDefines(kind, verb)) return null;
36
- let subject = m[1].trim();
37
- let object = m[3].trim();
38
- if (INHERITS_REVERSE_VERBS.includes(verb)) [subject, object] = [object, subject];
39
- return { shape: "ask", entityType: null, modifier: "direct", kind, subject, object };
36
+ return readConverse({
37
+ shape: "ask", entityType: null, modifier: "direct", kind,
38
+ subject: m[1].trim(), object: m[3].trim(),
39
+ }, verb);
40
40
  },
41
41
  },
42
- // T2 reverse: "which <entity> [<modifier>] <verb> <object>".
42
+ // T2 reverse: "which <entity> [<modifier>] <verb> <object>". A converse verb
43
+ // turns the same sentence into a forward read off the named object, keeping
44
+ // the asked entity filter.
43
45
  {
44
46
  name: "reverse",
45
47
  re: new RegExp(`^which\\s+(${ENTITY_ALT})\\s+(?:(${MODIFIER_ALT})\\s+)?(${VERB_ALT})\\s+(.+?)\\??$`, "i"),
@@ -47,13 +49,13 @@ const TEMPLATES = [
47
49
  const verb = m[3].toLowerCase();
48
50
  const kind = VERB_TO_KIND[verb];
49
51
  if (isHasFamilyDefines(kind, verb)) return null;
50
- return {
52
+ return readConverse({
51
53
  shape: "reverse",
52
54
  entityType: ENTITY_TO_TYPE[m[1].toLowerCase()],
53
55
  modifier: m[2] ? MODIFIER_TO_KIND[m[2].toLowerCase()] : "direct",
54
56
  kind,
55
57
  object: m[4].trim(),
56
- };
58
+ }, verb);
57
59
  },
58
60
  },
59
61
  // T3 forward: "what does <object> <verb>" — X is given, list its R-related things.
@@ -65,7 +67,7 @@ const TEMPLATES = [
65
67
  const verb = m[2].toLowerCase();
66
68
  const kind = VERB_TO_KIND[verb];
67
69
  if (isHasFamilyDefines(kind, verb)) return null;
68
- return { shape: "forward", entityType: null, modifier: "direct", kind, object: m[1].trim() };
70
+ return readConverse({ shape: "forward", entityType: null, modifier: "direct", kind, object: m[1].trim() }, verb);
69
71
  },
70
72
  },
71
73
  // T4 meta: "what does <term> mean" — a question about the graph's own vocabulary,
@@ -8,7 +8,8 @@
8
8
  import {
9
9
  VERB_TO_KIND, ENTITY_TO_TYPE, MODIFIER_TO_KIND,
10
10
  WHERE_MARKERS, MENTION_MARKERS, PLACEHOLDER_NOUNS, PASSIVE_PARTICIPLE_TO_KIND,
11
- INHERITS_REVERSE_VERBS, HAS_FAMILY_VERBS, CALLS_VERB_REPORT_NOUNS,
11
+ REDUCED_RELATIVE_CLAUSES,
12
+ readConverse, HAS_FAMILY_VERBS, CALLS_VERB_REPORT_NOUNS,
12
13
  } from "../../ask-vocab.mjs";
13
14
  import { STOPWORDS } from "../normalize.mjs";
14
15
  import { VOCAB_WORDS, eligibleForCanon, fuzzyVocabWord } from "../fuzzy.mjs";
@@ -243,6 +244,7 @@ export function parseKeywordSpot(text, nlp = null) {
243
244
  // against the canonicalized array, whose word IS the table key.
244
245
  const entityType = entityHit ? ENTITY_TO_TYPE[canonWords.slice(entityHit.start, entityHit.end).join(" ")] : null;
245
246
  const modifier = modifierHit ? MODIFIER_TO_KIND[canonWords.slice(modifierHit.start, modifierHit.end).join(" ")] : "direct";
247
+ const verbPhrase = canonWords.slice(verbHit.start, verbHit.end).join(" ");
246
248
 
247
249
  // "when" turns a touches decomposition temporal; other verbs fall through.
248
250
  if (kind === "touches" && lcWords.includes("when")) {
@@ -310,19 +312,30 @@ export function parseKeywordSpot(text, nlp = null) {
310
312
  if (verbFromParticiple && byIdx < 0 && afterText && lcWords[verbHit.start] === "called") return null;
311
313
 
312
314
  if (beforeText && afterText) {
313
- const verbPhrase = canonWords.slice(verbHit.start, verbHit.end).join(" ");
314
315
  // The bare have-family "ask" shape ("does X have Y") declines here, same
315
316
  // reasoning as grammar.mjs's T1 (see HAS_FAMILY_VERBS above) — never for
316
317
  // the entityType-driven forward/reverse branches below, which keep their
317
318
  // own tested grain-check decline.
318
319
  if (kind === "defines" && HAS_FAMILY_VERBS.has(verbPhrase)) return null;
319
320
  if (kind === "calls" && (leadsWithCallsReportNoun(afterText) || isBareCallsVerbWord(beforeText))) return null;
320
- // A semantically-reverse verb ("superclass of") swaps subject/object, same as
321
- // grammar.mjs's T1.
322
- let subject = beforeText;
323
- let object = afterText;
324
- if (INHERITS_REVERSE_VERBS.includes(verbPhrase)) [subject, object] = [object, subject];
325
- return stamp({ shape: "ask", entityType: null, modifier: "direct", kind, subject, object });
321
+ // A passive participle whose complement is introduced by a preposition
322
+ // rather than "by" ("is Widget DEFINED IN app/lib/b.mjs") names its AGENT
323
+ // after that preposition, so the leading term is the relation's object.
324
+ // REDUCED_RELATIVE_CLAUSES already curates which participle+preposition
325
+ // bigrams read that way; the "by" bigrams never reach here, since the
326
+ // passive branch above claims every sentence carrying one.
327
+ const bigram = verbFromParticiple && byIdx < 0
328
+ ? REDUCED_RELATIVE_CLAUSES[`${lcWords[verbHit.start]} ${lcWords[verbHit.end]}`]
329
+ : null;
330
+ if (bigram && bigram.role === "agent" && bigram.kind === kind) {
331
+ return stamp({ shape: "ask", entityType: null, modifier: "direct", kind, subject: afterText, object: beforeText });
332
+ }
333
+ // A converse verb ("superclass of", "belongs to") swaps subject/object, same
334
+ // as grammar.mjs's T1.
335
+ return stamp(readConverse({
336
+ shape: "ask", entityType: null, modifier: "direct", kind,
337
+ subject: beforeText, object: afterText,
338
+ }, verbPhrase));
326
339
  }
327
340
  if (afterText) {
328
341
  if (kind === "calls" && leadsWithCallsReportNoun(afterText)) return null;
@@ -333,7 +346,7 @@ export function parseKeywordSpot(text, nlp = null) {
333
346
  // answered "no classes" over a module-level graph. Only a type word on
334
347
  // the wh-side of the verb ("which CLASSES use Store") filters the result.
335
348
  const resultType = entityHit && entityHit.start >= verbHit.end ? null : entityType;
336
- return stamp({ shape: "reverse", entityType: resultType, modifier, kind, object: afterText });
349
+ return stamp(readConverse({ shape: "reverse", entityType: resultType, modifier, kind, object: afterText }, verbPhrase));
337
350
  }
338
351
  // "what is a kind of class": when the object is itself an entity-type noun, the
339
352
  // entity match swallows the whole post-verb span as a grain qualifier, leaving
@@ -365,7 +378,7 @@ export function parseKeywordSpot(text, nlp = null) {
365
378
  }
366
379
  // forward keeps the spotted entityType (traverse()'s commit-as-subject grain
367
380
  // selection); modifier stays hardcoded since no forward closure traversal exists.
368
- if (beforeText) return stamp({ shape: "forward", entityType, modifier: "direct", kind, object: beforeText });
381
+ if (beforeText) return stamp(readConverse({ shape: "forward", entityType, modifier: "direct", kind, object: beforeText }, verbPhrase));
369
382
  return null;
370
383
  }
371
384