@polycode-projects/the-mechanical-code-talker 5.0.36 → 5.0.38
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 +1 -1
- package/bin/tmct.mjs +22 -3
- package/package.json +1 -1
- package/src/domain/ask-vocab.mjs +52 -2
- package/src/domain/ask.mjs +271 -18
- package/src/domain/interpret/strategies/grammar.mjs +14 -12
- package/src/domain/interpret/strategies/keywords.mjs +23 -10
- package/src/surfaces/web/memory-ask-browser.bundle.js +117 -117
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*, *
|
|
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/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
|
-
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "5.0.38",
|
|
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-vocab.mjs
CHANGED
|
@@ -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",
|
|
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
|
|
package/src/domain/ask.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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,71 @@ 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
|
+
// Both stored membership relations answer "which module is this in": `defines`
|
|
1484
|
+
// runs Module -> symbol, `contains` runs Class -> member, and a member's own
|
|
1485
|
+
// recorded source site stands in for either edge when the index never wrote one.
|
|
1486
|
+
// So a converse-verb question at module grain ("which module does Button live
|
|
1487
|
+
// in") reaches the same site fallback the defines hop already uses.
|
|
1488
|
+
const MODULE_MEMBERSHIP_KINDS = new Set(["defines", "contains"]);
|
|
1489
|
+
const moduleMembershipHop = (kind, entityType) => entityType === "Module"
|
|
1490
|
+
&& kindsFor(kind).some((k) => MODULE_MEMBERSHIP_KINDS.has(k));
|
|
1491
|
+
|
|
1492
|
+
const askSiteMembersCache = new WeakMap();
|
|
1493
|
+
|
|
1494
|
+
/** Symbols grouped by the module their recorded SITE places them in — the same
|
|
1495
|
+
* edge/site asymmetry siteDefiningModules covers, read from the module's side. */
|
|
1496
|
+
function siteMembersByModule(graph) {
|
|
1497
|
+
let byModule = askSiteMembersCache.get(graph);
|
|
1498
|
+
if (byModule) return byModule;
|
|
1499
|
+
byModule = new Map();
|
|
1500
|
+
const byPath = modulesByPath(graph);
|
|
1501
|
+
for (const ind of graph.individuals || []) {
|
|
1502
|
+
if (ind.class === "Module") continue;
|
|
1503
|
+
const label = moduleLabelOf(ind);
|
|
1504
|
+
const mod = label ? byPath.get(normPath(label)) : null;
|
|
1505
|
+
if (!mod) continue;
|
|
1506
|
+
if (!byModule.has(mod.id)) byModule.set(mod.id, []);
|
|
1507
|
+
byModule.get(mod.id).push(ind);
|
|
1508
|
+
}
|
|
1509
|
+
askSiteMembersCache.set(graph, byModule);
|
|
1510
|
+
return byModule;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1326
1513
|
/** Reverse traversal over a SET of object ids (the nested "callers of {X…}" step) —
|
|
1327
1514
|
* mirrors traverse()'s reverse general case (symbol-grain sibling + defines-refine),
|
|
1328
1515
|
* but membership-tests e.object against a set instead of a single id. */
|
|
@@ -1340,10 +1527,25 @@ function reverseOverSet(graph, kind, entityType, objectIds) {
|
|
|
1340
1527
|
// branch for the flat path; the module-coarse case is byte-unchanged (no fine ids).
|
|
1341
1528
|
const objHasFine = !!symbolKind && [...objectIds].some((id) => FINE_ENTITY_TYPES.has(graph.byId.get(id)?.class));
|
|
1342
1529
|
const scanKinds = objHasFine ? [...kindsFor(kind), symbolKind] : kindsFor(kind);
|
|
1343
|
-
const
|
|
1530
|
+
const scanned = scanKinds.flatMap((k) => edgesOfKind(graph, k));
|
|
1531
|
+
let edges = scanned.filter((e) => objectIds.has(e.object));
|
|
1532
|
+
// cochange is symmetric but stored as one directed edge per pair, so a set
|
|
1533
|
+
// member recorded as the stored SUBJECT is just as much a cochange partner —
|
|
1534
|
+
// the same flip traverse() makes on the flat path.
|
|
1535
|
+
if (kind === "cochange") {
|
|
1536
|
+
edges = edges.concat(scanned.filter((e) => objectIds.has(e.subject)).map((e) => ({ ...e, subject: e.object, object: e.subject })));
|
|
1537
|
+
}
|
|
1344
1538
|
const subjects = uniqueById(edges.map((e) => graph.byId.get(e.subject)).filter(Boolean));
|
|
1345
1539
|
if (!entityType || entityType === "Change") return subjects;
|
|
1346
1540
|
const direct = subjects.filter((s) => s.class === entityType);
|
|
1541
|
+
if (moduleMembershipHop(kind, entityType)) {
|
|
1542
|
+
// Per-object, not per-set: "the module that defines {Widget, Button}" is the
|
|
1543
|
+
// union of each symbol's defining module, so a set where one member carries
|
|
1544
|
+
// the edge and another only a site must answer with both.
|
|
1545
|
+
const covered = new Set(edges.map((e) => e.object));
|
|
1546
|
+
const uncovered = new Set([...objectIds].filter((id) => !covered.has(id)));
|
|
1547
|
+
return uniqueById([...direct, ...siteDefiningModules(graph, uncovered)]);
|
|
1548
|
+
}
|
|
1347
1549
|
if (direct.length) return direct;
|
|
1348
1550
|
if (entityType !== "Module" && subjects.some((s) => s.class === "Module")) {
|
|
1349
1551
|
return refineToEntities(graph, new Set(subjects.filter((s) => s.class === "Module").map((s) => s.id)), entityType);
|
|
@@ -1473,7 +1675,14 @@ export function metaFallbackEntityAnswer(graph, term) {
|
|
|
1473
1675
|
* filtered to `entityType` when given. */
|
|
1474
1676
|
function membershipOwnSet(graph, id, entityType) {
|
|
1475
1677
|
const objs = uniqueById(MEMBERSHIP_KINDS.flatMap((k) => forwardOverSet(graph, k, new Set([id]))));
|
|
1476
|
-
|
|
1678
|
+
const direct = entityType ? objs.filter((o) => o.class === entityType) : objs;
|
|
1679
|
+
if (direct.length) return direct;
|
|
1680
|
+
// Fallback only: symbols this module SITES without a membership edge of their
|
|
1681
|
+
// own. A module can define a class through the edge while its methods are
|
|
1682
|
+
// recorded by site alone, so "methods in <module>" reads empty off the edges
|
|
1683
|
+
// and the where-lane still places every one of those methods in that module.
|
|
1684
|
+
const sited = siteMembersByModule(graph).get(id) || [];
|
|
1685
|
+
return entityType ? sited.filter((o) => o.class === entityType) : sited;
|
|
1477
1686
|
}
|
|
1478
1687
|
|
|
1479
1688
|
/** Resolve a "<kind> of/in <term>" owner term to either a directory scope (a
|
|
@@ -1768,6 +1977,15 @@ function evalSet(graph, ast, opts) {
|
|
|
1768
1977
|
const { own, inherited } = computeMembership(graph, owner.id, owner.entityClass, ast.entityType);
|
|
1769
1978
|
return own.length ? own : inherited;
|
|
1770
1979
|
}
|
|
1980
|
+
// Membership whose owner was itself a relative clause: the owners resolve as
|
|
1981
|
+
// a set, then every owner's members are collected and filtered to the asked
|
|
1982
|
+
// kind. An empty owner set stays empty rather than falling back to a
|
|
1983
|
+
// free-text resolve, which is what would guess.
|
|
1984
|
+
case "membershipSet": {
|
|
1985
|
+
const owners = evalSet(graph, ast.inner, opts);
|
|
1986
|
+
if (!owners.length) return [];
|
|
1987
|
+
return uniqueById(owners.flatMap((o) => membershipOwnSet(graph, o.id, ast.entityType)));
|
|
1988
|
+
}
|
|
1771
1989
|
case "qualifier": {
|
|
1772
1990
|
// a qualifier wrapping a MEMBERSHIP inner needs the filter applied INSIDE
|
|
1773
1991
|
// the inheritance walk, at each level, not once after a flat resolve —
|
|
@@ -1989,6 +2207,16 @@ function evalTemporal(graph, ast, opts) {
|
|
|
1989
2207
|
return { compositeKind: "temporal", matches: commits, entityType: ast.entityType, innerCount: inner.length };
|
|
1990
2208
|
}
|
|
1991
2209
|
|
|
2210
|
+
/** Where over a nested set: the inner set's members, each carrying its own
|
|
2211
|
+
* recorded site for the renderer to cite. */
|
|
2212
|
+
function evalWhereSet(graph, ast, opts) {
|
|
2213
|
+
const matches = evalSet(graph, ast.inner, opts);
|
|
2214
|
+
return {
|
|
2215
|
+
compositeKind: "whereSet", matches, entityType: ast.entityType,
|
|
2216
|
+
sites: matches.map((ind) => (ind.attributes || []).find((a) => a.key === "site")?.value || null),
|
|
2217
|
+
};
|
|
2218
|
+
}
|
|
2219
|
+
|
|
1992
2220
|
function evalSuperlative(graph, ast) {
|
|
1993
2221
|
let pool = graph.individuals.filter((i) => i.class === ast.entityType);
|
|
1994
2222
|
// A tests-metric ranking over Modules surveys COVERAGE, and a test module
|
|
@@ -2180,6 +2408,7 @@ function evalComposite(graph, ast, opts = {}) {
|
|
|
2180
2408
|
if (ast.node === "worldRelation") return evalWorldRelation(graph, ast);
|
|
2181
2409
|
if (ast.node === "superlative") return evalSuperlative(graph, ast);
|
|
2182
2410
|
if (ast.node === "temporal") return evalTemporal(graph, ast, opts);
|
|
2411
|
+
if (ast.node === "whereSet") return evalWhereSet(graph, ast, opts);
|
|
2183
2412
|
if (ast.node === "recentCommits") return evalRecentCommits(graph);
|
|
2184
2413
|
if (ast.node === "commitFilter") return evalCommitFilter(graph, ast);
|
|
2185
2414
|
if (ast.node === "anaphora") return evalAnaphora(graph, ast, opts);
|
|
@@ -2462,6 +2691,22 @@ function renderComposite(parsed, result, graph) {
|
|
|
2462
2691
|
miss: false, ambiguous: false, matches: result.matches,
|
|
2463
2692
|
};
|
|
2464
2693
|
}
|
|
2694
|
+
// where over a composed set: cite each resolved member's own location. An
|
|
2695
|
+
// empty inner set is an honest miss, and a member the index places nowhere is
|
|
2696
|
+
// said out loud rather than dropped, so the count of answers always matches
|
|
2697
|
+
// the count of entities the clause resolved to.
|
|
2698
|
+
if (result.compositeKind === "whereSet") {
|
|
2699
|
+
const setNoun = result.entityType ? nounFor(result.entityType, 2) : "entities";
|
|
2700
|
+
if (!result.matches.length) {
|
|
2701
|
+
return { content: `nothing in the index matches that clause (${setNoun}), so there is no location to cite. ${compositionalHint()}.`, miss: true, ambiguous: false, matches: [] };
|
|
2702
|
+
}
|
|
2703
|
+
const lines = result.matches.map((ind, i) => definedAtLine(ind, result.sites[i])
|
|
2704
|
+
|| `${ind.label} has no recorded code location in this index.`);
|
|
2705
|
+
const placed = result.matches.filter((ind, i) => definedAtLine(ind, result.sites[i]));
|
|
2706
|
+
return {
|
|
2707
|
+
content: lines.join(" "), miss: placed.length === 0, ambiguous: false, matches: result.matches,
|
|
2708
|
+
};
|
|
2709
|
+
}
|
|
2465
2710
|
// set-producing
|
|
2466
2711
|
if (!result.matches.length) {
|
|
2467
2712
|
const hint = coverageGrainNote(parsed, result.entityType) || touchesRephraseHint(graph);
|
|
@@ -3511,8 +3756,12 @@ export function traverse(graph, parsed, { contextId = null, prev = null, pinnedO
|
|
|
3511
3756
|
matches = subjects;
|
|
3512
3757
|
} else {
|
|
3513
3758
|
const direct = subjects.filter((s) => s.class === entityType);
|
|
3759
|
+
const sited = direct.length || !moduleMembershipHop(kind, entityType) ? [] : siteDefiningModules(graph, new Set([gObjMatch.id]));
|
|
3514
3760
|
if (direct.length) {
|
|
3515
3761
|
matches = direct;
|
|
3762
|
+
} else if (sited.length) {
|
|
3763
|
+
matches = sited;
|
|
3764
|
+
grainNote = `, falling back to ${gObjMatch.label}'s recorded source site (no defines edge)`;
|
|
3516
3765
|
} else if (entityType !== "Module" && subjects.some((s) => s.class === "Module")) {
|
|
3517
3766
|
const moduleIds = new Set(subjects.filter((s) => s.class === "Module").map((s) => s.id));
|
|
3518
3767
|
matches = refineToEntities(graph, moduleIds, entityType);
|
|
@@ -3542,6 +3791,21 @@ function moduleLabelOf(ind) {
|
|
|
3542
3791
|
return m ? m[1] : null;
|
|
3543
3792
|
}
|
|
3544
3793
|
|
|
3794
|
+
/** One entity's location sentence, cited off its recorded site, or null when
|
|
3795
|
+
* the index places it nowhere. "is defined in" stays unvaried on purpose —
|
|
3796
|
+
* pinned ground truth for "where is X defined", shared by the flat where-shape
|
|
3797
|
+
* and the composed where-over-a-relative-set so the two can never word the
|
|
3798
|
+
* same fact differently. */
|
|
3799
|
+
function definedAtLine(ind, site) {
|
|
3800
|
+
const m = String(site || "").match(/^(.*):(\d+)(?:-(\d+))?$/);
|
|
3801
|
+
if (m) {
|
|
3802
|
+
const lines = m[3] && m[3] !== m[2] ? `lines ${m[2]}-${m[3]}` : `line ${m[2]}`;
|
|
3803
|
+
return `${symbolLabelOf(ind)} is defined in ${m[1]} at ${lines}.`;
|
|
3804
|
+
}
|
|
3805
|
+
const mod = moduleLabelOf(ind);
|
|
3806
|
+
return mod ? `${symbolLabelOf(ind)} is defined in ${mod} (no line span recorded in this index).` : null;
|
|
3807
|
+
}
|
|
3808
|
+
|
|
3545
3809
|
function symbolLabelOf(ind) {
|
|
3546
3810
|
const label = String(ind.label || ind.id || "");
|
|
3547
3811
|
return ["Function", "Method"].includes(ind.class) ? `function ${label}()` : label;
|
|
@@ -3915,25 +4179,14 @@ function renderCore(parsed, result, graph) {
|
|
|
3915
4179
|
if (ind.class === "Commit") {
|
|
3916
4180
|
return { content: `${ind.label} is a commit, not a code location — try "what did commit ${ind.label} touch".`, miss: true, ambiguous: false };
|
|
3917
4181
|
}
|
|
3918
|
-
const
|
|
3919
|
-
if (
|
|
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) {
|
|
4182
|
+
const line = definedAtLine(ind, result.site);
|
|
4183
|
+
if (!line) {
|
|
3928
4184
|
return {
|
|
3929
4185
|
content: `${ind.label} has no recorded code location in this index — it carries no source site, and nothing places it in a module.`,
|
|
3930
4186
|
miss: true, ambiguous: false,
|
|
3931
4187
|
};
|
|
3932
4188
|
}
|
|
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
|
-
};
|
|
4189
|
+
return { content: line, miss: false, ambiguous: false, matches: result.matches };
|
|
3937
4190
|
}
|
|
3938
4191
|
// when: newest touching commit + its date; undated commits are said out loud
|
|
3939
4192
|
// (honest miss with the precise re-index hint), never silently skipped.
|
|
@@ -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
|
-
|
|
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.
|
|
27
|
-
//
|
|
28
|
-
//
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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,
|