@konneal/engine 0.2.102 → 0.2.103

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,7 +1,7 @@
1
1
  import {
2
2
  handleAsk
3
- } from "./chunk-FQVP3JUA.js";
4
- import "./chunk-QNLFNEI4.js";
3
+ } from "./chunk-NCZHN6QW.js";
4
+ import "./chunk-ANUHRJ4Z.js";
5
5
  import "./chunk-25ECO5M7.js";
6
6
  import "./chunk-KNCRYAX3.js";
7
7
  import "./chunk-DTW4UW2E.js";
@@ -80,170 +80,6 @@ function tableRetyped(text, availableTable) {
80
80
  return /(^|\n)\s*\|[^\n]+\|\s*(\n\s*\|[-: |]+\|\s*)?(\n|$)/.test(text) && (text.match(/\|/g) ?? []).length >= 6;
81
81
  }
82
82
 
83
- // workers/worker_public/src/modelplane.ts
84
- var NODE_RE = /(?:^|[\s("'`])\/(req|conf|term|constraint|characteristic|state-machine|dimension)\/([a-z0-9][a-z0-9_-]*(?:\/[a-z0-9][a-z0-9_-]*)?)(?=[\s)"'`,;:.]|$)/i;
85
- function modelNodeRefIn(text) {
86
- if (!text) return null;
87
- const m = text.match(NODE_RE);
88
- if (!m) return null;
89
- const id = `/${m[1].toLowerCase()}/${m[2]}`;
90
- return id.length <= 120 ? id : null;
91
- }
92
- function standardForDocNumber(docNumber) {
93
- if (!docNumber) return null;
94
- const models = P().sources?.models;
95
- if (!models?.standards?.length || !models?.standard_prefix) return null;
96
- return models.standards.includes(docNumber) ? `${models.standard_prefix}${docNumber}` : null;
97
- }
98
- function licensedEntryForPackage(packageId) {
99
- if (!packageId) return null;
100
- return (P().sources?.licensed ?? []).find((l) => l.package === packageId) ?? null;
101
- }
102
- function licensedEntryForDocNumber(docNumber) {
103
- if (!docNumber) return null;
104
- return (P().sources?.licensed ?? []).find((l) => String(l.doc_number ?? "") === docNumber) ?? null;
105
- }
106
- function licenseBoundaryNote(docNumber, standardKeys) {
107
- const entry = licensedEntryForDocNumber(docNumber);
108
- if (!entry || standardKeys && standardKeys.has(entry.key)) return void 0;
109
- const pointer = P().prompts?.vars?.license_declare_pointer;
110
- return `License boundary \u2014 the question is about ${licenseBoundaryName(entry)}, a licensed publication (entitlement key ${entry.key}). The caller's organization license does not cover its text, so no passage of it was retrieved and NONE of its procedural content (steps, parameters, severities, limits) may be stated, paraphrased or recalled from memory. You MAY answer at the citation level: name the standard and edition, and cite the invoking clause from the PUBLIC passages in context (the Recommendation's own applicability and normative references are public and stay answerable). Then say the organization's license does not cover the standard's text` + (pointer ? ` and point to the declare flow: ${pointer}.` : ".");
111
- }
112
- function licenseBoundaryName(entry) {
113
- const id = entry.doc_number ? ` ${entry.doc_number}` : ` ${entry.package}`;
114
- return `${entry.title ?? "standard"}${entry.edition ? ` (${entry.edition})` : ""} \u2014${id}`;
115
- }
116
- function licenseBoundaryRefusal(docNumber, standardKeys) {
117
- const entry = licensedEntryForDocNumber(docNumber);
118
- if (!entry || standardKeys && standardKeys.has(entry.key)) return void 0;
119
- const pointer = P().prompts?.vars?.license_declare_pointer;
120
- return `${licenseBoundaryName(entry)} is a licensed publication and your organization's license does not cover its text, so I can't quote or summarize its procedure. I can answer at the citation level \u2014 the standard's title and edition, and the clause your Recommendation invokes \u2014 and the public ${P().publisher.name} content in full.` + (pointer ? ` To unlock the full text, an org admin can declare the license under ${pointer}.` : "");
121
- }
122
- async function fetchNode(env, standard, nodeId) {
123
- try {
124
- const row = await env.DB.prepare(
125
- "SELECT standard, node_id, kind, name, clause_doc, clause_ref, content FROM model_nodes WHERE standard = ?1 AND node_id = ?2"
126
- ).bind(standard, nodeId).first();
127
- if (!row) return null;
128
- const content = JSON.parse(String(row.content));
129
- const clause = row.clause_doc && row.clause_ref ? { doc: String(row.clause_doc), ref: String(row.clause_ref), urn: `${row.clause_doc}#clause-${row.clause_ref}` } : row.clause_doc ? { doc: String(row.clause_doc), ref: "", urn: String(row.clause_doc) } : null;
130
- return {
131
- standard: String(row.standard),
132
- node_id: String(row.node_id),
133
- kind: String(row.kind),
134
- name: String(row.name ?? row.node_id),
135
- clause,
136
- content
137
- };
138
- } catch {
139
- return null;
140
- }
141
- }
142
- async function bindModelNode(env, opts) {
143
- const nodeId = modelNodeRefIn(opts.label) ?? modelNodeRefIn(opts.query);
144
- if (!nodeId) return null;
145
- const gate = (node) => {
146
- if (!node) return null;
147
- const entry = licensedEntryForPackage(node.standard);
148
- return entry && !(opts.standardKeys?.has(entry.key) ?? false) ? { ...node, gated: true, content: {} } : node;
149
- };
150
- if (opts.standard) return gate(await fetchNode(env, opts.standard, nodeId));
151
- try {
152
- const rows = await env.DB.prepare(
153
- "SELECT n.standard AS standard FROM model_nodes n LEFT JOIN model_plane_meta m ON m.standard = n.standard WHERE n.node_id = ?1 ORDER BY m.indexed_at DESC, n.standard DESC LIMIT 1"
154
- ).bind(nodeId).all();
155
- const standard = (rows?.results ?? []).map((r) => String(r.standard))[0];
156
- if (standard) return gate(await fetchNode(env, standard, nodeId));
157
- return null;
158
- } catch {
159
- return null;
160
- }
161
- }
162
- function clip(s, n = 500) {
163
- const t = String(s ?? "").trim();
164
- return t.length <= n ? t : t.slice(0, n - 1).trimEnd() + " \u2026";
165
- }
166
- function applicabilityText(app) {
167
- if (!app || typeof app !== "object") return "";
168
- const parts = [];
169
- for (const [dim, cond] of Object.entries(app)) {
170
- if (Array.isArray(cond)) parts.push(`${dim.replace(/_/g, " ")}: ${cond.join(", ")}`);
171
- else if (cond && typeof cond === "object" && Array.isArray(cond.values)) {
172
- parts.push(`${dim.replace(/_/g, " ")} (${cond.match ?? "any"}): ${cond.values.join(", ")}`);
173
- }
174
- }
175
- return parts.join("; ");
176
- }
177
- function modelGroundingBlock(node) {
178
- const c = node.content ?? {};
179
- const lines = [];
180
- lines.push(
181
- P().prompts.vars.model_grounding_intro ?? "Model grounding \u2014 the model plane's own statement:"
182
- );
183
- lines.push(`Node: ${node.node_id} (${node.kind.replace(/_/g, " ")}) \u2014 ${node.name} [${node.standard}]`);
184
- if (node.clause) lines.push(`Provenance: ${node.clause.urn}`);
185
- if (c.statement) lines.push(`Statement: ${clip(c.statement)}`);
186
- if (c.definition) lines.push(`Definition: ${clip(c.definition)}`);
187
- if (c.purpose) lines.push(`Purpose: ${clip(c.purpose)}`);
188
- const limit = c.limit ?? {};
189
- if (limit.expression) lines.push(`Machine limit (the constraint the platform's verdict engine evaluates \u2014 quote it verbatim): ${limit.expression}`);
190
- if (limit.accepts?.verdict) lines.push(`Machine limit: ${limit.accepts.verdict} ${limit.accepts.op} ${limit.accepts.limit} (the canonical acceptance chain)`);
191
- if (c.check) lines.push(`Machine check: ${c.check}`);
192
- if (c.derive) lines.push(`Derivation: ${c.derive}${Array.isArray(c.inputs) ? ` (inputs: ${c.inputs.join(", ")})` : ""}`);
193
- const app = applicabilityText(c.applicability);
194
- const scopeApp = applicabilityText(c.scope_applicability);
195
- if (app || scopeApp) lines.push(`Applicability: ${[scopeApp, app].filter(Boolean).join("; ")}`);
196
- if (Array.isArray(c.binds_to) && c.binds_to.length) lines.push(`Binds to: ${c.binds_to.join(", ")}`);
197
- if (Array.isArray(c.targets) && c.targets.length) lines.push(`Verifies requirements: ${c.targets.join(", ")}`);
198
- if (Array.isArray(c.preconditions) && c.preconditions.length) {
199
- const pcs = c.preconditions.map((p) => `${p.id}: ${clip(p.check ?? (p.state ? `state = ${p.state}` : ""), 120)}`).join("; ");
200
- lines.push(`Run-validity preconditions (a violation voids the run \u2014 invalid, never a fail): ${pcs}`);
201
- }
202
- if (c.acceptance_criteria?.description) lines.push(`Acceptance: ${clip(c.acceptance_criteria.description, 300)}`);
203
- if (c.violation_meaning) lines.push(`Violation meaning (verbatim): ${clip(c.violation_meaning, 300)} \u2014 on violation: ${c.on_violation ?? "invalid"}`);
204
- if (Array.isArray(c.values) && c.values.length) {
205
- lines.push(`Values: ${c.values.map((v) => `${v.id}${v.implies?.length ? ` (implies ${v.implies.join(", ")})` : ""}`).join("; ")}`);
206
- }
207
- if (c.source_discrepancy) {
208
- const sd = c.source_discrepancy;
209
- lines.push(
210
- `DECLARED SOURCE DISCREPANCY \u2014 the model and the text disagree; you MUST surface this and cite both: ${clip(sd.summary, 300)} Sources: ${(sd.sources ?? []).join(" and ")}. The model ${sd.resolution === "follows_clause_x" ? "follows one side" : "records the conflict without resolving it"}: ${clip(sd.rationale, 300)}`
211
- );
212
- }
213
- lines.push(
214
- "Rules for this answer: the machine facts (the constraint, the applicability, the acceptance, the provenance) come from THIS node \u2014 quote the machine limit verbatim, never invent one the node does not carry. If this model content and a prose passage disagree \u2014 including a passage from a different edition \u2014 say so explicitly and cite both (this node and the prose clause)."
215
- );
216
- return lines.join("\n");
217
- }
218
- function modelCitation(node) {
219
- return {
220
- doc_id: `model:${node.standard}`,
221
- docidentifier: `${P().publisher.name} SMART model (${(() => {
222
- const prefix = P().sources?.models?.standard_prefix ?? "";
223
- const letter = prefix.replace(/^.*-/, "").toUpperCase();
224
- return String(node.standard).replace(new RegExp(`^${prefix}`, "i"), `${letter} `);
225
- })()})`,
226
- edition: "",
227
- language: "en",
228
- clause_anchor: node.clause?.ref || "model",
229
- clause_title: `${node.kind.replace(/_/g, " ")} \u2014 ${node.name} (${node.node_id})`,
230
- status: "in-force",
231
- corpus: "smart-model",
232
- quality: "verified",
233
- url: void 0,
234
- snippet: `${node.node_id}${node.clause ? ` \xB7 ${node.clause.urn}` : ""}${node.content?.statement ? ` \u2014 ${clip(node.content.statement, 240)}` : ""}`,
235
- score: 1
236
- };
237
- }
238
- function modelEcho(node) {
239
- return {
240
- node_id: node.node_id.slice(0, 120),
241
- kind: node.kind.slice(0, 40),
242
- standard: node.standard.slice(0, 40),
243
- ...node.clause?.urn ? { clause: node.clause.urn.slice(0, 120) } : {}
244
- };
245
- }
246
-
247
83
  // workers/worker_public/src/verdict.ts
248
84
  function tokenize(src) {
249
85
  const toks = [];
@@ -501,6 +337,205 @@ function verdictNote(v, node) {
501
337
  return lines.join("\n");
502
338
  }
503
339
 
340
+ // workers/worker_public/src/modelplane.ts
341
+ var NODE_RE = /(?:^|[\s("'`])\/(req|conf|term|constraint|characteristic|state-machine|dimension)\/([a-z0-9][a-z0-9_-]*(?:\/[a-z0-9][a-z0-9_-]*)?)(?=[\s)"'`,;:.]|$)/i;
342
+ function modelNodeRefIn(text) {
343
+ if (!text) return null;
344
+ const m = text.match(NODE_RE);
345
+ if (!m) return null;
346
+ const id = `/${m[1].toLowerCase()}/${m[2]}`;
347
+ return id.length <= 120 ? id : null;
348
+ }
349
+ function standardForDocNumber(docNumber) {
350
+ if (!docNumber) return null;
351
+ const models = P().sources?.models;
352
+ if (!models?.standards?.length || !models?.standard_prefix) return null;
353
+ return models.standards.includes(docNumber) ? `${models.standard_prefix}${docNumber}` : null;
354
+ }
355
+ function licensedEntryForPackage(packageId) {
356
+ if (!packageId) return null;
357
+ return (P().sources?.licensed ?? []).find((l) => l.package === packageId) ?? null;
358
+ }
359
+ function licensedEntryForDocNumber(docNumber) {
360
+ if (!docNumber) return null;
361
+ return (P().sources?.licensed ?? []).find((l) => String(l.doc_number ?? "") === docNumber) ?? null;
362
+ }
363
+ function licenseBoundaryNote(docNumber, standardKeys) {
364
+ const entry = licensedEntryForDocNumber(docNumber);
365
+ if (!entry || standardKeys && standardKeys.has(entry.key)) return void 0;
366
+ const pointer = P().prompts?.vars?.license_declare_pointer;
367
+ return `License boundary \u2014 the question is about ${licenseBoundaryName(entry)}, a licensed publication (entitlement key ${entry.key}). The caller's organization license does not cover its text, so no passage of it was retrieved and NONE of its procedural content (steps, parameters, severities, limits) may be stated, paraphrased or recalled from memory. You MAY answer at the citation level: name the standard and edition, and cite the invoking clause from the PUBLIC passages in context (the Recommendation's own applicability and normative references are public and stay answerable). Then say the organization's license does not cover the standard's text` + (pointer ? ` and point to the declare flow: ${pointer}.` : ".");
368
+ }
369
+ function licenseBoundaryName(entry) {
370
+ const id = entry.doc_number ? ` ${entry.doc_number}` : ` ${entry.package}`;
371
+ return `${entry.title ?? "standard"}${entry.edition ? ` (${entry.edition})` : ""} \u2014${id}`;
372
+ }
373
+ function licenseBoundaryRefusal(docNumber, standardKeys) {
374
+ const entry = licensedEntryForDocNumber(docNumber);
375
+ if (!entry || standardKeys && standardKeys.has(entry.key)) return void 0;
376
+ const pointer = P().prompts?.vars?.license_declare_pointer;
377
+ return `${licenseBoundaryName(entry)} is a licensed publication and your organization's license does not cover its text, so I can't quote or summarize its procedure. I can answer at the citation level \u2014 the standard's title and edition, and the clause your Recommendation invokes \u2014 and the public ${P().publisher.name} content in full.` + (pointer ? ` To unlock the full text, an org admin can declare the license under ${pointer}.` : "");
378
+ }
379
+ async function fetchNode(env, standard, nodeId) {
380
+ try {
381
+ const row = await env.DB.prepare(
382
+ "SELECT standard, node_id, kind, name, clause_doc, clause_ref, content FROM model_nodes WHERE standard = ?1 AND node_id = ?2"
383
+ ).bind(standard, nodeId).first();
384
+ if (!row) return null;
385
+ const content = JSON.parse(String(row.content));
386
+ const clause = row.clause_doc && row.clause_ref ? { doc: String(row.clause_doc), ref: String(row.clause_ref), urn: `${row.clause_doc}#clause-${row.clause_ref}` } : row.clause_doc ? { doc: String(row.clause_doc), ref: "", urn: String(row.clause_doc) } : null;
387
+ return {
388
+ standard: String(row.standard),
389
+ node_id: String(row.node_id),
390
+ kind: String(row.kind),
391
+ name: String(row.name ?? row.node_id),
392
+ clause,
393
+ content
394
+ };
395
+ } catch {
396
+ return null;
397
+ }
398
+ }
399
+ async function bindModelNode(env, opts) {
400
+ const nodeId = modelNodeRefIn(opts.label) ?? modelNodeRefIn(opts.query);
401
+ if (!nodeId) return null;
402
+ const gate = (node) => {
403
+ if (!node) return null;
404
+ const entry = licensedEntryForPackage(node.standard);
405
+ return entry && !(opts.standardKeys?.has(entry.key) ?? false) ? { ...node, gated: true, content: {} } : node;
406
+ };
407
+ if (opts.standard) return gate(await fetchNode(env, opts.standard, nodeId));
408
+ try {
409
+ const rows = await env.DB.prepare(
410
+ "SELECT n.standard AS standard FROM model_nodes n LEFT JOIN model_plane_meta m ON m.standard = n.standard WHERE n.node_id = ?1 ORDER BY m.indexed_at DESC, n.standard DESC LIMIT 1"
411
+ ).bind(nodeId).all();
412
+ const standard = (rows?.results ?? []).map((r) => String(r.standard))[0];
413
+ if (standard) return gate(await fetchNode(env, standard, nodeId));
414
+ return null;
415
+ } catch {
416
+ return null;
417
+ }
418
+ }
419
+ async function bindConstraintByQuantities(env, query, standardKeys) {
420
+ const verdictish = /\b(acceptable|valid|violate|violation|within|comply|proposal|severity|conform)\b/i.test(query);
421
+ if (!verdictish) return null;
422
+ try {
423
+ const rows = await env.DB.prepare(
424
+ "SELECT standard, node_id, kind, name, clause_doc, clause_ref, content FROM model_nodes WHERE kind = 'constraint' LIMIT 120"
425
+ ).all();
426
+ const q = query.toLowerCase();
427
+ let best = null;
428
+ for (const r of rows.results ?? []) {
429
+ const checks = extractChecks(JSON.parse(String(r.content ?? "{}")));
430
+ if (!checks.length) continue;
431
+ const leaves = new Set(
432
+ symbolsIn(checks).map((sym) => sym.split(".").pop() ?? sym).filter((leaf) => leaf.length >= 2)
433
+ );
434
+ let matched = 0;
435
+ for (const leaf of leaves) {
436
+ const re = new RegExp(`(?<![a-z_])${leaf.replace(/[^a-z0-9_]/g, "")}(?![a-z_])`, "i");
437
+ if (re.test(q)) matched++;
438
+ }
439
+ if (matched >= 2 && (!best || matched > best.score)) {
440
+ best = { score: matched, standard: String(r.standard), node_id: String(r.node_id) };
441
+ }
442
+ }
443
+ if (!best) return null;
444
+ const gate = (node) => {
445
+ if (!node) return null;
446
+ const entry = licensedEntryForPackage(node.standard);
447
+ return entry && !(standardKeys?.has(entry.key) ?? false) ? { ...node, gated: true, content: {} } : node;
448
+ };
449
+ return gate(await fetchNode(env, best.standard, best.node_id));
450
+ } catch {
451
+ return null;
452
+ }
453
+ }
454
+ function clip(s, n = 500) {
455
+ const t = String(s ?? "").trim();
456
+ return t.length <= n ? t : t.slice(0, n - 1).trimEnd() + " \u2026";
457
+ }
458
+ function applicabilityText(app) {
459
+ if (!app || typeof app !== "object") return "";
460
+ const parts = [];
461
+ for (const [dim, cond] of Object.entries(app)) {
462
+ if (Array.isArray(cond)) parts.push(`${dim.replace(/_/g, " ")}: ${cond.join(", ")}`);
463
+ else if (cond && typeof cond === "object" && Array.isArray(cond.values)) {
464
+ parts.push(`${dim.replace(/_/g, " ")} (${cond.match ?? "any"}): ${cond.values.join(", ")}`);
465
+ }
466
+ }
467
+ return parts.join("; ");
468
+ }
469
+ function modelGroundingBlock(node) {
470
+ const c = node.content ?? {};
471
+ const lines = [];
472
+ lines.push(
473
+ P().prompts.vars.model_grounding_intro ?? "Model grounding \u2014 the model plane's own statement:"
474
+ );
475
+ lines.push(`Node: ${node.node_id} (${node.kind.replace(/_/g, " ")}) \u2014 ${node.name} [${node.standard}]`);
476
+ if (node.clause) lines.push(`Provenance: ${node.clause.urn}`);
477
+ if (c.statement) lines.push(`Statement: ${clip(c.statement)}`);
478
+ if (c.definition) lines.push(`Definition: ${clip(c.definition)}`);
479
+ if (c.purpose) lines.push(`Purpose: ${clip(c.purpose)}`);
480
+ const limit = c.limit ?? {};
481
+ if (limit.expression) lines.push(`Machine limit (the constraint the platform's verdict engine evaluates \u2014 quote it verbatim): ${limit.expression}`);
482
+ if (limit.accepts?.verdict) lines.push(`Machine limit: ${limit.accepts.verdict} ${limit.accepts.op} ${limit.accepts.limit} (the canonical acceptance chain)`);
483
+ if (c.check) lines.push(`Machine check: ${c.check}`);
484
+ if (c.derive) lines.push(`Derivation: ${c.derive}${Array.isArray(c.inputs) ? ` (inputs: ${c.inputs.join(", ")})` : ""}`);
485
+ const app = applicabilityText(c.applicability);
486
+ const scopeApp = applicabilityText(c.scope_applicability);
487
+ if (app || scopeApp) lines.push(`Applicability: ${[scopeApp, app].filter(Boolean).join("; ")}`);
488
+ if (Array.isArray(c.binds_to) && c.binds_to.length) lines.push(`Binds to: ${c.binds_to.join(", ")}`);
489
+ if (Array.isArray(c.targets) && c.targets.length) lines.push(`Verifies requirements: ${c.targets.join(", ")}`);
490
+ if (Array.isArray(c.preconditions) && c.preconditions.length) {
491
+ const pcs = c.preconditions.map((p) => `${p.id}: ${clip(p.check ?? (p.state ? `state = ${p.state}` : ""), 120)}`).join("; ");
492
+ lines.push(`Run-validity preconditions (a violation voids the run \u2014 invalid, never a fail): ${pcs}`);
493
+ }
494
+ if (c.acceptance_criteria?.description) lines.push(`Acceptance: ${clip(c.acceptance_criteria.description, 300)}`);
495
+ if (c.violation_meaning) lines.push(`Violation meaning (verbatim): ${clip(c.violation_meaning, 300)} \u2014 on violation: ${c.on_violation ?? "invalid"}`);
496
+ if (Array.isArray(c.values) && c.values.length) {
497
+ lines.push(`Values: ${c.values.map((v) => `${v.id}${v.implies?.length ? ` (implies ${v.implies.join(", ")})` : ""}`).join("; ")}`);
498
+ }
499
+ if (c.source_discrepancy) {
500
+ const sd = c.source_discrepancy;
501
+ lines.push(
502
+ `DECLARED SOURCE DISCREPANCY \u2014 the model and the text disagree; you MUST surface this and cite both: ${clip(sd.summary, 300)} Sources: ${(sd.sources ?? []).join(" and ")}. The model ${sd.resolution === "follows_clause_x" ? "follows one side" : "records the conflict without resolving it"}: ${clip(sd.rationale, 300)}`
503
+ );
504
+ }
505
+ lines.push(
506
+ "Rules for this answer: the machine facts (the constraint, the applicability, the acceptance, the provenance) come from THIS node \u2014 quote the machine limit verbatim, never invent one the node does not carry. If this model content and a prose passage disagree \u2014 including a passage from a different edition \u2014 say so explicitly and cite both (this node and the prose clause)."
507
+ );
508
+ return lines.join("\n");
509
+ }
510
+ function modelCitation(node) {
511
+ return {
512
+ doc_id: `model:${node.standard}`,
513
+ docidentifier: `${P().publisher.name} SMART model (${(() => {
514
+ const prefix = P().sources?.models?.standard_prefix ?? "";
515
+ const letter = prefix.replace(/^.*-/, "").toUpperCase();
516
+ return String(node.standard).replace(new RegExp(`^${prefix}`, "i"), `${letter} `);
517
+ })()})`,
518
+ edition: "",
519
+ language: "en",
520
+ clause_anchor: node.clause?.ref || "model",
521
+ clause_title: `${node.kind.replace(/_/g, " ")} \u2014 ${node.name} (${node.node_id})`,
522
+ status: "in-force",
523
+ corpus: "smart-model",
524
+ quality: "verified",
525
+ url: void 0,
526
+ snippet: `${node.node_id}${node.clause ? ` \xB7 ${node.clause.urn}` : ""}${node.content?.statement ? ` \u2014 ${clip(node.content.statement, 240)}` : ""}`,
527
+ score: 1
528
+ };
529
+ }
530
+ function modelEcho(node) {
531
+ return {
532
+ node_id: node.node_id.slice(0, 120),
533
+ kind: node.kind.slice(0, 40),
534
+ standard: node.standard.slice(0, 40),
535
+ ...node.clause?.urn ? { clause: node.clause.urn.slice(0, 120) } : {}
536
+ };
537
+ }
538
+
504
539
  // workers/worker_public/src/conditions.ts
505
540
  var NUM = String.raw`-?\d+(?:[.,]\d+)?`;
506
541
  function quantitiesIn(query) {
@@ -1143,19 +1178,20 @@ ${r.output}`;
1143
1178
  }
1144
1179
 
1145
1180
  export {
1181
+ evaluate,
1182
+ verdictNote,
1146
1183
  standardForDocNumber,
1147
1184
  licensedEntryForPackage,
1148
1185
  licenseBoundaryNote,
1149
1186
  licenseBoundaryRefusal,
1150
1187
  bindModelNode,
1188
+ bindConstraintByQuantities,
1151
1189
  modelGroundingBlock,
1152
1190
  modelCitation,
1153
1191
  modelEcho,
1154
1192
  resolveBlocks,
1155
1193
  contractV2,
1156
1194
  tableRetyped,
1157
- evaluate,
1158
- verdictNote,
1159
1195
  quantitiesIn,
1160
1196
  evaluateConditionSets,
1161
1197
  parseToolCall,
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  TOOL_DECLARATION,
3
+ bindConstraintByQuantities,
3
4
  bindModelNode,
4
5
  contractV2,
5
6
  evaluate,
@@ -18,7 +19,7 @@ import {
18
19
  tableRetyped,
19
20
  toolNote,
20
21
  verdictNote
21
- } from "./chunk-QNLFNEI4.js";
22
+ } from "./chunk-ANUHRJ4Z.js";
22
23
  import {
23
24
  NO_CONTEXT,
24
25
  answerQuality,
@@ -2059,7 +2060,7 @@ ${summary}` }] : [],
2059
2060
  query: q.query,
2060
2061
  standard: standardForDocNumber(modelDocHint?.doc_number),
2061
2062
  standardKeys
2062
- }) : null;
2063
+ }) ?? await bindConstraintByQuantities(env, q.query, standardKeys) : null;
2063
2064
  if (boundModel) {
2064
2065
  ctxApplied = { ...ctxApplied, model: modelEcho(boundModel) };
2065
2066
  console.log("model plane: bound", boundModel.node_id, `[${boundModel.standard}]`, boundModel.clause?.urn ?? "no-clause", boundModel.gated ? "(gated: license)" : "");
@@ -71,6 +71,17 @@ export declare function bindModelNode(env: any, opts: {
71
71
  standard?: string | null;
72
72
  standardKeys?: ReadonlySet<string> | null;
73
73
  }): Promise<BoundModelNode | null>;
74
+ /** A constraint-shaped question binds its constraint: when the question
75
+ * states two or more of a constraint node's own check symbols (the
76
+ * leaf names — d_max, e_max) alongside verdict vocabulary ("is that
77
+ * proposal acceptable"), the node binds by WHAT THE QUESTION STATES,
78
+ * not by whether the question spells a node id. The id grammar stays
79
+ * the primary bind; this is the fallback for the user-shaped question
80
+ * ("E_max 30000 v, testing to D_max 26000 v — acceptable?"), and it
81
+ * is deliberately narrow: constraint kind only (requirements are too
82
+ * numerous and too loosely tied to vocabulary), most-matched-symbols
83
+ * wins, license-gated like every model lane. */
84
+ export declare function bindConstraintByQuantities(env: any, query: string, standardKeys?: ReadonlySet<string> | null): Promise<BoundModelNode | null>;
74
85
  /** The structured grounding block for the prompt — every line is the
75
86
  * node's own declared content (the bundle projection), never a model
76
87
  * paraphrase. The discrepancy block, when the model declares one, is the
@@ -4,7 +4,7 @@ import {
4
4
  parseToolCall,
5
5
  runTool,
6
6
  toolNote
7
- } from "./chunk-QNLFNEI4.js";
7
+ } from "./chunk-ANUHRJ4Z.js";
8
8
  import "./chunk-KNCRYAX3.js";
9
9
  import "./chunk-U4ERFUOK.js";
10
10
  import "./chunk-BOAITSVV.js";
@@ -4,12 +4,12 @@ import {
4
4
  handleMemories,
5
5
  scoreFaithfulness,
6
6
  scoreJudge
7
- } from "../../chunk-FQVP3JUA.js";
7
+ } from "../../chunk-NCZHN6QW.js";
8
8
  import {
9
9
  TOOLS_REGISTRY,
10
10
  bindModelNode,
11
11
  modelGroundingBlock
12
- } from "../../chunk-QNLFNEI4.js";
12
+ } from "../../chunk-ANUHRJ4Z.js";
13
13
  import {
14
14
  handleSearch
15
15
  } from "../../chunk-TFGJ6NYS.js";
@@ -990,13 +990,13 @@ async function callToolOnce(env, ctx, _req, tier, key, name, args, t0) {
990
990
  // stream:false forces the JSON lane (anon defaults to SSE)
991
991
  body: JSON.stringify({ ...args, stream: false })
992
992
  });
993
- const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-ZNQY6ZMC.js");
993
+ const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-EXDADNWX.js");
994
994
  let payload;
995
995
  if (TOOLS_REGISTRY2.some((t) => t.name === name && t.audiences.includes("mcp"))) {
996
996
  const r = await runTool({ ...env, DB: env.DB }, { name, args }, "mcp");
997
997
  payload = r ? { tool: r.name, query: r.query, result: r.output } : { error: { message: `tool ${name} returned nothing for the given arguments` } };
998
998
  } else {
999
- const res = name === "ask" ? await (await import("../../ask-E6YJUOIP.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-5SNP5CHL.js")).handleSearch(env, ctx, inner, tier, key);
999
+ const res = name === "ask" ? await (await import("../../ask-M3VRAIJB.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-5SNP5CHL.js")).handleSearch(env, ctx, inner, tier, key);
1000
1000
  payload = await res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
1001
1001
  }
1002
1002
  telemetry(env, ctx, tier, `mcp:${name}`, null, !payload?.error, JSON.stringify(payload).length, await sha256Hex(`${name}:${JSON.stringify(args ?? {})}`), void 0, void 0, { durationMs: Date.now() - t0 });
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.102",
30
+ "version": "0.2.103",
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",
@@ -22,7 +22,7 @@ import { contractV2, tableRetyped } from "./refs";
22
22
  import { completeTables, completeFigures } from "./completion";
23
23
  import { NO_CONTEXT, appliedContext, contextNote, namedDocumentIn, parseContext, resolveDocScope, syntheticUnderstanding } from "./context";
24
24
  import { liveDataConfig, liveTokenFor, opCfg, opTokenMember, resolveLiveAccount, type LiveRecord } from "./livedata";
25
- import { bindModelNode, licenseBoundaryNote, licenseBoundaryRefusal, licensedEntryForPackage, modelCitation, modelEcho, modelGroundingBlock, standardForDocNumber } from "./modelplane";
25
+ import { bindModelNode, bindConstraintByQuantities, licenseBoundaryNote, licenseBoundaryRefusal, licensedEntryForPackage, modelCitation, modelEcho, modelGroundingBlock, standardForDocNumber } from "./modelplane";
26
26
  import { evaluate as machineEvaluate, verdictNote } from "./verdict";
27
27
  import { evaluateConditionSets, quantitiesIn, type ConditionVerdict } from "./conditions";
28
28
  import { evaluateAggregation, type AggregationVerdict } from "./aggregation";
@@ -857,12 +857,12 @@ let convEntities: Array<{ entity: string; kind: string }> = [];
857
857
  // unambiguous across the indexed standards.
858
858
  const modelDocHint = named ?? docScope ?? namedDocumentIn(q.query);
859
859
  const boundModel = P().publisher.features?.model_plane
860
- ? await bindModelNode(env, {
860
+ ? (await bindModelNode(env, {
861
861
  label: declaredCtx?.label,
862
862
  query: q.query,
863
863
  standard: standardForDocNumber(modelDocHint?.doc_number),
864
864
  standardKeys,
865
- })
865
+ })) ?? (await bindConstraintByQuantities(env, q.query, standardKeys))
866
866
  : null;
867
867
  if (boundModel) {
868
868
  ctxApplied = { ...ctxApplied, model: modelEcho(boundModel) };
@@ -30,6 +30,7 @@
30
30
  * /conf/<class>/<id>, /term/<id>, /constraint/<id>, /characteristic/<id>,
31
31
  * /state-machine/<id>, /dimension/<id>). */
32
32
  import { P } from "./profile.ts";
33
+ import { extractChecks, symbolsIn } from "./verdict.ts";
33
34
  const NODE_RE = /(?:^|[\s("'`])\/(req|conf|term|constraint|characteristic|state-machine|dimension)\/([a-z0-9][a-z0-9_-]*(?:\/[a-z0-9][a-z0-9_-]*)?)(?=[\s)"'`,;:.]|$)/i;
34
35
 
35
36
  /** The first model-node id a text names (the declared chip label first,
@@ -217,6 +218,60 @@ export async function bindModelNode(
217
218
  }
218
219
  }
219
220
 
221
+ // ── bind by stated quantities (the constraint resolution) ────────────
222
+
223
+ /** A constraint-shaped question binds its constraint: when the question
224
+ * states two or more of a constraint node's own check symbols (the
225
+ * leaf names — d_max, e_max) alongside verdict vocabulary ("is that
226
+ * proposal acceptable"), the node binds by WHAT THE QUESTION STATES,
227
+ * not by whether the question spells a node id. The id grammar stays
228
+ * the primary bind; this is the fallback for the user-shaped question
229
+ * ("E_max 30000 v, testing to D_max 26000 v — acceptable?"), and it
230
+ * is deliberately narrow: constraint kind only (requirements are too
231
+ * numerous and too loosely tied to vocabulary), most-matched-symbols
232
+ * wins, license-gated like every model lane. */
233
+ export async function bindConstraintByQuantities(
234
+ env: any,
235
+ query: string,
236
+ standardKeys?: ReadonlySet<string> | null,
237
+ ): Promise<BoundModelNode | null> {
238
+ const verdictish = /\b(acceptable|valid|violate|violation|within|comply|proposal|severity|conform)\b/i.test(query);
239
+ if (!verdictish) return null;
240
+ try {
241
+ const rows = await env.DB.prepare(
242
+ "SELECT standard, node_id, kind, name, clause_doc, clause_ref, content FROM model_nodes WHERE kind = 'constraint' LIMIT 120",
243
+ ).all();
244
+ const q = query.toLowerCase();
245
+ let best: { score: number; standard: string; node_id: string } | null = null;
246
+ for (const r of (rows.results ?? []) as any[]) {
247
+ const checks = extractChecks(JSON.parse(String(r.content ?? "{}")));
248
+ if (!checks.length) continue;
249
+ const leaves = new Set(
250
+ symbolsIn(checks)
251
+ .map((sym) => sym.split(".").pop() ?? sym)
252
+ .filter((leaf) => leaf.length >= 2),
253
+ );
254
+ let matched = 0;
255
+ for (const leaf of leaves) {
256
+ const re = new RegExp(`(?<![a-z_])${leaf.replace(/[^a-z0-9_]/g, "")}(?![a-z_])`, "i");
257
+ if (re.test(q)) matched++;
258
+ }
259
+ if (matched >= 2 && (!best || matched > best.score)) {
260
+ best = { score: matched, standard: String(r.standard), node_id: String(r.node_id) };
261
+ }
262
+ }
263
+ if (!best) return null;
264
+ const gate = (node: BoundModelNode | null): BoundModelNode | null => {
265
+ if (!node) return null;
266
+ const entry = licensedEntryForPackage(node.standard);
267
+ return entry && !(standardKeys?.has(entry.key) ?? false) ? { ...node, gated: true, content: {} } : node;
268
+ };
269
+ return gate(await fetchNode(env, best.standard, best.node_id));
270
+ } catch {
271
+ return null;
272
+ }
273
+ }
274
+
220
275
  // ── the grounding block (the node's own content, composed) ───────────
221
276
 
222
277
  function clip(s: unknown, n = 500): string {