clearotron 0.7.0-beta.4 → 0.8.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD-PARTY-NOTICES.md +71 -2
- package/build-info.json +2 -2
- package/demo/multi-country-focus-search/run/common-law-grid.json +1 -1
- package/docs/CLIENT-MCP.md +17 -0
- package/docs/assets/README.md +19 -3
- package/docs/assets/portal-clearance-report.jpg +0 -0
- package/docs/assets/portal-conflict-landscape.jpg +0 -0
- package/docs/assets/portal-new-clearance.png +0 -0
- package/driver/CHANGELOG.md +162 -0
- package/driver/config-inventory.mjs +15 -2
- package/driver/dev-portal.mjs +2 -0
- package/driver/effort-model.mjs +34 -4
- package/driver/engine/CONTRACT.md +8 -0
- package/driver/engine/anthropic-agent.mjs +74 -16
- package/driver/engine/jx-turn.mjs +11 -3
- package/driver/engine/openai-agent.mjs +33 -7
- package/driver/engine/run-choices.mjs +28 -7
- package/driver/engine/speed.mjs +107 -0
- package/driver/enqueue-schema.mjs +8 -0
- package/driver/enqueue.mjs +14 -2
- package/driver/jx-units.mjs +2 -2
- package/driver/jx.mjs +1 -1
- package/driver/knockout-plain-language.mjs +96 -0
- package/driver/ladder/attempt-record.mjs +14 -2
- package/driver/ladder/dispatch.mjs +2 -2
- package/driver/ladder/form-repair.mjs +1 -1
- package/driver/ladder/stage.mjs +7 -1
- package/driver/mark-logos.mjs +6 -1
- package/driver/order-receipt.mjs +184 -0
- package/driver/package.json +4 -1
- package/driver/picture-shrink-worker.mjs +21 -0
- package/driver/picture-thumbnail.mjs +132 -0
- package/driver/pipeline-knockout.mjs +14 -0
- package/driver/portal-confirmation.mjs +3 -0
- package/driver/portal-report.mjs +44 -1
- package/driver/portal-routes/run.mjs +19 -9
- package/driver/portal-runs.mjs +118 -63
- package/driver/portal-service.mjs +17 -2
- package/driver/predelivery-lint.mjs +3 -3
- package/driver/progress.mjs +33 -5
- package/driver/publish/column-queries.mjs +86 -0
- package/driver/publish/index.mjs +4 -4
- package/driver/publish/knockout.mjs +35 -8
- package/driver/publish/page-shell.mjs +5 -1
- package/driver/publish/read-document.mjs +3 -0
- package/driver/publish/render-knockout.mjs +61 -16
- package/driver/publish/render.mjs +171 -30
- package/driver/publish/search-depth.mjs +45 -1
- package/driver/publish/strings.mjs +23 -0
- package/driver/publish/templates/report.css +73 -0
- package/driver/research-answers.mjs +17 -6
- package/driver/research-checks.mjs +22 -4
- package/driver/research-records.mjs +81 -0
- package/driver/run-quote.mjs +3 -0
- package/driver/run-speed.mjs +89 -0
- package/driver/runner.mjs +50 -21
- package/driver/saved-register-pages.mjs +23 -22
- package/driver/stage-freshness.mjs +5 -0
- package/driver/stages.mjs +2 -2
- package/driver/steps/open-run.mjs +12 -1
- package/driver/suite-census.json +199 -37
- package/driver/tokens.mjs +3 -0
- package/driver/urgent-count.mjs +54 -0
- package/driver/usage-ledger.mjs +8 -2
- package/driver/web-pictures.mjs +532 -0
- package/mcp-server/CHANGELOG.md +22 -0
- package/mcp-server/lib/document-reads.mjs +28 -0
- package/mcp-server/lib/events.mjs +21 -12
- package/mcp-server/lib/findings.mjs +2 -1
- package/mcp-server/lib/knockout.mjs +3 -2
- package/mcp-server/lib/ops.mjs +103 -6
- package/mcp-server/lib/options.mjs +4 -0
- package/mcp-server/lib/plan.mjs +38 -4
- package/mcp-server/lib/result-shapes.mjs +66 -0
- package/mcp-server/lib/runs.mjs +46 -44
- package/mcp-server/lib/urgent.mjs +29 -0
- package/mcp-server/package.json +1 -1
- package/mcp-server/result-shapes.json +2978 -0
- package/mcp-server/server.mjs +67 -14
- package/package.json +4 -1
- package/portal-ui/dist/assets/{index-qNDhqCw9.js → index-DEkVU2FD.js} +1909 -766
- package/portal-ui/dist/assets/{index-CxAkJXIT.css → index-W6SAoDkS.css} +238 -1
- package/portal-ui/dist/index.html +2 -2
- package/portal-ui/package.json +1 -1
- package/providers/jx/src/turn-envelope.mjs +3 -1
- package/providers/oauth-mcp-bridge/CHANGELOG.md +8 -0
- package/providers/oauth-mcp-bridge/package.json +1 -1
- package/providers/signa/src/core.js +54 -12
- package/scripts/README.md +3 -0
- package/scripts/e2e-first-time.mjs +2 -2
- package/scripts/mint-result-shapes.mjs +199 -0
- package/scripts/readme-pictures.mjs +227 -0
- package/scripts/render-check.mjs +4 -1
- package/scripts/report-sections-render-check.mjs +191 -0
- package/scripts/settings-render-check.mjs +68 -11
- package/shared/brand.mjs +8 -0
- package/skills/clearotron-account/SKILL.md +24 -0
- package/skills/clearotron-ops/SKILL.md +23 -9
|
@@ -7,6 +7,22 @@
|
|
|
7
7
|
body{margin:0;background:var(--bg);color:var(--ink);font-family:var(--font);font-size:15px;line-height:1.55;
|
|
8
8
|
-webkit-font-smoothing:antialiased;text-rendering:optimizeLegibility}
|
|
9
9
|
.wrap{max-width:1120px;margin:0 auto;padding:0 26px 110px}
|
|
10
|
+
/* The column narrowed beside the conflict panel (owner, 2026-11-25): it becomes the query container its width rules'
|
|
11
|
+
twins ask (column-queries.mjs), at the width the page script sets. Screen only, so paper is never narrowed. */
|
|
12
|
+
@media screen{html.rep-narrow .wrap{container:repcol/inline-size;max-width:none;width:var(--rep-col);margin-left:var(--rep-left);margin-right:0}}
|
|
13
|
+
/* Where the window holds the full column and the conflict panel beside it (16 + 1120 + 30 + 500 + 16 px), a clearance
|
|
14
|
+
page keeps that room on the right from the start, so opening the panel moves nothing (design, 2026-11-26). */
|
|
15
|
+
@media screen and (min-width:1682px){body:has(> #cpanel-words) > .wrap{margin-left:16px;margin-right:auto}}
|
|
16
|
+
/* The conflict panel (owner, 2026-11-25): a conflict's card, opened beside the claim that cites it. The card is the page's
|
|
17
|
+
own markup, drawn at the panel's width by the width rules' twins (the panel is their query container). Never printed. */
|
|
18
|
+
.cpanel{position:absolute;z-index:20;container:repcol/inline-size;background:var(--card);border:1px solid var(--line);border-radius:16px;box-shadow:var(--shadow);outline:none}
|
|
19
|
+
.cpanel .card{margin:0;border:0;box-shadow:none;background:transparent}
|
|
20
|
+
.cpanel .cardhead{padding-right:40px}
|
|
21
|
+
.cpanel .copy-fi+.ask-fi{margin-left:8px}
|
|
22
|
+
.cp-close{position:absolute;top:6px;right:6px;z-index:1;width:44px;height:44px;border:0;border-radius:8px;background:transparent;color:var(--slate);display:inline-flex;align-items:center;justify-content:center;cursor:pointer}
|
|
23
|
+
.cp-close:hover{background:var(--bg2)}
|
|
24
|
+
.fa-ords a.cite-on{outline:2px solid var(--crimson);outline-offset:1px;border-radius:4px}
|
|
25
|
+
@media print{.cpanel{display:none!important}}
|
|
10
26
|
.label{font-size:10.5px;font-weight:700;letter-spacing:.18em;text-transform:uppercase;color:var(--slate)}
|
|
11
27
|
.mono{font-family:var(--mono)}
|
|
12
28
|
a{color:var(--crimson);text-decoration:none}
|
|
@@ -173,6 +189,23 @@
|
|
|
173
189
|
.land{padding:14px 14px 6px}
|
|
174
190
|
.land svg{width:100%;height:auto;display:block}
|
|
175
191
|
.land svg a{cursor:pointer}
|
|
192
|
+
/* A dot's panel (owner, 2026-11-25): a dark ring on the dot under the pointer or keyboard focus, and one small panel in
|
|
193
|
+
the chart's card that the page script fills and places. The chart's card stays a light surface in the dark theme, so
|
|
194
|
+
the panel's colours are the light ones, handed in by the renderer as custom properties. */
|
|
195
|
+
.land{position:relative}
|
|
196
|
+
.land svg a .qring{display:none}
|
|
197
|
+
.land svg a:hover .qring,.land svg a:focus-visible .qring,.land svg a.qhot .qring{display:inline}
|
|
198
|
+
.land svg a:focus-visible{outline:none}
|
|
199
|
+
.qtip{position:absolute;z-index:5;width:262px;max-width:calc(100% - 16px);box-sizing:border-box;padding:12px 14px;background:#FFFDF9;border:1px solid #D8CCB8;border-radius:10px;box-shadow:0 1px 2px rgba(37,9,2,.05),0 10px 30px rgba(37,9,2,.12);display:flex;flex-direction:column;gap:8px;color:var(--qt-ink);font-family:var(--font);text-align:left}
|
|
200
|
+
.qtip[hidden]{display:none}
|
|
201
|
+
.qtip .qt1{display:flex;align-items:center;gap:9px}
|
|
202
|
+
.qtip .qn{width:22px;height:22px;border-radius:50%;color:var(--qt-ink);font-size:11.5px;font-weight:700;display:inline-flex;align-items:center;justify-content:center;flex:none}
|
|
203
|
+
.qtip .qm{font-size:15px;font-weight:700;min-width:0;overflow-wrap:anywhere}
|
|
204
|
+
.qtip .qb{margin-left:auto;padding:2px 9px;border-radius:999px;font-size:11.5px;font-weight:700;white-space:nowrap;flex:none}
|
|
205
|
+
.qtip .qb.med{background:var(--qt-med-bg);color:var(--qt-med-tx)}
|
|
206
|
+
.qtip .qb.low{background:var(--qt-low-bg);color:var(--qt-low-tx)}
|
|
207
|
+
.qtip .qs{font-size:12.5px;color:var(--qt-sub);line-height:1.45}
|
|
208
|
+
.qtip .qs:empty{display:none}
|
|
176
209
|
.keypanel{padding:16px 18px;display:flex;flex-direction:column}
|
|
177
210
|
.keypanel .label{margin-bottom:6px}
|
|
178
211
|
.keyhint{font-size:11.5px;color:var(--slate);margin:0 0 12px}
|
|
@@ -264,6 +297,17 @@
|
|
|
264
297
|
.rr-lg img{display:block;width:94px;height:72px;object-fit:contain;background:#fff;border:1px solid var(--line);border-radius:8px;padding:5px;box-sizing:border-box}
|
|
265
298
|
.rr-lg figcaption{font-size:10.5px;letter-spacing:.04em;color:var(--slate);margin-top:3px}
|
|
266
299
|
.rr-band{max-width:none;justify-content:flex-start;gap:10px;margin:10px 0 12px}
|
|
300
|
+
/* The picture line (owner, 2026-11-25): each set in a bordered frame whose first line is its label, set as the card's
|
|
301
|
+
"Owner" label is. Frames sit side by side where the card is wide enough and stack, as wide as the wider one, where
|
|
302
|
+
it is not; on paper a frame keeps its label and a picture its caption. */
|
|
303
|
+
.pic-line{display:flex;flex-wrap:wrap;align-items:stretch;gap:14px;width:fit-content;max-width:100%;margin:12px 0 14px}
|
|
304
|
+
.pic-set{display:flex;flex-direction:column;align-items:flex-start;gap:8px;min-width:0;padding:8px 10px;border:1px solid var(--line);border-radius:8px;background:var(--bg);background:color-mix(in srgb,var(--card) 50%,var(--bg));break-inside:avoid}
|
|
305
|
+
.pic-head{display:flex;flex-wrap:wrap;align-items:center;gap:8px;min-height:17px}
|
|
306
|
+
.pic-lab{font-size:10.5px;letter-spacing:.12em;text-transform:uppercase;color:var(--slate);line-height:1.2}
|
|
307
|
+
.pic-set .rr-band{margin:0}
|
|
308
|
+
.pic-set .rr-lg{width:auto;min-width:94px;max-width:150px;break-inside:avoid}
|
|
309
|
+
.pic-set .rr-lg img{margin:0 auto}
|
|
310
|
+
.pic-set .rr-lg figcaption{overflow-wrap:anywhere}
|
|
267
311
|
.rn>summary .rr-sm{flex:0 0 100%;box-sizing:border-box;padding-left:14px;margin:2px 0 0}
|
|
268
312
|
.rr-more{align-self:center;font-size:11px;color:var(--slate)}
|
|
269
313
|
.rr-sm{max-width:none;justify-content:flex-start;gap:4px;margin-left:4px}
|
|
@@ -398,6 +442,11 @@
|
|
|
398
442
|
.rcode{font-family:var(--mono);font-size:10.5px;font-weight:700;color:var(--slate);background:var(--bg2);border:1px solid var(--line);padding:2px 6px;border-radius:5px;min-width:30px;text-align:center;flex:none}
|
|
399
443
|
.rname{font-weight:700;font-size:13px;flex:0 1 auto;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
400
444
|
.rsub{flex:1;min-width:0;font-size:11px}
|
|
445
|
+
/* The common-law row's name is the longest in the key, so beside its band and its count "Unregistered use" had no room
|
|
446
|
+
and ran under the count. Its header may take a second line: an item that does not fit moves down whole, the label
|
|
447
|
+
keeps its width and the count stays at the right of the last line. No words change. */
|
|
448
|
+
.rrow.rcl>summary{flex-wrap:wrap;row-gap:4px}
|
|
449
|
+
.rrow.rcl .rsub{flex:1 0 auto}
|
|
401
450
|
.rcount{font-size:11px;font-weight:700;color:var(--slate);flex:none}
|
|
402
451
|
.rbody{padding:2px 2px 6px 8px}
|
|
403
452
|
.rgroup{background:var(--card);border:1px solid var(--line);border-radius:16px;margin-bottom:13px;box-shadow:var(--shadow);overflow:hidden}
|
|
@@ -410,6 +459,20 @@
|
|
|
410
459
|
.gcount{font-size:11px;font-weight:700;color:var(--slate)}
|
|
411
460
|
.gbody{padding:0 12px 8px}
|
|
412
461
|
.rgroup .card{margin:0 0 10px} .rgroup .card:last-child{margin-bottom:4px}
|
|
462
|
+
/* The folded list of lower-rated conflicts (owner, 2026-11-25). Its header keeps its title and marker; a control at the
|
|
463
|
+
right says "Show all {n}" folded and "Hide" open, drawn as a card's Ask AI pill with crimson words, and drops to a
|
|
464
|
+
second row at the right where the header is too narrow. Folded, the list shows the edges of two more cards under it.
|
|
465
|
+
Screen only: the control is .no-print, and the pile and the room it takes sit under @media screen. */
|
|
466
|
+
.rgroup.lowerband>summary{flex-wrap:wrap;row-gap:8px}
|
|
467
|
+
.rgroup.lowerband>summary .gname{min-width:0}
|
|
468
|
+
.lb-show{margin-left:auto;flex:none;display:inline-flex;align-items:center;font:600 12px/1 var(--font);padding:7px 11px;border-radius:999px;border:1px solid var(--line2);background:transparent;color:var(--crimson);white-space:nowrap}
|
|
469
|
+
.rgroup.lowerband>summary:hover .lb-show{border-color:var(--crimson);color:var(--crimson)}
|
|
470
|
+
.lb-show .lb-open,.rgroup.lowerband[open]>summary .lb-show .lb-closed{display:none}
|
|
471
|
+
.rgroup.lowerband[open]>summary .lb-show .lb-open{display:inline}
|
|
472
|
+
@media screen{
|
|
473
|
+
.rgroup.lowerband{--pile:color-mix(in srgb,var(--faint) 55%,var(--line2));--sheet:color-mix(in srgb,var(--card) 80%,var(--line2))}
|
|
474
|
+
.rgroup.lowerband:not([open]){margin-bottom:32px;box-shadow:var(--shadow),0 13px 0 -6px var(--sheet),0 13px 0 -5px var(--pile),0 26px 0 -12px var(--sheet),0 26px 0 -11px var(--pile)}
|
|
475
|
+
}
|
|
413
476
|
|
|
414
477
|
/* a grouped reasoned negative. The shared ground is in the .fold-lead above the run of rows;
|
|
415
478
|
each row carries only what is its own, so the line has to stay ONE line's worth of weight: the mark
|
|
@@ -542,6 +605,7 @@
|
|
|
542
605
|
.fourans ul.fa-obstacles li{margin:0 0 4px;font-size:13px}
|
|
543
606
|
@media (max-width:640px){.fourans .fa-row{flex-direction:column;gap:2px}.fourans .fa-k{flex:auto}}
|
|
544
607
|
@media (max-width:640px){.rr-row{grid-template-columns:1fr;gap:0}.rr-band .rr-lg,.rr-band .rr-lg img{width:72px}.rr-band .rr-lg img{height:56px}}
|
|
608
|
+
@media (max-width:640px){.pic-line{display:grid;grid-template-columns:fit-content(100%);width:auto}.pic-set{padding:8px 6px}.pic-set .rr-band{gap:8px}.pic-set .rr-lg{min-width:72px;max-width:116px}}
|
|
545
609
|
|
|
546
610
|
/* ── the coverage ledger stops being the page's smallest print ─────────────────────────────
|
|
547
611
|
`details.scope` had NO screen rule at all: its summary rendered at the browser default, in the
|
|
@@ -617,6 +681,14 @@
|
|
|
617
681
|
.panel.courtp{padding:14px 18px}.panel.courtp p{margin:0;font-size:14px;line-height:1.5}
|
|
618
682
|
|
|
619
683
|
.ask-fi{margin-left:auto;font:600 12px/1 var(--font);padding:7px 10px;border-radius:999px;border:1px solid var(--line2);background:transparent;color:var(--ink);cursor:pointer;white-space:nowrap}
|
|
684
|
+
/* Copy link (owner, 2026-11-25): drawn as Ask AI is, left of it, and shown only when the frame bridge marks the page as
|
|
685
|
+
inside the portal. The tick replaces the link icon once the portal says the copy landed. */
|
|
686
|
+
.copy-fi{display:none;margin-left:auto;font:600 12px/1 var(--font);padding:7px 10px;border-radius:999px;border:1px solid var(--line2);background:transparent;color:var(--ink);cursor:pointer;white-space:nowrap;align-items:center;gap:7px}
|
|
687
|
+
html.rep-portal .copy-fi{display:inline-flex}
|
|
688
|
+
.fi-acts{margin-left:auto;display:inline-flex;flex-wrap:wrap;justify-content:flex-end;align-items:center;gap:8px}
|
|
689
|
+
.fi-acts .ask-fi,.fi-acts .copy-fi{margin-left:0}
|
|
690
|
+
.copy-fi .ci-tick,.copy-fi.copied .ci-link{display:none}
|
|
691
|
+
.copy-fi.copied .ci-tick{display:inline}
|
|
620
692
|
.tb-ask{margin-right:8px}
|
|
621
693
|
.cardhead .who.mark-first{font-size:17px;font-weight:800}
|
|
622
694
|
.cardhead .who .where{font-weight:500;color:var(--slate);font-size:14px}
|
|
@@ -639,6 +711,7 @@
|
|
|
639
711
|
.crow{display:grid;grid-template-columns:200px 1fr;gap:12px;align-items:start;padding:8px 0;border-top:1px solid var(--line);font-size:13px}
|
|
640
712
|
.crow .cm-mark{font-weight:700}.crow .cwho{color:var(--slate);line-height:1.45}
|
|
641
713
|
.crow .curl{color:var(--crimson);text-decoration:none;font-size:12.5px;word-break:break-all}
|
|
714
|
+
.crow .curl a{color:inherit;text-decoration:none}
|
|
642
715
|
.cmore{padding:10px 0 2px;font-size:12.5px}.wb{color:var(--crimson);text-decoration:none;font-weight:600}
|
|
643
716
|
|
|
644
717
|
details.searched{margin:14px 0;background:var(--card);border-radius:12px;box-shadow:var(--shadow)}
|
|
@@ -24,11 +24,13 @@
|
|
|
24
24
|
// message says how many there are and how to find one: by the owner's name, with the artifact search the stage holds.
|
|
25
25
|
// A first attempt has none, and its message is unchanged.
|
|
26
26
|
//
|
|
27
|
-
// A pure leaf: node:fs, node:path, node:crypto and
|
|
27
|
+
// A pure leaf: node:fs, node:path, node:crypto, run-record.mjs and research-records.mjs only, so the research server can
|
|
28
|
+
// import it.
|
|
28
29
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
29
30
|
import { createHash } from "node:crypto";
|
|
30
31
|
import { basename, dirname, join } from "node:path";
|
|
31
32
|
import { driverDir, paths, readJson } from "./run-record.mjs";
|
|
33
|
+
import { researchCall } from "./research-records.mjs"; // one reading of a research call's record, for every reader
|
|
32
34
|
|
|
33
35
|
export const RESEARCH_ANSWERS_FILE = "research-answers.jsonl";
|
|
34
36
|
|
|
@@ -283,6 +285,10 @@ export const sameStageSession = (a, b) => {
|
|
|
283
285
|
* its answer where the run kept it, and `from`: "handed" or "asked". `sessionKey` is the writer's session, and every
|
|
284
286
|
* session of its stage counts (`sameStageSession`). With no session, only what was handed is held. null when there is no
|
|
285
287
|
* run. IMPURE.
|
|
288
|
+
*
|
|
289
|
+
* The map also says, in its `unreadable` property, how many of its stage's research calls had a record that could not be
|
|
290
|
+
* read (research-records.mjs). None of them is held: a call whose record cannot be read is not a completed one, and is
|
|
291
|
+
* never read as a search that found nothing.
|
|
286
292
|
*/
|
|
287
293
|
export function heldResearchAnswers(runDir, sessionKey = null) {
|
|
288
294
|
if (!runDir) return null;
|
|
@@ -297,12 +303,17 @@ export function heldResearchAnswers(runDir, sessionKey = null) {
|
|
|
297
303
|
for (const r of kept) if (own(r?.session) && typeof r.task === "string" && isResearchAnswer(r.text)) put(r.task, oneLine(r.text), "asked");
|
|
298
304
|
// A replayed answer is the run's own, read from the copy of its answers the replay's marker names, outside the arm.
|
|
299
305
|
const replayFrom = replayAnswersFrom(runDir);
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
306
|
+
let unreadable = 0;
|
|
307
|
+
for (const row of rows(paths(runDir).readingLog)) {
|
|
308
|
+
const call = researchCall(row);
|
|
309
|
+
if (!call || !own(call.session)) continue;
|
|
310
|
+
if (!call.known) { unreadable++; continue; }
|
|
311
|
+
if (!call.ok || call.kind !== "question") continue;
|
|
312
|
+
const text = (call.replay && replayFrom ? savedResearchAnswer(replayFrom, call.question)?.text : null)
|
|
313
|
+
?? kept.filter((x) => typeof x?.task === "string" && x.task.trim() === call.question.trim() && isResearchAnswer(x.text)).pop()?.text ?? null;
|
|
314
|
+
put(call.question, text == null ? null : oneLine(text), "asked");
|
|
305
315
|
}
|
|
316
|
+
Object.defineProperty(held, "unreadable", { value: unreadable, enumerable: false });
|
|
306
317
|
return held;
|
|
307
318
|
}
|
|
308
319
|
|
|
@@ -14,6 +14,7 @@ import { readFileSync, writeFileSync, renameSync } from "node:fs";
|
|
|
14
14
|
import { join } from "node:path";
|
|
15
15
|
import { isUseCheckNoResult } from "./findings-model.mjs";
|
|
16
16
|
import { questionKey, sameStageSession } from "./research-answers.mjs";
|
|
17
|
+
import { researchCall } from "./research-records.mjs"; // one reading of a research call's record, for every reader
|
|
17
18
|
import { RESEARCH_CHECKS_FILE, paths, readJson } from "./run-record.mjs";
|
|
18
19
|
|
|
19
20
|
export { RESEARCH_CHECKS_FILE };
|
|
@@ -63,6 +64,26 @@ export function researchChecksText(findings, held, asked) {
|
|
|
63
64
|
return out.join("\n") + "\n";
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
/**
|
|
68
|
+
* The research questions the stage of `sessionKey` asked, oldest first, as `asked` ({ question, ok, error }), and how many
|
|
69
|
+
* of that stage's research calls had a record that could not be read (`unreadable`). A grid is not a question. A call
|
|
70
|
+
* whose record cannot be read, but whose question can, is listed as not completed: it is never a search that found
|
|
71
|
+
* nothing. IMPURE.
|
|
72
|
+
*/
|
|
73
|
+
export function researchAsked(runDir, sessionKey) {
|
|
74
|
+
const own = (s) => sameStageSession(s, sessionKey);
|
|
75
|
+
const asked = [];
|
|
76
|
+
let unreadable = 0;
|
|
77
|
+
for (const row of rows(paths(runDir).readingLog)) {
|
|
78
|
+
const call = researchCall(row);
|
|
79
|
+
if (!call || !own(call.session)) continue;
|
|
80
|
+
if (!call.known) unreadable++;
|
|
81
|
+
if (call.kind === "grid" || typeof call.question !== "string" || !call.question.trim()) continue;
|
|
82
|
+
asked.push({ question: call.question, ok: call.known && call.ok === true, error: (call.known ? call.error : row?.error) ?? null });
|
|
83
|
+
}
|
|
84
|
+
return { asked, unreadable };
|
|
85
|
+
}
|
|
86
|
+
|
|
66
87
|
/**
|
|
67
88
|
* Write the file for the record that now stands (`findingsAt`, the folded findings.json). `held` is what the record
|
|
68
89
|
* checked against; `sessionKey` the writer's session: every session of its stage asked as the writer, so the file the
|
|
@@ -72,10 +93,7 @@ export function researchChecksText(findings, held, asked) {
|
|
|
72
93
|
export function writeResearchChecks(runDir, { findingsAt, held = null, sessionKey = null } = {}) {
|
|
73
94
|
try {
|
|
74
95
|
const doc = readJson(findingsAt);
|
|
75
|
-
const
|
|
76
|
-
const asked = rows(paths(runDir).readingLog)
|
|
77
|
-
.filter((r) => r?.tool === "perplexity_research" && own(r.session) && !r.args?.grid && typeof r.args?.task === "string" && r.args.task.trim())
|
|
78
|
-
.map((r) => ({ question: r.args.task, ok: r.ok === true, error: r.error ?? null }));
|
|
96
|
+
const { asked } = researchAsked(runDir, sessionKey);
|
|
79
97
|
const at = join(runDir, RESEARCH_CHECKS_FILE);
|
|
80
98
|
writeFileSync(`${at}.tmp`, researchChecksText(doc?.findings, held, asked));
|
|
81
99
|
renameSync(`${at}.tmp`, at);
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
// research-records.mjs — the run's saved web research, read one way for every reader.
|
|
5
|
+
//
|
|
6
|
+
// Three readers took the run's research records apart, each by itself: the answers a writer holds
|
|
7
|
+
// (research-answers.mjs), the research behind the findings' use checks (research-checks.mjs) and the register pages the
|
|
8
|
+
// research saved (saved-register-pages.mjs). Each recognised one service's records by its tool name and its own field
|
|
9
|
+
// names, so a record of any other shape read as no research at all. This module is the one reading of those records.
|
|
10
|
+
// Each reader keeps its own rules: whose session counts, a question or a grid, a completed call or an attempted one,
|
|
11
|
+
// which pages are whole.
|
|
12
|
+
//
|
|
13
|
+
// THREE ANSWERS, NEVER TWO. A record is research this module reads (`known: true`), research it cannot read
|
|
14
|
+
// (`known: false`), or not research (null). Research that cannot be read is never research that found nothing: a search
|
|
15
|
+
// that ran and found nothing is a readable record with nothing in it, and a reader can tell the two apart.
|
|
16
|
+
//
|
|
17
|
+
// THE SERVICE IS THE RECORD'S OWN. A record that names the service that produced it (`service`) is read as that
|
|
18
|
+
// service's. A record written before that field existed is attributed only where its tool name positively identifies
|
|
19
|
+
// the service. Nothing here looks at which keys an installation holds.
|
|
20
|
+
//
|
|
21
|
+
// WHICH RECORDS ARE RESEARCH. A call-log row is research where its tool is a research tool this module knows. A saved
|
|
22
|
+
// result is research where the research server named the file, `<time>-<pid>-<N>.json`, N being the number of the
|
|
23
|
+
// server's call; the same folder also holds owner checks and meaning searches asked again, which are not research
|
|
24
|
+
// results and are not read here.
|
|
25
|
+
//
|
|
26
|
+
// A pure leaf with no imports, so the research server, the band server and the readers can all import it.
|
|
27
|
+
|
|
28
|
+
/** The research tools this module reads, each with the service a record written before `service` existed is attributed to. */
|
|
29
|
+
const RESEARCH_TOOLS = Object.freeze({ perplexity_research: "perplexity" });
|
|
30
|
+
|
|
31
|
+
const isObject = (v) => v != null && typeof v === "object" && !Array.isArray(v);
|
|
32
|
+
|
|
33
|
+
/** The service that produced a research record: the record's own `service`, else the one its tool name identifies. PURE. */
|
|
34
|
+
const serviceOf = (rec) => (typeof rec?.service === "string" && rec.service.trim() ? rec.service.trim() : RESEARCH_TOOLS[rec?.tool] ?? null);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* One row of the run's call log (`_driver/reading-log.jsonl`), read as a research call. PURE.
|
|
38
|
+
* null: not a research call, such as another tool's row.
|
|
39
|
+
* { known: false, service, session, question, kind }: a research call whose record this module cannot read.
|
|
40
|
+
* `question` and `kind` are given where they can still be read, else null.
|
|
41
|
+
* { known: true, service, kind, question, ok, error, session, replay }: `kind` is "grid" or "question"; `ok` whether
|
|
42
|
+
* the call completed; `replay` whether a replay answered it from the run's saved research.
|
|
43
|
+
*/
|
|
44
|
+
export function researchCall(row) {
|
|
45
|
+
if (!isObject(row) || !Object.hasOwn(RESEARCH_TOOLS, row.tool)) return null;
|
|
46
|
+
const service = serviceOf(row);
|
|
47
|
+
const session = typeof row.session === "string" ? row.session : null;
|
|
48
|
+
const args = isObject(row.args) ? row.args : null;
|
|
49
|
+
const question = typeof args?.task === "string" ? args.task : null;
|
|
50
|
+
if (!args || question == null || typeof row.ok !== "boolean")
|
|
51
|
+
return { known: false, service, session, question, kind: args ? (args.grid ? "grid" : "question") : null };
|
|
52
|
+
return { known: true, service, kind: args.grid ? "grid" : "question", question, ok: row.ok, error: row.error ?? null,
|
|
53
|
+
session, replay: Boolean(args.replay) };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// The research server's name for the file a call's results are kept in: the time it was kept, with ":" and "." made
|
|
57
|
+
// "-", the server's process id, and the number of the call (perplexity-server.mjs `keepRaw`).
|
|
58
|
+
const RESULT_FILE = /^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z-\d+-(\d+)\.json$/;
|
|
59
|
+
|
|
60
|
+
/** The number of the research server's call whose results a file in `_driver/web-results/` keeps, or null where the research server did not name the file. PURE. */
|
|
61
|
+
export const researchResultCall = (name) => { const m = RESULT_FILE.exec(String(name ?? "")); return m ? Number(m[1]) : null; };
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* One research result the research server kept, as parsed from its file, read as evidence. PURE.
|
|
65
|
+
* { known: false, service }: a kept result this module cannot read.
|
|
66
|
+
* { known: true, service, kind, session, pages }: `kind` is "question" or "grid"; `pages` are the pages the call
|
|
67
|
+
* fetched, [{url, text}], as fetched, whole or not. A search's snippets are not pages, and a grid's result has none.
|
|
68
|
+
*/
|
|
69
|
+
export function researchResult(result) {
|
|
70
|
+
const service = serviceOf(result);
|
|
71
|
+
if (!isObject(result) || !Object.hasOwn(RESEARCH_TOOLS, result.tool) || (result.kind !== "question" && result.kind !== "grid")
|
|
72
|
+
|| !Array.isArray(result.items)) return { known: false, service };
|
|
73
|
+
const pages = [];
|
|
74
|
+
if (result.kind === "question") {
|
|
75
|
+
for (const item of result.items) {
|
|
76
|
+
if (item?.type !== "fetch_url_results" || !Array.isArray(item.contents)) continue;
|
|
77
|
+
for (const page of item.contents) pages.push({ url: String(page?.url ?? "").trim(), text: page?.snippet });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { known: true, service, kind: result.kind, session: typeof result.session === "string" ? result.session : null, pages };
|
|
81
|
+
}
|
package/driver/run-quote.mjs
CHANGED
|
@@ -70,6 +70,9 @@ export function quoteForJob({ job, profile = null, searchPolicy = null, scope =
|
|
|
70
70
|
// disagree with it no longer exists.
|
|
71
71
|
caseLaw: searchPolicy?.caseLaw === true,
|
|
72
72
|
territories: eff?.jurisdictions ?? [],
|
|
73
|
+
// AN URGENT ORDER, as the job states it: `true` and nothing else, the reading the run itself makes
|
|
74
|
+
// when it starts (enqueue-schema.mjs). It moves the count and the turnaround row, not the work.
|
|
75
|
+
urgent: job?.urgent === true,
|
|
73
76
|
});
|
|
74
77
|
return quoteEffort({
|
|
75
78
|
levers: { ...levers, nativeLanguage: levers.nativeLanguage && nativeLaneRuns({ job, profile, searchPolicy }) },
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
// run-speed.mjs — one run's speed in one line: whether it was ordered Urgent, and what every session it started asked
|
|
4
|
+
// for and was served.
|
|
5
|
+
//
|
|
6
|
+
// Read from the run's own records: every attempt row on `_driver/run.jsonl` (ladder/attempt-record.mjs) and every
|
|
7
|
+
// native-language turn on `_driver/jx-completions.jsonl` carries its turn's speed record, written by the adapter that
|
|
8
|
+
// ran it: what it asked for, why it asked for standard in a fast run, and what the program reported serving. A run
|
|
9
|
+
// admitted Urgent that the vendor dropped to standard partway still counts as ordered Urgent; this line says how many
|
|
10
|
+
// sessions ran fast.
|
|
11
|
+
//
|
|
12
|
+
// THE COUNTS, per session:
|
|
13
|
+
// fastRequested asked the vendor for the faster setting;
|
|
14
|
+
// fastConfirmed of those, the program reported serving fast (the Claude program reports it; a turn whose calls were
|
|
15
|
+
// mixed is a fallback, not a confirmation);
|
|
16
|
+
// servedUnknown of those, the program said nothing about what it served (the Codex program never does);
|
|
17
|
+
// fallback of those, the program reported serving standard or mixed, or said it ran a fast request at standard
|
|
18
|
+
// speed (out of usage credits);
|
|
19
|
+
// unsupported a session of a fast run whose model has no faster setting, so it asked for standard (by reason);
|
|
20
|
+
// standard a session that asked for standard with nothing to explain: every session of a standard run.
|
|
21
|
+
// Tokens are summed by what each session asked for, as recorded facts. Nothing here judges them.
|
|
22
|
+
import { readFileSync } from "node:fs";
|
|
23
|
+
import { paths } from "./run-record.mjs";
|
|
24
|
+
import { urgentForRun } from "./engine/run-choices.mjs";
|
|
25
|
+
import { runLog } from "./log.mjs";
|
|
26
|
+
|
|
27
|
+
const tokensOf = (u) => (u && Number.isFinite(Number(u.total)) ? Number(u.total) : 0);
|
|
28
|
+
|
|
29
|
+
/** The rollup, from the session rows given (attempt rows and native-language turns alike). PURE. */
|
|
30
|
+
export function speedRollup(rows = [], urgent = null) {
|
|
31
|
+
const sessions = { total: 0, fastRequested: 0, fastConfirmed: 0, servedUnknown: 0, fallback: 0, unsupported: 0, standard: 0,
|
|
32
|
+
unsupportedBecause: {}, tokens: { fastRequested: 0, standard: 0 } };
|
|
33
|
+
for (const r of rows) {
|
|
34
|
+
const sp = r?.speed ?? null;
|
|
35
|
+
sessions.total++;
|
|
36
|
+
if (sp?.requested === "fast") {
|
|
37
|
+
sessions.fastRequested++;
|
|
38
|
+
sessions.tokens.fastRequested += tokensOf(r.usage);
|
|
39
|
+
const notice = typeof sp.notice === "string" && sp.notice;
|
|
40
|
+
if (sp.served === "fast" && !notice) sessions.fastConfirmed++;
|
|
41
|
+
else if (sp.served === "standard" || sp.served === "mixed" || notice) sessions.fallback++;
|
|
42
|
+
else sessions.servedUnknown++;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
sessions.tokens.standard += tokensOf(r.usage);
|
|
46
|
+
if (sp?.standardBecause) {
|
|
47
|
+
sessions.unsupported++;
|
|
48
|
+
sessions.unsupportedBecause[sp.standardBecause] = (sessions.unsupportedBecause[sp.standardBecause] ?? 0) + 1;
|
|
49
|
+
} else sessions.standard++;
|
|
50
|
+
}
|
|
51
|
+
return { ordered: urgent?.ordered === true, fast: urgent?.fast === true, reason: urgent?.reason ?? null, sessions };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const readRows = (file, keep) => {
|
|
55
|
+
let raw;
|
|
56
|
+
try { raw = readFileSync(file, "utf8"); } catch { return []; }
|
|
57
|
+
const out = [];
|
|
58
|
+
for (const ln of raw.split("\n")) {
|
|
59
|
+
if (!ln.trim()) continue;
|
|
60
|
+
try { const r = JSON.parse(ln); if (keep(r)) out.push(r); } catch { /* a torn line is skipped */ }
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** Every attempt row on the run's spine. A spine that cannot be read gives none. */
|
|
66
|
+
export function attemptRows(runDir) {
|
|
67
|
+
return readRows(paths(runDir).run, (r) => r?.event === "attempt");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Every session the run started that has a record: the stages' attempt rows, and the native-language turns that ran a
|
|
72
|
+
* model (a row a fixture or an injected executor wrote ran none, and is stamped not provider-billed: jx-lanes.mjs).
|
|
73
|
+
*/
|
|
74
|
+
export function sessionRows(runDir) {
|
|
75
|
+
return [...attemptRows(runDir), ...readRows(paths(runDir).jxCompletions, (r) => r && (r.speed || (r.engine && r.engine !== "not-provider-billed")))];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Write the rollup to the run's spine at a terminal, beside the token rollup that fires at every one. Best-effort: a
|
|
80
|
+
* measurement never affects a run.
|
|
81
|
+
*/
|
|
82
|
+
export function stampSpeedRollup(runDir, phase) {
|
|
83
|
+
if (!runDir) return null;
|
|
84
|
+
try {
|
|
85
|
+
const rollup = speedRollup(sessionRows(runDir), urgentForRun(runDir));
|
|
86
|
+
runLog(runDir, { event: "speed-rollup", phase, ...rollup });
|
|
87
|
+
return rollup;
|
|
88
|
+
} catch { return null; }
|
|
89
|
+
}
|
package/driver/runner.mjs
CHANGED
|
@@ -29,7 +29,8 @@ import { crossBuildResumeRefusal } from "./one-build-per-run.mjs"; // a run is
|
|
|
29
29
|
// claim-sidecar names, because a harness check retyped four of them from memory and false-alarmed on the
|
|
30
30
|
// other nine. Behaviour here is unchanged: the same object and the same three suffixes, sourced.
|
|
31
31
|
import { isLiveQueueMarker, PROSE_PARTS, CLAIM_SIDECAR_SUFFIXES, TERMINAL_QUEUE_SUFFIXES, withFoldedGoods } from "./queue-markers.mjs";
|
|
32
|
-
import { matterLedgerPath, DEFAULT_CLIENT_DAILY_RUNS } from "./usage-ledger.mjs";
|
|
32
|
+
import { matterLedgerPath, DEFAULT_CLIENT_DAILY_RUNS, ledgerSearches } from "./usage-ledger.mjs";
|
|
33
|
+
import { admittedSearches, oneLeftRefusal } from "./urgent-count.mjs"; // what an order counts against its allowance, decided at claim // ONE ledger-path calculation, shared with the portal pre-check
|
|
33
34
|
import { orderTimeRefusal, START_ENV_FILE_FLAG } from "./run-requirements.mjs"; // one authority for what a run needs, and when it is asked for
|
|
34
35
|
import { runTables } from "./order-tables.mjs"; // the tables the portal's order door reads too, so the two cannot disagree
|
|
35
36
|
import { howItRuns } from "./how-it-runs.mjs"; // how this runner runs, for the remedy its refusal names
|
|
@@ -183,7 +184,19 @@ function readMatterLedger(qdir) {
|
|
|
183
184
|
// never collapse on an empty key). TRADEOFF: a mark *correction* in a proceed-reply (same thread, slightly
|
|
184
185
|
// different mark string) now runs twice — accepted vs. the production false-positive, and that case belongs
|
|
185
186
|
// in the §B5b late-bind, not a fresh enqueue.
|
|
186
|
-
|
|
187
|
+
// ── WHOSE MATTER IT IS (design, 2026-11-26) ───────────────────────────────────────────────────────────────────────────
|
|
188
|
+
// A duplicate is the same matter ordered again by the SAME account: the one the order counts against, and for Generic
|
|
189
|
+
// the organisation within it, exactly as recordMatter writes them and the caps read them. Two companies, or two
|
|
190
|
+
// Generic organisations, that send one forwarder's same mark and classes are two orders, and both run. A row whose
|
|
191
|
+
// owner the ledger does not hold cannot show that an order with a known owner is the same account's, so it never
|
|
192
|
+
// refuses one; an order whose own owner is unknown is compared only with rows that are as ownerless as it is.
|
|
193
|
+
function matterOwner(account, organisation) {
|
|
194
|
+
if (!account) return null;
|
|
195
|
+
return account === "generic" ? `generic|${organisation ?? ""}` : String(account);
|
|
196
|
+
}
|
|
197
|
+
const rowOwner = (e) => matterOwner(e?.profileKey ?? null, e?.organisation ?? null);
|
|
198
|
+
|
|
199
|
+
function findDuplicateMatter(qdir, { sig, conversationId, msgId, owner = null }, now) {
|
|
187
200
|
if (DEDUP_WINDOW_MS <= 0) return null;
|
|
188
201
|
const curMark = sig.split("|")[1] || "";
|
|
189
202
|
const hasMark = Boolean(curMark);
|
|
@@ -209,6 +222,7 @@ function findDuplicateMatter(qdir, { sig, conversationId, msgId }, now) {
|
|
|
209
222
|
// stopped tracking it".
|
|
210
223
|
for (const e of readMatterLedger(qdir)) {
|
|
211
224
|
if (e.failed || e.msgId === msgId || (now - (e.ts ?? 0)) >= DEDUP_WINDOW_MS) continue; // failed rows never block a re-send (they still count for the monthly cap)
|
|
225
|
+
if (rowOwner(e) !== owner) continue; // another account's order, or one whose owner is not known to be this one
|
|
212
226
|
const priorMark = String(e.sig ?? "").split("|")[1] || "";
|
|
213
227
|
const marksAgree = !curMark || !priorMark || curMark === priorMark; // conservative when either absent
|
|
214
228
|
// Search-depth spine (review 2026-07-17): the THREAD dimension must be level-aware too — the headline
|
|
@@ -252,7 +266,9 @@ function recordMatter(qdir, entry) {
|
|
|
252
266
|
// test is how the screen comes to advertise one allowance while the gate enforces another.
|
|
253
267
|
export { DEFAULT_CLIENT_DAILY_RUNS };
|
|
254
268
|
|
|
255
|
-
|
|
269
|
+
// `searches` is what the order in hand counts (urgent-count.mjs admittedSearches): 2 for an Urgent order that runs
|
|
270
|
+
// fast here, else 1. Each ledger row counts what its own admission recorded (usage-ledger.mjs ledgerSearches).
|
|
271
|
+
export function checkRunCaps({ account, caps, queueDirs, inHandTagged = true, now = Date.now(), clientRun = false, organisation = null, searches = 1 }) {
|
|
256
272
|
// GENERIC IS CAPPED LIKE ANY COMPANY, one lane per organisation (ruling 2026-09-10: "every
|
|
257
273
|
// organisation's Generic lane carries the daily cap; the exemption goes"). A Generic run counts in the
|
|
258
274
|
// lane of the organisation it was filed under and nowhere else, so one organisation's day cannot use up
|
|
@@ -313,10 +329,13 @@ export function checkRunCaps({ account, caps, queueDirs, inHandTagged = true, no
|
|
|
313
329
|
// is why a monthlyRuns value is worth setting on any account this matters for.
|
|
314
330
|
if (e.failed === true) continue;
|
|
315
331
|
if (inLane(e.profileKey, e.organisation) && e.clientPrincipal === true
|
|
316
|
-
&& typeof e.ts === "number" && new Date(e.ts).toISOString().slice(0, 10) === dayKey) today
|
|
332
|
+
&& typeof e.ts === "number" && new Date(e.ts).toISOString().slice(0, 10) === dayKey) today += ledgerSearches(e);
|
|
317
333
|
}
|
|
318
334
|
}
|
|
319
|
-
if (today +
|
|
335
|
+
if (today + searches > caps.dailyRuns) {
|
|
336
|
+
// One left and an order that counts two: refused in the order screen's words, never run as Standard.
|
|
337
|
+
const oneLeft = oneLeftRefusal({ used: today, limit: caps.dailyRuns, searches });
|
|
338
|
+
if (oneLeft) return oneLeft;
|
|
320
339
|
return `daily allowance: ${lane} has started ${today} search(es) today (runCaps.dailyRuns=${caps.dailyRuns}) — the allowance resets at midnight UTC, or ask your ${BRAND.name} contact to run this one for you`;
|
|
321
340
|
}
|
|
322
341
|
}
|
|
@@ -324,10 +343,10 @@ export function checkRunCaps({ account, caps, queueDirs, inHandTagged = true, no
|
|
|
324
343
|
let month = 0;
|
|
325
344
|
for (const qd of queueDirs) {
|
|
326
345
|
for (const e of readMatterLedger(qd)) {
|
|
327
|
-
if (inLane(e.profileKey, e.organisation) && typeof e.ts === "number" && new Date(e.ts).toISOString().slice(0, 7) === monthKey) month
|
|
346
|
+
if (inLane(e.profileKey, e.organisation) && typeof e.ts === "number" && new Date(e.ts).toISOString().slice(0, 7) === monthKey) month += ledgerSearches(e);
|
|
328
347
|
}
|
|
329
348
|
}
|
|
330
|
-
if (month +
|
|
349
|
+
if (month + searches > caps.monthlyRuns) {
|
|
331
350
|
return `admission cap: ${lane} has started ${month} run(s) this month (runCaps.monthlyRuns=${caps.monthlyRuns}) — the cap resets at month end; raise it in the customer profile if this is intended growth`;
|
|
332
351
|
}
|
|
333
352
|
}
|
|
@@ -347,7 +366,7 @@ function dropMatter(qdir, msgId) {
|
|
|
347
366
|
}
|
|
348
367
|
|
|
349
368
|
// Exported for unit tests (the integration path exercises them via claimAndRun).
|
|
350
|
-
export { matterSignature, matterLedgerPath, findDuplicateMatter, recordMatter, dropMatter, readMatterLedger };
|
|
369
|
+
export { matterSignature, matterOwner, matterLedgerPath, findDuplicateMatter, recordMatter, dropMatter, readMatterLedger };
|
|
351
370
|
|
|
352
371
|
// WHOSE NOTICE THIS IS, for the three notices filed before any run exists. A run's account is read from
|
|
353
372
|
// the profile frozen into it; these notices have no run, so the door could not tell whose they were and
|
|
@@ -622,7 +641,7 @@ async function failAtIntake(procPath, qdir, base, agentId, job, v, reasons) {
|
|
|
622
641
|
|
|
623
642
|
// Best-effort duplicate-skip notice (mirrors intakeNotify: one outbox packet). Returns the audit-trail
|
|
624
643
|
// outcome string for the .reason file.
|
|
625
|
-
async function duplicateNotify(agentId, base, job, prior = null, sig = null) {
|
|
644
|
+
async function duplicateNotify(agentId, base, job, prior = null, sig = null, shown = true) {
|
|
626
645
|
const mark = job?.markName ?? job?.name ?? job?.marks?.[0]?.name ?? base;
|
|
627
646
|
// ── A REFUSAL DELIVERED AS SILENCE IS INDISTINGUISHABLE FROM A LOST JOB ────────
|
|
628
647
|
//
|
|
@@ -640,8 +659,10 @@ async function duplicateNotify(agentId, base, job, prior = null, sig = null) {
|
|
|
640
659
|
// so it is where the override belongs; `--dup-override` on the CLI, `dupOverride` on `start_run` and
|
|
641
660
|
// the cockpit's checkbox are the product paths, and naming one here is what stops a hand edit to the
|
|
642
661
|
// ledger being the only route anybody finds.
|
|
643
|
-
|
|
644
|
-
|
|
662
|
+
// THE EARLIER ORDER IS NAMED ONLY TO ITS OWN ACCOUNT (design, 2026-11-26): its reference, when it was recorded and
|
|
663
|
+
// the matter's signature are told to a requester who may see that order, and to nobody else.
|
|
664
|
+
const when = shown && prior?.ts ? new Date(prior.ts).toISOString() : null;
|
|
665
|
+
const which = shown && prior?.msgId
|
|
645
666
|
? ` The run already under way was submitted as ${prior.msgId}${when ? ` at ${when}` : ""} — that is the one that will deliver.`
|
|
646
667
|
: " The earlier run will deliver.";
|
|
647
668
|
const text = `⚠️ Clearotron request "${mark}" matches a matter already in progress or just delivered, so it was `
|
|
@@ -657,9 +678,9 @@ async function duplicateNotify(agentId, base, job, prior = null, sig = null) {
|
|
|
657
678
|
// THE COLLIDING SIGNATURE AND THE PRIOR RUN, AS FIELDS. The sentence is for a person; these are for
|
|
658
679
|
// whatever reads the packet — and a field is what lets a surface show which run without re-deriving
|
|
659
680
|
// a signature it would compute differently.
|
|
660
|
-
matterSignature: sig ?? null,
|
|
661
|
-
priorMsgId: prior?.msgId ?? null,
|
|
662
|
-
priorJobId: prior?.id ?? null,
|
|
681
|
+
matterSignature: shown ? (sig ?? null) : null,
|
|
682
|
+
priorMsgId: shown ? (prior?.msgId ?? null) : null,
|
|
683
|
+
priorJobId: shown ? (prior?.id ?? null) : null,
|
|
663
684
|
priorRecordedAt: when,
|
|
664
685
|
matchedBy: prior?.conversationId && prior.conversationId === String(job?.conversationId ?? "").trim()
|
|
665
686
|
? "thread" : "matter-signature",
|
|
@@ -671,22 +692,25 @@ async function duplicateNotify(agentId, base, job, prior = null, sig = null) {
|
|
|
671
692
|
// Park a claimed job as a DUPLICATE: consume the .processing claim (so the 90s timer never re-claims it),
|
|
672
693
|
// record why, ping the forwarder once. Recoverable — re-enqueue with "dupOverride": true to force a genuine
|
|
673
694
|
// re-run (a bare .duplicate -> .json rename re-matches the prior within the dedup window and re-parks).
|
|
674
|
-
async function parkDuplicate(procPath, qdir, base, agentId, job, prior, sig) {
|
|
695
|
+
async function parkDuplicate(procPath, qdir, base, agentId, job, prior, sig, owner = null) {
|
|
675
696
|
renameSync(procPath, join(qdir, `${base}.duplicate`));
|
|
676
697
|
cleanupClaimSidecars(procPath);
|
|
677
698
|
cleanupProseParts(qdir, base);
|
|
678
699
|
const conv = String(job.conversationId ?? "").trim();
|
|
679
700
|
const matchedBy = prior.conversationId && prior.conversationId === conv ? "thread (conversationId)" : "matter signature";
|
|
701
|
+
// Named only where the requester's account is known and is the earlier order's own (findDuplicateMatter matched on it).
|
|
702
|
+
const shown = owner !== null && rowOwner(prior) === owner;
|
|
680
703
|
const reason = [
|
|
681
704
|
`duplicate clearotron — not run (a second search for the same matter)`,
|
|
682
705
|
`matched by: ${matchedBy}`,
|
|
683
706
|
`matter: ${sig}`,
|
|
684
707
|
`conversationId: ${conv || "-"}`,
|
|
685
|
-
`matches prior msgId ${prior.msgId} (recorded ${new Date(prior.ts).toISOString()}, within ${DEDUP_WINDOW_MS / 3600000}h)
|
|
708
|
+
shown ? `matches prior msgId ${prior.msgId} (recorded ${new Date(prior.ts).toISOString()}, within ${DEDUP_WINDOW_MS / 3600000}h)`
|
|
709
|
+
: `matches an earlier order within ${DEDUP_WINDOW_MS / 3600000}h whose account could not be established, so it is not named`,
|
|
686
710
|
`to force a genuine re-run, re-enqueue with "dupOverride": true (a bare ${base}.duplicate -> ${base}.json rename re-matches the prior within the ${DEDUP_WINDOW_MS / 3600000}h window and re-parks)`,
|
|
687
711
|
].join("\n");
|
|
688
712
|
writeFileSync(join(qdir, `${base}.duplicate.reason`), reason + "\n");
|
|
689
|
-
const notified = await duplicateNotify(agentId, base, job, prior, sig);
|
|
713
|
+
const notified = await duplicateNotify(agentId, base, job, prior, sig, shown);
|
|
690
714
|
try { appendFileSync(join(qdir, `${base}.duplicate.reason`), `notify: ${notified}\n`); } catch { /* best-effort */ }
|
|
691
715
|
}
|
|
692
716
|
|
|
@@ -1024,9 +1048,12 @@ async function claimAndPrep(jsonFile, qdir, agentId) {
|
|
|
1024
1048
|
// Per-account admission caps (Phase 3b) — the resolved effective profile is in hand; over-cap
|
|
1025
1049
|
// clarifies before any spend and before the matter is recorded.
|
|
1026
1050
|
if (!effProfile) note(`[runner] ${base} run-caps skipped — profile resolution errored, caps not evaluable for this admission (fail-open by doctrine, logged for visibility)`);
|
|
1051
|
+
// WHAT THIS ORDER COUNTS, decided once, here: 2 for an Urgent order that runs fast on this installation, else 1.
|
|
1052
|
+
// The cap is checked against it and the ledger row records it, so tomorrow's count reads what today charged.
|
|
1053
|
+
const searches = admittedSearches(job);
|
|
1027
1054
|
const capMsg = checkRunCaps({ account: effProfile?.key ?? null, caps: effProfile?.runCaps, queueDirs: config.queueDirs,
|
|
1028
1055
|
inHandTagged: Boolean(job.profileKey), clientRun: job.clientPrincipal === true,
|
|
1029
|
-
organisation: typeof job.tenant === "string" && job.tenant ? job.tenant : null });
|
|
1056
|
+
organisation: typeof job.tenant === "string" && job.tenant ? job.tenant : null, searches });
|
|
1030
1057
|
if (capMsg) {
|
|
1031
1058
|
note(`[runner] ${base} ${capMsg}`);
|
|
1032
1059
|
await failAtIntake(procPath, qdir, base, agentId, job, { classify: "clarify", errors: [capMsg] }, [capMsg]);
|
|
@@ -1039,6 +1066,8 @@ async function claimAndPrep(jsonFile, qdir, agentId) {
|
|
|
1039
1066
|
// RESOLVED level (a level change is never a duplicate — the escalation flow).
|
|
1040
1067
|
const sig = matterSignature(job, { product: policy.product });
|
|
1041
1068
|
const conversationId = String(job.conversationId ?? "").trim();
|
|
1069
|
+
// The order's owner, as the ledger row below records it: only this owner's earlier orders can make it a duplicate.
|
|
1070
|
+
const owner = matterOwner(effProfile?.key ?? null, effProfile?.key === "generic" && typeof job.tenant === "string" && job.tenant ? job.tenant : null);
|
|
1042
1071
|
const dupNow = Date.now();
|
|
1043
1072
|
// dupOverride: an explicit, requester-confirmed "yes, genuinely re-run this mark". Skip the dedup GATE
|
|
1044
1073
|
// but STILL record the matter, so a forced run seeds the ledger and any later true duplicate is caught.
|
|
@@ -1046,14 +1075,14 @@ async function claimAndPrep(jsonFile, qdir, agentId) {
|
|
|
1046
1075
|
if (job.dupOverride) {
|
|
1047
1076
|
note(`[runner] ${base} carries dupOverride — skipping matter-dedup gate (forced run; sig=${sig} conv=${conversationId || "-"})`);
|
|
1048
1077
|
} else {
|
|
1049
|
-
const prior = findDuplicateMatter(qdir, { sig, conversationId, msgId: job.msgId }, dupNow);
|
|
1078
|
+
const prior = findDuplicateMatter(qdir, { sig, conversationId, msgId: job.msgId, owner }, dupNow);
|
|
1050
1079
|
if (prior) {
|
|
1051
1080
|
note(`[runner] duplicate ${base} (sig=${sig} conv=${conversationId || "-"}) matches msgId ${prior.msgId} — parking as .duplicate, not running`);
|
|
1052
|
-
await parkDuplicate(procPath, qdir, base, agentId, job, prior, sig);
|
|
1081
|
+
await parkDuplicate(procPath, qdir, base, agentId, job, prior, sig, owner);
|
|
1053
1082
|
return null;
|
|
1054
1083
|
}
|
|
1055
1084
|
}
|
|
1056
|
-
recordMatter(qdir, { sig, conversationId, msgId: job.msgId, id: job.id, ts: dupNow,
|
|
1085
|
+
recordMatter(qdir, { sig, conversationId, msgId: job.msgId, id: job.id, ts: dupNow, searches,
|
|
1057
1086
|
// Generic is tagged too, with the organisation whose lane it counts in. An untagged Generic row
|
|
1058
1087
|
// counted towards nothing, which was the exemption the owner's 2026-09-10 ruling removed.
|
|
1059
1088
|
...(effProfile?.key ? { profileKey: effProfile.key } : {}),
|