clearotron 0.5.0 → 0.5.1-beta.1
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/CONTRIBUTING.md +2 -2
- package/INSTALL.md +351 -308
- package/QUICKSTART.md +12 -4
- package/README.md +12 -7
- package/THIRD-PARTY-NOTICES.md +4 -4
- package/bin/README.md +14 -11
- package/bin/clearotron.mjs +1 -1
- package/bin/connect.mjs +73 -25
- package/bin/example.mjs +4 -2
- package/bin/onboard.mjs +647 -352
- package/bin/start.mjs +213 -66
- package/bin/update.mjs +26 -13
- package/build-info.json +2 -2
- package/docs/CLIENT-MCP.md +1 -1
- package/docs/PORTAL.md +2 -2
- package/docs/architecture/02-architecture.md +3 -3
- package/docs/architecture/04-configuration-reference.md +2 -3
- package/docs/architecture/05-config-governance.md +1 -1
- package/docs/architecture/06-operations-runbook.md +1 -1
- package/driver/CHANGELOG.md +91 -0
- package/driver/README.md +2 -2
- package/driver/config-inventory.mjs +20 -11
- package/driver/contract-e3-backlog.mjs +27 -27
- package/driver/contract-e3-baseline.json +2 -2
- package/driver/contract-vocabulary.mjs +1 -1
- package/driver/degraded-parts.mjs +67 -3
- package/driver/dev-portal.mjs +1 -1
- package/driver/digest-queue.mjs +5 -5
- package/driver/driver.config.mjs +9 -9
- package/driver/engine/CONTRACT.md +1 -1
- package/driver/engine/anthropic-agent.mjs +4 -2
- package/driver/engine/jx-turn.mjs +10 -2
- package/driver/engine/mcp/band-server.mjs +1 -21
- package/driver/engine/mcp/clarivate-propose-tool.mjs +26 -0
- package/driver/engine/mcp/clarivate-server.mjs +2 -18
- package/driver/engine/mcp/fixture-register-server.mjs +33 -0
- package/driver/engine/mcp/gather-config.mjs +48 -7
- package/driver/engine/mcp/recording-server.mjs +206 -14
- package/driver/engine/mcp/supplemental.mjs +4 -2
- package/driver/engine/openai-agent.mjs +3 -1
- package/driver/engine/probe.mjs +10 -0
- package/driver/filing-goods.mjs +95 -0
- package/driver/findings-model.mjs +3 -0
- package/driver/gateway.mjs +42 -40
- package/driver/how-it-runs.mjs +103 -0
- package/driver/knockout-assess-record.mjs +54 -4
- package/driver/knockout-correction-record.mjs +342 -0
- package/driver/knockout-frame-record.mjs +4 -2
- package/driver/knockout-register-read.mjs +705 -0
- package/driver/knockout-register-record.mjs +222 -0
- package/driver/knockout-review-record.mjs +96 -25
- package/driver/narrative-refutation-record.mjs +87 -1
- package/driver/order-tables.mjs +23 -0
- package/driver/owner-use-check.mjs +5 -2
- package/driver/package.json +1 -1
- package/driver/partial-payload-baseline.json +8 -0
- package/driver/pipeline-knockout.mjs +506 -313
- package/driver/pipeline.mjs +179 -86
- package/driver/portal-local-auth.mjs +7 -1
- package/driver/portal-service.mjs +99 -9
- package/driver/progress.mjs +2 -2
- package/driver/publish/index.mjs +18 -21
- package/driver/publish/knockout.mjs +40 -18
- package/driver/publish/render-knockout.mjs +40 -27
- package/driver/publish/report-dates.mjs +43 -0
- package/driver/recall-reconciliation.mjs +2 -2
- package/driver/record-goods.mjs +50 -9
- package/driver/register-count.mjs +12 -59
- package/driver/register-fixture-marker.mjs +22 -0
- package/driver/register-plan.mjs +48 -0
- package/driver/register-records.mjs +84 -266
- package/driver/register-taint.mjs +2 -2
- package/driver/repair-composers.mjs +15 -8
- package/driver/result-noun-fields.mjs +6 -2
- package/driver/run-requirements.mjs +111 -37
- package/driver/runner.mjs +9 -16
- package/driver/skills/clearance-register/providers/clarivate.md +2 -2
- package/driver/skills/knockout-assess/SKILL.md +101 -100
- package/driver/skills/knockout-frame/SKILL.md +3 -1
- package/driver/skills/knockout-register-read/SKILL.md +77 -0
- package/driver/stages-knockout.mjs +159 -98
- package/driver/stages.mjs +4 -2
- package/driver/suite-census.json +435 -81
- package/driver/systemd/README.md +2 -2
- package/driver/unit-environment.mjs +19 -0
- package/driver/verify-knockout.mjs +175 -39
- package/driver/verify.mjs +10 -9
- package/mcp-server/CHANGELOG.md +8 -0
- package/mcp-server/CONNECT.md +4 -0
- package/mcp-server/demo-mode.mjs +6 -0
- package/mcp-server/lib/demo-texts.mjs +38 -0
- package/mcp-server/lib/http-handler.mjs +7 -1
- package/mcp-server/lib/knockout.mjs +3 -2
- package/mcp-server/lib/options.mjs +3 -1
- package/mcp-server/lib/plan.mjs +6 -1
- package/mcp-server/lib/runs.mjs +7 -2
- package/mcp-server/mint-token.mjs +1 -1
- package/mcp-server/package.json +1 -1
- package/mcp-server/serve.mjs +11 -0
- package/mcp-server/server.mjs +13 -5
- package/package.json +1 -1
- package/portal-ui/dist/assets/{index-D2wrw9cH.css → index-AtB9ZpDH.css} +29 -0
- package/portal-ui/dist/assets/{index-DcLbvFmQ.js → index-fPqAU0sx.js} +237 -231
- package/portal-ui/dist/index.html +2 -2
- package/portal-ui/package.json +4 -4
- package/providers/README.md +4 -4
- package/providers/_shared/execute-plan.mjs +45 -1
- package/providers/_shared/term-shape.mjs +1 -1
- package/providers/clarivate/src/capabilities.js +7 -6
- package/providers/clarivate/src/core.js +11 -7
- package/providers/clarivate/src/wider-list.js +104 -0
- package/providers/oauth-mcp-bridge/CHANGELOG.md +8 -0
- package/providers/oauth-mcp-bridge/package.json +1 -1
- package/providers/signa/src/capabilities.js +0 -9
- package/scripts/e2e-first-time.mjs +8 -7
- package/scripts/freeze-example-run.mjs +2 -2
- package/scripts/settings-render-check.mjs +5 -3
- package/scripts/test-run.mjs +8 -2
- package/shared/client-door.mjs +11 -8
- package/shared/connect-clients.mjs +10 -4
- package/shared/demo-connection.mjs +43 -0
- package/shared/demo-start-args.mjs +7 -2
- package/shared/invocation.mjs +18 -3
- package/shared/permanent-install.mjs +24 -0
- package/shared/scope.mjs +8 -1
- package/shared/server-units.mjs +37 -1
- package/shared/stdio-connect.mjs +43 -21
- package/shared/trigger-lane.mjs +7 -0
- package/shared/tty-style.mjs +21 -5
|
@@ -52,9 +52,9 @@ const STRIP = Object.freeze([
|
|
|
52
52
|
['summary', 'Summary'], ['findings', 'Findings'], ['filings', 'Also considered'], ['next', 'Next steps'],
|
|
53
53
|
]);
|
|
54
54
|
import { COUNT_BASIS, COUNT_PREDICATES, countsForMark, countLine, variantFormsLine, disclosedFloor, moreThan, countNote } from '../register-count.mjs';
|
|
55
|
-
import {
|
|
55
|
+
import { recordBasisOf, readByJudgment, noneCarriedForward, NONE_CARRIED_FORWARD, recordsForMark, recordsLine } from '../register-records.mjs';
|
|
56
56
|
import { officeLinkSentences } from './office-record-links.mjs';
|
|
57
|
-
import { knockoutFindingViews, splitKnockoutNotes } from '../findings-model.mjs';
|
|
57
|
+
import { knockoutFindingViews, splitKnockoutNotes, KNOCKOUT_CARD_ORDER } from '../findings-model.mjs';
|
|
58
58
|
import { inputsLine } from '../framework-method.mjs';
|
|
59
59
|
import { demoBannerHtml, servedModelsLine } from './render.mjs'; // — the SAME banner the clearance template renders, not a second wording
|
|
60
60
|
import { EXPORT_TOGGLE, exportPopover, EXPORT_MENU_JS } from './report-topbar.mjs'; // — the export menu's shell and behaviour, shared with the clearance template // — the SAME banner the clearance template renders, not a second wording
|
|
@@ -391,16 +391,24 @@ function batchTitle(marks) {
|
|
|
391
391
|
// UNNUMBERED straight under the hero. Counts + per-name reads merge into ONE numbered section named
|
|
392
392
|
// like the clearance spine ("On-field conflicts" — counts are the D2 form of "who is in the way"),
|
|
393
393
|
// and "Scope & method" takes the clearance Scope name. Same names, same order, fewer rows.
|
|
394
|
+
// A NAME'S BAND COLUMN: its one band and classes, or where the evidence divides them, a band and its classes per
|
|
395
|
+
// group, in the order the merged gate left them, highest first. The same chip and the same line either way, so no
|
|
396
|
+
// words are added. A mark with no groups, which is every archived run, keeps its markup byte for byte.
|
|
397
|
+
function bandColumn(m, framework) {
|
|
398
|
+
const chip = (band, qualifier, classes) => `<span class="ko-band" style="background:var(${bandStop(framework, band)})">${esc(band ?? '—')}</span>
|
|
399
|
+
${qualifierHtml(qualifier)}
|
|
400
|
+
${classes?.length ? `<p class="ko-classes">Classes ${esc(classes.join(', '))}</p>` : ''}`;
|
|
401
|
+
if (!Array.isArray(m.classGroups) || !m.classGroups.length) return chip(m.rating, m.ratingQualifier, m.classesSearched);
|
|
402
|
+
return m.classGroups.map((g) => chip(g.band, g.ratingQualifier, g.classes)).join('\n ');
|
|
403
|
+
}
|
|
404
|
+
|
|
394
405
|
function glanceSection(marks, framework, registerCounts) {
|
|
395
406
|
const rows = marks.map((m) => {
|
|
396
|
-
const stop = bandStop(framework, m.rating);
|
|
397
407
|
const counted = registerCounts ? countLine(countsForMark(registerCounts, m.name)) : null;
|
|
398
408
|
return `<div class="ko-row">
|
|
399
409
|
<div>
|
|
400
410
|
<p class="ko-name">${esc(m.name)}</p>
|
|
401
|
-
|
|
402
|
-
${qualifierHtml(m.ratingQualifier)}
|
|
403
|
-
${m.classesSearched?.length ? `<p class="ko-classes">Classes ${esc(m.classesSearched.join(', '))}</p>` : ''}
|
|
411
|
+
${bandColumn(m, framework)}
|
|
404
412
|
</div>
|
|
405
413
|
<div>
|
|
406
414
|
${counted ? `<p class="ko-count">${esc(counted)}</p>` : ''}
|
|
@@ -752,7 +760,7 @@ function filingsSection(marks, registerRecords) {
|
|
|
752
760
|
const more = e.records.length > shown.length
|
|
753
761
|
? ` Showing ${shown.length} of ${e.records.length}, most material first — the filings this`
|
|
754
762
|
+ ` assessment weighed before the rest, then live filings before dead,`
|
|
755
|
-
+ ` in the searched classes before outside them, the name itself before its close variations.`
|
|
763
|
+
+ ` in the searched classes before outside them, the name itself before ${readByJudgment(registerRecords) ? 'other searches' : 'its close variations'}.`
|
|
756
764
|
+ ` The full list is in the audit workbook's Register Filings sheet.`
|
|
757
765
|
: ' The same rows are in the audit workbook\'s Register Filings sheet, most material first.';
|
|
758
766
|
return `<div class="ko-filings">
|
|
@@ -761,7 +769,7 @@ function filingsSection(marks, registerRecords) {
|
|
|
761
769
|
<p class="ko-basis">${esc(line ?? '')}${esc(more)}</p>
|
|
762
770
|
</div>`;
|
|
763
771
|
}).join('');
|
|
764
|
-
return `<div class="panel ko-glance">${blocks}<p class="ko-basis">${esc(
|
|
772
|
+
return `<div class="panel ko-glance">${blocks}<p class="ko-basis">${esc(recordBasisOf(registerRecords))}${officeLinkNote(registerRecords)}</p></div>`;
|
|
765
773
|
}
|
|
766
774
|
|
|
767
775
|
// Once, under the filings: what a linked number opens and, per office, why the rest are cited by number.
|
|
@@ -1071,8 +1079,9 @@ function registerStatement(r, provider) {
|
|
|
1071
1079
|
? `class${classes.length === 1 ? '' : 'es'} ${classes.join(', ')}`
|
|
1072
1080
|
: 'classes not stated on the record';
|
|
1073
1081
|
// A close-variation card says WHICH near-form matched, because the name at the head of the sentence is
|
|
1074
|
-
// then not the name the client asked about and a reader must not have to guess which it is.
|
|
1075
|
-
|
|
1082
|
+
// then not the name the client asked about and a reader must not have to guess which it is. A filing the reading
|
|
1083
|
+
// step found names its question, and that question may be a wider search, which is no close variation.
|
|
1084
|
+
const via = r.matchedBasis === 'close' && r.matchedForm ? (r.question ? ` Found by a search on ${r.matchedForm}.` : ` Found under the close variation ${r.matchedForm}.`) : '';
|
|
1076
1085
|
return `${lead} ${owner}, ${cls}.${via}`;
|
|
1077
1086
|
}
|
|
1078
1087
|
|
|
@@ -1480,7 +1489,7 @@ function registerPositionClause(mark, registerCounts, registerRecords, cards = [
|
|
|
1480
1489
|
const classWhere = classes.length ? ` in class${classes.length === 1 ? '' : 'es'} ${classes.join(', ')}` : '';
|
|
1481
1490
|
const one = cards.length === 1;
|
|
1482
1491
|
const refs = cards.map((c) => c.ref).join(', ');
|
|
1483
|
-
return `${one ? 'A filing' : `${cards.length} filings`} of this name or a close variation of it `
|
|
1492
|
+
return `${one ? 'A filing' : `${cards.length} filings`} of this name or ${readByJudgment(registerRecords) ? 'a name near it' : 'a close variation of it'} `
|
|
1484
1493
|
+ `stand${one ? 's' : ''} on ${provider}${classWhere} — ${refs} ${where}.`;
|
|
1485
1494
|
}
|
|
1486
1495
|
const records = entry.records ?? [];
|
|
@@ -1492,9 +1501,10 @@ function registerPositionClause(mark, registerCounts, registerRecords, cards = [
|
|
|
1492
1501
|
// term was asked and answered, and none was left unanswered. Anything else is a listing that did not
|
|
1493
1502
|
// finish, which this page already has the sentence for.
|
|
1494
1503
|
const terms = entry.terms ?? [];
|
|
1495
|
-
const ranAndAnswered = terms.length > 0 && terms.every((t) => t.ok);
|
|
1504
|
+
const ranAndAnswered = terms.length > 0 && terms.every((t) => t.ok && !t.setAside);
|
|
1496
1505
|
return ranAndAnswered
|
|
1497
1506
|
? `No filing of this name or a close variation of it stands on ${provider}, in the classes counted.`
|
|
1507
|
+
: noneCarriedForward(entry) ? NONE_CARRIED_FORWARD
|
|
1498
1508
|
: 'The filings listing for this name did not complete, so nothing here says whether one stands.';
|
|
1499
1509
|
}
|
|
1500
1510
|
return `${records.length} filing${records.length === 1 ? ' is' : 's are'} listed for this name below; `
|
|
@@ -1673,14 +1683,14 @@ function readBlock(m, framework) {
|
|
|
1673
1683
|
].filter(Boolean).join('');
|
|
1674
1684
|
}
|
|
1675
1685
|
|
|
1676
|
-
function analysisSection(marks, framework, { registerCounts = null, probeRan = false, registerRecords = null, ownerChecks = [], frameworkMethod = null } = {}) {
|
|
1686
|
+
function analysisSection(marks, framework, { registerCounts = null, probeRan = false, registerRecords = null, ownerChecks = [], frameworkMethod = null, cardOrder = null } = {}) {
|
|
1677
1687
|
const cards = marks.map((m, markIndex) => {
|
|
1678
|
-
const stop = bandStop(framework, m.rating);
|
|
1679
1688
|
const bullets = readBlock(m, framework);
|
|
1680
|
-
// — the promoted register filings, in the SAME list as the common-law conflicts.
|
|
1681
|
-
//
|
|
1682
|
-
//
|
|
1683
|
-
//
|
|
1689
|
+
// — the promoted register filings, in the SAME list as the common-law conflicts. A name's filing evidence
|
|
1690
|
+
// leads and its web use follows, the order a lawyer's report takes: first the findings that weigh a filing,
|
|
1691
|
+
// then the filing cards, then the findings resting on use alone. Each keeps its own order, so the
|
|
1692
|
+
// position says which evidence this is, and the band inside each says how much it blocks. A run recorded
|
|
1693
|
+
// before this order keeps the one it was delivered with: its findings, then its filing cards.
|
|
1684
1694
|
const reg = registerCardViews(m, framework, registerRecords);
|
|
1685
1695
|
const drawn = registerCardsOnPage(reg.cards, m, framework);
|
|
1686
1696
|
const regBlocks = drawn.map((v) => registerFindingBlock(v, markIndex, m?.registerReads, framework, ownerChecks, frameworkMethod)).join('');
|
|
@@ -1696,12 +1706,16 @@ function analysisSection(marks, framework, { registerCounts = null, probeRan = f
|
|
|
1696
1706
|
// were all typed fell to the fallback below: "No adverse signals recorded for this name on this
|
|
1697
1707
|
// screen." A MARK WITH CONFLICTS RENDERED AS A CLEAN MARK, on the client-facing document, with
|
|
1698
1708
|
// nothing anywhere saying so. findings-model.mjs's view reads both shapes and drops nothing.
|
|
1699
|
-
const
|
|
1709
|
+
const views = knockoutFindingViews(m, { manifest: framework });
|
|
1710
|
+
const weighsAFiling = (v) => Array.isArray(v?.weighedFilings) && v.weighedFilings.length > 0;
|
|
1711
|
+
const findsOf = (list) => list.map((v) => findingBlock(v, framework, markIndex, frameworkMethod)).join('');
|
|
1700
1712
|
// — THE REGISTER CARDS ARE INSIDE `body`, and that is the fall-through guard. A mark whose only
|
|
1701
1713
|
// conflict is a filing on the register used to reach the sentence below and be published as clean.
|
|
1702
1714
|
// The guard is deliberately TIGHT: a listed filing that is dead or out of the counted classes does
|
|
1703
1715
|
// not suppress it, because for that mark the sentence is true and the filings section says so.
|
|
1704
|
-
const body =
|
|
1716
|
+
const body = (cardOrder === KNOCKOUT_CARD_ORDER
|
|
1717
|
+
? [bullets, findsOf(views.filter(weighsAFiling)), regBlocks, overflow, findsOf(views.filter((v) => !weighsAFiling(v)))]
|
|
1718
|
+
: [bullets, findsOf(views), regBlocks, overflow]).filter(Boolean).join('');
|
|
1705
1719
|
// A BAND WITH NO LADDER NAMED IS A NUMBER WITH NO SCALE. The framework's name rides the rating card,
|
|
1706
1720
|
// and that card is only built for a mark with a structured read — an archived run whose marks carry
|
|
1707
1721
|
// bullets and nothing else draws no card, and its band chips were then shown with no statement
|
|
@@ -1717,9 +1731,7 @@ function analysisSection(marks, framework, { registerCounts = null, probeRan = f
|
|
|
1717
1731
|
return `<div class="ko-row">
|
|
1718
1732
|
<div>
|
|
1719
1733
|
<p class="ko-name">${esc(m.name)}</p>
|
|
1720
|
-
|
|
1721
|
-
${qualifierHtml(m.ratingQualifier)}
|
|
1722
|
-
${m.classesSearched?.length ? `<p class="ko-classes">Classes ${esc(m.classesSearched.join(', '))}</p>` : ''}
|
|
1734
|
+
${bandColumn(m, framework)}
|
|
1723
1735
|
</div>
|
|
1724
1736
|
<div>
|
|
1725
1737
|
${body || '<p class="ko-bul">No adverse signals recorded for this name on this screen.</p>'}
|
|
@@ -1816,7 +1828,7 @@ const CAVEAT_LEAD = 'This screen also carries the following limits:';
|
|
|
1816
1828
|
* had forgotten asserted it was the one product it provably was not.
|
|
1817
1829
|
*/
|
|
1818
1830
|
export function renderKnockoutHtml(findings, framework, {
|
|
1819
|
-
runId, overall, issued = null, auditFile = null, probeRan = false, registerCounts = null,
|
|
1831
|
+
runId, overall, issued = null, searched = null, auditFile = null, probeRan = false, registerCounts = null,
|
|
1820
1832
|
registerRecords = null,
|
|
1821
1833
|
// — was the filings sidecar PRESENT but unreadable? Defaults to false, so every existing caller — the
|
|
1822
1834
|
// unit fixtures and both render-check scripts, none of which pass one — renders exactly as it did. It
|
|
@@ -1921,12 +1933,12 @@ export function renderKnockoutHtml(findings, framework, {
|
|
|
1921
1933
|
// a disclosure, which is the one failure that would matter on a client-facing page. A similarity score
|
|
1922
1934
|
// could; that is why there isn't one.
|
|
1923
1935
|
const newCaveats = caveats.filter((c) => saysSomethingNew(c, SCOPE_BLOCK_TEXT));
|
|
1924
|
-
const analysis = analysisSection(marks, framework, { registerCounts, probeRan, registerRecords, ownerChecks, frameworkMethod });
|
|
1936
|
+
const analysis = analysisSection(marks, framework, { registerCounts, probeRan, registerRecords, ownerChecks, frameworkMethod, cardOrder: findings?.cardOrder });
|
|
1925
1937
|
// The request-level notes, gathered across every mark on the document and rendered ONCE at the top.
|
|
1926
1938
|
// They are about the asking, not about a name, so a batch repeating them per mark would be the same
|
|
1927
1939
|
// sentence three times. reviewerNotesBlock renders the rest, under that mark's own cards.
|
|
1928
1940
|
const requestNotes = marks.flatMap((m) => splitKnockoutNotes(m).request);
|
|
1929
|
-
const aboutRequest = aboutRequestBlock(instructedScope, requestNotes, depthNote, productContext,
|
|
1941
|
+
const aboutRequest = aboutRequestBlock(instructedScope, requestNotes, depthNote, productContext, searched, registerCounts);
|
|
1930
1942
|
const provider = hasCounts ? (registerCounts.providerLabel ?? registerCounts.provider ?? 'the register') : null;
|
|
1931
1943
|
// The filings appendix renders only when the run produced a listing artifact — never on its absence,
|
|
1932
1944
|
// and never as an empty table. A knockout with no sidecar publishes exactly the counts-only document.
|
|
@@ -2146,6 +2158,7 @@ export function knockoutReportData(findings, framework, { runId, codename, overa
|
|
|
2146
2158
|
contextFraming: m.contextFraming ?? null,
|
|
2147
2159
|
classesSearched: m.classesSearched ?? [],
|
|
2148
2160
|
classesDriving: m.classesDriving ?? [],
|
|
2161
|
+
...(Array.isArray(m.classGroups) && m.classGroups.length ? { classGroups: m.classGroups } : {}),
|
|
2149
2162
|
degraded: Boolean(m.degraded),
|
|
2150
2163
|
points: m.bullets ?? [],
|
|
2151
2164
|
// ── THE ASSESSMENT THE RUN ALREADY WROTE ──────────────────────────────────────────────────
|
|
@@ -2295,7 +2308,7 @@ export function knockoutReportData(findings, framework, { runId, codename, overa
|
|
|
2295
2308
|
};
|
|
2296
2309
|
}),
|
|
2297
2310
|
registerCountBasis: registerCounts ? COUNT_BASIS : null,
|
|
2298
|
-
registerFilingsBasis: registerRecords && !registerRecords.unavailable ?
|
|
2311
|
+
registerFilingsBasis: registerRecords && !registerRecords.unavailable ? recordBasisOf(registerRecords) : null,
|
|
2299
2312
|
registerProvider: registerCounts ? (registerCounts.providerLabel ?? registerCounts.provider ?? null) : null,
|
|
2300
2313
|
};
|
|
2301
2314
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright 2026 Cordillera Sàrl. Additional terms under section 7 of the AGPL-3.0 apply — see ADDITIONAL-TERMS.md
|
|
3
|
+
//
|
|
4
|
+
// report-dates.mjs — the dates a report prints, read from the report's record.
|
|
5
|
+
//
|
|
6
|
+
// Opening or republishing a report does not mean a new search happened, or that the report was issued again.
|
|
7
|
+
// Both publishers stamped the clock at publish, so a demo's finished example read as searched and issued today,
|
|
8
|
+
// and a republished report's "Issued on" disagreed with the first issue time its own meta.json had kept.
|
|
9
|
+
//
|
|
10
|
+
// THE SEARCH DATE IS WHEN THE RUN STARTED, from its status.json. A source with none has no date to print, and the
|
|
11
|
+
// report's own missing-value presentation applies; today is never the answer.
|
|
12
|
+
// THE ISSUE DATE IS THE FIRST ONE: what the pool's meta.json kept, or the delivery the run recorded when the pool
|
|
13
|
+
// holds no copy (a demo, or a run republished into an empty pool), and the clock only when neither exists, which is
|
|
14
|
+
// a first publish. `renderedAt` is this publish, recorded apart from both.
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
|
|
18
|
+
const readJson = (file) => { try { return JSON.parse(readFileSync(file, "utf8")); } catch { return null; } };
|
|
19
|
+
const instant = (value) => (typeof value === "string" && !Number.isNaN(Date.parse(value)) ? value : null);
|
|
20
|
+
|
|
21
|
+
/** `{searchedAt, issuedAt, renderedAt}` as ISO strings. `searchedAt` is null when the run records no start. */
|
|
22
|
+
export function reportDates({ runDir, poolRunDir, now = new Date() }) {
|
|
23
|
+
const status = readJson(join(runDir, "status.json"));
|
|
24
|
+
const kept = readJson(join(poolRunDir, "meta.json"));
|
|
25
|
+
return {
|
|
26
|
+
searchedAt: instant(status?.startedAt),
|
|
27
|
+
issuedAt: instant(kept?.issuedAt) ?? instant(status?.deliveredAt) ?? now.toISOString(),
|
|
28
|
+
renderedAt: now.toISOString(),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** An instant as `<date> · <time>` in the firm's locale (Europe/Zurich), with its zone when asked. null when there is none. */
|
|
33
|
+
export function zurichStamp(iso, { zone = false } = {}) {
|
|
34
|
+
if (!instant(iso)) return null;
|
|
35
|
+
try {
|
|
36
|
+
const d = new Date(iso);
|
|
37
|
+
const date = new Intl.DateTimeFormat("en-CA", { timeZone: "Europe/Zurich", year: "numeric", month: "2-digit", day: "2-digit" }).format(d);
|
|
38
|
+
const time = new Intl.DateTimeFormat("en-GB", { timeZone: "Europe/Zurich", hour: "2-digit", minute: "2-digit", hour12: false }).format(d);
|
|
39
|
+
if (!zone) return `${date} · ${time}`;
|
|
40
|
+
const tz = new Intl.DateTimeFormat("en-US", { timeZone: "Europe/Zurich", timeZoneName: "short" }).formatToParts(d).find((p) => p.type === "timeZoneName")?.value || "CET";
|
|
41
|
+
return `${date} · ${time} ${tz}`;
|
|
42
|
+
} catch { return null; }
|
|
43
|
+
}
|
|
@@ -320,7 +320,7 @@ export function unendedSignature(artifact) {
|
|
|
320
320
|
* ROUND-2 FIX (review problem 5) — the followup receipt that must SURVIVE a re-derive.
|
|
321
321
|
* `deriveRecallReconciliation` replaces the artifact file wholesale on every pass; the attempt
|
|
322
322
|
* counter lives in that file, so without this carry-forward the counter reset to 0 on every read and
|
|
323
|
-
* RECALL_FOLLOWUP_MAX never engaged (an unbounded
|
|
323
|
+
* RECALL_FOLLOWUP_MAX never engaged (an unbounded digest followup turn per pass, on a 2,596-record band).
|
|
324
324
|
* Returns the keys to merge over the fresh artifact: the prior receipt is kept only while the
|
|
325
325
|
* unended set is UNCHANGED — a different set is genuinely new work and gets a fresh budget. PURE.
|
|
326
326
|
*/
|
|
@@ -331,7 +331,7 @@ export function carryRecallFollowup(priorArtifact, freshArtifact) {
|
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
/**
|
|
334
|
-
* The
|
|
334
|
+
* The followup text for an unended reconciliation — dictates the three ending forms verbatim,
|
|
335
335
|
* with the CURRENT code-computed residual count for the crowd row (so the declared count can never
|
|
336
336
|
* drift below the census). The counts and the unit here come from the SAME artifact reconcileRecall
|
|
337
337
|
* produced, so what the digest is told to declare and what the gate re-computes are one number
|
package/driver/record-goods.mjs
CHANGED
|
@@ -45,6 +45,22 @@ const textOf = (v) => (typeof v === "string" ? v
|
|
|
45
45
|
: Array.isArray(v) ? v.map(textOf).filter(Boolean).join("; ")
|
|
46
46
|
: v && typeof v === "object" ? textOf(v.text ?? v.terms ?? v.description ?? "") : "");
|
|
47
47
|
|
|
48
|
+
// A PROVIDER'S WORDS FOR NO GOODS ARE NOT GOODS. A record can carry a statement whose whole text is a provider's marker: "No
|
|
49
|
+
// goods available", or "No greek supported" in the Greek slot of an EU record beside the real statements. Read as goods, the
|
|
50
|
+
// first made a record with nothing listed read as complete, and its words were tested against the client's as a statement that
|
|
51
|
+
// missed them. Measured 2026-11-05 on 142,151 distinct saved records: 965 descriptions and 387 translations of the first, on
|
|
52
|
+
// offices across the world and in several languages; 20,848 of "No greek supported" on Greek-tagged statements and 18,894 of
|
|
53
|
+
// "No bulgarian supported" on Bulgarian-tagged ones, all EU records. So the first is matched whole wherever it stands, and the
|
|
54
|
+
// second only on the slot of the language it names. A shape seen a handful of times ("not listed", "-") or as a translation of
|
|
55
|
+
// held wording ("no list", "not specified") is not treated as a marker: this rule describes provider boilerplate, and does not
|
|
56
|
+
// decide what counts as plausible goods. The record itself stays as it is.
|
|
57
|
+
const LANGUAGE_SLOT_MARKERS = Object.freeze({ el: "no greek supported", bg: "no bulgarian supported" });
|
|
58
|
+
/** Is this whole statement a provider's marker for no goods? `language` is the statement's own tag. PURE. */
|
|
59
|
+
export function isNoGoodsMarker(text, language = null) {
|
|
60
|
+
const t = String(text ?? "").trim().replace(/^[-–—\s]+/, "").replace(/[.\s]+$/, "").toLowerCase();
|
|
61
|
+
return t === "no goods available" || (t !== "" && t === LANGUAGE_SLOT_MARKERS[String(language ?? "").trim().toLowerCase()]);
|
|
62
|
+
}
|
|
63
|
+
|
|
48
64
|
/**
|
|
49
65
|
* The goods of one official record body: [{classes, text}], one entry per class statement, or [] when the body
|
|
50
66
|
* carries none. PURE. Each provider's shape, as its own code writes it:
|
|
@@ -62,19 +78,24 @@ export function recordGoods(body, { english = true } = {}) {
|
|
|
62
78
|
const out = [];
|
|
63
79
|
// `en: false` marks a statement with no English the engine can use: its words cannot be tested against the
|
|
64
80
|
// client's English goods words, so it is unknown to the goods test, never a mismatch.
|
|
65
|
-
const push = (classes, text, original = null, en = true) => {
|
|
81
|
+
const push = (classes, text, original = null, en = true, extra = null) => {
|
|
66
82
|
const t = String(text ?? "").trim(), o = String(original ?? "").trim();
|
|
67
|
-
if (t) out.push({ classes: [...new Set((classes ?? []).map(niceClass).filter(Boolean))], text: t, ...(o && o !== t ? { alt: o } : {}), ...(en ? {} : { en: false }) });
|
|
83
|
+
if (t && !isNoGoodsMarker(t)) out.push({ classes: [...new Set((classes ?? []).map(niceClass).filter(Boolean))], text: t, ...(o && o !== t ? { alt: o } : {}), ...(en ? {} : { en: false }), ...extra });
|
|
68
84
|
};
|
|
69
85
|
const tagged = (lang) => String(lang ?? "").trim() !== "";
|
|
70
86
|
if (Array.isArray(b.goodsServices)) {
|
|
71
87
|
for (const g of b.goodsServices) {
|
|
72
88
|
// English as written; untagged, English only on an English-language register; else the translation,
|
|
73
89
|
// tagged English, or untagged on such a register; else the original, unread.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
90
|
+
// A marker where a statement or its translation should be is no wording. A translation that is one gives way to
|
|
91
|
+
// the held original, which says what language it is in, because the engine cannot test it against English words.
|
|
92
|
+
const description = isNoGoodsMarker(textOf(g?.description), g?.language) ? "" : textOf(g?.description);
|
|
93
|
+
const translationMarked = isNoGoodsMarker(textOf(g?.translation), g?.translation_language);
|
|
94
|
+
const translation = translationMarked ? null : g?.translation;
|
|
95
|
+
if (isEnglish(g?.language)) push(g?.classes, description, null, true);
|
|
96
|
+
else if (!tagged(g?.language) && !translation) push(g?.classes, description, null, english);
|
|
97
|
+
else if (translation && (isEnglish(g?.translation_language) || (!tagged(g?.translation_language) && english))) push(g?.classes, textOf(translation), description, true);
|
|
98
|
+
else push(g?.classes, description || textOf(translation), null, false, translationMarked && description && tagged(g?.language) ? { language: String(g.language).trim() } : null);
|
|
78
99
|
}
|
|
79
100
|
}
|
|
80
101
|
if (out.length === 0 && Array.isArray(b?._raw?.classifications)) {
|
|
@@ -124,12 +145,12 @@ export function recordGoods(body, { english = true } = {}) {
|
|
|
124
145
|
export function recordGoodsProvenance(body) {
|
|
125
146
|
const b = Array.isArray(body) ? body[0] : body;
|
|
126
147
|
if (!b || typeof b !== "object") return { operation: "undocumented", field: "none" };
|
|
127
|
-
const said = (v) => String(textOf(v) ?? "").trim() !== "";
|
|
148
|
+
const said = (v, language = null) => { const t = String(textOf(v) ?? "").trim(); return t !== "" && !isNoGoodsMarker(t, language); };
|
|
128
149
|
if (Array.isArray(b.goodsServices))
|
|
129
|
-
return { operation: "record-text", field: b.goodsServices.some((g) => said(g?.description) || said(g?.translation)) ? "listed" : "empty" };
|
|
150
|
+
return { operation: "record-text", field: b.goodsServices.some((g) => said(g?.description, g?.language) || said(g?.translation, g?.translation_language)) ? "listed" : "empty" };
|
|
130
151
|
if (Array.isArray(b?._raw?.classifications))
|
|
131
152
|
return { operation: "retrieve", field: b._raw.classifications.some((c) => said(c?.goods_services_text)) ? "listed" : "empty" };
|
|
132
|
-
if (typeof b.goodsAndServices === "string") return { operation: "bulk-register", field: b.goodsAndServices
|
|
153
|
+
if (typeof b.goodsAndServices === "string") return { operation: "bulk-register", field: said(b.goodsAndServices) ? "listed" : "empty" };
|
|
133
154
|
if (b.goodsAndServices != null) return { operation: "undocumented", field: recordGoods(b).length ? "listed" : "empty" };
|
|
134
155
|
return { operation: "undocumented", field: "none" };
|
|
135
156
|
}
|
|
@@ -164,6 +185,26 @@ export function rawGoodsCarried(body) {
|
|
|
164
185
|
});
|
|
165
186
|
}
|
|
166
187
|
|
|
188
|
+
// A RECORD'S GOODS ARE SERVED ONCE. A Clarivate record carries the register's raw goods list beside the
|
|
189
|
+
// normalised goods the provider maps from it item for item (record-goods.mjs `rawGoodsCarried`), so every goods
|
|
190
|
+
// statement was read twice. On a crowded test run, 2026-10-13, one synthesis attempt read 10.79 MB of record
|
|
191
|
+
// text in 549 calls; served this way, the same records come to 6.04 MB in 398. Where the normalised goods carry
|
|
192
|
+
// the raw list, the record is served without that list, in the file's own layout and field order, and anything
|
|
193
|
+
// else in the raw goods block stays; where they do not, or the text is not a record, it is served as it
|
|
194
|
+
// stands. The file on disk is never touched, and the reading audit says how much was left out.
|
|
195
|
+
export function recordAsServed(text) {
|
|
196
|
+
let body;
|
|
197
|
+
try { body = JSON.parse(text); } catch { return { text, audit: {} }; }
|
|
198
|
+
if (!rawGoodsCarried(body)) return { text, audit: {} };
|
|
199
|
+
const goods = { ...body._raw.goodsServices };
|
|
200
|
+
delete goods.intClassDescriptions;
|
|
201
|
+
const raw = { ...body._raw, goodsServices: goods };
|
|
202
|
+
if (!Object.keys(goods).length) delete raw.goodsServices;
|
|
203
|
+
const indent = /^\{\n( +)"/.exec(text)?.[1]?.length ?? 0;
|
|
204
|
+
const served = JSON.stringify({ ...body, _raw: raw }, null, indent) + (text.endsWith("\n") ? "\n" : "");
|
|
205
|
+
return { text: served, audit: { raw_goods_left_out: text.length - served.length } };
|
|
206
|
+
}
|
|
207
|
+
|
|
167
208
|
/**
|
|
168
209
|
* Every record's goods this run holds, by canonical record uri: Map(uri → [{classes, text}]). Read from the
|
|
169
210
|
* record ledger, then from `_records/`, the later copy of a record winning, as `band_record` reads them. A
|
|
@@ -302,7 +302,7 @@ function cellSettled(cell, predicate, forms = null) {
|
|
|
302
302
|
export async function countRegisterHits({
|
|
303
303
|
marks, classes = null, jurisdictions = null, provider, capabilities,
|
|
304
304
|
counter, concurrency = 3, ledgerPath = null, prior = null, now = () => new Date(),
|
|
305
|
-
variantCap = VARIANT_CAP, unreachable = [],
|
|
305
|
+
variantCap = VARIANT_CAP, unreachable = [], joinForms = false,
|
|
306
306
|
}) {
|
|
307
307
|
const { regions: coveredRegions, deferred, worldwide } = resolveRegions(jurisdictions, capabilities);
|
|
308
308
|
// — the office split the plan lane does at compile, done here, because this lane compiles no
|
|
@@ -319,7 +319,6 @@ export async function countRegisterHits({
|
|
|
319
319
|
? { counted: regions, uncounted: dropped.map((d) => ({ office: d.office, memberId: d.memberId, missing: [...(d.missing ?? [])] })) }
|
|
320
320
|
: null;
|
|
321
321
|
const priorByName = new Map((prior?.marks ?? []).map((m) => [String(m.name), m]));
|
|
322
|
-
const answeredByListing = listingAnswers(listed, { regions });
|
|
323
322
|
const batchClasses = (Array.isArray(classes) ? classes : []).filter((n) => Number.isInteger(n));
|
|
324
323
|
|
|
325
324
|
const rows = await runBatched(marks ?? [], concurrency, async (m) => {
|
|
@@ -328,25 +327,10 @@ export async function countRegisterHits({
|
|
|
328
327
|
const scoped = own.length ? own : batchClasses;
|
|
329
328
|
const reused = priorByName.get(name);
|
|
330
329
|
const variants = variantForms(name, { cap: variantCap });
|
|
331
|
-
// The listing's answers for THIS mark, used only when it was asked over the same classes — see
|
|
332
|
-
// listingAnswers for why a different scope is a different question.
|
|
333
|
-
const listedForMark = answeredByListing?.get(name.toLowerCase()) ?? null;
|
|
334
|
-
const fromListing = listedForMark && sameScope(listedForMark.classes, scoped.length ? scoped : null) ? listedForMark.terms : null;
|
|
335
|
-
|
|
336
330
|
// ONE PROBE = ONE PROVIDER CALL = ONE LEDGER LINE. Extracted so the aggregate predicate below bills,
|
|
337
331
|
// records and degrades through exactly the same path as the two simple ones — a second copy of this
|
|
338
332
|
// for the variant loop is how the two would come to disagree about what a failure means.
|
|
339
333
|
const probe = async (term, p, { form = null } = {}) => {
|
|
340
|
-
// ANSWERED BY THE LISTING, and not asked again. The listing ran this exact question — the
|
|
341
|
-
// provider's exact predicate, this term, these classes, these territories — and its answer carried
|
|
342
|
-
// the register's total. No call is made, so no receipt line is written; the cell says where its
|
|
343
|
-
// figure came from.
|
|
344
|
-
const listedAnswer = p.matchMode === "exact" ? fromListing?.get(String(term).trim().toUpperCase()) : null;
|
|
345
|
-
if (listedAnswer) {
|
|
346
|
-
return listedAnswer.approximate === true
|
|
347
|
-
? { total: null, approximate: true, floor: listedAnswer.floor ?? null, source: "listing" }
|
|
348
|
-
: { total: listedAnswer.total, source: "listing" };
|
|
349
|
-
}
|
|
350
334
|
const started = Date.now();
|
|
351
335
|
let r;
|
|
352
336
|
try { r = await counter(term, p, { classes: scoped, regions }); }
|
|
@@ -377,7 +361,7 @@ export async function countRegisterHits({
|
|
|
377
361
|
// THE BILLABLE UNIT IS THE FORM, so the form is on the line. A close-variation row costs N
|
|
378
362
|
// calls, not one, and the receipts ledger is where that multiplier is read off — a single
|
|
379
363
|
// aggregate line would report one call and understate the bill by a factor of N.
|
|
380
|
-
...(form ? { term, variant_form: form } : {}),
|
|
364
|
+
...(form ? { term: Array.isArray(term) ? form : term, variant_form: form } : {}),
|
|
381
365
|
classes: scoped, regions, provider, probe: r?.probe ?? null,
|
|
382
366
|
ok, total: ok ? r.total : null, took_ms: Date.now() - started,
|
|
383
367
|
// An approximation is recorded as what it is. It billed and it answered, so a receipt
|
|
@@ -425,6 +409,15 @@ export async function countRegisterHits({
|
|
|
425
409
|
// provider returns transient failures, a transient failure nulls the whole close column, and the
|
|
426
410
|
// product silently loses the number it was rebuilt to add. Peak in-flight is unchanged from the
|
|
427
411
|
// two-predicate lane; only the wall-clock of the count step grows.
|
|
412
|
+
// ONE QUESTION FOR THE WHOLE SET, on a register that answers a joined exact question with one count. A filing has
|
|
413
|
+
// one spelling, so the joined total is the sum the per-form questions would add up to, for one call instead of up
|
|
414
|
+
// to twelve. The forms stay listed beside it; only the per-form split is not asked for.
|
|
415
|
+
if (joinForms && variants.forms.length > 1) {
|
|
416
|
+
const joined = await probe(variants.forms.map((f) => f.form), p, { form: variants.forms.map((f) => f.form).join(" | ") });
|
|
417
|
+
const forms = variants.forms.map((f) => ({ form: f.form, rules: [...f.rules] }));
|
|
418
|
+
return { ...joined, forms, joined: true, generated: variants.generated, truncated: variants.truncated,
|
|
419
|
+
counted: Number.isFinite(joined.total) ? forms.length : 0 };
|
|
420
|
+
}
|
|
428
421
|
const results = await runBatched(variants.forms, 1, async (f) => ({
|
|
429
422
|
form: f.form, rules: [...f.rules], ...(await probe(f.form, p, { form: f.form })),
|
|
430
423
|
}));
|
|
@@ -510,46 +503,6 @@ export async function countRegisterHits({
|
|
|
510
503
|
};
|
|
511
504
|
}
|
|
512
505
|
|
|
513
|
-
/**
|
|
514
|
-
* The listing's answers, by mark and by term, for the count lane to take instead of asking again.
|
|
515
|
-
*
|
|
516
|
-
* WHY A LISTING CAN ANSWER A COUNT. The identical and close columns are the provider's exact predicate
|
|
517
|
-
* over a term, and the knockout's listing (register-records.mjs) asks that same predicate over the same
|
|
518
|
-
* terms. On a provider whose search answer carries the register's own total, the listing therefore
|
|
519
|
-
* already holds the count, and asking again is a second bill for a figure in hand.
|
|
520
|
-
*
|
|
521
|
-
* ONLY THE SAME QUESTION. A term is taken only when the listing answered it (asked, answered, with a
|
|
522
|
-
* total or a disclosed approximation), and only when the territories match here and the classes match
|
|
523
|
-
* per mark (the caller checks those with `sameScope`). A term the listing did not reach — the cap, a
|
|
524
|
-
* failure — is counted by the count lane as it always was. `containing` is never answered here: the
|
|
525
|
-
* listing never asks it. Terms are keyed upper-case, because register-variants.mjs asks them upper-case
|
|
526
|
-
* and name predicates are case-insensitive on every wired provider.
|
|
527
|
-
*
|
|
528
|
-
* Null when there is no listing: the caller passes one only on a register that declares
|
|
529
|
-
* `listingAnswersCount` (pipeline-knockout.mjs). PURE.
|
|
530
|
-
*/
|
|
531
|
-
export function listingAnswers(listed, { regions = [] } = {}) {
|
|
532
|
-
if (!listed || !Array.isArray(listed.marks)) return null;
|
|
533
|
-
if (!sameScope(listed.scope?.regions ?? null, regions.length ? regions : null)) return null;
|
|
534
|
-
const byMark = new Map();
|
|
535
|
-
for (const m of listed.marks) {
|
|
536
|
-
const terms = new Map();
|
|
537
|
-
for (const t of Array.isArray(m?.terms) ? m.terms : []) {
|
|
538
|
-
if (t?.ok !== true || t.notAsked) continue;
|
|
539
|
-
if (!Number.isFinite(t.total) && t.approximate !== true) continue;
|
|
540
|
-
terms.set(String(t.term ?? "").trim().toUpperCase(), t);
|
|
541
|
-
}
|
|
542
|
-
byMark.set(String(m?.name ?? "").trim().toLowerCase(), { classes: Array.isArray(m?.classes) ? m.classes : null, terms });
|
|
543
|
-
}
|
|
544
|
-
return byMark;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
/** Two scopes are the same question when they list the same values in the same order, or are both unset. */
|
|
548
|
-
export function sameScope(a, b) {
|
|
549
|
-
const norm = (v) => (Array.isArray(v) && v.length ? v.map(String) : null);
|
|
550
|
-
return JSON.stringify(norm(a)) === JSON.stringify(norm(b));
|
|
551
|
-
}
|
|
552
|
-
|
|
553
506
|
/** How many marks got at least ONE number. Zero of them means the product did not happen. */
|
|
554
507
|
export function countedMarks(doc) {
|
|
555
508
|
return (doc?.marks ?? []).filter((m) => COUNT_PREDICATES.some((p) => Number.isFinite(m?.counts?.[p.key]?.total))).length;
|
|
@@ -704,7 +657,7 @@ export function variantFormsLine(entry) {
|
|
|
704
657
|
// place that can say which. Keyed off the cell's own total, so the sentence and the column can never
|
|
705
658
|
// disagree about whether there is a figure.
|
|
706
659
|
if (Number.isFinite(cell.total)) return `Close variations counted${truncated}: ${forms}.`;
|
|
707
|
-
const missed = cell.forms.filter((f) => !Number.isFinite(f.total));
|
|
660
|
+
const missed = cell.joined ? (Number.isFinite(cell.total) ? [] : cell.forms) : cell.forms.filter((f) => !Number.isFinite(f.total));
|
|
708
661
|
// The missing forms are NAMED only when naming them adds something. On a capability gap every form
|
|
709
662
|
// misses, and repeating the list it has just printed makes the one sentence a reader has to parse
|
|
710
663
|
// twice as long and no more informative.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright 2026 Cordillera Sàrl. Additional terms under section 7 of the AGPL-3.0 apply — see ADDITIONAL-TERMS.md
|
|
3
|
+
//
|
|
4
|
+
// register-fixture-marker.mjs — whether this run's register answers come from a fixture directory. From the job, never
|
|
5
|
+
// the environment: it is a fact about the run, and every tool server a stage spawns reads it here.
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { driverDir, ensureDriverDir } from "../shared/driver-dir.mjs";
|
|
8
|
+
|
|
9
|
+
export const REGISTER_FIXTURE_MARKER = "register-fixtures.json";
|
|
10
|
+
|
|
11
|
+
/** Mount the fixture register for this run's stages. */
|
|
12
|
+
export function writeFixtureMarker(runDir, records) {
|
|
13
|
+
ensureDriverDir(runDir);
|
|
14
|
+
writeFileSync(driverDir(runDir, REGISTER_FIXTURE_MARKER), JSON.stringify({ records }, null, 2) + "\n");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The fixture directory this run's register answers come from, or null on a run that asks the register. */
|
|
18
|
+
export function fixtureRecordsDir(runDir) {
|
|
19
|
+
const p = driverDir(runDir, REGISTER_FIXTURE_MARKER);
|
|
20
|
+
if (!existsSync(p)) return null;
|
|
21
|
+
try { return JSON.parse(readFileSync(p, "utf8"))?.records ?? null; } catch { return null; }
|
|
22
|
+
}
|
package/driver/register-plan.mjs
CHANGED
|
@@ -300,6 +300,48 @@ export function containsFormSubstitution(term, capabilities) {
|
|
|
300
300
|
+ `same classes and goods words` };
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
+
// ── AN EXACT PHRASE THE REGISTER CANNOT STATE IS ASKED AS ITS WORDS IN ORDER (ruled 2026-11-05) ─────────────────────────
|
|
304
|
+
//
|
|
305
|
+
// A register that parses AND, OR and NOT inside its exact field refuses a phrase holding one, and the question used to be
|
|
306
|
+
// set aside and disclosed. The same phrase compiles on the contains form: the operator word is dropped and the gap it
|
|
307
|
+
// leaves widens, so the phrase's words are asked in order. That holds the phrase as written and may hold more. The entry
|
|
308
|
+
// asks that form with the same classes, offices, goods words and owner, and carries `exact_substituted`, so the plan says
|
|
309
|
+
// which question was asked in another form and why; the coverage ledger reads it as any other search. A term of nothing
|
|
310
|
+
// but such words has no name left to search and stays set aside. Single letters are words like any other, and a register
|
|
311
|
+
// that declares no such words is never touched. A plan frozen before this keeps its exact entry and its deferral.
|
|
312
|
+
//
|
|
313
|
+
// In a stack, only the phrase moves: it takes its own entry, and the other names stay exact and ask as written.
|
|
314
|
+
|
|
315
|
+
/** The substitution an exact phrase needs on this register, or null when it needs none. PURE. */
|
|
316
|
+
export function exactOperatorSubstitution(term, capabilities) {
|
|
317
|
+
const declared = capabilities?.exactOperatorWords;
|
|
318
|
+
if (!Array.isArray(declared) || !declared.length) return null;
|
|
319
|
+
const words = String(term ?? "").replace(/[^\p{L}\p{N}\s]+/gu, " ").split(/\s+/).filter(Boolean);
|
|
320
|
+
const isOperator = (w) => declared.includes(w.toUpperCase());
|
|
321
|
+
if (!words.some(isOperator) || words.every(isOperator)) return null;
|
|
322
|
+
return { from: "exact", to: "default", term: String(term),
|
|
323
|
+
reason: `the register (${capabilities.id ?? "unknown"}) reads AND, OR and NOT as commands inside an exact phrase, so this term was `
|
|
324
|
+
+ `asked as its words in order, with the same classes, offices and goods words` };
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* An exact entry with its phrases moved to entries of their own, or null when none needs it. Parentheses come out of a moved
|
|
329
|
+
* phrase, because the exact form strips them and the contains form refuses them. PURE.
|
|
330
|
+
*/
|
|
331
|
+
export function exactOperatorEntries(entry, capabilities) {
|
|
332
|
+
if (String(entry?.predicate ?? "") !== "exact") return null;
|
|
333
|
+
const names = Array.isArray(entry.terms) ? entry.terms : [entry.term];
|
|
334
|
+
const moved = names.filter((t) => exactOperatorSubstitution(t, capabilities));
|
|
335
|
+
if (!moved.length) return null;
|
|
336
|
+
const { terms: _terms, term: _term, ...rest } = entry;
|
|
337
|
+
const kept = names.filter((t) => !moved.includes(t));
|
|
338
|
+
return [
|
|
339
|
+
...(kept.length ? [{ ...rest, ...(kept.length === 1 ? { term: kept[0] } : { terms: kept }) }] : []),
|
|
340
|
+
...moved.map((t) => ({ ...rest, predicate: "default", term: String(t).replace(/[()]/g, " ").replace(/\s+/g, " ").trim(),
|
|
341
|
+
exact_substituted: exactOperatorSubstitution(t, capabilities) })),
|
|
342
|
+
];
|
|
343
|
+
}
|
|
344
|
+
|
|
303
345
|
/**
|
|
304
346
|
* 2026-07-29 hardening — is a VARIANTS-MODEL value un-searchable as a mark term? Returns the
|
|
305
347
|
* plain-English reason, or null. Two classes shipped as silent nil "cleans" on the 2026-07-28 run
|
|
@@ -1185,6 +1227,10 @@ export function compileRegisterPlan({ manifest, job, form = null, skillVersion =
|
|
|
1185
1227
|
const entries = [];
|
|
1186
1228
|
const seen = new Set();
|
|
1187
1229
|
const push = (e) => {
|
|
1230
|
+
const moved = exactOperatorEntries(e, caps);
|
|
1231
|
+
return moved ? moved.map(pushOne)[0] : pushOne(e);
|
|
1232
|
+
};
|
|
1233
|
+
const pushOne = (e) => {
|
|
1188
1234
|
// — termIdentity, not slug. The `#N` loop STAYS: it is the net for a genuine duplicate
|
|
1189
1235
|
// question, and `register_plan_qid_duplicate` throws only on entries that reach it already
|
|
1190
1236
|
// identical. What changes is that it stops firing for terms that merely share a script — it was
|
|
@@ -2721,6 +2767,8 @@ export function joinPlanToBands(plan, bandBlocksByAxis, { released = new Set(),
|
|
|
2721
2767
|
...(typeof b.total_counts === "string" ? { total_counts: b.total_counts } : {}),
|
|
2722
2768
|
// The register's floor when it answered "at least N" instead of a count: total_hits stays null beside it.
|
|
2723
2769
|
...(Number.isFinite(b.total_floor) ? { total_floor: b.total_floor } : {}),
|
|
2770
|
+
// An answer the run already held: nothing was sent, and this names the search it came from.
|
|
2771
|
+
...(b.reused_from ? { reused_from: b.reused_from } : {}),
|
|
2724
2772
|
});
|
|
2725
2773
|
}
|
|
2726
2774
|
const planQids = new Set(plan.entries.map((e) => e.qid));
|