@polycode-projects/the-mechanical-code-talker 5.0.38 → 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/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.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.",
|
package/src/domain/ask.mjs
CHANGED
|
@@ -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]
|
|
701
|
-
let i =
|
|
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: `"
|
|
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
|
|
@@ -1555,22 +1574,55 @@ function reverseOverSet(graph, kind, entityType, objectIds) {
|
|
|
1555
1574
|
|
|
1556
1575
|
const GIT_PROV_REF_RE = /^git:(.+)$/i;
|
|
1557
1576
|
|
|
1558
|
-
/**
|
|
1559
|
-
*
|
|
1560
|
-
*
|
|
1561
|
-
*
|
|
1562
|
-
*
|
|
1563
|
-
*
|
|
1564
|
-
*
|
|
1565
|
-
*
|
|
1566
|
-
*
|
|
1567
|
-
*
|
|
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. */
|
|
1568
1616
|
function commitTouchCount(graph, objectIds) {
|
|
1569
1617
|
const shas = new Set(reverseOverSet(graph, "touches", "Commit", objectIds).map((c) => String(c.label || "").toLowerCase()));
|
|
1618
|
+
const attestable = provenanceAttestableShas(graph);
|
|
1570
1619
|
for (const id of objectIds) {
|
|
1571
1620
|
for (const ref of graph.byId.get(id)?.derived_from || []) {
|
|
1572
1621
|
const m = GIT_PROV_REF_RE.exec(String(ref || ""));
|
|
1573
|
-
if (m)
|
|
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);
|
|
1574
1626
|
}
|
|
1575
1627
|
}
|
|
1576
1628
|
return shas.size;
|
|
@@ -1932,6 +1984,10 @@ function evalSet(graph, ast, opts) {
|
|
|
1932
1984
|
const positive = new Set(forwardOverSet(graph, ast.kind, new Set([r.match.id])).map((x) => x.id));
|
|
1933
1985
|
return graph.individuals.filter((i) => i.class === universeType && !positive.has(i.id));
|
|
1934
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;
|
|
1935
1991
|
case "reverseSet": {
|
|
1936
1992
|
const ids = new Set(evalSet(graph, ast.inner, opts).map((i) => i.id));
|
|
1937
1993
|
return reverseOverSet(graph, ast.kind, ast.entityType, ids);
|
|
@@ -2148,7 +2204,7 @@ const COMMIT_FILTER_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
|
2148
2204
|
* here, beside the fully typed result, before render() flattens it all to a
|
|
2149
2205
|
* sentence; the session layer is what registers them into its record. */
|
|
2150
2206
|
function evalCommitFilter(graph, ast) {
|
|
2151
|
-
const { op, pivotRaw } = ast;
|
|
2207
|
+
const { op, pivotRaw, entityType = null } = ast;
|
|
2152
2208
|
const dateOf = (c) => String((c.attributes || []).find((a) => a.key === "date")?.value || "").slice(0, 10);
|
|
2153
2209
|
let pivotDate = null;
|
|
2154
2210
|
let pivotId = null;
|
|
@@ -2163,8 +2219,11 @@ function evalCommitFilter(graph, ast) {
|
|
|
2163
2219
|
pivotDate = dateOf(match);
|
|
2164
2220
|
}
|
|
2165
2221
|
}
|
|
2166
|
-
if (!pivotDate) return { compositeKind: "commitFilter", op, pivotRaw, pivotResolved: false, matches: [] };
|
|
2167
|
-
|
|
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
|
|
2168
2227
|
.filter((i) => i.class === "Commit" && i.id !== pivotId && dateOf(i))
|
|
2169
2228
|
.filter((c) => {
|
|
2170
2229
|
const d = dateOf(c);
|
|
@@ -2173,12 +2232,19 @@ function evalCommitFilter(graph, ast) {
|
|
|
2173
2232
|
if (op === "after") return d > pivotDate;
|
|
2174
2233
|
return d === pivotDate; // "on"
|
|
2175
2234
|
})
|
|
2176
|
-
.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;
|
|
2177
2242
|
const referents = [];
|
|
2178
2243
|
if (matches.length) {
|
|
2244
|
+
const setClass = touched ? entityType : "Commit";
|
|
2179
2245
|
referents.push({
|
|
2180
|
-
kind: "set", class:
|
|
2181
|
-
label: `${matches.length}
|
|
2246
|
+
kind: "set", class: setClass,
|
|
2247
|
+
label: `${matches.length} ${nounFor(setClass, matches.length)} ${op} ${pivotRaw}`,
|
|
2182
2248
|
ids: matches.map((c) => c.id),
|
|
2183
2249
|
attrs: { count: matches.length, op, ...(pivotId ? { pivot: pivotId } : {}) },
|
|
2184
2250
|
lane: "commitFilter",
|
|
@@ -2191,7 +2257,10 @@ function evalCommitFilter(graph, ast) {
|
|
|
2191
2257
|
lane: "commitFilter",
|
|
2192
2258
|
});
|
|
2193
2259
|
}
|
|
2194
|
-
return {
|
|
2260
|
+
return {
|
|
2261
|
+
compositeKind: "commitFilter", op, pivotRaw, pivotDate, pivotResolved: true,
|
|
2262
|
+
entityType, windowCount: inWindow.length, matches, referents,
|
|
2263
|
+
};
|
|
2195
2264
|
}
|
|
2196
2265
|
|
|
2197
2266
|
/** Temporal over a nested set: the commits that touched any member of the
|
|
@@ -2395,6 +2464,13 @@ function evalComposite(graph, ast, opts = {}) {
|
|
|
2395
2464
|
if (ast.node === "qualCheck") return evalQualCheck(graph, ast, opts);
|
|
2396
2465
|
if (ast.node === "universal") return evalUniversal(graph, ast, opts);
|
|
2397
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
|
+
}
|
|
2398
2474
|
// "how many commits touched <X>" — count against provenance attestation
|
|
2399
2475
|
// (commitTouchCount), not the bare touches-edge set evalSet(base) would
|
|
2400
2476
|
// give: see commitTouchCount's own doc for why the two can disagree.
|
|
@@ -2641,9 +2717,18 @@ function renderComposite(parsed, result, graph) {
|
|
|
2641
2717
|
miss: true, ambiguous: false, matches: [],
|
|
2642
2718
|
};
|
|
2643
2719
|
}
|
|
2644
|
-
if (!result.
|
|
2720
|
+
if (!result.windowCount) {
|
|
2645
2721
|
return { content: `no commits recorded ${result.op} ${result.pivotRaw}.`, miss: true, ambiguous: false, matches: [] };
|
|
2646
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
|
+
}
|
|
2647
2732
|
const dateOf = (c) => String((c.attributes || []).find((a) => a.key === "date")?.value || "");
|
|
2648
2733
|
const shown = result.matches.slice(0, HISTORY_CAP).map((c) => {
|
|
2649
2734
|
const day = dateOf(c).slice(0, 10);
|
package/src/domain/codegraph.mjs
CHANGED
|
@@ -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:
|
|
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}]` : ""}`);
|