@polycode-projects/the-mechanical-code-talker 5.0.15 → 5.0.16
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 +11 -3
- package/bin/tmct.mjs +16 -0
- package/corpus/LICENSES.json +3 -3
- package/corpus/domains/code/LICENSE-NOTICE +43 -0
- package/corpus/{seon → domains/code}/README.md +22 -24
- package/corpus/domains/code/vocab.json +43 -0
- package/corpus/reference/manifest.json +126 -126
- package/corpus/reference/shards/ref-00.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-01.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-02.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-03.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-04.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-05.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-06.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-07.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-08.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-09.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0a.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0b.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0c.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0d.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0e.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0f.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-10.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-11.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-12.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-13.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-14.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-15.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-16.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-17.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-18.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-19.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1a.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1b.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1c.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1d.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1e.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1f.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-20.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-21.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-22.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-23.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-24.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-25.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-26.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-27.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-28.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-29.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2a.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2b.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2c.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2d.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2e.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2f.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-30.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-31.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-32.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-33.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-34.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-35.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-36.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-37.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-38.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-39.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3a.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3b.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3c.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3d.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3e.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3f.jsonl.gz +0 -0
- package/corpus/tier2/vocab-empty.json +6 -0
- package/data/templates/responses.jsonl +3 -0
- package/package.json +17 -1
- package/src/adapters/corpus/conceptnet.mjs +7 -3
- package/src/adapters/corpus/courtesy.mjs +129 -0
- package/src/adapters/corpus/research-source.mjs +120 -0
- package/src/adapters/corpus/wikidata-live.mjs +262 -0
- package/src/adapters/corpus/wikipedia-live.mjs +52 -108
- package/src/domain/codegraph.mjs +10 -2
- package/src/domain/grammar/lexicon-core.json +1 -0
- package/src/domain/reference-pack.mjs +61 -9
- package/src/services/chat-session.mjs +48 -7
- package/src/services/chat.mjs +359 -115
- package/src/services/extensions.mjs +203 -3
- package/src/services/init.mjs +6 -5
- package/src/services/lane-vocab-data.mjs +56 -0
- package/src/surfaces/web/claims-browser-entry.mjs +26 -0
- package/src/surfaces/web/memory-ask-browser.bundle.js +130 -128
- package/src/surfaces/web/planner-instances.mjs +152 -0
- package/src/tools/handlers/tmct-untested.mjs +2 -2
- package/src/tools/server.mjs +9 -4
- package/corpus/seon/LICENSE-NOTICE +0 -37
- /package/corpus/{seon → domains/code}/concepts.jsonl +0 -0
- /package/corpus/{seon → domains/code}/definitions.jsonl +0 -0
- /package/corpus/{seon → domains/code}/relations.jsonl +0 -0
package/src/services/chat.mjs
CHANGED
|
@@ -46,7 +46,7 @@ import { setConstructionBanks } from "../domain/interpret/strategies/constructio
|
|
|
46
46
|
import { nlpAdapter } from "../adapters/ask-nlp.mjs";
|
|
47
47
|
import { readConstructionFiles } from "../adapters/corpus/construction-banks.mjs";
|
|
48
48
|
import { fuzzyMatchInSet, fuzzyBound } from "../domain/interpret/fuzzy.mjs";
|
|
49
|
-
import { loadLexicon, lookupNoun, readsAsIndividualName } from "../domain/grammar/lexicon.mjs";
|
|
49
|
+
import { loadLexicon, lookupNoun, lookupVerb, lookupAdjective, lookupProperName, readsAsIndividualName } from "../domain/grammar/lexicon.mjs";
|
|
50
50
|
import { pickPhrase } from "../domain/answer-variants.mjs";
|
|
51
51
|
import {
|
|
52
52
|
REFERENCE_PACK_NAME, cleanMissReferenceTerm, renderReferenceAnswer, referenceProvenanceTag,
|
|
@@ -461,28 +461,11 @@ export function asBareCommand(line) {
|
|
|
461
461
|
// header (individuals grouped by class, relation groups by predicate), not by
|
|
462
462
|
// dispatching to the ask engine. Deterministic, fully in-ethos. ----
|
|
463
463
|
|
|
464
|
-
/**
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
package: "Package", packages: "Package",
|
|
470
|
-
method: "Method", methods: "Method",
|
|
471
|
-
attribute: "Attribute", attributes: "Attribute",
|
|
472
|
-
variable: "GlobalVariable", variables: "GlobalVariable", global: "GlobalVariable", globals: "GlobalVariable",
|
|
473
|
-
commit: "Commit", commits: "Commit",
|
|
474
|
-
session: "Session", sessions: "Session",
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
/** class → [singular, plural] display noun, for echoing a count back in English. */
|
|
478
|
-
const CLASS_LABELS = {
|
|
479
|
-
Class: ["class", "classes"], Function: ["function", "functions"],
|
|
480
|
-
Module: ["module", "modules"], Package: ["package", "packages"],
|
|
481
|
-
Method: ["method", "methods"],
|
|
482
|
-
Attribute: ["attribute", "attributes"], GlobalVariable: ["variable", "variables"],
|
|
483
|
-
Commit: ["commit", "commits"], Session: ["session", "sessions"],
|
|
484
|
-
};
|
|
485
|
-
const classNoun = (cls, n) => { const [s, p] = CLASS_LABELS[cls] || [cls, `${cls}s`]; return n === 1 ? s : p; };
|
|
464
|
+
/** class → [singular, plural] display noun, for echoing a count back in English.
|
|
465
|
+
* `classLabels` comes from the active session's merged lane vocabulary (empty
|
|
466
|
+
* by default — see resolveLaneVocab/mergedLaneVocab, extensions.mjs); a
|
|
467
|
+
* session with no code pack active never falls back to a hardcoded table. */
|
|
468
|
+
const classNoun = (cls, n, classLabels) => { const [s, p] = classLabels[cls] || [cls, `${cls}s`]; return n === 1 ? s : p; };
|
|
486
469
|
|
|
487
470
|
/** Count individuals of a class in the loaded graph (live, not the header field).
|
|
488
471
|
* No individual is ever stored with class "Package" — packages are the
|
|
@@ -494,14 +477,29 @@ const countClass = (graph, cls) => (cls === "Package"
|
|
|
494
477
|
|
|
495
478
|
/** Every kind the counter answers to, as a human list — what it can count once a
|
|
496
479
|
* graph is loaded, as opposed to countableKinds, which is what THIS graph holds. */
|
|
497
|
-
const
|
|
498
|
-
.map((cls) =>
|
|
480
|
+
const countableKindWords = (countNouns, classLabels) => [...new Set(Object.values(countNouns))]
|
|
481
|
+
.map((cls) => classLabels[cls]?.[1] ?? `${cls}s`);
|
|
499
482
|
|
|
500
483
|
/** The classes this graph can actually count, as a human list ("classes, functions, …"). */
|
|
501
|
-
function countableKinds(graph) {
|
|
484
|
+
function countableKinds(graph, classLabels) {
|
|
502
485
|
const present = new Set(graph.individuals.map((i) => i.class).filter(Boolean));
|
|
503
486
|
if (present.has("Module")) present.add("Package");
|
|
504
|
-
return Object.keys(
|
|
487
|
+
return Object.keys(classLabels).filter((c) => present.has(c)).map((c) => classLabels[c][1]);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/** The shipped code pack's own count-noun table (extensions.mjs's
|
|
491
|
+
* defaultCodeLaneVocab, memoized), loaded unconditionally — the PRECEDENCE
|
|
492
|
+
* guard a handful of taught-fact lanes use to defer to the graph-count lanes
|
|
493
|
+
* for a word like "class"/"function" ("answerCount owns this noun, don't
|
|
494
|
+
* answer it as a taught fact instead"). Every caller of this guard already
|
|
495
|
+
* runs only once the code domain is active (either directly gated, or
|
|
496
|
+
* reached only after answerCount itself returned a real count), so reading
|
|
497
|
+
* the shipped default here — rather than threading the session's own merge
|
|
498
|
+
* through each one — reproduces today's precedence exactly, with the noun
|
|
499
|
+
* table itself no longer duplicated as a chat.mjs literal. */
|
|
500
|
+
async function codeCountNouns() {
|
|
501
|
+
const { defaultCodeLaneVocab } = await import("./extensions.mjs");
|
|
502
|
+
return (await defaultCodeLaneVocab()).countNouns;
|
|
505
503
|
}
|
|
506
504
|
|
|
507
505
|
/** A discourse-anaphoric count/list head — "how many [of] those/them/these",
|
|
@@ -599,9 +597,24 @@ const RESTRICTOR_VERB_RE = new RegExp(
|
|
|
599
597
|
*
|
|
600
598
|
* `uiContext` picks the empty-graph remedy: only a terminal session can run
|
|
601
599
|
* the index/--repo commands, so a page names what it can actually offer
|
|
602
|
-
* instead (see vocabExampleHint's own split).
|
|
603
|
-
|
|
600
|
+
* instead (see vocabExampleHint's own split).
|
|
601
|
+
*
|
|
602
|
+
* `codeDomainActive` (the session-level predicate, see below) gates the
|
|
603
|
+
* whole lane: with no code domain active, this returns null unconditionally
|
|
604
|
+
* so a bare "how many classes are there" falls through to the taught-class
|
|
605
|
+
* count and the ordinary miss instead of a code-graph-flavored decline (or,
|
|
606
|
+
* worse, "0 classes." for a class nothing here actually holds). Omitted
|
|
607
|
+
* (null), it derives from the graph alone — every existing caller that
|
|
608
|
+
* passes a real code graph keeps its answer unchanged.
|
|
609
|
+
*
|
|
610
|
+
* `countNouns`/`classLabels` are this session's merged lane vocabulary
|
|
611
|
+
* (chat-session.mjs's resolveLaneVocab, threaded via ctx.laneVocab) — empty
|
|
612
|
+
* by default, so a caller that omits them alongside an inactive domain never
|
|
613
|
+
* sees code-graph vocabulary. */
|
|
614
|
+
export function answerCount(graph, query, { uiContext = "cli", codeDomainActive = null, countNouns = {}, classLabels = {} } = {}) {
|
|
604
615
|
if (!graph) return null;
|
|
616
|
+
const domainActive = codeDomainActive ?? (moduleCountOf(graph) > 0);
|
|
617
|
+
if (!domainActive) return null;
|
|
605
618
|
// ANAPHORIC counts ("how many of those are tested", "count them", "how many of
|
|
606
619
|
// them") count the PREVIOUS answer's set, not a graph kind — decline so the turn
|
|
607
620
|
// falls through to the ask engine's anaphora node (which threads `prev`). Without
|
|
@@ -615,14 +628,14 @@ export function answerCount(graph, query, { uiContext = "cli" } = {}) {
|
|
|
615
628
|
const m = String(query).match(/\b(?:how many|number of|count(?:\s+the)?)\s+([a-z]+)\b/i);
|
|
616
629
|
if (!m) return null;
|
|
617
630
|
const noun = m[1].toLowerCase();
|
|
618
|
-
const cls =
|
|
631
|
+
const cls = countNouns[noun];
|
|
619
632
|
if (cls) {
|
|
620
633
|
const tail = String(query).slice(m.index + m[0].length);
|
|
621
634
|
if (RESTRICTOR_VERB_RE.test(tail)) return null;
|
|
622
635
|
if (countTailIsUnhandledRestrictor(tail)) return null;
|
|
623
636
|
}
|
|
624
637
|
if (!cls) {
|
|
625
|
-
const kinds = countableKinds(graph);
|
|
638
|
+
const kinds = countableKinds(graph, classLabels);
|
|
626
639
|
// When no code graph is loaded, countableKinds(graph) is genuinely
|
|
627
640
|
// empty — an honest, non-dangling message pointing at how to load one.
|
|
628
641
|
if (!kinds.length) {
|
|
@@ -635,7 +648,7 @@ export function answerCount(graph, query, { uiContext = "cli" } = {}) {
|
|
|
635
648
|
// promise that indexing would let it count moons. The REMEDY is about the
|
|
636
649
|
// session, and a terminal can act on it, so it stays — worded as its own
|
|
637
650
|
// fact rather than as the answer to what was asked.
|
|
638
|
-
return `I can't count "${noun}" — I count the kinds a code graph holds: ${
|
|
651
|
+
return `I can't count "${noun}" — I count the kinds a code graph holds: ${countableKindWords(countNouns, classLabels).join(", ")}. `
|
|
639
652
|
+ `This session has no code graph loaded either — index this repo with "tmct index", `
|
|
640
653
|
+ `point me at another with --repo, or run "npm run example:mini".`;
|
|
641
654
|
}
|
|
@@ -643,15 +656,15 @@ export function answerCount(graph, query, { uiContext = "cli" } = {}) {
|
|
|
643
656
|
`Try "how many classes are there".`;
|
|
644
657
|
}
|
|
645
658
|
const n = countClass(graph, cls);
|
|
646
|
-
return `${n} ${classNoun(cls, n)}.`;
|
|
659
|
+
return `${n} ${classNoun(cls, n, classLabels)}.`;
|
|
647
660
|
}
|
|
648
661
|
|
|
649
662
|
/** singular+plural display forms for the edge-nominalized nouns answerEdgeCount
|
|
650
663
|
* (below) actually answers — a small subset of EDGE_NOUN_TO_METRIC's keys, the
|
|
651
664
|
* ones that read as a real countable noun ("3 callers.") rather than a
|
|
652
665
|
* participle only natural in a superlative ("most USED", not "how many used").
|
|
653
|
-
* A key with no entry here echoes the user's own word unchanged (
|
|
654
|
-
*
|
|
666
|
+
* A key with no entry here echoes the user's own word unchanged (the same
|
|
667
|
+
* safe-default shape classNoun's own fallback uses above). */
|
|
655
668
|
const EDGE_NOUN_LABELS = {
|
|
656
669
|
test: ["test", "tests"], tests: ["test", "tests"],
|
|
657
670
|
importers: ["importer", "importers"], dependents: ["dependent", "dependents"],
|
|
@@ -702,8 +715,8 @@ function extractEdgeCountEntity(tail, metric) {
|
|
|
702
715
|
|
|
703
716
|
/** Bare "how many <edge-noun> <verb> <entity>" / "how many <edge-noun> does
|
|
704
717
|
* <entity> have" — "how many tests cover X", "how many importers does X
|
|
705
|
-
* have", "how many callers does X have". answerCount's own
|
|
706
|
-
*
|
|
718
|
+
* have", "how many callers does X have". answerCount's own count-noun table
|
|
719
|
+
* only maps a counted noun to a graph INDIVIDUAL CLASS (Module/Class/…);
|
|
707
720
|
* an edge-nominalized noun like "tests"/"importers"/"callers" names an EDGE
|
|
708
721
|
* KIND instead — ask-vocab.mjs's EDGE_NOUN_TO_METRIC, the SAME table the
|
|
709
722
|
* superlative lane ("which module has the most tests") reads. This reuses
|
|
@@ -714,8 +727,8 @@ function extractEdgeCountEntity(tail, metric) {
|
|
|
714
727
|
*
|
|
715
728
|
* Checked BEFORE answerCount in runTurn so it gets first look; declines
|
|
716
729
|
* (returns null, letting answerCount's existing message stand) whenever:
|
|
717
|
-
* - the noun isn't edge-nominalized at all (a
|
|
718
|
-
* unknown), or
|
|
730
|
+
* - the noun isn't edge-nominalized at all (a real graph-countable class, or
|
|
731
|
+
* truly unknown), or
|
|
719
732
|
* - no entity term could be extracted from the tail
|
|
720
733
|
* (extractEdgeCountEntity), or
|
|
721
734
|
* - the extracted term doesn't resolve to exactly one graph entity.
|
|
@@ -724,15 +737,23 @@ function extractEdgeCountEntity(tail, metric) {
|
|
|
724
737
|
* named entity in the tail) declines here and keeps answerCount's existing
|
|
725
738
|
* "I can't count 'tests'" honest miss — what a GLOBAL edge count would even
|
|
726
739
|
* mean (every test edge in the graph? distinct test modules? distinct tested
|
|
727
|
-
* modules?) is a genuine, undecided design question.
|
|
728
|
-
|
|
740
|
+
* modules?) is a genuine, undecided design question.
|
|
741
|
+
*
|
|
742
|
+
* `codeDomainActive`: same gate as answerCount's own — with no code domain
|
|
743
|
+
* active, this declines unconditionally rather than reading an edge kind off
|
|
744
|
+
* a graph nothing here actually indexed. `countNouns` is the session's merged
|
|
745
|
+
* lane vocabulary (see answerCount's own docblock) — the same table, so this
|
|
746
|
+
* lane defers to answerCount for exactly the nouns answerCount owns. */
|
|
747
|
+
async function answerEdgeCount(graph, query, { codeDomainActive = null, countNouns = {} } = {}) {
|
|
729
748
|
if (!graph) return null;
|
|
749
|
+
const domainActive = codeDomainActive ?? (moduleCountOf(graph) > 0);
|
|
750
|
+
if (!domainActive) return null;
|
|
730
751
|
const q = String(query);
|
|
731
752
|
if (ANAPHORA_COUNT_RE.test(q) || IMPLICIT_ANAPHORA_COUNT_RE.test(q.trim())) return null;
|
|
732
753
|
const m = q.match(/\b(?:how many|number of|count(?:\s+the)?)\s+([a-z]+)\b/i);
|
|
733
754
|
if (!m) return null;
|
|
734
755
|
const noun = m[1].toLowerCase();
|
|
735
|
-
if (
|
|
756
|
+
if (countNouns[noun]) return null; // a real graph class — answerCount owns it
|
|
736
757
|
const metric = EDGE_NOUN_TO_METRIC[noun];
|
|
737
758
|
if (!metric) return null; // not edge-nominalized either — answerCount's "I can't count" stands
|
|
738
759
|
const term = extractEdgeCountEntity(q.slice(m.index + m[0].length), metric);
|
|
@@ -758,7 +779,8 @@ async function countFromFacts(graph, memoryDir, query, biasByBundle = {}, cache
|
|
|
758
779
|
const m = String(query).match(/\b(?:how many|number of|count(?:\s+the)?)\s+([a-z]+)\b/i);
|
|
759
780
|
if (!m) return null;
|
|
760
781
|
const asked = m[1].toLowerCase();
|
|
761
|
-
|
|
782
|
+
const countNouns = await codeCountNouns();
|
|
783
|
+
if (countNouns[asked]) return null; // a real graph kind — answerCount owns it
|
|
762
784
|
let normFactTerm;
|
|
763
785
|
try { ({ normFactTerm } = await import("../adapters/memory/core.mjs")); } catch { return null; }
|
|
764
786
|
const objVariants = factTermVariants(normFactTerm, asked);
|
|
@@ -768,7 +790,7 @@ async function countFromFacts(graph, memoryDir, query, biasByBundle = {}, cache
|
|
|
768
790
|
// countable graph class (rankByBiasThenTrust: bias-tied/unconfigured degrades
|
|
769
791
|
// to the same trust-desc scan this always ran).
|
|
770
792
|
for (const f of rankByBiasThenTrust(isa, biasByBundle)) {
|
|
771
|
-
const cls =
|
|
793
|
+
const cls = countNouns[String(f.subject).toLowerCase()];
|
|
772
794
|
if (cls) { const n = countClass(graph, cls); return `${n} ${asked}.`; }
|
|
773
795
|
}
|
|
774
796
|
return null;
|
|
@@ -778,7 +800,7 @@ async function countFromFacts(graph, memoryDir, query, biasByBundle = {}, cache
|
|
|
778
800
|
// few"/"every"), NEVER real cardinality counting. Dispatched ahead of
|
|
779
801
|
// answerCount in runTurn (else its noun-scan regex would short-circuit to an
|
|
780
802
|
// "I can't count 'Xs'" miss first). Claims authority only when the subject
|
|
781
|
-
// isn't a real graph-countable class (
|
|
803
|
+
// isn't a real graph-countable class (codeCountNouns) AND tmct has some
|
|
782
804
|
// isa-family fact about it — otherwise falls through to answerCount untouched.
|
|
783
805
|
const HOW_MANY_ARE_RE = /^how\s+many\s+([\w-]+)\s+(?:are|is)\s+(.+?)[?.!\s]*$/i;
|
|
784
806
|
async function answerQuantifierRecall(memoryDir, query, biasByBundle = {}, cache = null) {
|
|
@@ -786,7 +808,7 @@ async function answerQuantifierRecall(memoryDir, query, biasByBundle = {}, cache
|
|
|
786
808
|
const m = String(query).trim().match(HOW_MANY_ARE_RE);
|
|
787
809
|
if (!m) return null;
|
|
788
810
|
const asked = m[1].toLowerCase();
|
|
789
|
-
if (
|
|
811
|
+
if ((await codeCountNouns())[asked]) return null; // a real graph-countable class — answerCount owns it
|
|
790
812
|
let normFactTerm;
|
|
791
813
|
try { ({ normFactTerm } = await import("../adapters/memory/core.mjs")); } catch { return null; }
|
|
792
814
|
const subjVariants = factTermVariants(normFactTerm, asked);
|
|
@@ -1011,7 +1033,7 @@ function taughtMembersUnder(isa, children, variants, biasByBundle) {
|
|
|
1011
1033
|
async function longestTaughtClassInRun(memoryDir, nounRun, trailing, biasByBundle, cache) {
|
|
1012
1034
|
const words = String(nounRun || "").trim().split(/\s+/).filter(Boolean);
|
|
1013
1035
|
if (!words.length) return null;
|
|
1014
|
-
if (
|
|
1036
|
+
if ((await codeCountNouns())[words[0].toLowerCase()]) return null; // a real graph-countable class — the code lanes own it
|
|
1015
1037
|
let normFactTerm;
|
|
1016
1038
|
try { ({ normFactTerm } = await import("../adapters/memory/core.mjs")); } catch { return null; }
|
|
1017
1039
|
const rows = await factRows(memoryDir, cache);
|
|
@@ -1065,7 +1087,8 @@ async function answerTaughtClassCount(memoryDir, query, biasByBundle = {}, cache
|
|
|
1065
1087
|
// one class-level fact. Only a DIRECT member triggers the deferral: an
|
|
1066
1088
|
// inherited member reached through a taught subclass is still a genuine
|
|
1067
1089
|
// count of this class's membership.
|
|
1068
|
-
|
|
1090
|
+
const countNouns = await codeCountNouns();
|
|
1091
|
+
if (hit.directMembers.some((f) => countNouns[String(f.subject).toLowerCase()])) return null;
|
|
1069
1092
|
const n = new Set(hit.members.map((f) => String(f.subject).toLowerCase())).size;
|
|
1070
1093
|
const noun = n === 1 ? hit.asked.replace(/s$/, "") : hit.asked;
|
|
1071
1094
|
// Sense reporting: cluster the classes the members were found under,
|
|
@@ -1880,12 +1903,21 @@ const T_GREETING_EMPTY = "conversational-greeting-empty";
|
|
|
1880
1903
|
const T_GREETING_EMPTY_BROWSER = "conversational-greeting-empty-browser";
|
|
1881
1904
|
const T_ORIENTATION_EMPTY = "orientation-empty";
|
|
1882
1905
|
const T_ORIENTATION_EMPTY_BROWSER = "orientation-empty-browser";
|
|
1883
|
-
/**
|
|
1884
|
-
*
|
|
1885
|
-
*
|
|
1886
|
-
*
|
|
1906
|
+
/** No-code-domain siblings of the two CLI ids just above, read only when
|
|
1907
|
+
* codeDomainActive is false: the browser twins already name no code
|
|
1908
|
+
* vocabulary (a page never had a `--repo`/`tmct index` remedy to offer), so
|
|
1909
|
+
* they serve both domain states unchanged — only the CLI wording needed a
|
|
1910
|
+
* second, domain-gated version. */
|
|
1911
|
+
const T_GREETING_EMPTY_NEUTRAL = "conversational-greeting-empty-neutral";
|
|
1912
|
+
const T_ORIENTATION_EMPTY_NEUTRAL = "orientation-empty-neutral";
|
|
1913
|
+
/** IDENTITY answers — self-description and the "no LLM" clarification.
|
|
1914
|
+
* identity-self DOES vary with uiContext (its `--repo <path>` clause is
|
|
1915
|
+
* CLI-only) and now with codeDomainActive too: identity-self-neutral drops
|
|
1916
|
+
* the code-graph clause outright and serves both ui contexts, since neither
|
|
1917
|
+
* had anything left to differ on once that clause is gone. */
|
|
1887
1918
|
const T_IDENTITY_SELF = "identity-self";
|
|
1888
1919
|
const T_IDENTITY_SELF_BROWSER = "identity-self-browser";
|
|
1920
|
+
const T_IDENTITY_SELF_NEUTRAL = "identity-self-neutral";
|
|
1889
1921
|
const T_IDENTITY_NOT_LLM = "identity-not-an-llm";
|
|
1890
1922
|
const T_IDENTITY_NO_FEELINGS = "identity-no-feelings";
|
|
1891
1923
|
/** Confirms the honest-miss promise itself when a user asks about it directly
|
|
@@ -2280,6 +2312,20 @@ export function renderVerbose(last) {
|
|
|
2280
2312
|
* apply to hand-written prose, applied here to which DATA row gets rendered. */
|
|
2281
2313
|
const uiTemplateId = (uiContext, id, browserId) => (uiContext === "browser" ? browserId : id);
|
|
2282
2314
|
|
|
2315
|
+
/** Picks among an empty-graph surface's three template ids: the browser id
|
|
2316
|
+
* (already free of code vocabulary, so it serves both domain states), or —
|
|
2317
|
+
* on the CLI — the domain-active id (today's wording, verbatim) versus the
|
|
2318
|
+
* neutral one when codeDomainActive is false. */
|
|
2319
|
+
const emptyGraphTemplateId = (uiContext, codeDomainActive, activeId, neutralId, browserId) =>
|
|
2320
|
+
(uiContext === "browser" ? browserId : (codeDomainActive ? activeId : neutralId));
|
|
2321
|
+
|
|
2322
|
+
/** identity-self doesn't vary with graph state, only with uiContext (CLI vs
|
|
2323
|
+
* browser) and codeDomainActive (whether its code-graph clause applies at
|
|
2324
|
+
* all) — the neutral id serves both ui contexts, since dropping that clause
|
|
2325
|
+
* leaves nothing left for them to differ on. */
|
|
2326
|
+
const identitySelfTemplateId = (uiContext, codeDomainActive) =>
|
|
2327
|
+
(codeDomainActive ? uiTemplateId(uiContext, T_IDENTITY_SELF, T_IDENTITY_SELF_BROWSER) : T_IDENTITY_SELF_NEUTRAL);
|
|
2328
|
+
|
|
2283
2329
|
/** The "here's what you CAN ask" tail on a decline that names no term of its own
|
|
2284
2330
|
* (the SQL-statement and arithmetic shapes below). `ctx.vocabHint` already
|
|
2285
2331
|
* carries the session-gated vocabulary/teach pointer, so only the CODE-graph
|
|
@@ -2375,7 +2421,7 @@ function conversationalTurn(line, ctx) {
|
|
|
2375
2421
|
// over-promising "ask me about this codebase". Phrase-specific variants (good
|
|
2376
2422
|
// morning, hello there) keep their wording; only the default greeting swaps.
|
|
2377
2423
|
const id = (!T_GREETING_BY_PHRASE[greetHit] && noCodeGraph(ctx.graph))
|
|
2378
|
-
?
|
|
2424
|
+
? emptyGraphTemplateId(ctx.uiContext, ctx.codeDomainActive, T_GREETING_EMPTY, T_GREETING_EMPTY_NEUTRAL, T_GREETING_EMPTY_BROWSER)
|
|
2379
2425
|
: (T_GREETING_BY_PHRASE[greetHit] || T_GREETING);
|
|
2380
2426
|
note(ctx.trace, `pattern: template "${id}" (data/templates/responses.jsonl)`);
|
|
2381
2427
|
return mk(t(id, { vocabHint: ctx.vocabHint }), { lane: "greeting" });
|
|
@@ -2435,7 +2481,7 @@ function conversationalTurn(line, ctx) {
|
|
|
2435
2481
|
if (identityPhraseMatch(raw)) {
|
|
2436
2482
|
note(ctx.trace, "goal: identity — who/what tmct is, not a capability listing");
|
|
2437
2483
|
note(ctx.trace, "lane: conversational — identity (IDENTITY_PHRASES closed set)");
|
|
2438
|
-
return mk(t(
|
|
2484
|
+
return mk(t(identitySelfTemplateId(ctx.uiContext, ctx.codeDomainActive), { vocabHint: ctx.vocabHint }), { lane: "help" });
|
|
2439
2485
|
}
|
|
2440
2486
|
{
|
|
2441
2487
|
const metaHit = META_COMMAND_ANSWERS.find(([re]) => re.test(raw));
|
|
@@ -2455,7 +2501,7 @@ function conversationalTurn(line, ctx) {
|
|
|
2455
2501
|
|| CAPABILITY_PHRASES.some((re) => re.test(applyPreambleFrames(raw))) || ORIENT_OPENERS.has(q)) {
|
|
2456
2502
|
note(ctx.trace, "goal: get oriented — what can tmct answer, how do I start");
|
|
2457
2503
|
note(ctx.trace, "lane: conversational — help/orientation (CAPABILITY_PHRASES/ORIENT_OPENERS / bare help / ?)");
|
|
2458
|
-
return mk(orientationAnswer(ctx.templates, ctx.graph, ctx.vocabHint, ctx.uiContext), { lane: "help" });
|
|
2504
|
+
return mk(orientationAnswer(ctx.templates, ctx.graph, ctx.vocabHint, ctx.uiContext, ctx.codeDomainActive), { lane: "help" });
|
|
2459
2505
|
}
|
|
2460
2506
|
// Fuzzy-typo fallback (A4): every exact/collapsed closed-set lookup above missed —
|
|
2461
2507
|
// try a bounded edit-distance match against the flattened conversational phrase
|
|
@@ -2472,9 +2518,9 @@ function conversationalTurn(line, ctx) {
|
|
|
2472
2518
|
if (bucket === "bye") return mk(t(T_FAREWELL), { end: true });
|
|
2473
2519
|
if (bucket === "thanks") return mk(t(T_THANKS), { lane: "thanks" });
|
|
2474
2520
|
if (bucket === "identity") {
|
|
2475
|
-
return mk(t(
|
|
2521
|
+
return mk(t(identitySelfTemplateId(ctx.uiContext, ctx.codeDomainActive), { vocabHint: ctx.vocabHint }), { lane: "help" });
|
|
2476
2522
|
}
|
|
2477
|
-
if (bucket === "capability") return mk(orientationAnswer(ctx.templates, ctx.graph, ctx.vocabHint, ctx.uiContext), { lane: "help" });
|
|
2523
|
+
if (bucket === "capability") return mk(orientationAnswer(ctx.templates, ctx.graph, ctx.vocabHint, ctx.uiContext, ctx.codeDomainActive), { lane: "help" });
|
|
2478
2524
|
const id = (!T_GREETING_BY_PHRASE[fuzzyHit] && noCodeGraph(ctx.graph))
|
|
2479
2525
|
? uiTemplateId(ctx.uiContext, T_GREETING_EMPTY, T_GREETING_EMPTY_BROWSER)
|
|
2480
2526
|
: (T_GREETING_BY_PHRASE[fuzzyHit] || T_GREETING);
|
|
@@ -2496,6 +2542,18 @@ export { moduleCountOf };
|
|
|
2496
2542
|
* orientation/greeting only fires when we actually hold an empty graph. */
|
|
2497
2543
|
export const noCodeGraph = (graph) => !!graph && moduleCountOf(graph) === 0;
|
|
2498
2544
|
|
|
2545
|
+
/** Whether THIS session's loaded graph or active bundles carry any code-domain
|
|
2546
|
+
* content: a graph with at least one Module individual, or the seon
|
|
2547
|
+
* code-domain corpus active in this session's extensions. Computed once per
|
|
2548
|
+
* session (chat-session.mjs) and threaded through runTurn's ctx so a lane
|
|
2549
|
+
* that would otherwise speak code vocabulary with nothing here to ground it
|
|
2550
|
+
* — a count, a banner clause, a code-shaped miss, a help row — reads this
|
|
2551
|
+
* instead of asking the graph directly. A null/absent graph and no active
|
|
2552
|
+
* seon bundle reads as inactive (the safe default: no evidence, no domain). */
|
|
2553
|
+
export function codeDomainActive({ graph, seonActive = false } = {}) {
|
|
2554
|
+
return (!!graph && moduleCountOf(graph) > 0) || !!seonActive;
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2499
2557
|
/** LIVE orientation examples: the example queries on the orientation card name
|
|
2500
2558
|
* entities from the LOADED graph — the sorted-first Module label and the
|
|
2501
2559
|
* sorted-first Function/Method label, deterministically — so a stranger who
|
|
@@ -2534,10 +2592,11 @@ function orientationExamples(graph) {
|
|
|
2534
2592
|
/** The orientation surface, module-aware: the empty variant (→ the provably-correct
|
|
2535
2593
|
* vocabulary hint + --repo/tmct init, or its browser twin) when there's no code
|
|
2536
2594
|
* graph, the standard one (with live {example1}/{example2} query examples from
|
|
2537
|
-
* the loaded graph) otherwise.
|
|
2538
|
-
|
|
2595
|
+
* the loaded graph) otherwise. `codeDomainActive` picks the empty variant's own
|
|
2596
|
+
* wording: today's code-structure clause when true, a neutral one when false. */
|
|
2597
|
+
function orientationAnswer(templates, graph, vocabHint, uiContext = "cli", codeDomainActive = false) {
|
|
2539
2598
|
if (noCodeGraph(graph)) {
|
|
2540
|
-
const id =
|
|
2599
|
+
const id = emptyGraphTemplateId(uiContext, codeDomainActive, T_ORIENTATION_EMPTY, T_ORIENTATION_EMPTY_NEUTRAL, T_ORIENTATION_EMPTY_BROWSER);
|
|
2541
2600
|
return tRender(templates, id, { vocabHint }) ?? TEMPLATES_UNAVAILABLE;
|
|
2542
2601
|
}
|
|
2543
2602
|
return tRender(templates, T_ORIENTATION, orientationExamples(graph)) ?? TEMPLATES_UNAVAILABLE;
|
|
@@ -2558,15 +2617,18 @@ const ORIENTATION_EMPTY_FALLBACK_BROWSER = "I'm tmct — a deterministic, offlin
|
|
|
2558
2617
|
* through the SAME template (T_ORIENTATION_EMPTY/T_ORIENTATION_EMPTY_BROWSER)
|
|
2559
2618
|
* conversationalTurn's orientation branch uses, so there is exactly one copy of
|
|
2560
2619
|
* that wording to keep in sync, not two hand-duplicated strings. */
|
|
2561
|
-
function orientationText(graph, templates, vocabHint, uiContext = "cli") {
|
|
2620
|
+
function orientationText(graph, templates, vocabHint, uiContext = "cli", codeDomainActive = false) {
|
|
2562
2621
|
// A null (never-loaded) graph reads as "unknown, not empty" to noCodeGraph,
|
|
2563
2622
|
// which is the right call for the greeting/orientation CARD — but there is no
|
|
2564
2623
|
// entity count to render from one either, so the empty wording is the only
|
|
2565
2624
|
// truthful thing left to say. Without this the entity tally below threw on a
|
|
2566
2625
|
// graph-less runTurn.
|
|
2567
2626
|
if (!graph || noCodeGraph(graph)) {
|
|
2568
|
-
const id =
|
|
2569
|
-
|
|
2627
|
+
const id = emptyGraphTemplateId(uiContext, codeDomainActive, T_ORIENTATION_EMPTY, T_ORIENTATION_EMPTY_NEUTRAL, T_ORIENTATION_EMPTY_BROWSER);
|
|
2628
|
+
// ORIENTATION_EMPTY_FALLBACK_BROWSER already carries no code vocabulary,
|
|
2629
|
+
// so it doubles as the neutral CLI fallback too — only the domain-active
|
|
2630
|
+
// CLI branch needs its own (code-pointer-carrying) fallback text.
|
|
2631
|
+
const fallback = (uiContext === "browser" || !codeDomainActive) ? ORIENTATION_EMPTY_FALLBACK_BROWSER : ORIENTATION_EMPTY_FALLBACK;
|
|
2570
2632
|
return tRender(templates, id, { vocabHint }) ?? fallback;
|
|
2571
2633
|
}
|
|
2572
2634
|
const by = (cls) => (graph.individuals || []).filter((i) => (i.class || "") === cls).length;
|
|
@@ -4448,16 +4510,71 @@ async function generalVerbTeach(payload) {
|
|
|
4448
4510
|
// polarity prefix swap. Negating first would hand the fold an mgxneg: CURIE
|
|
4449
4511
|
// its /^mgx:[a-z]+$/ guard rejects, stranding "on water" inside the object of
|
|
4450
4512
|
// "a penguin cannot rest on water" — the very bug the fold exists to prevent.
|
|
4451
|
-
const
|
|
4513
|
+
const mintedPredicate = await generalVerbPredicate(verb);
|
|
4514
|
+
const folded = foldPrepositionIntoPredicate(mintedPredicate, objectRaw);
|
|
4452
4515
|
// "the" strips alongside "a"/"an": the read-back side already strips a
|
|
4453
4516
|
// leading determiner off the queried term, so leaving it on here stores an
|
|
4454
4517
|
// object no question can match.
|
|
4455
4518
|
const object = folded.object.replace(/^(?:an?|the)\s+/i, "").trim();
|
|
4456
4519
|
if (!subject || !object) return null; // no well-formed triple — honest decline (point 6)
|
|
4457
4520
|
if (PLACE_ADVERB_OBJECT_RE.test(object)) return null; // a place adverb is never a real object
|
|
4521
|
+
if (await readsAsNarratedEvent(verb, folded.predicate !== mintedPredicate)) return null;
|
|
4522
|
+
if (await readsAsUnknownEverywhere(subject, verb, object)) return null;
|
|
4458
4523
|
return { subject, predicate: negated ? negatedPredicate(folded.predicate) : folded.predicate, object };
|
|
4459
4524
|
}
|
|
4460
4525
|
|
|
4526
|
+
/** Does this word read as a WORD at all — the committed lexicon knows it as a
|
|
4527
|
+
* noun/verb/adjective/proper name, or wink's lemmatizer folds it onto a
|
|
4528
|
+
* different base form, which it only does for a word in its own dictionary.
|
|
4529
|
+
* Gibberish satisfies neither: "qpwoe" is in no lexicon and lemmatizes to
|
|
4530
|
+
* itself. A base-form real word ("rest") lemmatizes to itself too, which is
|
|
4531
|
+
* why this is only ever asked of a whole sentence at once, never one slot. */
|
|
4532
|
+
function readsAsKnownWord(word, lemma) {
|
|
4533
|
+
const w = String(word || "").toLowerCase();
|
|
4534
|
+
if (!w) return false;
|
|
4535
|
+
const lex = loadLexicon();
|
|
4536
|
+
if (lookupNoun(lex, w) || lookupVerb(lex, w) || lookupAdjective(lex, w) || lookupProperName(lex, w)) return true;
|
|
4537
|
+
return Boolean(lemma && lemma(w) !== w);
|
|
4538
|
+
}
|
|
4539
|
+
|
|
4540
|
+
/** A past-tense verb whose object opens with a preposition is narration of
|
|
4541
|
+
* something that happened, not a relation anyone can ask back: "the old
|
|
4542
|
+
* bridge creaked under the weight of the truck" would mint mgx:creak-under
|
|
4543
|
+
* over "weight of the truck", a fact no question this build can ask will
|
|
4544
|
+
* ever match. Decline instead of storing the garble.
|
|
4545
|
+
*
|
|
4546
|
+
* The tense test is the closed "-ed" strip confirmed by wink's lemma, the
|
|
4547
|
+
* same pair matchRelationalVerbTeach uses — so the present-tense teaches this
|
|
4548
|
+
* frame exists for ("disk-1 rests on peg-a", "wolf-1 stands on bank-east")
|
|
4549
|
+
* never reach it, and neither does a past tense with no prepositional tail,
|
|
4550
|
+
* which the frames above already own. */
|
|
4551
|
+
async function readsAsNarratedEvent(verb, prepositionFolded) {
|
|
4552
|
+
if (!prepositionFolded) return false;
|
|
4553
|
+
const v = String(verb || "").toLowerCase();
|
|
4554
|
+
if (!pastVerbBase(v)) return false;
|
|
4555
|
+
try {
|
|
4556
|
+
const { proseLemma } = await import("../adapters/prose-nlp.mjs");
|
|
4557
|
+
const lemma = proseLemma();
|
|
4558
|
+
if (lemma && lemma(v) === v) return false; // wink says this is a base form, not a past
|
|
4559
|
+
} catch { /* no lemmatizer — the closed strip stands on its own */ }
|
|
4560
|
+
return true;
|
|
4561
|
+
}
|
|
4562
|
+
|
|
4563
|
+
/** A sentence in which NOTHING is a word — no slot is in the lexicon and none
|
|
4564
|
+
* lemmatizes, so "asdkjhaskjdh qpwoe zzxx" would mint mgx:qpwoe over two
|
|
4565
|
+
* more non-words. One recognized word anywhere is enough for the frame to
|
|
4566
|
+
* stand, which is what keeps a teach about names nothing has heard of
|
|
4567
|
+
* ("grace mentors alan") storing normally. */
|
|
4568
|
+
async function readsAsUnknownEverywhere(subject, verb, object) {
|
|
4569
|
+
let lemma = null;
|
|
4570
|
+
try {
|
|
4571
|
+
const { proseLemma } = await import("../adapters/prose-nlp.mjs");
|
|
4572
|
+
lemma = proseLemma();
|
|
4573
|
+
} catch { /* no lemmatizer — the lexicon answers alone */ }
|
|
4574
|
+
const words = `${subject} ${verb} ${object}`.split(/[\s-]+/).filter(Boolean);
|
|
4575
|
+
return !words.some((w) => readsAsKnownWord(w, lemma));
|
|
4576
|
+
}
|
|
4577
|
+
|
|
4461
4578
|
/** Is `word` a genuine NOUN/PROPN, per wink-nlp's optional POS tagger
|
|
4462
4579
|
* (ask-nlp.mjs's nlpAdapter, the SAME adapter the closed structural grammar
|
|
4463
4580
|
* already leans on)? Used to let ONE narrow bare (unwrapped) general-verb
|
|
@@ -6647,9 +6764,16 @@ const MODULE_ORIENT_POLITENESS_RE = /^(?:(?:please|kindly)\s+)*(?:explain\s+(?:t
|
|
|
6647
6764
|
* resolution via resolveEntity, else null — never a guess. Pronoun/self
|
|
6648
6765
|
* subjects ("what does it/this do", "what's it for") are META_ORIENT_RE's/
|
|
6649
6766
|
* isConversational's territory, not this lane's — declined here so they
|
|
6650
|
-
* fall through unchanged.
|
|
6651
|
-
|
|
6767
|
+
* fall through unchanged.
|
|
6768
|
+
*
|
|
6769
|
+
* Declines outright with no code domain active: every resolution below
|
|
6770
|
+
* requires a real graph entity, so an inactive domain (no modules, no seon
|
|
6771
|
+
* bundle) can never actually reach a hit here — this just makes that decline
|
|
6772
|
+
* explicit rather than incidental. */
|
|
6773
|
+
async function moduleOrientLane(query, { graph, codeDomainActive = null }) {
|
|
6652
6774
|
if (!graph) return null;
|
|
6775
|
+
const domainActive = codeDomainActive ?? (moduleCountOf(graph) > 0);
|
|
6776
|
+
if (!domainActive) return null;
|
|
6653
6777
|
let q = String(query).trim().replace(/[?.!]+$/, "").replace(/\s+/g, " ");
|
|
6654
6778
|
// This lane reads the ORIGINAL (case-preserving) query text, so it needs its
|
|
6655
6779
|
// own normalization: correctMisspellings for a typo'd anchor word ("waht
|
|
@@ -6741,7 +6865,7 @@ async function moduleOrientLane(query, { graph }) {
|
|
|
6741
6865
|
return null;
|
|
6742
6866
|
}
|
|
6743
6867
|
|
|
6744
|
-
async function metaLane(query, { graph, memoryDir, last = null, templates = null, vocabHint = null, focus = null, uiContext = "cli" }) {
|
|
6868
|
+
async function metaLane(query, { graph, memoryDir, last = null, templates = null, vocabHint = null, focus = null, uiContext = "cli", codeDomainActive = false }) {
|
|
6745
6869
|
// Preamble-peeled twin of `q`: a self-intro/greeting lead ("I'm new here,
|
|
6746
6870
|
// what should I read first") wraps exactly the orientation questions this
|
|
6747
6871
|
// lane owns, and the anchored META_ORIENT_RE can't see past it. Peeling
|
|
@@ -6752,7 +6876,7 @@ async function metaLane(query, { graph, memoryDir, last = null, templates = null
|
|
|
6752
6876
|
return { text: await memorySummary(memoryDir, graph, uiContext), via: "meta" };
|
|
6753
6877
|
}
|
|
6754
6878
|
if (peeled !== q && META_ORIENT_RE.test(peeled)) {
|
|
6755
|
-
const text = orientationText(graph, templates, vocabHint, uiContext);
|
|
6879
|
+
const text = orientationText(graph, templates, vocabHint, uiContext, codeDomainActive);
|
|
6756
6880
|
return { text: last?.answer === text ? META_ORIENT_REPEAT_ONELINER : text, via: "meta" };
|
|
6757
6881
|
}
|
|
6758
6882
|
if (META_ORIENT_RE.test(q)) {
|
|
@@ -6762,7 +6886,7 @@ async function metaLane(query, { graph, memoryDir, last = null, templates = null
|
|
|
6762
6886
|
// reprints orientationText(graph) verbatim on every repeat, never
|
|
6763
6887
|
// collapsing. Mirrors ORIENTATION_REPEAT_ONELINER's identity-check
|
|
6764
6888
|
// pattern exactly, with its own distinct oneliner text.
|
|
6765
|
-
const text = orientationText(graph, templates, vocabHint, uiContext);
|
|
6889
|
+
const text = orientationText(graph, templates, vocabHint, uiContext, codeDomainActive);
|
|
6766
6890
|
return { text: last?.answer === text ? META_ORIENT_REPEAT_ONELINER : text, via: "meta" };
|
|
6767
6891
|
}
|
|
6768
6892
|
// A bare "what is in here" with NO standing focus — see
|
|
@@ -6777,7 +6901,7 @@ async function metaLane(query, { graph, memoryDir, last = null, templates = null
|
|
|
6777
6901
|
if (!focus?.label) {
|
|
6778
6902
|
const stripped = normalizeQuery(String(query)).trim().replace(/[?.!]+$/, "").trim();
|
|
6779
6903
|
if (NO_FOCUS_WHATS_IN_HERE_RE.test(stripped)) {
|
|
6780
|
-
const text = orientationText(graph, templates, vocabHint, uiContext);
|
|
6904
|
+
const text = orientationText(graph, templates, vocabHint, uiContext, codeDomainActive);
|
|
6781
6905
|
return { text: last?.answer === text ? META_ORIENT_REPEAT_ONELINER : text, via: "meta" };
|
|
6782
6906
|
}
|
|
6783
6907
|
}
|
|
@@ -6785,7 +6909,7 @@ async function metaLane(query, { graph, memoryDir, last = null, templates = null
|
|
|
6785
6909
|
// list didn't claim — try the module-grain overview before falling through to
|
|
6786
6910
|
// the author-sha check below (disjoint triggers; order doesn't matter, but
|
|
6787
6911
|
// this reads MORE of the query shape space, so it goes first).
|
|
6788
|
-
const moduleOrient = await moduleOrientLane(query, { graph });
|
|
6912
|
+
const moduleOrient = await moduleOrientLane(query, { graph, codeDomainActive });
|
|
6789
6913
|
if (moduleOrient) return moduleOrient;
|
|
6790
6914
|
// The sha-authorship form ("who authored a1b2c3d") can be as short as
|
|
6791
6915
|
// THREE words, which the conversational-orientation branch (step 2) would grab
|
|
@@ -7118,8 +7242,13 @@ function gameOwnWord(query, planHolder) {
|
|
|
7118
7242
|
const WALL_REPEAT_ONELINER = "still couldn't parse that — /help lists every query shape.";
|
|
7119
7243
|
/** The graph-less bootstrap wall's opening line — shared with the teach-offer
|
|
7120
7244
|
* collapse below, which treats this wall (like the shortened generic wall)
|
|
7121
|
-
* as text a term-specific offer REPLACES rather than stacks under.
|
|
7245
|
+
* as text a term-specific offer REPLACES rather than stacks under. Rendered
|
|
7246
|
+
* only when the code domain is active; NEUTRAL_BOOTSTRAP_WALL_LEAD stands in
|
|
7247
|
+
* for it otherwise. */
|
|
7122
7248
|
const NO_GRAPH_BOOTSTRAP_WALL_LEAD = "I can't answer that as a code question — no code graph is loaded in this session.";
|
|
7249
|
+
/** The no-code-domain sibling of the lead above: same role (the bootstrap
|
|
7250
|
+
* wall's opening line), no code vocabulary. */
|
|
7251
|
+
const NEUTRAL_BOOTSTRAP_WALL_LEAD = "I couldn't ground that in anything I know.";
|
|
7123
7252
|
|
|
7124
7253
|
/** The orientation-repeat one-liner. The conversational
|
|
7125
7254
|
* orientation branch sits OUTSIDE the composed-only wall-shortening gate (it
|
|
@@ -7156,13 +7285,28 @@ async function resolveEntity(graph, term) {
|
|
|
7156
7285
|
return null;
|
|
7157
7286
|
}
|
|
7158
7287
|
|
|
7159
|
-
/** The `/help` body: the bare-question default +
|
|
7160
|
-
*
|
|
7161
|
-
*
|
|
7162
|
-
|
|
7288
|
+
/** The `/help` body: the bare-question default + the code-domain command rows
|
|
7289
|
+
* + the tmct_ask question shapes, pulled from the engine's own rephraseHint()
|
|
7290
|
+
* so the shapes are exactly the ones the grammar supports.
|
|
7291
|
+
* `codeDomainActive` gates the trailing counts row: it names the code-graph
|
|
7292
|
+
* count vocabulary (classes/functions/modules/…), so it renders only when a
|
|
7293
|
+
* code domain is actually active this session.
|
|
7294
|
+
*
|
|
7295
|
+
* `helpRows` is the code-domain command rows to render — the session's own
|
|
7296
|
+
* merged lane vocabulary (ctx.laneVocab.helpRows, empty when the domain is
|
|
7297
|
+
* inactive: see resolveLaneVocab). COMMANDS itself stays the dispatch source
|
|
7298
|
+
* of truth (every /command's tool/arg wiring, unconditionally); this is only
|
|
7299
|
+
* what /help DISPLAYS. Omitted (undefined, not an explicit `[]`) — the shape
|
|
7300
|
+
* a bare/library `helpText(true)` call takes — falls back to COMMANDS'
|
|
7301
|
+
* own rows, gated the same way, so a caller outside the session seam still
|
|
7302
|
+
* sees every command with none of chat-session.mjs's plumbing. */
|
|
7303
|
+
export async function helpText(codeDomainActive = false, helpRows = undefined) {
|
|
7304
|
+
const codeRows = helpRows !== undefined
|
|
7305
|
+
? helpRows
|
|
7306
|
+
: (codeDomainActive ? Object.entries(COMMANDS).map(([name, s]) => [`/${name}${s.arg ? (s.optional ? ` [${s.arg}]` : ` <${s.arg}>`) : ""}`, s.help]) : []);
|
|
7163
7307
|
const rows = [
|
|
7164
7308
|
["<question>", "ask the graph in plain English (the default for any non-slash line)"],
|
|
7165
|
-
...
|
|
7309
|
+
...codeRows,
|
|
7166
7310
|
["/stats", "a one-screen overview: entity counts, relationship counts, packages"],
|
|
7167
7311
|
["/memory [verbose]", "what tmct remembers: facts, utterances, sessions, folded blocks"],
|
|
7168
7312
|
["/focus <symbol>", "set the current focus (reused by 'it'/'this' and no-arg entity commands)"],
|
|
@@ -7194,7 +7338,7 @@ export async function helpText() {
|
|
|
7194
7338
|
return [
|
|
7195
7339
|
"commands:", ...lines, "",
|
|
7196
7340
|
"question shapes for a bare line (tmct_ask):", ` ${shapes}`,
|
|
7197
|
-
'plus counts: "how many <classes|functions|modules|methods|commits> are there".',
|
|
7341
|
+
...(codeDomainActive ? ['plus counts: "how many <classes|functions|modules|methods|commits> are there".'] : []),
|
|
7198
7342
|
].join("\n");
|
|
7199
7343
|
}
|
|
7200
7344
|
|
|
@@ -9878,12 +10022,19 @@ const WHOLE_RECALL_RE = /^(?:what\s+(?:did|have)\s+(?:i|we)\s+(?:told?|tell|said
|
|
|
9878
10022
|
/** The singular class-noun of the graph entity a term names ("app/lib/a.mjs" →
|
|
9879
10023
|
* "module", "Widget" → "class"), via the ask engine's own resolver + the loaded
|
|
9880
10024
|
* graph's class map — or null on a miss/ambiguity/no-graph. Lets forward
|
|
9881
|
-
* membership answer over a graph INSTANCE, not just a bare class word.
|
|
10025
|
+
* membership answer over a graph INSTANCE, not just a bare class word. A
|
|
10026
|
+
* resolved `cls` only ever happens over a real code graph, so reading the
|
|
10027
|
+
* shipped code pack's own class labels here (codeCountNouns' sibling, same
|
|
10028
|
+
* "runs only when the domain is already active" reasoning) is safe
|
|
10029
|
+
* regardless of whether the pack extension itself is formally active. */
|
|
9882
10030
|
async function entityClassNoun(graph, term) {
|
|
9883
10031
|
const ent = await resolveEntity(graph, term);
|
|
9884
10032
|
if (!ent) return null;
|
|
9885
10033
|
const cls = (graph?.byId?.get?.(ent.id) || (graph?.individuals || []).find((i) => i?.id === ent.id))?.class;
|
|
9886
|
-
|
|
10034
|
+
if (!cls) return null;
|
|
10035
|
+
const { defaultCodeLaneVocab } = await import("./extensions.mjs");
|
|
10036
|
+
const { classLabels } = await defaultCodeLaneVocab();
|
|
10037
|
+
return classLabels[cls] ? classLabels[cls][0] : null;
|
|
9887
10038
|
}
|
|
9888
10039
|
|
|
9889
10040
|
/** A relation group that carries class-inheritance edges — the same token family
|
|
@@ -11734,13 +11885,13 @@ function reverseCleftRewrite(query) {
|
|
|
11734
11885
|
return m ? `${m[1].toLowerCase()} ${m[2].trim()}` : null;
|
|
11735
11886
|
}
|
|
11736
11887
|
|
|
11737
|
-
// ---- curated SEON definitions (corpus/
|
|
11888
|
+
// ---- curated SEON definitions (corpus/domains/code/definitions.jsonl) ----
|
|
11738
11889
|
// A "what is a <term>" for a LEXICON term prefers the curated one-sentence
|
|
11739
11890
|
// definition, cited via:"corpus/seon" — but only when this repo carries the
|
|
11740
11891
|
// SEON concept seed, and a fact the USER personally asserted still wins.
|
|
11741
11892
|
|
|
11742
11893
|
let seonDefsPromise = null;
|
|
11743
|
-
/** Load corpus/
|
|
11894
|
+
/** Load corpus/domains/code/definitions.jsonl once → Map(normFactTerm(term) → definition).
|
|
11744
11895
|
* Lazy + failure-tolerated (chat.mjs ethos): any failure degrades to an empty map. */
|
|
11745
11896
|
function seonDefinitions() {
|
|
11746
11897
|
if (!seonDefsPromise) {
|
|
@@ -11765,8 +11916,8 @@ function seonDefinitions() {
|
|
|
11765
11916
|
}
|
|
11766
11917
|
|
|
11767
11918
|
let seonRelsPromise = null;
|
|
11768
|
-
/** Load corpus/
|
|
11769
|
-
* the concept key ("imports","calls",…). Sits beside definitions.jsonl (same
|
|
11919
|
+
/** Load corpus/domains/code/relations.jsonl once → Map(relationTerm → definition), keyed on
|
|
11920
|
+
* the concept key ("imports","calls",…). Sits beside definitions.jsonl (same
|
|
11770
11921
|
* dir), loaded the same lazy + failure-tolerated way — any failure degrades to an
|
|
11771
11922
|
* empty map, so the relation force simply declines rather than throwing. */
|
|
11772
11923
|
function relationDefinitions() {
|
|
@@ -12563,7 +12714,7 @@ async function completionsRescueAnswer(query, { memoryDir, graph }) {
|
|
|
12563
12714
|
* definition + real example EDGES + pre-validated follow-ups) for a vague touch on a
|
|
12564
12715
|
* relation/edge kind ("what about imports", "tell me about contains"), or null
|
|
12565
12716
|
* when it isn't one. Loads the definition from the shipped
|
|
12566
|
-
* corpus/
|
|
12717
|
+
* corpus/domains/code/relations.jsonl, so it works without per-repo memory seeding.
|
|
12567
12718
|
* Returns { text, pending, kind } — `kind` is the resolved RELATION_TERM
|
|
12568
12719
|
* canonical kind, the SAME vocabulary GOAL_BY_KIND keys on. */
|
|
12569
12720
|
async function relationForceAnswer(query, envelope, { graph, config, source, templates }) {
|
|
@@ -13412,7 +13563,7 @@ const ARCH_OVERVIEW_PHRASES = [
|
|
|
13412
13563
|
new RegExp(`^${ARCH_OVERVIEW_LEAD}(?:(?:an?|the)\\s+)?(?:overview|map|diagram)\\s+${ARCH_OVERVIEW_OF_REPO}(?:\\s+here)?\\??$`, "i"),
|
|
13413
13564
|
];
|
|
13414
13565
|
|
|
13415
|
-
async function runAsk(query, { config, source, graph, focus, last, templates, memoryDir, sessionId = "", lexicon = null, env, trace, vocabHint = null, tel = null, biasByBundle = {}, cache = null, vocabAntecedent = null, planHolder = null, discourseHolder = null, gameConfig = DEFAULT_GAME_CONFIG, liveReference = false, onLiveLookup = null, uiContext = "cli", synthesisBudget = AUTO_SYNTHESIS_BUDGET }) {
|
|
13566
|
+
async function runAsk(query, { config, source, graph, focus, last, templates, memoryDir, sessionId = "", lexicon = null, env, trace, vocabHint = null, tel = null, biasByBundle = {}, cache = null, vocabAntecedent = null, planHolder = null, discourseHolder = null, gameConfig = DEFAULT_GAME_CONFIG, liveReference = false, onLiveLookup = null, uiContext = "cli", synthesisBudget = AUTO_SYNTHESIS_BUDGET, codeDomainActive = false }) {
|
|
13416
13567
|
const ts = new Date().toISOString();
|
|
13417
13568
|
// The surface this turn runs on ("cli" default; "browser" from a web entry) —
|
|
13418
13569
|
// the honest-miss tail below points a browser/adventure miss at the teach
|
|
@@ -13803,8 +13954,11 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
13803
13954
|
answer = (!graph || noCodeGraph(graph)) && (!config || e?.emptyGraph || /^cannot read graph artifact\b/.test(thrown))
|
|
13804
13955
|
// A browser session has no `tmct init in a repo` to reach for, so its
|
|
13805
13956
|
// fallback drops that CLI-only remedy and keeps just the teach pointer.
|
|
13806
|
-
|
|
13807
|
-
|
|
13957
|
+
// No code domain active: the lead drops the code-question framing, and
|
|
13958
|
+
// the CLI-only "index one" remedy drops too — there is nothing to index
|
|
13959
|
+
// toward without a code domain.
|
|
13960
|
+
? `${codeDomainActive ? NO_GRAPH_BOOTSTRAP_WALL_LEAD : NEUTRAL_BOOTSTRAP_WALL_LEAD} ${vocabHint
|
|
13961
|
+
|| (browser || !codeDomainActive
|
|
13808
13962
|
? "I can still remember and answer taught facts (try \"every bug is an issue\")."
|
|
13809
13963
|
: "I can still remember and answer taught facts (try \"every bug is an issue\"), or run `tmct init` in a repo to index one.")}`
|
|
13810
13964
|
: thrown;
|
|
@@ -13875,7 +14029,17 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
13875
14029
|
}
|
|
13876
14030
|
}
|
|
13877
14031
|
const answeredIds = (envelope?.matches || []).map((m) => m?.id).filter(Boolean);
|
|
13878
|
-
|
|
14032
|
+
// The ask engine carries its OWN aggregate/count grammar (parseAggregate,
|
|
14033
|
+
// ask.mjs), independent of answerCount's own gate earlier in dispatchTurn —
|
|
14034
|
+
// it answers a code-graph class count (parsed.node "count") straight off
|
|
14035
|
+
// the graph regardless of what's actually loaded. With no code domain
|
|
14036
|
+
// active this session has no code-graph vocabulary to answer such a count
|
|
14037
|
+
// from, so treat it as a miss here too: the honest-empty-polish pass below
|
|
14038
|
+
// reads this exact shape (a code-shaped, structurally-worded answer) and
|
|
14039
|
+
// declines it to the ordinary wall, the same outcome answerCount's own gate
|
|
14040
|
+
// produces for the phrasing it owns.
|
|
14041
|
+
const codeCountWithNoDomain = envelope?.parsed?.node === "count" && !codeDomainActive;
|
|
14042
|
+
const askMiss = codeCountWithNoDomain || (envelope ? !!envelope.miss : true);
|
|
13879
14043
|
// GRAPH-FACT-VS-TAUGHT-FACT PRECEDENCE: a plain declarative "X is a kind of
|
|
13880
14044
|
// Y" sentence whose SUBJECT already names a real graph entity could get
|
|
13881
14045
|
// silently "answered" by the ask engine's own relaxation cascade instead of
|
|
@@ -13992,7 +14156,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
13992
14156
|
// codebase", "how do i start") → a summary / orientation, answered before the
|
|
13993
14157
|
// fact-dump readers so "what do you know" gets a summary, not raw facts.
|
|
13994
14158
|
if (!handled && miss) {
|
|
13995
|
-
const meta = await metaLane(query, { graph, memoryDir, last, templates, vocabHint, focus, uiContext });
|
|
14159
|
+
const meta = await metaLane(query, { graph, memoryDir, last, templates, vocabHint, focus, uiContext, codeDomainActive });
|
|
13996
14160
|
if (meta) {
|
|
13997
14161
|
// A lane may answer with a better-worded decline (the module-orient
|
|
13998
14162
|
// residue guard) — still a miss in the turn record, like the isa
|
|
@@ -14410,7 +14574,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
14410
14574
|
// 3 words with no STRUCT_WORDS token, so without this guard
|
|
14411
14575
|
// isConversational would discard a correct, already-composed answer for
|
|
14412
14576
|
// the generic orientation wall.
|
|
14413
|
-
const orientation = orientationAnswer(templates, graph, vocabHint, uiContext);
|
|
14577
|
+
const orientation = orientationAnswer(templates, graph, vocabHint, uiContext, codeDomainActive);
|
|
14414
14578
|
const repeat = last?.answer === orientation;
|
|
14415
14579
|
answer = repeat ? ORIENTATION_REPEAT_ONELINER : orientation;
|
|
14416
14580
|
via = "template"; handled = true;
|
|
@@ -14424,20 +14588,31 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
14424
14588
|
// first (factAnswer), then the reverse-membership read-back (factReadBack) so an
|
|
14425
14589
|
// asserted "every X is a Y" answers "what is a Y" too.
|
|
14426
14590
|
// Raw query first (the long-standing contract), then ONE retry with the
|
|
14427
|
-
//
|
|
14428
|
-
//
|
|
14429
|
-
//
|
|
14430
|
-
//
|
|
14431
|
-
//
|
|
14432
|
-
//
|
|
14433
|
-
//
|
|
14434
|
-
//
|
|
14435
|
-
|
|
14591
|
+
// courtesy wrapper peeled off. A politeness-wrapped vocabulary question
|
|
14592
|
+
// ("could you tell me what a dog is", "please tell me what you know about
|
|
14593
|
+
// dog") reaches this lane still wearing a wrapper no reader matches, so
|
|
14594
|
+
// without the retry it walls while its bare form answers.
|
|
14595
|
+
//
|
|
14596
|
+
// The peel is applyPreambleFrames, not the full normalizeQuery. Only the
|
|
14597
|
+
// closed wrapper frames are wanted here; normalizeQuery goes on to strip
|
|
14598
|
+
// filler words, and one of those is the pronoun in "what do you know
|
|
14599
|
+
// about X" — the very word that shape's reader anchors on. Peeling
|
|
14600
|
+
// rebuilt the question and the filler strip took it straight back apart,
|
|
14601
|
+
// which is why a courtesy-wrapped memory question about a term this
|
|
14602
|
+
// session KNOWS used to wall. It is also why the retry no longer has to
|
|
14603
|
+
// be held to the no-envelope bootstrap turn: what made an unrestricted
|
|
14604
|
+
// retry unsafe was normalization-mangled text reaching readers whose
|
|
14605
|
+
// guards were written for the raw surface, and the closed frames do not
|
|
14606
|
+
// mangle — they either match a whole wrapper or leave the string alone.
|
|
14607
|
+
//
|
|
14608
|
+
// The retry can only run when the raw read already returned nothing, so
|
|
14609
|
+
// it turns a wall into an answer and never overrides one.
|
|
14610
|
+
const peeledForFacts = applyPreambleFrames(String(query));
|
|
14436
14611
|
const fact = (await factAnswer(memoryDir, query, envelope, miss, biasByBundle, cache, newFocus?.label))
|
|
14437
14612
|
?? (await factReadBack(memoryDir, query, envelope, miss, graph, newFocus?.label, biasByBundle, cache))
|
|
14438
|
-
?? (
|
|
14439
|
-
? (await factAnswer(memoryDir,
|
|
14440
|
-
?? (await factReadBack(memoryDir,
|
|
14613
|
+
?? (peeledForFacts && peeledForFacts !== String(query).trim()
|
|
14614
|
+
? (await factAnswer(memoryDir, peeledForFacts, envelope, miss, biasByBundle, cache, newFocus?.label))
|
|
14615
|
+
?? (await factReadBack(memoryDir, peeledForFacts, envelope, miss, graph, newFocus?.label, biasByBundle, cache))
|
|
14441
14616
|
: null);
|
|
14442
14617
|
if (fact) {
|
|
14443
14618
|
answer = fact.replace ? fact.text : `${answer}\n${fact.text}`;
|
|
@@ -14929,8 +15104,22 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
14929
15104
|
answer = `${answer}\n(I don't know that yet — you can teach me: say "remember: <thing> is a <kind>".)`;
|
|
14930
15105
|
note(trace, "intermediate: HONEST-EMPTY POLISH — a browser miss points at the teach lane, not the CLI-only --repo remedy");
|
|
14931
15106
|
} else if (looksCodeish(String(query), String(query).toLowerCase())) {
|
|
14932
|
-
|
|
14933
|
-
|
|
15107
|
+
if (codeDomainActive) {
|
|
15108
|
+
answer = `${answer}\n(this repo has no code graph — index it with \`tmct index\`, point me at a \`.tmct/graph.json\` with \`--repo <path>\`, or run \`npm run example:mini\`.)`;
|
|
15109
|
+
note(trace, "intermediate: HONEST-EMPTY POLISH — the loaded graph has 0 modules, so the dead-end got a tmct index/--repo pointer appended");
|
|
15110
|
+
} else {
|
|
15111
|
+
// No code domain active this session: a code-shaped miss here would
|
|
15112
|
+
// otherwise repeat the engine's own code-graph vocabulary. Decline to
|
|
15113
|
+
// the same neutral wall a genuinely unparsed line gets — as if this
|
|
15114
|
+
// lane's grammar had never matched — rather than pointing at a
|
|
15115
|
+
// command that has nothing here to index.
|
|
15116
|
+
answer = vocabHint
|
|
15117
|
+
? `I couldn't read that as a question I can answer. ${vocabHint} Type /help for all query shapes.`
|
|
15118
|
+
: shortMissHint(query);
|
|
15119
|
+
via = "miss";
|
|
15120
|
+
genericWallMiss = true;
|
|
15121
|
+
note(trace, "intermediate: HONEST-EMPTY POLISH — no code domain active, so the code-shaped miss declined to the ordinary wall instead of a code-graph pointer");
|
|
15122
|
+
}
|
|
14934
15123
|
} else {
|
|
14935
15124
|
// Nothing in the question is code-shaped, so indexing a repo would not
|
|
14936
15125
|
// help. "who won the 2031 world cup" used to carry the pointer anyway,
|
|
@@ -14944,7 +15133,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
14944
15133
|
// names no term, so keeping it above the offer stacks two messages
|
|
14945
15134
|
// where one carries everything. A receipt-bearing specific miss keeps
|
|
14946
15135
|
// the offer appended beneath it, unchanged.
|
|
14947
|
-
const genericWall = genericWallMiss || answer.startsWith(NO_GRAPH_BOOTSTRAP_WALL_LEAD);
|
|
15136
|
+
const genericWall = genericWallMiss || answer.startsWith(NO_GRAPH_BOOTSTRAP_WALL_LEAD) || answer.startsWith(NEUTRAL_BOOTSTRAP_WALL_LEAD);
|
|
14948
15137
|
answer = genericWall ? teachOffer : `${answer}\n${teachOffer}`;
|
|
14949
15138
|
note(trace, `intermediate: TEACH-OFFER — the term is unknown to both the graph and memory, so the miss ${genericWall ? "collapsed to the offer to learn" : "got an offer to learn appended"}`);
|
|
14950
15139
|
}
|
|
@@ -15108,7 +15297,23 @@ const GOAL_BY_COMMAND = {
|
|
|
15108
15297
|
* cases). Returns the same { answer, logLines, record, focus } shape as
|
|
15109
15298
|
* runAsk. Also carries a `goal` field mirroring runAsk's own, so
|
|
15110
15299
|
* withGoalLine's "Goal (inferred): …" line fires for command dispatches too. */
|
|
15111
|
-
|
|
15300
|
+
/** One loaded domain as /capabilities renders it: the pack's name, the
|
|
15301
|
+
* grounding channel it declares, and what its lane vocabulary adds. A pack
|
|
15302
|
+
* that declares no grounding channel gets no grounding clause — the listing
|
|
15303
|
+
* never fills that gap in for it. */
|
|
15304
|
+
function domainPackLine({ name, groundingKind, groundingAdapter, commandCount, countNounCount }) {
|
|
15305
|
+
const parts = [];
|
|
15306
|
+
if (groundingKind === "extraction" && groundingAdapter) parts.push(`grounded by extraction through ${groundingAdapter}`);
|
|
15307
|
+
else if (groundingKind === "extraction") parts.push("grounded by extraction");
|
|
15308
|
+
else if (groundingKind === "taught-only") parts.push("grounded by the teach lane only");
|
|
15309
|
+
const adds = [];
|
|
15310
|
+
if (commandCount) adds.push(`${commandCount} command${commandCount === 1 ? "" : "s"}`);
|
|
15311
|
+
if (countNounCount) adds.push(`${countNounCount} count noun${countNounCount === 1 ? "" : "s"}`);
|
|
15312
|
+
if (adds.length) parts.push(`adds ${adds.join(" and ")}`);
|
|
15313
|
+
return parts.length ? `${name} — ${parts.join("; ")}` : String(name);
|
|
15314
|
+
}
|
|
15315
|
+
|
|
15316
|
+
async function runCommand(line, { config, source, graph, focus, memoryDir, trace, narrate = false, liveReference = false, tel = null, biasByBundle = {}, cache = null, codeDomainActive = false, laneVocab = null, domainPacks = null }) {
|
|
15112
15317
|
const ts = new Date().toISOString();
|
|
15113
15318
|
const sp = line.indexOf(" ");
|
|
15114
15319
|
const name = (sp === -1 ? line.slice(1) : line.slice(1, sp)).toLowerCase();
|
|
@@ -15123,9 +15328,16 @@ async function runCommand(line, { config, source, graph, focus, memoryDir, trace
|
|
|
15123
15328
|
...(liveReferenceNext !== undefined ? { liveReference: liveReferenceNext } : {}),
|
|
15124
15329
|
});
|
|
15125
15330
|
|
|
15126
|
-
if (name === "help") { note(trace, "goal: get oriented / learn available commands"); return mk(await helpText()); }
|
|
15331
|
+
if (name === "help") { note(trace, "goal: get oriented / learn available commands"); return mk(await helpText(codeDomainActive, codeDomainActive ? laneVocab?.helpRows : [])); }
|
|
15127
15332
|
if (name === "stats") {
|
|
15128
15333
|
note(trace, "goal: get a one-screen overview of the loaded graph");
|
|
15334
|
+
if (!codeDomainActive) {
|
|
15335
|
+
// No code domain active: renderStats' own module/package counts would
|
|
15336
|
+
// be code vocabulary with nothing here to ground it. Report the
|
|
15337
|
+
// session's actual, neutral shape instead.
|
|
15338
|
+
const factCount = memoryDir ? (await factRows(memoryDir, cache)).length : 0;
|
|
15339
|
+
return mk(`no graph loaded — this session holds ${factCount} fact${factCount === 1 ? "" : "s"}. Teach me directly, or /memory to inspect what's stored.`, { miss: true });
|
|
15340
|
+
}
|
|
15129
15341
|
return graph ? mk(renderStats(graph)) : mk("no graph loaded — /stats needs an index.", { miss: true });
|
|
15130
15342
|
}
|
|
15131
15343
|
|
|
@@ -15184,9 +15396,14 @@ async function runCommand(line, { config, source, graph, focus, memoryDir, trace
|
|
|
15184
15396
|
}
|
|
15185
15397
|
|
|
15186
15398
|
// /capabilities — everything a /plan request can plan over: the built-in
|
|
15187
|
-
// read-only graph-query tools,
|
|
15399
|
+
// read-only graph-query tools, the taught action families read straight
|
|
15188
15400
|
// from this store (they only live in the registry inside a /plan request,
|
|
15189
|
-
// so listing them means reading the rules, not the registry)
|
|
15401
|
+
// so listing them means reading the rules, not the registry), and this
|
|
15402
|
+
// session's loaded domain packs. Each domain line restates that pack's own
|
|
15403
|
+
// declaration — its grounding channel and what its vocabulary adds — so the
|
|
15404
|
+
// surface reports what the pack says about itself rather than a second,
|
|
15405
|
+
// drifting description of it. A session with no pack active lists no
|
|
15406
|
+
// domains and says nothing about them.
|
|
15190
15407
|
if (name === "capabilities") {
|
|
15191
15408
|
note(trace, "goal: see what /plan can plan over — built-in query tools and taught actions");
|
|
15192
15409
|
const { declaredCapabilityNames } = await import("../domain/router/drive.mjs");
|
|
@@ -15211,6 +15428,11 @@ async function runCommand(line, { config, source, graph, focus, memoryDir, trace
|
|
|
15211
15428
|
lines.push(` taught:${familyName} — ${sig}`);
|
|
15212
15429
|
}
|
|
15213
15430
|
}
|
|
15431
|
+
const packs = Array.isArray(domainPacks) ? domainPacks : [];
|
|
15432
|
+
if (packs.length) {
|
|
15433
|
+
lines.push("loaded domains:");
|
|
15434
|
+
for (const pack of packs) lines.push(` ${domainPackLine(pack)}`);
|
|
15435
|
+
}
|
|
15214
15436
|
return mk(lines.join("\n"));
|
|
15215
15437
|
}
|
|
15216
15438
|
|
|
@@ -15431,7 +15653,7 @@ async function runCommand(line, { config, source, graph, focus, memoryDir, trace
|
|
|
15431
15653
|
|
|
15432
15654
|
let answer;
|
|
15433
15655
|
try {
|
|
15434
|
-
answer = await dispatchTool(spec.tool, spec.arg ? { [spec.arg]: value } : {}, { config, source, tel });
|
|
15656
|
+
answer = await dispatchTool(spec.tool, spec.arg ? { [spec.arg]: value } : {}, { config, source, tel, codeDomainActive });
|
|
15435
15657
|
} catch (e) {
|
|
15436
15658
|
note(trace, `intermediate: dispatchTool("${spec.tool}") threw — ${String(e?.message || e)}`);
|
|
15437
15659
|
return mk(String(e?.message || e), { miss: true }); // the tool's own clean error, never a stack
|
|
@@ -16355,13 +16577,35 @@ export async function runTurn(input, options = {}) {
|
|
|
16355
16577
|
return { ...result, factsTouched: await factsTouchedSince(memoryDir, before) };
|
|
16356
16578
|
}
|
|
16357
16579
|
|
|
16358
|
-
async function dispatchTurn(input, { config, source = defaultSource, graph = null, focus = null, last = null, memoryDir = null, sessionId = "", env = process.env, lexicon = null, narrate = false, liveReference = false, onLiveLookup = null, vocabHint = null, tel = null, biasByBundle = {}, factRowsCache: injectedFactRowsCache = null, planState = null, gameConfig = null, uiContext = "cli", synthesisBudget = AUTO_SYNTHESIS_BUDGET, researchState = null, researchConfig = null, discourse = null, _noSplit = false, actingSubject = "player" } = {}) {
|
|
16580
|
+
async function dispatchTurn(input, { config, source = defaultSource, graph = null, focus = null, last = null, memoryDir = null, sessionId = "", env = process.env, lexicon = null, narrate = false, liveReference = false, onLiveLookup = null, vocabHint = null, tel = null, biasByBundle = {}, factRowsCache: injectedFactRowsCache = null, planState = null, gameConfig = null, uiContext = "cli", synthesisBudget = AUTO_SYNTHESIS_BUDGET, researchState = null, researchConfig = null, discourse = null, _noSplit = false, actingSubject = "player", codeDomainActive = null, laneVocab = null, domainPacks = null } = {}) {
|
|
16359
16581
|
// Every game's tuning knobs (spider-fly's mass economy, guess-the-number's
|
|
16360
16582
|
// bounds, the shared plan lane's search-depth cap) — a caller's own
|
|
16361
16583
|
// gameConfig (chat-session.mjs resolves one per session from tmct.toml)
|
|
16362
16584
|
// wins outright; direct/library callers that omit it get the shipped
|
|
16363
16585
|
// defaults, byte-identical to before this seam existed.
|
|
16364
16586
|
const resolvedGameConfig = gameConfig ?? DEFAULT_GAME_CONFIG;
|
|
16587
|
+
// chat-session.mjs computes this ONCE per session (a loaded graph with
|
|
16588
|
+
// modules, or the seon bundle active) and passes it through; a direct/
|
|
16589
|
+
// library caller that omits it gets the graph-only signal — correct for
|
|
16590
|
+
// every existing caller that hands runTurn a real code graph, and
|
|
16591
|
+
// correctly inactive for a graph-less or empty one.
|
|
16592
|
+
const domainActive = codeDomainActive ?? (!!graph && moduleCountOf(graph) > 0);
|
|
16593
|
+
// This turn's lane vocabulary (count nouns/class labels/help rows/the
|
|
16594
|
+
// miss-recovery pointer): the caller's own — chat-session.mjs threads the
|
|
16595
|
+
// real per-session merge (extensions.mjs's mergedLaneVocab) — or, for a
|
|
16596
|
+
// direct/library caller that hands this a real code graph but no merge,
|
|
16597
|
+
// the shipped code pack's own vocabulary (the same "a real graph is
|
|
16598
|
+
// enough" fallback domainActive itself applies, above). An inactive
|
|
16599
|
+
// domain never sees an import, and never sees code-domain vocabulary.
|
|
16600
|
+
const laneVocabValue = laneVocab ?? (domainActive
|
|
16601
|
+
? await (await import("./extensions.mjs")).defaultCodeLaneVocab()
|
|
16602
|
+
: { countNouns: {}, classLabels: {}, helpRows: [], missRecoveryPointer: "" });
|
|
16603
|
+
// The packs behind that vocabulary, each read from its own declaration —
|
|
16604
|
+
// the same caller-first-then-"a real graph is enough" rule as the
|
|
16605
|
+
// vocabulary. An inactive domain lists no packs at all.
|
|
16606
|
+
const domainPacksValue = domainPacks ?? (domainActive
|
|
16607
|
+
? await (await import("./extensions.mjs")).defaultCodeDomainPacks()
|
|
16608
|
+
: []);
|
|
16365
16609
|
const line = String(input ?? "").trim();
|
|
16366
16610
|
// ONE fresh, empty cache for this turn only — every factRows() reader
|
|
16367
16611
|
// reached from this call shares it, so the first reader computes
|
|
@@ -16425,7 +16669,7 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
16425
16669
|
// an answer's typed content is in hand (runAsk, off the ask envelope's
|
|
16426
16670
|
// `discourse` referents); the caller re-threads whatever comes back.
|
|
16427
16671
|
const discourseHolder = { record: discourse ?? emptyDiscourseRecord() };
|
|
16428
|
-
const ctx = { config, source, graph, focus, last, memoryDir, sessionId, templates, env, lexicon, trace, narrate, liveReference, onLiveLookup, vocabHint: resolvedVocabHint, tel, biasByBundle, cache: factRowsCache, vocabAntecedent, planHolder, discourseHolder, gameConfig: resolvedGameConfig, uiContext, synthesisBudget };
|
|
16672
|
+
const ctx = { config, source, graph, focus, last, memoryDir, sessionId, templates, env, lexicon, trace, narrate, liveReference, onLiveLookup, vocabHint: resolvedVocabHint, tel, biasByBundle, cache: factRowsCache, vocabAntecedent, planHolder, discourseHolder, gameConfig: resolvedGameConfig, uiContext, synthesisBudget, codeDomainActive: domainActive, laneVocab: laneVocabValue, domainPacks: domainPacksValue };
|
|
16429
16673
|
// A DISPATCHED turn (count / slash-command / ask) becomes the new "last
|
|
16430
16674
|
// answer" that why/say-more re-renders; a conversational turn does not.
|
|
16431
16675
|
// Every dispatched turn's result passes through finish() here — the LAST
|
|
@@ -16969,7 +17213,7 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
16969
17213
|
// short-circuit straight to "I can't count 'tests'" before this lane ever
|
|
16970
17214
|
// got a turn. Declines (null) for anything answerCount should own, or a bare
|
|
16971
17215
|
// global count with no named entity — see answerEdgeCount's own docblock.
|
|
16972
|
-
const edgeCount = await answerEdgeCount(graph, workingLine);
|
|
17216
|
+
const edgeCount = await answerEdgeCount(graph, workingLine, { codeDomainActive: domainActive, countNouns: laneVocabValue.countNouns });
|
|
16973
17217
|
if (edgeCount != null) {
|
|
16974
17218
|
note(trace, 'goal: get a per-entity count of an edge-nominalized kind ("how many tests cover X", "how many callers does X have")');
|
|
16975
17219
|
note(trace, "lane: answerEdgeCount — matched an EDGE_NOUN_TO_METRIC noun with a resolvable named entity, answered via the same degreeMetric the superlative lane uses");
|
|
@@ -16977,7 +17221,7 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
16977
17221
|
}
|
|
16978
17222
|
// Aggregate/count questions are answered mechanically off the loaded graph header,
|
|
16979
17223
|
// BEFORE falling through to the ask engine (focus unchanged — a count names no entity).
|
|
16980
|
-
const count = answerCount(graph, workingLine, { uiContext });
|
|
17224
|
+
const count = answerCount(graph, workingLine, { uiContext, codeDomainActive: domainActive, countNouns: laneVocabValue.countNouns, classLabels: laneVocabValue.classLabels });
|
|
16981
17225
|
if (count != null) {
|
|
16982
17226
|
// An "I can't count <noun>" from a bare kind may still be answerable from an
|
|
16983
17227
|
// ASSERTED vocabulary fact ("every class is a type" → "how many types" = the
|