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

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/bin/tmct.mjs CHANGED
@@ -1426,7 +1426,13 @@ async function main() {
1426
1426
  const { resolveRuntimeConfig, strFlag } = await import("../src/services/cli-args.mjs");
1427
1427
  const { newsTurn, resolveNewsConfig, createNewsState } = await import("../src/services/news.mjs");
1428
1428
  const { loadMemory, readFactRows, appendFacts, openMemoryBackend } = await import("../src/adapters/memory/core.mjs");
1429
- const { loadTomlConfig } = await import("../src/adapters/toml-config.mjs");
1429
+ // The same fetcher factory news.html's own session builds from
1430
+ // (src/surfaces/web/news-browser-entry.mjs) — real sources over Node's
1431
+ // own global fetch, each behind createNewsFetcher's courtesy gate so a
1432
+ // CLI poll paces its requests exactly like every other surface.
1433
+ const { newsSourceRecords, normalizeNewsSourceIds, createNewsFetcher, preflightNewsUrl } =
1434
+ await import("../src/adapters/corpus/news-sources.mjs");
1435
+ const { getResearchProvider } = await import("../src/adapters/corpus/wikipedia-live.mjs");
1430
1436
  const { repo, toml } = await resolveRuntimeConfig({ argv: rest });
1431
1437
  // Same env > tmct.toml > default backend resolution as `tmct memory` — the
1432
1438
  // news facts must land in the store chat reads back.
@@ -1435,15 +1441,28 @@ async function main() {
1435
1441
  const store = { loadMemory, readFactRows, appendFacts };
1436
1442
  const memory = await loadMemory(memoryDir);
1437
1443
  const rows = readFactRows(memory);
1438
- const config = resolveNewsConfig(toml?.news);
1444
+ // resolveNewsConfig unwraps `toml?.news` itself (the tmct.toml [news]
1445
+ // table) — pass the whole toml, not its news sub-table, or a `[news]`
1446
+ // table in tmct.toml is silently never read.
1447
+ const config = resolveNewsConfig(toml);
1439
1448
  const state = createNewsState();
1449
+ const newsFetchers = new Map();
1450
+ for (const id of normalizeNewsSourceIds(config.sources)) {
1451
+ const record = newsSourceRecords().find((r) => r.id === id);
1452
+ if (record) newsFetchers.set(id, createNewsFetcher(record, { fetchImpl: fetch }));
1453
+ }
1454
+ const providers = {
1455
+ newsFetchers,
1456
+ getResearchProvider,
1457
+ preflightNewsUrl: (url) => preflightNewsUrl(url, { fetchImpl: fetch }),
1458
+ };
1440
1459
  let res;
1441
1460
  try {
1442
1461
  const line = rest.join(" ").trim();
1443
1462
  // Prepend `/news` to make parseNewsRequest recognize the subcommand.
1444
1463
  const newsLine = line ? `/news ${line}` : "/news poll";
1445
1464
  res = await newsTurn(newsLine, {
1446
- memoryDir, rows, store, config, state, now: () => new Date().toISOString(),
1465
+ memoryDir, rows, store, config, state, providers, now: () => new Date().toISOString(),
1447
1466
  });
1448
1467
  } finally {
1449
1468
  await closeMemoryStore();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polycode-projects/the-mechanical-code-talker",
3
- "version": "5.0.36",
3
+ "version": "5.0.37",
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.",
@@ -289,13 +289,16 @@ function parseComposite(text, nlp) {
289
289
  || parseNegatedAsk(w, lc, nlp)
290
290
  || parseForwardNegation(w, lc, nlp)
291
291
  || parseTemporal(w, lc, nlp, 0)
292
+ || parseWhereSet(w, lc, nlp, 0)
292
293
  || parseCommitFilter(w, lc)
293
294
  || parseAnaphora(w, lc, nlp)
294
295
  || parseAggregate(w, lc, nlp)
295
296
  || parseSuperlative(w, lc, nlp)
296
297
  || parseFind(w, lc, nlp, 0)
297
298
  || parseList(w, lc, nlp, 0)
299
+ || parseDefinitionSiteMembership(w, lc, nlp, 0)
298
300
  || parseNested(w, lc, nlp, 0)
301
+ || parseRelativeSubjectForward(w, lc, nlp, 0)
299
302
  || parsePluralAnaphoraObject(w, lc, nlp)
300
303
  || parseStackedReducedRelative(w, lc)
301
304
  || parseRelationalOrQualified(w, lc, nlp, 0);
@@ -513,8 +516,12 @@ function parseSetPhrase(text, nlp, depth) {
513
516
  if (negated) return negated;
514
517
  const w = splitWords(text);
515
518
  const lc = w.map((x) => x.toLowerCase());
519
+ const definitionSite = parseDefinitionSiteMembership(w, lc, nlp, depth);
520
+ if (definitionSite) return definitionSite;
516
521
  const nested = parseNested(w, lc, nlp, depth);
517
522
  if (nested) return nested;
523
+ const relSubject = parseRelativeSubjectForward(w, lc, nlp, depth);
524
+ if (relSubject) return relSubject;
518
525
  const rel = parseRelationalOrQualified(w, lc, nlp, depth);
519
526
  if (rel) return rel;
520
527
  const clause = parseSimpleClause(text, nlp);
@@ -567,6 +574,65 @@ function parseNested(w, lc, nlp, depth) {
567
574
  return null;
568
575
  }
569
576
 
577
+ // A LONE reduced relative naming the definition site: "<kind> [are] defined in
578
+ // <owner>". parseStackedReducedRelative needs two such bigrams on one head noun,
579
+ // so a single one had no route at all and the flat parser read the participle as
580
+ // part of the owner's name. The phrase means exactly "<kind> in <owner>", which
581
+ // the membership atom already resolves — including an owner that is itself a
582
+ // relative clause.
583
+ const DEFINITION_SITE_PARTICIPLES = new Set(["defined", "declared"]);
584
+ function parseDefinitionSiteMembership(w, lc, nlp, depth) {
585
+ let i = 0;
586
+ if (FRAME_WORDS.has(lc[i]) || MEMBERSHIP_OWNER_DET.has(lc[i])) i += 1;
587
+ const noun = entityNoun(lc[i]);
588
+ if (!noun || noun.placeholder || !noun.entityType) return null;
589
+ i += 1;
590
+ if (COPULA_WORDS.has(lc[i])) i += 1;
591
+ if (!DEFINITION_SITE_PARTICIPLES.has(lc[i]) || lc[i + 1] !== "in") return null;
592
+ const owner = w.slice(i + 2);
593
+ if (!owner.length) return null;
594
+ return membershipAtom(noun.entityType, owner, nlp, depth);
595
+ }
596
+
597
+ // SUBJECT-POSITION relative clause: "which <kind> <the <kind> that <inner>>
598
+ // <verb>" — the relative clause is the outer verb's SUBJECT, and the verb
599
+ // dangles with no object of its own ("which class the class that inherits from
600
+ // Widget inherits from"). parseNested only reads OBJECT-position relatives, so
601
+ // this shape otherwise falls through to the flat clause parser, which reads the
602
+ // embedded clause's own words as one term. Gated hard: the text must END with a
603
+ // relation verb phrase and carry a relative pronoun before it, a combination no
604
+ // other production claims.
605
+ function parseRelativeSubjectForward(w, lc, nlp, depth) {
606
+ let i = 0;
607
+ if (!FRAME_WORDS.has(lc[0])) return null;
608
+ i += 1;
609
+ const noun = entityNoun(lc[i]);
610
+ if (!noun) return null;
611
+ i += 1;
612
+ const rest = w.slice(i);
613
+ const restLc = lc.slice(i);
614
+ if (rest.length < 2) return null;
615
+ // the dangling verb: the SHORTEST trailing phrase that is a whole relation verb.
616
+ let verb = null;
617
+ for (let k = rest.length - 1; k > 0; k -= 1) {
618
+ const tail = restLc.slice(k);
619
+ const vh = findPhrase(tail, VERB_TO_KIND);
620
+ if (vh && vh.start === 0 && vh.end === tail.length) { verb = { kind: vh.kind, at: k }; break; }
621
+ }
622
+ if (!verb) return null;
623
+ const subjWords = rest.slice(0, verb.at);
624
+ const subjLc = restLc.slice(0, verb.at);
625
+ if (!subjLc.some((x) => RELATIVE_PRONOUNS.includes(x))) return null;
626
+ let head = subjWords;
627
+ let headLc = subjLc;
628
+ while (headLc.length && MEMBERSHIP_OWNER_DET.has(headLc[0])) { head = head.slice(1); headLc = headLc.slice(1); }
629
+ if (!headLc.length || !entityNoun(headLc[0])) return null;
630
+ const framed = FRAME_WORDS.has(headLc[0]) ? head.join(" ") : `which ${head.join(" ")}`;
631
+ const inner = parseSetPhrase(framed, nlp, depth + 1);
632
+ if (!inner || inner.node === "miss") return { node: "miss", reason: (inner && inner.reason) || "the embedded subject clause didn't parse" };
633
+ return { node: "forwardSet", kind: verb.kind, entityType: noun.entityType, inner };
634
+ }
635
+
570
636
  // Plural anaphora object: "those"/"them" standing alone as a reverse-clause
571
637
  // object ("what tests cover those") or forward-clause subject ("what do
572
638
  // those import") refer to the full id set of ask()'s `prev`. Reuses
@@ -641,6 +707,58 @@ function parseCommitFilter(w, lc) {
641
707
  return { node: "commitFilter", op, pivotRaw };
642
708
  }
643
709
 
710
+ // "<kind> in|of <owner>" where the OWNER is itself a relative clause ("functions
711
+ // in the module that imports X"). The owner has to be resolved as a set first:
712
+ // handed to the term resolver as one free-text string it fuzzy-matches the name
713
+ // sitting inside the relative clause, and the answer then describes the wrong
714
+ // entity with full confidence — the exact shape the miss-over-guess contract
715
+ // forbids. Falls back to the plain free-text membership node whenever the owner
716
+ // carries no relative marker, so every other membership query is untouched.
717
+ const MEMBERSHIP_OWNER_DET = new Set(["the", "a", "an", "all", "those", "these", "any"]);
718
+ function membershipAtom(entityType, termWords, nlp, depth) {
719
+ const termLc = termWords.map((x) => x.toLowerCase());
720
+ if (termLc.some((t) => RELATIVE_PRONOUNS.includes(t))) {
721
+ let head = termWords;
722
+ let headLc = termLc;
723
+ while (headLc.length && MEMBERSHIP_OWNER_DET.has(headLc[0])) { head = head.slice(1); headLc = headLc.slice(1); }
724
+ if (headLc.length && entityNoun(headLc[0])) {
725
+ const framed = FRAME_WORDS.has(headLc[0]) ? head.join(" ") : `which ${head.join(" ")}`;
726
+ const owners = parseSetPhrase(framed, nlp, depth + 1);
727
+ if (!owners || owners.node === "miss") {
728
+ return { node: "miss", reason: (owners && owners.reason) || "the owner clause of this membership query didn't parse" };
729
+ }
730
+ return { node: "membershipSet", entityType, inner: owners };
731
+ }
732
+ }
733
+ return { node: "membership", entityType, term: termWords.join(" ") };
734
+ }
735
+
736
+ // Where-over-relative: "where is <relative set> defined" resolves the relative
737
+ // clause to real entities FIRST, then cites each one's own source site — the
738
+ // same compose-then-answer order parseTemporal uses for "when did <relative
739
+ // set> change". Without it the whole clause is handed to the flat where-shape
740
+ // as one free-text term, which fuzzy-matches its wordiest name and answers a
741
+ // confident location for the wrong entity. Fires only for a relative subject;
742
+ // "where is Widget defined" stays on the flat path.
743
+ const WHERE_SET_AUX = new Set(["is", "are", "was", "were", "does", "do", "did"]);
744
+ const WHERE_SET_DET = new Set(["the", "a", "an", "all", "those", "these", "any"]);
745
+ function parseWhereSet(w, lc, nlp, depth = 0) {
746
+ if (lc[0] !== "where") return null;
747
+ if (!WHERE_SET_AUX.has(lc[1])) return null;
748
+ if (!WHERE_MARKER_WORDS.has(lc[lc.length - 1])) return null; // needs the definition-site tail
749
+ let subjWords = w.slice(2, lc.length - 1);
750
+ let subjLc = lc.slice(2, lc.length - 1);
751
+ while (subjLc.length && WHERE_SET_DET.has(subjLc[0])) { subjWords = subjWords.slice(1); subjLc = subjLc.slice(1); }
752
+ if (!subjWords.length) return null;
753
+ if (!subjLc.some((x) => RELATIVE_PRONOUNS.includes(x))) return null;
754
+ const noun = entityNoun(subjLc[0]);
755
+ if (!noun) return null; // needs a kind noun to frame the inner query
756
+ const framed = FRAME_WORDS.has(subjLc[0]) ? subjWords.join(" ") : `which ${subjWords.join(" ")}`;
757
+ const inner = parseSetPhrase(framed, nlp, depth + 1);
758
+ if (!inner || inner.node === "miss") return { node: "miss", reason: (inner && inner.reason) || "the inner set of the location query didn't parse" };
759
+ return { node: "whereSet", inner, entityType: noun.entityType || null };
760
+ }
761
+
644
762
  // Minimal code-identifier token shape: dotted paths, Capitalized symbols, or
645
763
  // lowerCamelCase. Duplicated from chat.mjs's NAME_TOKEN_RE rather than
646
764
  // imported, since chat.mjs only imports ask.mjs lazily.
@@ -1116,7 +1234,9 @@ function buildPredicateAtoms(entityType, subjPrefix, predLc, predWords, nlp, dep
1116
1234
  const qc = dropLeadCopula(bw, blc);
1117
1235
  if (qc.blc.length && qc.blc.every((x) => QUALIFIERS[x])) { atoms.push({ op, kind: "qual", filters: qc.blc }); continue; }
1118
1236
  if (blc[0] === "of" || blc[0] === "in") {
1119
- atoms.push({ op, kind: "set", ast: { node: "membership", entityType, term: bw.slice(1).join(" ") } });
1237
+ const owned = membershipAtom(entityType, bw.slice(1), nlp, depth);
1238
+ if (owned.node === "miss") return { miss: owned.reason };
1239
+ atoms.push({ op, kind: "set", ast: owned });
1120
1240
  continue;
1121
1241
  }
1122
1242
  let phrase = bw;
@@ -1255,7 +1375,9 @@ function parseRelationalOrQualified(w, lc, nlp, depth) {
1255
1375
  const qc = dropLeadCopula(bw, blc);
1256
1376
  if (qc.blc.length && qc.blc.every((x) => QUALIFIERS[x])) { atoms.push({ op, kind: "qual", filters: qc.blc }); continue; }
1257
1377
  if (blc[0] === "of" || blc[0] === "in") {
1258
- atoms.push({ op, kind: "set", ast: { node: "membership", entityType, term: bw.slice(1).join(" ") } });
1378
+ const owned = membershipAtom(entityType, bw.slice(1), nlp, depth + 1);
1379
+ if (owned.node === "miss") return owned;
1380
+ atoms.push({ op, kind: "set", ast: owned });
1259
1381
  continue;
1260
1382
  }
1261
1383
  let phrase = bw;
@@ -1323,6 +1445,64 @@ function splitBoolean(predLc, predWords) {
1323
1445
  // same primitives (edgesOfKind, resolveObject, refineToEntities, traverse) the
1324
1446
  // simple path uses. Pure given (graph, ast, opts). ----
1325
1447
 
1448
+ const askModuleByPathCache = new WeakMap();
1449
+
1450
+ /** Module individuals keyed by normalized repo path, so a recorded source site
1451
+ * ("app/lib/c.mjs:1-10") can be turned back into the Module node it names. */
1452
+ function modulesByPath(graph) {
1453
+ let byPath = askModuleByPathCache.get(graph);
1454
+ if (byPath) return byPath;
1455
+ byPath = new Map();
1456
+ for (const ind of graph.individuals || []) {
1457
+ if (ind.class === "Module") byPath.set(normPath(ind.label), ind);
1458
+ }
1459
+ askModuleByPathCache.set(graph, byPath);
1460
+ return byPath;
1461
+ }
1462
+
1463
+ /** The modules a set of symbols is defined in, read off each symbol's recorded
1464
+ * SITE rather than a stored `defines` edge. An extractor can site a symbol
1465
+ * without writing the edge (the fixture does exactly that for Button and
1466
+ * Widget.render), and the `where` lane already answers "Button is defined in
1467
+ * app/lib/c.mjs" from that same attribute — so a `defines` hop that reads only
1468
+ * the edge contradicts the `where` answer and turns a chain into a false empty.
1469
+ * Fallback only: a symbol the edge already covers never reaches here. */
1470
+ function siteDefiningModules(graph, objectIds) {
1471
+ const byPath = modulesByPath(graph);
1472
+ const out = [];
1473
+ for (const id of objectIds) {
1474
+ const ind = graph.byId.get(id);
1475
+ if (!ind || ind.class === "Module") continue;
1476
+ const label = moduleLabelOf(ind);
1477
+ const mod = label ? byPath.get(normPath(label)) : null;
1478
+ if (mod) out.push(mod);
1479
+ }
1480
+ return uniqueById(out);
1481
+ }
1482
+
1483
+ const definesHop = (kind, entityType) => entityType === "Module" && kindsFor(kind).includes("defines");
1484
+
1485
+ const askSiteMembersCache = new WeakMap();
1486
+
1487
+ /** Symbols grouped by the module their recorded SITE places them in — the same
1488
+ * edge/site asymmetry siteDefiningModules covers, read from the module's side. */
1489
+ function siteMembersByModule(graph) {
1490
+ let byModule = askSiteMembersCache.get(graph);
1491
+ if (byModule) return byModule;
1492
+ byModule = new Map();
1493
+ const byPath = modulesByPath(graph);
1494
+ for (const ind of graph.individuals || []) {
1495
+ if (ind.class === "Module") continue;
1496
+ const label = moduleLabelOf(ind);
1497
+ const mod = label ? byPath.get(normPath(label)) : null;
1498
+ if (!mod) continue;
1499
+ if (!byModule.has(mod.id)) byModule.set(mod.id, []);
1500
+ byModule.get(mod.id).push(ind);
1501
+ }
1502
+ askSiteMembersCache.set(graph, byModule);
1503
+ return byModule;
1504
+ }
1505
+
1326
1506
  /** Reverse traversal over a SET of object ids (the nested "callers of {X…}" step) —
1327
1507
  * mirrors traverse()'s reverse general case (symbol-grain sibling + defines-refine),
1328
1508
  * but membership-tests e.object against a set instead of a single id. */
@@ -1340,10 +1520,25 @@ function reverseOverSet(graph, kind, entityType, objectIds) {
1340
1520
  // branch for the flat path; the module-coarse case is byte-unchanged (no fine ids).
1341
1521
  const objHasFine = !!symbolKind && [...objectIds].some((id) => FINE_ENTITY_TYPES.has(graph.byId.get(id)?.class));
1342
1522
  const scanKinds = objHasFine ? [...kindsFor(kind), symbolKind] : kindsFor(kind);
1343
- const edges = scanKinds.flatMap((k) => edgesOfKind(graph, k)).filter((e) => objectIds.has(e.object));
1523
+ const scanned = scanKinds.flatMap((k) => edgesOfKind(graph, k));
1524
+ let edges = scanned.filter((e) => objectIds.has(e.object));
1525
+ // cochange is symmetric but stored as one directed edge per pair, so a set
1526
+ // member recorded as the stored SUBJECT is just as much a cochange partner —
1527
+ // the same flip traverse() makes on the flat path.
1528
+ if (kind === "cochange") {
1529
+ edges = edges.concat(scanned.filter((e) => objectIds.has(e.subject)).map((e) => ({ ...e, subject: e.object, object: e.subject })));
1530
+ }
1344
1531
  const subjects = uniqueById(edges.map((e) => graph.byId.get(e.subject)).filter(Boolean));
1345
1532
  if (!entityType || entityType === "Change") return subjects;
1346
1533
  const direct = subjects.filter((s) => s.class === entityType);
1534
+ if (definesHop(kind, entityType)) {
1535
+ // Per-object, not per-set: "the module that defines {Widget, Button}" is the
1536
+ // union of each symbol's defining module, so a set where one member carries
1537
+ // the edge and another only a site must answer with both.
1538
+ const covered = new Set(edges.map((e) => e.object));
1539
+ const uncovered = new Set([...objectIds].filter((id) => !covered.has(id)));
1540
+ return uniqueById([...direct, ...siteDefiningModules(graph, uncovered)]);
1541
+ }
1347
1542
  if (direct.length) return direct;
1348
1543
  if (entityType !== "Module" && subjects.some((s) => s.class === "Module")) {
1349
1544
  return refineToEntities(graph, new Set(subjects.filter((s) => s.class === "Module").map((s) => s.id)), entityType);
@@ -1473,7 +1668,14 @@ export function metaFallbackEntityAnswer(graph, term) {
1473
1668
  * filtered to `entityType` when given. */
1474
1669
  function membershipOwnSet(graph, id, entityType) {
1475
1670
  const objs = uniqueById(MEMBERSHIP_KINDS.flatMap((k) => forwardOverSet(graph, k, new Set([id]))));
1476
- return entityType ? objs.filter((o) => o.class === entityType) : objs;
1671
+ const direct = entityType ? objs.filter((o) => o.class === entityType) : objs;
1672
+ if (direct.length) return direct;
1673
+ // Fallback only: symbols this module SITES without a membership edge of their
1674
+ // own. A module can define a class through the edge while its methods are
1675
+ // recorded by site alone, so "methods in <module>" reads empty off the edges
1676
+ // and the where-lane still places every one of those methods in that module.
1677
+ const sited = siteMembersByModule(graph).get(id) || [];
1678
+ return entityType ? sited.filter((o) => o.class === entityType) : sited;
1477
1679
  }
1478
1680
 
1479
1681
  /** Resolve a "<kind> of/in <term>" owner term to either a directory scope (a
@@ -1768,6 +1970,15 @@ function evalSet(graph, ast, opts) {
1768
1970
  const { own, inherited } = computeMembership(graph, owner.id, owner.entityClass, ast.entityType);
1769
1971
  return own.length ? own : inherited;
1770
1972
  }
1973
+ // Membership whose owner was itself a relative clause: the owners resolve as
1974
+ // a set, then every owner's members are collected and filtered to the asked
1975
+ // kind. An empty owner set stays empty rather than falling back to a
1976
+ // free-text resolve, which is what would guess.
1977
+ case "membershipSet": {
1978
+ const owners = evalSet(graph, ast.inner, opts);
1979
+ if (!owners.length) return [];
1980
+ return uniqueById(owners.flatMap((o) => membershipOwnSet(graph, o.id, ast.entityType)));
1981
+ }
1771
1982
  case "qualifier": {
1772
1983
  // a qualifier wrapping a MEMBERSHIP inner needs the filter applied INSIDE
1773
1984
  // the inheritance walk, at each level, not once after a flat resolve —
@@ -1989,6 +2200,16 @@ function evalTemporal(graph, ast, opts) {
1989
2200
  return { compositeKind: "temporal", matches: commits, entityType: ast.entityType, innerCount: inner.length };
1990
2201
  }
1991
2202
 
2203
+ /** Where over a nested set: the inner set's members, each carrying its own
2204
+ * recorded site for the renderer to cite. */
2205
+ function evalWhereSet(graph, ast, opts) {
2206
+ const matches = evalSet(graph, ast.inner, opts);
2207
+ return {
2208
+ compositeKind: "whereSet", matches, entityType: ast.entityType,
2209
+ sites: matches.map((ind) => (ind.attributes || []).find((a) => a.key === "site")?.value || null),
2210
+ };
2211
+ }
2212
+
1992
2213
  function evalSuperlative(graph, ast) {
1993
2214
  let pool = graph.individuals.filter((i) => i.class === ast.entityType);
1994
2215
  // A tests-metric ranking over Modules surveys COVERAGE, and a test module
@@ -2180,6 +2401,7 @@ function evalComposite(graph, ast, opts = {}) {
2180
2401
  if (ast.node === "worldRelation") return evalWorldRelation(graph, ast);
2181
2402
  if (ast.node === "superlative") return evalSuperlative(graph, ast);
2182
2403
  if (ast.node === "temporal") return evalTemporal(graph, ast, opts);
2404
+ if (ast.node === "whereSet") return evalWhereSet(graph, ast, opts);
2183
2405
  if (ast.node === "recentCommits") return evalRecentCommits(graph);
2184
2406
  if (ast.node === "commitFilter") return evalCommitFilter(graph, ast);
2185
2407
  if (ast.node === "anaphora") return evalAnaphora(graph, ast, opts);
@@ -2462,6 +2684,22 @@ function renderComposite(parsed, result, graph) {
2462
2684
  miss: false, ambiguous: false, matches: result.matches,
2463
2685
  };
2464
2686
  }
2687
+ // where over a composed set: cite each resolved member's own location. An
2688
+ // empty inner set is an honest miss, and a member the index places nowhere is
2689
+ // said out loud rather than dropped, so the count of answers always matches
2690
+ // the count of entities the clause resolved to.
2691
+ if (result.compositeKind === "whereSet") {
2692
+ const setNoun = result.entityType ? nounFor(result.entityType, 2) : "entities";
2693
+ if (!result.matches.length) {
2694
+ return { content: `nothing in the index matches that clause (${setNoun}), so there is no location to cite. ${compositionalHint()}.`, miss: true, ambiguous: false, matches: [] };
2695
+ }
2696
+ const lines = result.matches.map((ind, i) => definedAtLine(ind, result.sites[i])
2697
+ || `${ind.label} has no recorded code location in this index.`);
2698
+ const placed = result.matches.filter((ind, i) => definedAtLine(ind, result.sites[i]));
2699
+ return {
2700
+ content: lines.join(" "), miss: placed.length === 0, ambiguous: false, matches: result.matches,
2701
+ };
2702
+ }
2465
2703
  // set-producing
2466
2704
  if (!result.matches.length) {
2467
2705
  const hint = coverageGrainNote(parsed, result.entityType) || touchesRephraseHint(graph);
@@ -3511,8 +3749,12 @@ export function traverse(graph, parsed, { contextId = null, prev = null, pinnedO
3511
3749
  matches = subjects;
3512
3750
  } else {
3513
3751
  const direct = subjects.filter((s) => s.class === entityType);
3752
+ const sited = direct.length || !definesHop(kind, entityType) ? [] : siteDefiningModules(graph, new Set([gObjMatch.id]));
3514
3753
  if (direct.length) {
3515
3754
  matches = direct;
3755
+ } else if (sited.length) {
3756
+ matches = sited;
3757
+ grainNote = `, falling back to ${gObjMatch.label}'s recorded source site (no defines edge)`;
3516
3758
  } else if (entityType !== "Module" && subjects.some((s) => s.class === "Module")) {
3517
3759
  const moduleIds = new Set(subjects.filter((s) => s.class === "Module").map((s) => s.id));
3518
3760
  matches = refineToEntities(graph, moduleIds, entityType);
@@ -3542,6 +3784,21 @@ function moduleLabelOf(ind) {
3542
3784
  return m ? m[1] : null;
3543
3785
  }
3544
3786
 
3787
+ /** One entity's location sentence, cited off its recorded site, or null when
3788
+ * the index places it nowhere. "is defined in" stays unvaried on purpose —
3789
+ * pinned ground truth for "where is X defined", shared by the flat where-shape
3790
+ * and the composed where-over-a-relative-set so the two can never word the
3791
+ * same fact differently. */
3792
+ function definedAtLine(ind, site) {
3793
+ const m = String(site || "").match(/^(.*):(\d+)(?:-(\d+))?$/);
3794
+ if (m) {
3795
+ const lines = m[3] && m[3] !== m[2] ? `lines ${m[2]}-${m[3]}` : `line ${m[2]}`;
3796
+ return `${symbolLabelOf(ind)} is defined in ${m[1]} at ${lines}.`;
3797
+ }
3798
+ const mod = moduleLabelOf(ind);
3799
+ return mod ? `${symbolLabelOf(ind)} is defined in ${mod} (no line span recorded in this index).` : null;
3800
+ }
3801
+
3545
3802
  function symbolLabelOf(ind) {
3546
3803
  const label = String(ind.label || ind.id || "");
3547
3804
  return ["Function", "Method"].includes(ind.class) ? `function ${label}()` : label;
@@ -3915,25 +4172,14 @@ function renderCore(parsed, result, graph) {
3915
4172
  if (ind.class === "Commit") {
3916
4173
  return { content: `${ind.label} is a commit, not a code location — try "what did commit ${ind.label} touch".`, miss: true, ambiguous: false };
3917
4174
  }
3918
- const m = String(result.site || "").match(/^(.*):(\d+)(?:-(\d+))?$/);
3919
- if (m) {
3920
- // "is defined in" stays unvaried here on purpose — pinned ground truth
3921
- // for "where is X defined". The other two "defined in" call sites
3922
- // answer a different query shape and carry the phrasing variety instead.
3923
- const lines = m[3] && m[3] !== m[2] ? `lines ${m[2]}-${m[3]}` : `line ${m[2]}`;
3924
- return { content: `${symbolLabelOf(ind)} is defined in ${m[1]} at ${lines}.`, miss: false, ambiguous: false, matches: result.matches };
3925
- }
3926
- const mod = moduleLabelOf(ind);
3927
- if (!mod) {
4175
+ const line = definedAtLine(ind, result.site);
4176
+ if (!line) {
3928
4177
  return {
3929
4178
  content: `${ind.label} has no recorded code location in this index — it carries no source site, and nothing places it in a module.`,
3930
4179
  miss: true, ambiguous: false,
3931
4180
  };
3932
4181
  }
3933
- return {
3934
- content: `${symbolLabelOf(ind)} is defined in ${mod} (no line span recorded in this index).`,
3935
- miss: false, ambiguous: false, matches: result.matches,
3936
- };
4182
+ return { content: line, miss: false, ambiguous: false, matches: result.matches };
3937
4183
  }
3938
4184
  // when: newest touching commit + its date; undated commits are said out loud
3939
4185
  // (honest miss with the precise re-index hint), never silently skipped.