@polycode-projects/the-mechanical-code-talker 2.0.3 → 2.3.0

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.
Files changed (57) hide show
  1. package/README.md +1 -1
  2. package/ROADMAP.md +27 -4
  3. package/bin/tmct.mjs +4 -5
  4. package/corpus/generated/ace-surface-variants.jsonl +1 -0
  5. package/corpus/generated/manifest.json +3 -3
  6. package/corpus/wordnet/generate.mjs +6 -7
  7. package/package.json +30 -2
  8. package/src/adapters/corpus/conceptnet.mjs +1 -1
  9. package/src/adapters/graph-build.mjs +3 -3
  10. package/src/adapters/memory/blocks.mjs +2 -2
  11. package/src/adapters/memory/core.mjs +5 -5
  12. package/src/adapters/providers/bootstrap.mjs +1 -1
  13. package/src/adapters/providers/fixture.mjs +1 -1
  14. package/src/adapters/toml-config.mjs +0 -1
  15. package/src/adapters/wink-model.mjs +1 -1
  16. package/src/adapters/wordnet-source.mjs +70 -0
  17. package/src/domain/answer-variants.json +1 -1
  18. package/src/domain/ask-vocab.mjs +2 -2
  19. package/src/domain/ask.mjs +4 -4
  20. package/src/domain/codegraph.mjs +7 -71
  21. package/src/domain/corpus-matrix.mjs +87 -0
  22. package/src/domain/grammar/ace.mjs +11 -11
  23. package/src/domain/grammar/lexicon.mjs +3 -3
  24. package/src/domain/inflect.mjs +67 -0
  25. package/src/domain/interpret/fuzzy.mjs +1 -1
  26. package/src/domain/interpret/merge.mjs +1 -1
  27. package/src/domain/interpret/normalize.mjs +1 -1
  28. package/src/domain/licences.mjs +68 -0
  29. package/src/domain/markdown-links.mjs +55 -0
  30. package/src/domain/memory/capability.mjs +1 -1
  31. package/src/domain/memory/trust.mjs +2 -2
  32. package/src/domain/persona/codegen.mjs +123 -0
  33. package/src/domain/persona/examples.mjs +26 -0
  34. package/src/domain/persona/tiers.mjs +270 -0
  35. package/src/domain/publish-gate.mjs +41 -0
  36. package/src/domain/router/call-validator.mjs +1 -1
  37. package/src/domain/router/drive.mjs +3 -4
  38. package/src/domain/router/registry.mjs +12 -13
  39. package/src/domain/router/resolver.mjs +18 -5
  40. package/src/domain/router/results.mjs +3 -3
  41. package/src/domain/router/taught.mjs +4 -3
  42. package/src/domain/schemaorg/turtle.mjs +25 -0
  43. package/src/domain/semcor/parse.mjs +87 -0
  44. package/src/domain/syllogise.mjs +6 -6
  45. package/src/domain/version-stamp.mjs +36 -0
  46. package/src/domain/wordnet/yaml.mjs +133 -0
  47. package/src/services/chat-session.mjs +2 -2
  48. package/src/services/chat.mjs +2 -2
  49. package/src/services/cli-args.mjs +4 -4
  50. package/src/services/finish.mjs +1 -1
  51. package/src/services/ledger-viz.mjs +2 -3
  52. package/src/services/sessions.mjs +4 -4
  53. package/src/services/viz-theme.mjs +3 -4
  54. package/src/surfaces/web/memory-ask-browser.bundle.js +4 -94
  55. package/src/adapters/embed.mjs +0 -169
  56. package/src/domain/router/guardrail.mjs +0 -116
  57. package/src/domain/vector.mjs +0 -12
@@ -42,13 +42,13 @@ function requireStore(store, needed, caller) {
42
42
  /** scm-sco: the subClassOf-transitivity rule, and the provenance tag its
43
43
  * conclusions carry. */
44
44
  export const SUBCLASS_PREDICATE = "rdfs:subClassOf";
45
- export const SYLLOGISE_RULE = "subClassOf";
45
+ const SYLLOGISE_RULE = "subClassOf";
46
46
  export const ENTAILED_PROVENANCE = `entailed:${SYLLOGISE_RULE}`;
47
47
 
48
48
  /** cax-sco: the type-propagation rule, and the provenance tag its conclusions
49
49
  * carry. */
50
50
  export const TYPE_PREDICATE = "rdf:type";
51
- export const CAX_SCO_RULE = "type";
51
+ const CAX_SCO_RULE = "type";
52
52
  export const ENTAILED_TYPE_PROVENANCE = `entailed:${CAX_SCO_RULE}`;
53
53
 
54
54
  /** cax-dw: x rdf:type C1, C1 owl:disjointWith C2 |= x is NOT of type C2 — a
@@ -396,7 +396,7 @@ export function deriveSomeValuesFromApplication(propertyEdges, typeEdges, subCla
396
396
  // deriveSomeValuesFromApplication reconstructs someValuesFrom restrictions.
397
397
  const HAS_PROPERTY_KEY = "has"; // synthetic marker parseCardinality always mints, never a real taught verb
398
398
  const CARDINALITY_KIND_OF = { "owl:cardinality": "exactly", "owl:mincardinality": "min", "owl:maxcardinality": "max" };
399
- export const ON_CLASS_PREDICATE = "owl:onClass";
399
+ const ON_CLASS_PREDICATE = "owl:onClass";
400
400
 
401
401
  /** Reconstructs pattern-5 cardinality restriction records from raw stored
402
402
  * rows touching a restriction node. A restriction is only admitted when its
@@ -525,7 +525,7 @@ function findOwnCardinalityRestriction(subClassEdges, cardinalityRestrictionEdge
525
525
  }
526
526
 
527
527
  // ---- cardinality monotonicity (outside OWL 2 RL's own decidable profile) ----
528
- export const SCM_CARD_RULE = "cardinalityMonotonicity";
528
+ const SCM_CARD_RULE = "cardinalityMonotonicity";
529
529
  /** Same sub-1 discount as CAX_DW_RULE_CONFIDENCE. No `syllogise()` call site
530
530
  * (this rule is query-rooted, never an enumerable Fact) — defined anyway so
531
531
  * chat.mjs's live proof chase can attach an auditable confidence figure
@@ -557,7 +557,7 @@ export function proveCardinalityAtLeast(subClassEdges, cardinalityRestrictionEdg
557
557
  // generalization — see this file's header comment; `cax-` prefix per this
558
558
  // ladder's "produces a provable no" naming convention, same epistemic status
559
559
  // as cax-dw) ----
560
- export const CAX_MAXC0_RULE = "maxCardinalityZero";
560
+ const CAX_MAXC0_RULE = "maxCardinalityZero";
561
561
  /** Same sub-1 discount and query-rooted caveat as CARDINALITY_RULE_CONFIDENCE. */
562
562
  export const CAX_MAXC0_RULE_CONFIDENCE = 0.95;
563
563
 
@@ -989,7 +989,7 @@ function buildSurvivorDerivabilityCheck(rows) {
989
989
  * A survivor keeps its stale, still-single justification as-is; a later
990
990
  * retraction of its OTHER supporting path therefore won't re-examine it.
991
991
  * Re-grounding survivors — or tracking every alternate justification set —
992
- * is the ATMS horizon (PLAN_SYLLOGIST.md §3), not this bounded slice.
992
+ * is the ATMS horizon, not this bounded slice.
993
993
  *
994
994
  * Returns { retracted, count, budget, depth, truncated, found } — `found` is
995
995
  * false when `subject ⊑ object` was never a stored fact.
@@ -0,0 +1,36 @@
1
+ // version-stamp.mjs — the home page's #pkg-version element, written and read
2
+ // from one place. Pure: strings in, strings out, no imports, so the deploy
3
+ // smoke check can reach it without npm ci.
4
+ //
5
+ // This existed three times and the copies had already drifted: the writer
6
+ // matched [^<]*, the smoke check demanded \d+\.\d+\.\d+, and the estate test
7
+ // accepted [^<\s]*. A writer that accepts what its reader rejects is a green
8
+ // build and a failed deploy, so the pattern lives here and all three call it.
9
+
10
+ /** The element that carries the version, and the value inside it. */
11
+ const STAMP = /(id="pkg-version"[^>]*>)\s*v?([^<]*?)\s*(<)/;
12
+
13
+ /** A semver core, which is what the deploy smoke check is entitled to expect. */
14
+ const SEMVER = /^\d+\.\d+\.\d+$/;
15
+
16
+ /** True iff `html` carries an element the stamp can be written into. */
17
+ export function hasVersionStamp(html) {
18
+ return STAMP.test(html);
19
+ }
20
+
21
+ /** The version `html` displays, or null when the element is absent or holds
22
+ * something that is not a semver core (an unstamped placeholder, say). */
23
+ export function parseVersionStamp(html) {
24
+ const found = STAMP.exec(html);
25
+ if (!found) return null;
26
+ const value = found[2].trim();
27
+ return SEMVER.test(value) ? value : null;
28
+ }
29
+
30
+ /** `html` with the stamp set to `version`. Throws when there is nothing to
31
+ * stamp — a page that lost its element would otherwise publish blank. */
32
+ export function stampVersion(html, version) {
33
+ if (!SEMVER.test(version)) throw new Error(`not a stampable version: "${version}"`);
34
+ if (!hasVersionStamp(html)) throw new Error("no #pkg-version element to stamp");
35
+ return html.replace(STAMP, `$1${version}$3`);
36
+ }
@@ -0,0 +1,133 @@
1
+ // yaml.mjs — a reader for the small YAML subset the Open English WordNet dump
2
+ // uses: 2-space-indented block mappings/sequences, quoted or bare scalars, and
3
+ // long scalar list-items that simply WRAP onto a further-indented continuation
4
+ // line. No block scalars, no anchors, no flow style — confirmed by direct
5
+ // inspection of the dump. This reads exactly that subset; it is not a general
6
+ // YAML parser.
7
+ //
8
+ // Pure: text in, object out, no imports, so it is testable without the WordNet
9
+ // clone the scripts that call it need.
10
+
11
+ /** Non-greedy key group so a MULTI-WORD entry key ("M-1 rifle", "ice cream")
12
+ * still matches — the first ": "/end-of-line colon wins, exactly as real
13
+ * YAML's block-mapping key/value split works. A plain wrapped scalar
14
+ * continuation line (a definition/example fragment) only coincidentally
15
+ * matches this if it ALSO happens to contain a bare "word: " sequence — rare
16
+ * in this corpus's prose, and this feeds a maintainer worksheet whose output
17
+ * is hand-reviewed, not a correctness-critical parser. */
18
+ const KEY_RE = /^(.+?):(\s+(.*)|)$/;
19
+
20
+ const isDash = (t) => t === "-" || t.startsWith("- ");
21
+
22
+ function parseScalar(s) {
23
+ const t = s.trim();
24
+ if ((t.startsWith("'") && t.endsWith("'") && t.length >= 2) || (t.startsWith('"') && t.endsWith('"') && t.length >= 2)) {
25
+ return t.slice(1, -1);
26
+ }
27
+ return t;
28
+ }
29
+
30
+ export function parseYaml(text) {
31
+ const rawLines = text.split("\n");
32
+ const lines = [];
33
+ for (const line of rawLines) {
34
+ if (!line.trim() || line.trim().startsWith("#")) continue;
35
+ const indent = line.length - line.trimStart().length;
36
+ lines.push({ indent, text: line.trimStart() });
37
+ }
38
+ let pos = 0;
39
+
40
+ // A scalar that may continue on subsequent MORE-indented lines with no
41
+ // "key:"/"- " marker of their own (WordNet's definition-wrapping style). A
42
+ // QUOTED scalar ('...' or "...") is handled separately: WordNet definitions
43
+ // routinely contain a literal ": " inside the quoted text itself (e.g. "…
44
+ // Matthew, Mark, Luke, and John" split across a line boundary right after a
45
+ // colon) — the bare-scalar heuristic below would misread that continuation
46
+ // line as a new "key:" line and truncate the string. Once inside an open
47
+ // quote, EVERY line is a continuation until one ends with the matching
48
+ // closing quote, full stop — the key/dash heuristic never applies inside it.
49
+ function parseScalarOrContinue(first, minContinIndent) {
50
+ const trimmed = first.trim();
51
+ const quote = trimmed[0] === "'" || trimmed[0] === '"' ? trimmed[0] : null;
52
+ if (quote) {
53
+ const closes = (s) => s.length >= 2 && s.endsWith(quote);
54
+ let buf = trimmed;
55
+ while (!closes(buf) && pos < lines.length && lines[pos].indent >= minContinIndent) {
56
+ buf += " " + lines[pos].text.trim();
57
+ pos += 1;
58
+ }
59
+ return closes(buf) ? buf.slice(1, -1) : buf;
60
+ }
61
+ let s = parseScalar(first);
62
+ while (pos < lines.length && lines[pos].indent >= minContinIndent
63
+ && !isDash(lines[pos].text) && !KEY_RE.test(lines[pos].text)) {
64
+ s += " " + lines[pos].text.trim();
65
+ pos += 1;
66
+ }
67
+ return s;
68
+ }
69
+
70
+ /** The value that follows a "key:" (bare, no inline scalar) — peeks at the
71
+ * next line to decide whether it's a nested sequence (which YAML allows to
72
+ * sit at the SAME indent as the key itself, not just deeper) or a nested
73
+ * mapping (which must be deeper) or simply absent (null). `parentIndent`
74
+ * is the indent of the "key:" line whose value this resolves. */
75
+ function parseValue(parentIndent) {
76
+ if (pos >= lines.length || lines[pos].indent < parentIndent) return null;
77
+ const line = lines[pos];
78
+ if (isDash(line.text)) return parseSeq(line.indent);
79
+ if (line.indent > parentIndent && KEY_RE.test(line.text)) return parseMap(line.indent);
80
+ return null;
81
+ }
82
+
83
+ function parseSeq(indent) {
84
+ const arr = [];
85
+ while (pos < lines.length && lines[pos].indent === indent && isDash(lines[pos].text)) {
86
+ const dashIndent = indent;
87
+ const rest = lines[pos].text === "-" ? "" : lines[pos].text.slice(2);
88
+ pos += 1;
89
+ if (rest === "") {
90
+ arr.push(parseValue(dashIndent));
91
+ continue;
92
+ }
93
+ // A quoted scalar is classified FIRST, unconditionally — WordNet
94
+ // definitions routinely contain a literal ": " (or a colon at the very
95
+ // end of a wrapped line, e.g. "…including:\n whales, …") inside quoted
96
+ // prose, which KEY_RE would otherwise misread as an inline "- key:"
97
+ // mapping. Only an UNQUOTED rest is even considered for that shape.
98
+ const quoted = rest[0] === "'" || rest[0] === '"';
99
+ const m = quoted ? null : KEY_RE.exec(rest);
100
+ if (m) {
101
+ // "- key: value" or "- key:" — an inline mapping for this list item;
102
+ // sibling keys of the SAME item are indented +2 from the dash.
103
+ const obj = {};
104
+ obj[m[1]] = m[3] !== undefined && m[3] !== "" ? parseScalarOrContinue(m[3], dashIndent + 2) : parseValue(dashIndent + 2);
105
+ while (pos < lines.length && lines[pos].indent === dashIndent + 2 && KEY_RE.test(lines[pos].text)) {
106
+ const mm = KEY_RE.exec(lines[pos].text);
107
+ pos += 1;
108
+ obj[mm[1]] = mm[3] !== undefined && mm[3] !== "" ? parseScalarOrContinue(mm[3], dashIndent + 4) : parseValue(dashIndent + 2);
109
+ }
110
+ arr.push(obj);
111
+ } else {
112
+ // a plain (or quoted) scalar list item — may wrap onto continuation lines
113
+ arr.push(parseScalarOrContinue(rest, dashIndent + 2));
114
+ }
115
+ }
116
+ return arr;
117
+ }
118
+
119
+ function parseMap(indent) {
120
+ const obj = {};
121
+ while (pos < lines.length && lines[pos].indent === indent && KEY_RE.test(lines[pos].text)) {
122
+ const m = KEY_RE.exec(lines[pos].text);
123
+ const key = parseScalar(m[1]);
124
+ pos += 1;
125
+ obj[key] = m[3] !== undefined && m[3] !== "" ? parseScalarOrContinue(m[3], indent + 2) : parseValue(indent);
126
+ // (parseValue(indent) — not indent+2 — so a same-indent sequence value
127
+ // is recognized; parseValue itself accepts child indent >= indent.)
128
+ }
129
+ return obj;
130
+ }
131
+
132
+ return parseMap(0);
133
+ }
@@ -9,8 +9,8 @@
9
9
  //
10
10
  // createSession(…) is the SESSION SINK every shell shares (runChat's
11
11
  // readline loop below, src/surfaces/tui/app.mjs's Ink shell). chat.mjs re-exports
12
- // createSession/runChat/gitToplevel and the session constants so existing
13
- // import sites keep working.
12
+ // createSession/runChat and the session constants so existing import sites
13
+ // keep working.
14
14
 
15
15
  import { join, resolve } from "node:path";
16
16
  import { createWriteStream } from "node:fs";
@@ -62,8 +62,8 @@ export { uuidv7 };
62
62
  // in the session layer so runTurn and the fact engine below stay free of
63
63
  // node:fs/child_process/os/readline. Re-exported here (services → services) so
64
64
  // every existing import site — bin, tui, server-http, index, tests — keeps
65
- // importing createSession/runChat/gitToplevel/SESSION_LOG_DIR/PROMPT from chat.mjs.
66
- export { createSession, runChat, gitToplevel, SESSION_LOG_DIR, PROMPT } from "./chat-session.mjs";
65
+ // importing createSession/runChat/SESSION_LOG_DIR/PROMPT from chat.mjs.
66
+ export { createSession, runChat, SESSION_LOG_DIR, PROMPT } from "./chat-session.mjs";
67
67
 
68
68
  /** dispatchTool("tmct_ask", …) returns the prose answer plus a delimited
69
69
  * machine-readable envelope; the TUI shows the prose only. Reused verbatim
@@ -15,8 +15,8 @@
15
15
  // 3. tmct.toml's `graph_file` / `graph_files`
16
16
  // 4. <repo>/.tmct/graph.json, where repo is --repo, else git root, else cwd
17
17
  //
18
- // Deliberately does NOT import chat.mjs (would be circular) — the git-root lookup below
19
- // is a small, self-contained copy of chat.mjs's own gitToplevel().
18
+ // Deliberately does NOT import chat-session.mjs (would be circular) — the git-root lookup
19
+ // below is a small, self-contained copy of chat-session.mjs's own gitToplevel().
20
20
 
21
21
  import { spawnSync } from "node:child_process";
22
22
  import { dirname, resolve } from "node:path";
@@ -26,8 +26,8 @@ import { loadTomlConfig, normalizeConfig, mergeEffective, CONFIG_FILE } from "..
26
26
  import { DEFAULT_GRAPH_REL } from "../adapters/config.mjs";
27
27
 
28
28
  /** The git top-level for `cwd`, or null if not in a repo (or git is
29
- * unavailable). A deliberate re-declaration of chat.mjs's gitToplevel (not an
30
- * import) — see the file docblock for why. */
29
+ * unavailable). A deliberate re-declaration of chat-session.mjs's gitToplevel
30
+ * (not an import) — see the file docblock for why. */
31
31
  function defaultGitRoot(cwd) {
32
32
  try {
33
33
  const r = spawnSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf8" });
@@ -18,7 +18,7 @@ export { flatten };
18
18
 
19
19
  const GRAMMAR_DIR = dirname(fileURLToPath(import.meta.url));
20
20
  /** The data-driven grammar-rule table. */
21
- export const GRAMMAR_RULES_FILE = join(GRAMMAR_DIR, "..", "..", "data", "templates", "grammar-rules.toml");
21
+ const GRAMMAR_RULES_FILE = join(GRAMMAR_DIR, "..", "..", "data", "templates", "grammar-rules.toml");
22
22
 
23
23
  /** The segment type vocabulary. `prose` is the only unprotected type. */
24
24
  export const SEGMENT_TYPES = Object.freeze([
@@ -1,6 +1,5 @@
1
1
  // ledger-viz.mjs — `tmct viz`: the memory graph as a readable ledger of
2
- // fact-sentences around one focus term, with the in-page chat dock
3
- // (PLAN_VIZ_LEDGER.md).
2
+ // fact-sentences around one focus term, with the in-page chat dock.
4
3
  //
5
4
  // Three pure/impure-separated pieces:
6
5
  // - computeLedgerData(repoDir, opts) — I/O (loadMemory) + derivation
@@ -16,7 +15,7 @@ import { readFile } from "node:fs/promises";
16
15
  import { fileURLToPath } from "node:url";
17
16
  import { dirname, join } from "node:path";
18
17
 
19
- export const LEDGER_ROW_LIMIT_DEFAULT = 20000;
18
+ const LEDGER_ROW_LIMIT_DEFAULT = 20000;
20
19
 
21
20
  /** Read the checked-in browser memory-ask-engine bundle
22
21
  * (`src/surfaces/web/memory-ask-browser.bundle.js`) — the real memory-graph answer engine
@@ -24,7 +24,7 @@ import { turnKey } from "../domain/memory/session-turns.mjs";
24
24
  export const SESSIONS_DIR_REL = join(".tmct", "sessions");
25
25
 
26
26
  export const SESSION_CLASS = "Session";
27
- export const ASKS_ABOUT_PREDICATE = "asksAbout";
27
+ const ASKS_ABOUT_PREDICATE = "asksAbout";
28
28
  export const ASKS_ABOUT_PROP = "mgx:asksAbout";
29
29
 
30
30
  const QUERIES_ATTR_CAP = 500; // joined-queries attribute cap (mirrors commitMessage's cap idea)
@@ -111,9 +111,9 @@ export function upsertSession(entities, record) {
111
111
  attributes: [
112
112
  // referenced via the imported constant (single-sourced from memory/core.mjs)
113
113
  { prop: CREATED_AT_PROP, key: "createdAt", value: priorCreatedAt || started || new Date().toISOString() },
114
- // this IS a genuinely-mutated individual (re-written every chat turn, PLAN_VIZ.md §2's
115
- // concrete "Session" case) — stamp updatedAt explicitly since the derived "max over edges"
116
- // rule can't see an own-attribute rewrite that touches no edge.
114
+ // a Session really is mutated re-written every chat turn so stamp updatedAt
115
+ // explicitly: the derived "max over edges" rule cannot see an own-attribute rewrite
116
+ // that touches no edge.
117
117
  { prop: UPDATED_AT_PROP, key: "updatedAt", value: new Date().toISOString() },
118
118
  { prop: "mgx:sessionStarted", key: "started", value: started },
119
119
  { prop: "mgx:sessionEnded", key: "ended", value: ended },
@@ -1,7 +1,6 @@
1
1
  // viz-theme.mjs — the shared assets for tmct's generated HTML pages
2
- // (the ledger explorer and the plan player): the visual token table
3
- // (PLAN_VIZ_LEDGER.md's reference values) plus the escaping helpers every
4
- // page builder needs.
2
+ // (the ledger explorer and the plan player): the visual token table plus the
3
+ // escaping helpers every page builder needs.
5
4
  //
6
5
  // Trust tiers are precomputed rgba() values per provenance color so pages
7
6
  // render identically on browsers without color-mix() support.
@@ -30,7 +29,7 @@ function rgba(hex, alpha) {
30
29
  return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;
31
30
  }
32
31
 
33
- export const TOKENS = Object.freeze({
32
+ const TOKENS = Object.freeze({
34
33
  light: Object.freeze({
35
34
  bg: "#F7F6F2", ink: "#23272B", muted: "#6E7168", line: "#DDD9D0", card: "#FFFFFF",
36
35
  taught: "#2E7D4F", corpus: "#5A80AC", entail: "#B07C2E", alert: "#B0503F",
@@ -936,23 +936,6 @@
936
936
  }
937
937
  });
938
938
 
939
- // src/domain/vector.mjs
940
- function cosine(a, b) {
941
- let dot = 0, na = 0, nb = 0;
942
- const n = Math.min(a.length, b.length);
943
- for (let i = 0; i < n; i++) {
944
- dot += a[i] * b[i];
945
- na += a[i] * a[i];
946
- nb += b[i] * b[i];
947
- }
948
- if (na === 0 || nb === 0) return 0;
949
- return dot / (Math.sqrt(na) * Math.sqrt(nb));
950
- }
951
- var init_vector = __esm({
952
- "src/domain/vector.mjs"() {
953
- }
954
- });
955
-
956
939
  // src/domain/memory/trust.mjs
957
940
  function parseChatTagRest(rest) {
958
941
  const at = rest.indexOf("@");
@@ -1307,27 +1290,6 @@
1307
1290
  }
1308
1291
  return idx;
1309
1292
  }
1310
- function moduleEmbedTexts(graph) {
1311
- const texts = /* @__PURE__ */ new Map();
1312
- const defIdx = definesIndex(graph);
1313
- const docs = /* @__PURE__ */ new Map();
1314
- for (const ind of graph.individuals) {
1315
- const doc = (ind.attributes || []).find((a) => a.key === "doc")?.value;
1316
- if (!doc) continue;
1317
- const modId = (ind.class || "") === "Module" ? ind.id : moduleIdOf(graph, ind);
1318
- if (!modId) continue;
1319
- let arr = docs.get(modId);
1320
- if (!arr) docs.set(modId, arr = []);
1321
- if (arr.length < EMB_TEXT_DOC_CAP) arr.push(String(doc).split("\n")[0]);
1322
- }
1323
- for (const ind of graph.individuals) {
1324
- if ((ind.class || "") !== "Module") continue;
1325
- const parts = String(ind.label).split(/[^a-zA-Z0-9_]+/).filter(Boolean);
1326
- const syms = (defIdx.get(ind.id) || []).slice(0, EMB_TEXT_SYMBOL_CAP);
1327
- texts.set(ind.id, [...parts, ...syms, ...docs.get(ind.id) || []].join(" "));
1328
- }
1329
- return texts;
1330
- }
1331
1293
  function identComponents(name) {
1332
1294
  return new Set(String(name).replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean));
1333
1295
  }
@@ -1499,7 +1461,7 @@
1499
1461
  return results;
1500
1462
  }
1501
1463
  function scoreModules(graph, tokens, opts = {}) {
1502
- const { demoteNonProd = false, callAdjacency = false, implOfInterface = false, beamSearch = false, spiral = false, proseBoost = false, proseLayers = false, literalMention = false, embedRank = false, rawQuery = "" } = opts;
1464
+ const { demoteNonProd = false, callAdjacency = false, implOfInterface = false, beamSearch = false, spiral = false, proseBoost = false, proseLayers = false, literalMention = false, rawQuery = "" } = opts;
1503
1465
  const beamWidth = Number.isFinite(opts.beamWidth) && opts.beamWidth > 0 ? opts.beamWidth : 8;
1504
1466
  const defIdx = definesIndex(graph);
1505
1467
  const modules = [];
@@ -1691,34 +1653,6 @@
1691
1653
  s.score += Math.min(signal * PROSE_LAYER_FRAC, s.score * PROSE_LAYER_CAP_FRAC);
1692
1654
  }
1693
1655
  }
1694
- if (embedRank) {
1695
- if (!opts.embedder) {
1696
- if (!embedWarned) {
1697
- embedWarned = true;
1698
- process.stderr.write("tmct: embedRank requested but no embedder available (weights not fetched? see `npm run refs:embeddings`) \u2014 flag is a no-op\n");
1699
- }
1700
- } else if (scored.length) {
1701
- const embedder = opts.embedder;
1702
- let cache2 = EMB_CACHE.get(graph);
1703
- if (!cache2 || cache2.embedder !== embedder) {
1704
- cache2 = { embedder, texts: moduleEmbedTexts(graph), vecs: /* @__PURE__ */ new Map() };
1705
- EMB_CACHE.set(graph, cache2);
1706
- }
1707
- const qv = embedder.embed(rawQuery || tokens.join(" "));
1708
- let maxBase = 0;
1709
- for (const s of scored) maxBase = Math.max(maxBase, s.score);
1710
- for (const s of scored) {
1711
- let v = cache2.vecs.get(s.ind.id);
1712
- if (!v) {
1713
- v = embedder.embed(cache2.texts.get(s.ind.id) || String(s.ind.label));
1714
- cache2.vecs.set(s.ind.id, v);
1715
- }
1716
- const sim = Math.max(0, cosine(qv, v));
1717
- if (!sim) continue;
1718
- s.score += Math.min(sim * maxBase * EMB_FRAC, s.score * EMB_CAP_FRAC);
1719
- }
1720
- }
1721
- }
1722
1656
  if (beamSearch && scored.length > 1) beamExpand(graph, scored, beamWidth);
1723
1657
  if (spiral && scored.length) spiralExpand(graph, scored, {
1724
1658
  depth: Number.isFinite(opts.spiralDepth) && opts.spiralDepth > 0 ? opts.spiralDepth : SPIRAL_DEPTH_DEFAULT,
@@ -1732,7 +1666,7 @@
1732
1666
  const raw = String(query || "");
1733
1667
  const tokens = raw.toLowerCase().split(/[^a-z0-9_]+/).filter(Boolean);
1734
1668
  if (!tokens.length) return [];
1735
- const effOpts = opts.literalMention || opts.embedRank ? { ...opts, rawQuery: raw } : opts;
1669
+ const effOpts = opts.literalMention ? { ...opts, rawQuery: raw } : opts;
1736
1670
  return scoreModules(graph, tokens, effOpts).map((s) => ({ path: String(s.ind.label), score: s.score }));
1737
1671
  }
1738
1672
  function renderSearch(graph, query, { limit = SEARCH_LIMIT, kind = "", decorator = "", name = "" } = {}) {
@@ -2414,11 +2348,10 @@ ${shown.join("\n")}${tail}`;
2414
2348
  ${list.join("\n ")}` + (edges.length > EXPORTS_CAP ? `
2415
2349
  \u2026+${edges.length - EXPORTS_CAP} more` : "");
2416
2350
  }
2417
- var PROP_KIND, isProvRef, DESCRIBE_EDGE_CAP, PROV_CAP, IMPACT_DEPTHS_LISTED, IMPACT_PER_DEPTH, IMPACT_TESTS_PER_DEP, SEARCH_LIMIT, SEARCH_SYMBOLS_SHOWN, PATH_W, SYM_W, EXACT_W, SYM_MATCH_CAP, PROX_FRAC, PROX_CAP_FRAC, isTestLabel, NONPROD_DEMOTE, isNonProdLabel, CALL_PROX_FRAC, CALL_PROX_CAP_FRAC, IMPL_PROX_FRAC, IMPL_PROX_CAP_FRAC, isCsModuleLabel, looksLikeCsInterface, PROSE_PROX_FRAC, PROSE_PROX_CAP_FRAC, PROSE_LOOKUP_LIMIT, PROSE_LAYER_FRAC, PROSE_LAYER_CAP_FRAC, PROSE_LAYER_DISCOUNT, LIT_W, LIT_MIN_COMPONENTS, LIT_COMP_CAP, LIT_FRAC, LIT_CAP_FRAC, EMB_FRAC, EMB_CAP_FRAC, EMB_TEXT_SYMBOL_CAP, EMB_TEXT_DOC_CAP, EMB_CACHE, embedWarned, BEAM_MARGIN_FRAC, BEAM_PROX_FRAC, BEAM_PROX_CAP_FRAC, BEAM_OVERFLOW_CAP, BEAM_PLIES, BEAM_EDGE_GROUPS, SPIRAL_DEPTH_DEFAULT, SPIRAL_NODE_LIMIT_DEFAULT, SPIRAL_Q_DEFAULT, SPIRAL_EXPAND_KINDS, SPIRAL_EMIT_FRAC, SPIRAL_HOP_DECAY, SPIRAL_PROX_FRAC, SPIRAL_PROX_CAP_FRAC, edgesOfKindCache, MEMBERS_CAP, SUBCLASS_CAP, CALL_CAP, attrVal, ARCH_PKG_CAP, ARCH_HUB_CAP, COVERAGE_CAP, TESTS_GRAIN_NOTE, HISTORY_CAP, CALL_SYMBOL_CLASSES, CALL_HINT_CAP, SYMBOL_CLASSES, CONTEXT_SIBLING_CAP, CLASS_MEMBER_CAP, COCHANGE_MID_CAP, CONTEXT_TESTS_CAP, TINY_MAX_LOC, TINY_MAX_ARITY, LARGE_CLASS_MEMBERS, INLINE_CALLEE_CAP, splitDecs, tokenize, countParams, modeOf, COCHANGE_CAP, EXPORTS_CAP;
2351
+ var PROP_KIND, isProvRef, DESCRIBE_EDGE_CAP, PROV_CAP, IMPACT_DEPTHS_LISTED, IMPACT_PER_DEPTH, IMPACT_TESTS_PER_DEP, SEARCH_LIMIT, SEARCH_SYMBOLS_SHOWN, PATH_W, SYM_W, EXACT_W, SYM_MATCH_CAP, PROX_FRAC, PROX_CAP_FRAC, isTestLabel, NONPROD_DEMOTE, isNonProdLabel, CALL_PROX_FRAC, CALL_PROX_CAP_FRAC, IMPL_PROX_FRAC, IMPL_PROX_CAP_FRAC, isCsModuleLabel, looksLikeCsInterface, PROSE_PROX_FRAC, PROSE_PROX_CAP_FRAC, PROSE_LOOKUP_LIMIT, PROSE_LAYER_FRAC, PROSE_LAYER_CAP_FRAC, PROSE_LAYER_DISCOUNT, LIT_W, LIT_MIN_COMPONENTS, LIT_COMP_CAP, LIT_FRAC, LIT_CAP_FRAC, BEAM_MARGIN_FRAC, BEAM_PROX_FRAC, BEAM_PROX_CAP_FRAC, BEAM_OVERFLOW_CAP, BEAM_PLIES, BEAM_EDGE_GROUPS, SPIRAL_DEPTH_DEFAULT, SPIRAL_NODE_LIMIT_DEFAULT, SPIRAL_Q_DEFAULT, SPIRAL_EXPAND_KINDS, SPIRAL_EMIT_FRAC, SPIRAL_HOP_DECAY, SPIRAL_PROX_FRAC, SPIRAL_PROX_CAP_FRAC, edgesOfKindCache, MEMBERS_CAP, SUBCLASS_CAP, CALL_CAP, attrVal, ARCH_PKG_CAP, ARCH_HUB_CAP, COVERAGE_CAP, TESTS_GRAIN_NOTE, HISTORY_CAP, CALL_SYMBOL_CLASSES, CALL_HINT_CAP, SYMBOL_CLASSES, CONTEXT_SIBLING_CAP, CLASS_MEMBER_CAP, COCHANGE_MID_CAP, CONTEXT_TESTS_CAP, TINY_MAX_LOC, TINY_MAX_ARITY, LARGE_CLASS_MEMBERS, INLINE_CALLEE_CAP, splitDecs, tokenize, countParams, modeOf, COCHANGE_CAP, EXPORTS_CAP;
2418
2352
  var init_codegraph = __esm({
2419
2353
  "src/domain/codegraph.mjs"() {
2420
2354
  init_prose();
2421
- init_vector();
2422
2355
  init_trust();
2423
2356
  PROP_KIND = {
2424
2357
  // v2.0 faithful tokens (SEON-faithful realign)
@@ -2484,12 +2417,6 @@ ${shown.join("\n")}${tail}`;
2484
2417
  LIT_COMP_CAP = 4;
2485
2418
  LIT_FRAC = 1;
2486
2419
  LIT_CAP_FRAC = 0.9;
2487
- EMB_FRAC = 0.2;
2488
- EMB_CAP_FRAC = 0.35;
2489
- EMB_TEXT_SYMBOL_CAP = 64;
2490
- EMB_TEXT_DOC_CAP = 12;
2491
- EMB_CACHE = /* @__PURE__ */ new WeakMap();
2492
- embedWarned = false;
2493
2420
  BEAM_MARGIN_FRAC = 0.5;
2494
2421
  BEAM_PROX_FRAC = 0.2;
2495
2422
  BEAM_PROX_CAP_FRAC = 0.35;
@@ -3545,18 +3472,14 @@ ${shown.join("\n")}${tail}`;
3545
3472
  applyNegationFrames: () => applyNegationFrames,
3546
3473
  ask: () => ask,
3547
3474
  classDisplayName: () => classDisplayName,
3548
- compositionalHint: () => compositionalHint,
3549
3475
  degreeMetric: () => degreeMetric,
3550
- evalComposite: () => evalComposite,
3551
3476
  metaFallbackEntityAnswer: () => metaFallbackEntityAnswer,
3552
3477
  normalizeQuery: () => normalizeQuery,
3553
3478
  parseQuery: () => parseQuery,
3554
3479
  parseQueryFull: () => parseQueryFull,
3555
- relaxParse: () => relaxParse,
3556
3480
  render: () => render,
3557
3481
  rephraseHint: () => rephraseHint,
3558
3482
  resolveObject: () => resolveObject,
3559
- touchesRephraseHint: () => touchesRephraseHint,
3560
3483
  traverse: () => traverse
3561
3484
  });
3562
3485
  function edgesOfKind2(graph, kind) {
@@ -7300,9 +7223,7 @@ ${bodyText}` : graphText, tier });
7300
7223
  CARDINALITY_RULE_CONFIDENCE: () => CARDINALITY_RULE_CONFIDENCE,
7301
7224
  CAX_DW_RULE: () => CAX_DW_RULE,
7302
7225
  CAX_DW_RULE_CONFIDENCE: () => CAX_DW_RULE_CONFIDENCE,
7303
- CAX_MAXC0_RULE: () => CAX_MAXC0_RULE,
7304
7226
  CAX_MAXC0_RULE_CONFIDENCE: () => CAX_MAXC0_RULE_CONFIDENCE,
7305
- CAX_SCO_RULE: () => CAX_SCO_RULE,
7306
7227
  CLS_SVF1_RULE: () => CLS_SVF1_RULE,
7307
7228
  CLS_SVF1_RULE_CONFIDENCE: () => CLS_SVF1_RULE_CONFIDENCE,
7308
7229
  DISJOINT_PREDICATE: () => DISJOINT_PREDICATE,
@@ -7311,14 +7232,11 @@ ${bodyText}` : graphText, tier });
7311
7232
  ENTAILED_SCM_SVF_PROVENANCE: () => ENTAILED_SCM_SVF_PROVENANCE,
7312
7233
  ENTAILED_SVF1_PROVENANCE: () => ENTAILED_SVF1_PROVENANCE,
7313
7234
  ENTAILED_TYPE_PROVENANCE: () => ENTAILED_TYPE_PROVENANCE,
7314
- ON_CLASS_PREDICATE: () => ON_CLASS_PREDICATE,
7315
7235
  ON_PROPERTY_PREDICATE: () => ON_PROPERTY_PREDICATE,
7316
- SCM_CARD_RULE: () => SCM_CARD_RULE,
7317
7236
  SCM_SVF_RULE: () => SCM_SVF_RULE,
7318
7237
  SCM_SVF_RULE_CONFIDENCE: () => SCM_SVF_RULE_CONFIDENCE,
7319
7238
  SOME_VALUES_FROM_PREDICATE: () => SOME_VALUES_FROM_PREDICATE,
7320
7239
  SUBCLASS_PREDICATE: () => SUBCLASS_PREDICATE,
7321
- SYLLOGISE_RULE: () => SYLLOGISE_RULE,
7322
7240
  TYPE_PREDICATE: () => TYPE_PREDICATE,
7323
7241
  buildCardinalityRestrictions: () => buildCardinalityRestrictions,
7324
7242
  deriveDisjointViolations: () => deriveDisjointViolations,
@@ -8040,7 +7958,7 @@ ${bodyText}` : graphText, tier });
8040
7958
  }
8041
7959
  return null;
8042
7960
  }
8043
- var SUBCLASS_PREDICATE, SYLLOGISE_RULE, ENTAILED_PROVENANCE, TYPE_PREDICATE, CAX_SCO_RULE, ENTAILED_TYPE_PROVENANCE, DISJOINT_PREDICATE, CAX_DW_RULE, ENTAILED_DISJOINT_PROVENANCE, CAX_DW_RULE_CONFIDENCE, ON_PROPERTY_PREDICATE, SOME_VALUES_FROM_PREDICATE, CLS_SVF1_RULE, ENTAILED_SVF1_PROVENANCE, CLS_SVF1_RULE_CONFIDENCE, SEP, isSubClassOf, isType, isDisjoint, isOnProperty, isSomeValuesFrom, isOnClass, RESERVED_PREDICATES, HAS_PROPERTY_KEY, CARDINALITY_KIND_OF, ON_CLASS_PREDICATE, SCM_SVF_RULE, ENTAILED_SCM_SVF_PROVENANCE, SCM_SVF_RULE_CONFIDENCE, SCM_CARD_RULE, CARDINALITY_RULE_CONFIDENCE, CAX_MAXC0_RULE, CAX_MAXC0_RULE_CONFIDENCE;
7961
+ var SUBCLASS_PREDICATE, SYLLOGISE_RULE, ENTAILED_PROVENANCE, TYPE_PREDICATE, CAX_SCO_RULE, ENTAILED_TYPE_PROVENANCE, DISJOINT_PREDICATE, CAX_DW_RULE, ENTAILED_DISJOINT_PROVENANCE, CAX_DW_RULE_CONFIDENCE, ON_PROPERTY_PREDICATE, SOME_VALUES_FROM_PREDICATE, CLS_SVF1_RULE, ENTAILED_SVF1_PROVENANCE, CLS_SVF1_RULE_CONFIDENCE, SEP, isSubClassOf, isType, isDisjoint, isOnProperty, isSomeValuesFrom, isOnClass, RESERVED_PREDICATES, HAS_PROPERTY_KEY, CARDINALITY_KIND_OF, SCM_SVF_RULE, ENTAILED_SCM_SVF_PROVENANCE, SCM_SVF_RULE_CONFIDENCE, CARDINALITY_RULE_CONFIDENCE, CAX_MAXC0_RULE_CONFIDENCE;
8044
7962
  var init_syllogise = __esm({
8045
7963
  "src/domain/syllogise.mjs"() {
8046
7964
  init_hash();
@@ -8076,13 +7994,10 @@ ${bodyText}` : graphText, tier });
8076
7994
  ]);
8077
7995
  HAS_PROPERTY_KEY = "has";
8078
7996
  CARDINALITY_KIND_OF = { "owl:cardinality": "exactly", "owl:mincardinality": "min", "owl:maxcardinality": "max" };
8079
- ON_CLASS_PREDICATE = "owl:onClass";
8080
7997
  SCM_SVF_RULE = "someValuesFromSubsumption";
8081
7998
  ENTAILED_SCM_SVF_PROVENANCE = `entailed:${SCM_SVF_RULE}`;
8082
7999
  SCM_SVF_RULE_CONFIDENCE = 0.95;
8083
- SCM_CARD_RULE = "cardinalityMonotonicity";
8084
8000
  CARDINALITY_RULE_CONFIDENCE = 0.95;
8085
- CAX_MAXC0_RULE = "maxCardinalityZero";
8086
8001
  CAX_MAXC0_RULE_CONFIDENCE = 0.95;
8087
8002
  }
8088
8003
  });
@@ -8372,10 +8287,8 @@ ${bodyText}` : graphText, tier });
8372
8287
  __export(core_exports, {
8373
8288
  CANONICALISED_FROM_PROP: () => CANONICALISED_FROM_PROP,
8374
8289
  CAPABLE_OF_PREDICATE: () => CAPABLE_OF_PREDICATE2,
8375
- CONTRADICTION_TRUST_FLOOR: () => CONTRADICTION_TRUST_FLOOR,
8376
8290
  CREATED_AT_PROP: () => CREATED_AT_PROP,
8377
8291
  DEFAULT_RETENTION: () => DEFAULT_RETENTION,
8378
- DERIVED_FROM_PROP: () => DERIVED_FROM_PROP,
8379
8292
  FACT_CLASS: () => FACT_CLASS,
8380
8293
  HAS_A_PREDICATE: () => HAS_A_PREDICATE,
8381
8294
  IN_REPLY_TO_PROP: () => IN_REPLY_TO_PROP,
@@ -8386,7 +8299,6 @@ ${bodyText}` : graphText, tier });
8386
8299
  MULTI_VALUED_PREDICATES: () => MULTI_VALUED_PREDICATES,
8387
8300
  OPERATOR_SOURCE_ID: () => OPERATOR_SOURCE_ID,
8388
8301
  RULE_CLASS: () => RULE_CLASS,
8389
- RULE_KINDS: () => RULE_KINDS2,
8390
8302
  RULE_KIND_ACTION_CONSTRAINT: () => RULE_KIND_ACTION_CONSTRAINT,
8391
8303
  RULE_KIND_ACTION_EFFECT: () => RULE_KIND_ACTION_EFFECT,
8392
8304
  RULE_KIND_ACTION_PRECOND: () => RULE_KIND_ACTION_PRECOND,
@@ -8395,12 +8307,10 @@ ${bodyText}` : graphText, tier });
8395
8307
  RULE_KIND_FILTER: () => RULE_KIND_FILTER,
8396
8308
  RULE_KIND_PROP: () => RULE_KIND_PROP,
8397
8309
  RULE_KIND_RECURSIVE: () => RULE_KIND_RECURSIVE,
8398
- RULE_NAME_PROP: () => RULE_NAME_PROP,
8399
8310
  SAID_IN_SESSION_PROP: () => SAID_IN_SESSION_PROP,
8400
8311
  SOURCE_CLASS: () => SOURCE_CLASS,
8401
8312
  SOURCE_RELIABILITY_PROP: () => SOURCE_RELIABILITY_PROP,
8402
8313
  STATED_BY_PROP: () => STATED_BY_PROP,
8403
- TEACH_SOURCE_ID: () => TEACH_SOURCE_ID,
8404
8314
  UPDATED_AT_PROP: () => UPDATED_AT_PROP,
8405
8315
  UTTERANCE_CLASS: () => UTTERANCE_CLASS,
8406
8316
  appendFact: () => appendFact,