@konneal/engine 0.2.69 → 0.2.71

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  handleAsk
3
- } from "./chunk-PENTOBUO.js";
3
+ } from "./chunk-EOQVQBS6.js";
4
4
  import "./chunk-TPV5GPY2.js";
5
5
  import "./chunk-SPKPH54J.js";
6
6
  import "./chunk-A3QHHUN5.js";
@@ -1906,17 +1906,59 @@ ${r.output}`;
1906
1906
  function isOperationIntent(query) {
1907
1907
  return /\b(operations?|endpoints?)\b/i.test(query);
1908
1908
  }
1909
+ var ACTION_STEMS = [
1910
+ "updat",
1911
+ "upsert",
1912
+ "writ",
1913
+ "put",
1914
+ "delet",
1915
+ "remov",
1916
+ "read",
1917
+ "fetch",
1918
+ "get",
1919
+ "creat",
1920
+ "declar",
1921
+ "confirm",
1922
+ "approv",
1923
+ "declin",
1924
+ "decide",
1925
+ "revok",
1926
+ "grant",
1927
+ "notify",
1928
+ "advanc",
1929
+ "announc",
1930
+ "download"
1931
+ ];
1932
+ function matchOperations(query, rows) {
1933
+ const q = query.toLowerCase();
1934
+ const stems = ACTION_STEMS.filter((s) => q.includes(s));
1935
+ if (!stems.length) return [];
1936
+ const scored = [];
1937
+ for (const r of rows) {
1938
+ const hay = `${r.anchor} ${r.text}`.toLowerCase();
1939
+ const score = stems.filter((s) => hay.includes(s)).length;
1940
+ if (score > 0) scored.push({ ...r, score });
1941
+ }
1942
+ return scored.sort((a, b) => b.score - a.score).slice(0, 4);
1943
+ }
1909
1944
  function catalogNote(anchors) {
1910
1945
  if (!anchors.length) return "";
1911
- return `The platform's indexed operations (the COMPLETE surface \u2014 every operation the system exposes; the answer must name the operation from this list when one matches the question):
1946
+ return `The COMPLETE name index of the platform's operations:
1912
1947
  ${anchors.map((a) => `- ${a}`).join("\n")}`;
1913
1948
  }
1914
1949
  async function operationsCatalogNote(db, query) {
1915
1950
  if (!isOperationIntent(query)) return void 0;
1916
1951
  try {
1917
- const rows = (await db.prepare("SELECT clause_anchor FROM chunks WHERE corpus = 'smart-ops' AND clause_anchor IS NOT NULL ORDER BY clause_anchor").all()).results ?? [];
1918
- const note = catalogNote(rows.map((r) => r.clause_anchor).filter(Boolean));
1919
- return note || void 0;
1952
+ const rows = (await db.prepare("SELECT clause_anchor AS anchor, substr(text, 1, 220) AS text FROM chunks WHERE corpus = 'smart-ops' AND clause_anchor IS NOT NULL ORDER BY clause_anchor").all()).results ?? [];
1953
+ const opRows = rows.map((r) => ({ anchor: String(r.anchor ?? ""), text: String(r.text ?? "") })).filter((r) => r.anchor);
1954
+ const matched = matchOperations(query, opRows);
1955
+ const parts = [];
1956
+ if (matched.length) {
1957
+ parts.push(`Operations whose description matches the question's action (AUTHORITATIVE \u2014 if one matches, the answer MUST name it and cite its line; never answer that the information is missing):
1958
+ ${matched.map((m) => `- ${m.text}`).join("\n")}`);
1959
+ }
1960
+ parts.push(catalogNote(opRows.map((r) => r.anchor)));
1961
+ return parts.filter(Boolean).join("\n\n") || void 0;
1920
1962
  } catch {
1921
1963
  return void 0;
1922
1964
  }
@@ -2686,7 +2728,7 @@ Answer account questions from these records ONLY: name the record when you use i
2686
2728
  q.lang,
2687
2729
  keptHistory,
2688
2730
  // stage-extracted graph facts (GraphRAG) ride the same note channel
2689
- [processNote, eNote, regNote, opsCatalog, contextNote(declaredCtx, docScope), accountNote, modelNote, vocabNote, memNote, machineNote, conditionNote, aggregationNote, boundaryNote, licenseNote, ...retrieved.notes ?? []].filter(Boolean).join("\n") || void 0,
2731
+ [opsCatalog, processNote, eNote, regNote, contextNote(declaredCtx, docScope), accountNote, modelNote, vocabNote, memNote, machineNote, conditionNote, aggregationNote, boundaryNote, licenseNote, ...retrieved.notes ?? []].filter(Boolean).join("\n") || void 0,
2690
2732
  summary,
2691
2733
  budget
2692
2734
  );
@@ -1,3 +1,10 @@
1
1
  export declare function isOperationIntent(query: string): boolean;
2
+ export declare function matchOperations(query: string, rows: {
3
+ anchor: string;
4
+ text: string;
5
+ }[]): {
6
+ anchor: string;
7
+ text: string;
8
+ }[];
2
9
  export declare function catalogNote(anchors: string[]): string;
3
10
  export declare function operationsCatalogNote(db: any, query: string): Promise<string | undefined>;
@@ -6,7 +6,7 @@ import {
6
6
  modelGroundingBlock,
7
7
  scoreFaithfulness,
8
8
  scoreJudge
9
- } from "../../chunk-PENTOBUO.js";
9
+ } from "../../chunk-EOQVQBS6.js";
10
10
  import {
11
11
  handleSearch
12
12
  } from "../../chunk-FLNX4O7C.js";
@@ -959,7 +959,7 @@ async function handleMcp(env, ctx, req, tier, key) {
959
959
  // stream:false forces the JSON lane (anon defaults to SSE)
960
960
  body: JSON.stringify({ ...args, stream: false })
961
961
  });
962
- const res = name === "ask" ? await (await import("../../ask-UC5IVQDH.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-PBOODCMQ.js")).handleSearch(env, ctx, inner, tier, key);
962
+ const res = name === "ask" ? await (await import("../../ask-OUNG3JIC.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-PBOODCMQ.js")).handleSearch(env, ctx, inner, tier, key);
963
963
  return res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
964
964
  });
965
965
  if (out.ok && "accepted" in out) return new Response(null, { status: 202 });
package/package.json CHANGED
@@ -27,7 +27,7 @@
27
27
  "playwright": "^1.62.1",
28
28
  "yaml": "^2.9.1"
29
29
  },
30
- "version": "0.2.69",
30
+ "version": "0.2.71",
31
31
  "description": "The Konneal engine: the publisher-agnostic build pipeline and API plane for standards intelligence (retrieval, answer contract, verdicts, evaluation).",
32
32
  "license": "BSD-3-Clause",
33
33
  "type": "module",
@@ -1148,7 +1148,7 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
1148
1148
  q.lang,
1149
1149
  keptHistory,
1150
1150
  // stage-extracted graph facts (GraphRAG) ride the same note channel
1151
- [processNote, eNote, regNote, opsCatalog, contextNote(declaredCtx, docScope), accountNote, modelNote, vocabNote, memNote, machineNote, conditionNote, aggregationNote, boundaryNote, licenseNote, ...(retrieved.notes ?? [])].filter(Boolean).join("\n") || undefined,
1151
+ [opsCatalog, processNote, eNote, regNote, contextNote(declaredCtx, docScope), accountNote, modelNote, vocabNote, memNote, machineNote, conditionNote, aggregationNote, boundaryNote, licenseNote, ...(retrieved.notes ?? [])].filter(Boolean).join("\n") || undefined,
1152
1152
  summary,
1153
1153
  budget,
1154
1154
  );
@@ -1,26 +1,53 @@
1
1
  // The operations catalog lane (TODO.new-era/6's platform surface): the
2
- // smart-ops corpus is SMALL (169 operations) and name-addressable. When
3
- // a question is operation-intent, the ENTIRE operation-name index rides
4
- // the notes channel — the model matches "updates an entity record" to
5
- // putEntityRecord semantically from the complete surface, instead of
6
- // gambling on which sibling passage retrieval happens to surface.
2
+ // smart-ops corpus is SMALL (169 operations) and name-addressable. An
3
+ // operation-intent question gets (1) the operations whose description
4
+ // matches the question's action stems — with their full lines, and (2)
5
+ // the complete name index. The note is AUTHORITATIVE: the model must
6
+ // name the operation from it, never answer from the passages' silence.
7
7
  // Pure composition lives here; the D1 call is a thin wrapper.
8
8
 
9
9
  export function isOperationIntent(query: string): boolean {
10
10
  return /\b(operations?|endpoints?)\b/i.test(query);
11
11
  }
12
12
 
13
+ /** The action stems the register's descriptions use, mapped from the
14
+ * words a question actually asks ("updates" → updat; "upserts" shares
15
+ * the stem). */
16
+ const ACTION_STEMS = [
17
+ "updat", "upsert", "writ", "put", "delet", "remov", "read", "fetch", "get", "creat", "declar",
18
+ "confirm", "approv", "declin", "decide", "revok", "grant", "notify", "advanc", "announc", "download",
19
+ ];
20
+
21
+ export function matchOperations(query: string, rows: { anchor: string; text: string }[]): { anchor: string; text: string }[] {
22
+ const q = query.toLowerCase();
23
+ const stems = ACTION_STEMS.filter((s) => q.includes(s));
24
+ if (!stems.length) return [];
25
+ const scored: { anchor: string; text: string; score: number }[] = [];
26
+ for (const r of rows) {
27
+ const hay = `${r.anchor} ${r.text}`.toLowerCase();
28
+ const score = stems.filter((s) => hay.includes(s)).length;
29
+ if (score > 0) scored.push({ ...r, score });
30
+ }
31
+ return scored.sort((a, b) => b.score - a.score).slice(0, 4);
32
+ }
33
+
13
34
  export function catalogNote(anchors: string[]): string {
14
35
  if (!anchors.length) return "";
15
- return `The platform's indexed operations (the COMPLETE surface — every operation the system exposes; the answer must name the operation from this list when one matches the question):\n${anchors.map((a) => `- ${a}`).join("\n")}`;
36
+ return `The COMPLETE name index of the platform's operations:\n${anchors.map((a) => `- ${a}`).join("\n")}`;
16
37
  }
17
38
 
18
39
  export async function operationsCatalogNote(db: any, query: string): Promise<string | undefined> {
19
40
  if (!isOperationIntent(query)) return undefined;
20
41
  try {
21
- const rows = (await db.prepare("SELECT clause_anchor FROM chunks WHERE corpus = 'smart-ops' AND clause_anchor IS NOT NULL ORDER BY clause_anchor").all()).results ?? [];
22
- const note = catalogNote((rows as any[]).map((r) => r.clause_anchor).filter(Boolean));
23
- return note || undefined;
42
+ const rows = (await db.prepare("SELECT clause_anchor AS anchor, substr(text, 1, 220) AS text FROM chunks WHERE corpus = 'smart-ops' AND clause_anchor IS NOT NULL ORDER BY clause_anchor").all()).results ?? [];
43
+ const opRows = (rows as any[]).map((r) => ({ anchor: String(r.anchor ?? ""), text: String(r.text ?? "") })).filter((r) => r.anchor);
44
+ const matched = matchOperations(query, opRows);
45
+ const parts: string[] = [];
46
+ if (matched.length) {
47
+ parts.push(`Operations whose description matches the question's action (AUTHORITATIVE — if one matches, the answer MUST name it and cite its line; never answer that the information is missing):\n${matched.map((m) => `- ${m.text}`).join("\n")}`);
48
+ }
49
+ parts.push(catalogNote(opRows.map((r) => r.anchor)));
50
+ return parts.filter(Boolean).join("\n\n") || undefined;
24
51
  } catch {
25
52
  return undefined; // the lane is optional
26
53
  }