@polycode-projects/the-mechanical-code-talker 5.0.37 → 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/package.json +1 -1
- package/src/domain/ask-vocab.mjs +52 -2
- package/src/domain/ask.mjs +10 -3
- 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 +104 -104
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/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
|
@@ -1480,7 +1480,14 @@ function siteDefiningModules(graph, objectIds) {
|
|
|
1480
1480
|
return uniqueById(out);
|
|
1481
1481
|
}
|
|
1482
1482
|
|
|
1483
|
-
|
|
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));
|
|
1484
1491
|
|
|
1485
1492
|
const askSiteMembersCache = new WeakMap();
|
|
1486
1493
|
|
|
@@ -1531,7 +1538,7 @@ function reverseOverSet(graph, kind, entityType, objectIds) {
|
|
|
1531
1538
|
const subjects = uniqueById(edges.map((e) => graph.byId.get(e.subject)).filter(Boolean));
|
|
1532
1539
|
if (!entityType || entityType === "Change") return subjects;
|
|
1533
1540
|
const direct = subjects.filter((s) => s.class === entityType);
|
|
1534
|
-
if (
|
|
1541
|
+
if (moduleMembershipHop(kind, entityType)) {
|
|
1535
1542
|
// Per-object, not per-set: "the module that defines {Widget, Button}" is the
|
|
1536
1543
|
// union of each symbol's defining module, so a set where one member carries
|
|
1537
1544
|
// the edge and another only a site must answer with both.
|
|
@@ -3749,7 +3756,7 @@ export function traverse(graph, parsed, { contextId = null, prev = null, pinnedO
|
|
|
3749
3756
|
matches = subjects;
|
|
3750
3757
|
} else {
|
|
3751
3758
|
const direct = subjects.filter((s) => s.class === entityType);
|
|
3752
|
-
const sited = direct.length || !
|
|
3759
|
+
const sited = direct.length || !moduleMembershipHop(kind, entityType) ? [] : siteDefiningModules(graph, new Set([gObjMatch.id]));
|
|
3753
3760
|
if (direct.length) {
|
|
3754
3761
|
matches = direct;
|
|
3755
3762
|
} else if (sited.length) {
|
|
@@ -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,
|
|
@@ -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
|
-
|
|
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
|
|
321
|
-
//
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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
|
|