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
package/driver/portal-report.mjs
CHANGED
|
@@ -645,6 +645,15 @@ const EMBED_JS = `
|
|
|
645
645
|
// dark rules key on. That control sits in the top bar embedding strips, and a sandboxed frame cannot
|
|
646
646
|
// read the portal's saved choice, so this is the one route by which an embedded report turns dark.
|
|
647
647
|
// Two values and nothing else; the answer says which was applied, so the shell knows it took.
|
|
648
|
+
// THE PORTAL SAYS A COPY LANDED. The card's "Copy link" asked it to (below); only a copy that landed shows the tick
|
|
649
|
+
// and says "Copied" to a screen reader, and both go after a moment.
|
|
650
|
+
if(d.command==='copied'){
|
|
651
|
+
if(copyBtn&&d.value===true&©Live){
|
|
652
|
+
var cb=copyBtn; cb.classList.add('copied'); copyLive.textContent=cb.getAttribute('data-copied')||'';
|
|
653
|
+
clearTimeout(copyTimer); copyTimer=setTimeout(function(){cb.classList.remove('copied');copyLive.textContent='';},1600);
|
|
654
|
+
}
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
648
657
|
if(d.command==='theme'){
|
|
649
658
|
var th=d.value==='dark'?'dark':'light';
|
|
650
659
|
document.documentElement.setAttribute('data-theme',th);
|
|
@@ -701,6 +710,38 @@ const EMBED_JS = `
|
|
|
701
710
|
// (the one that measurably needs the delegation) working, and only ever degrades to native scrolling
|
|
702
711
|
// when we can positively see there is no other window.
|
|
703
712
|
var framed=false; try{framed=window.parent!==window;}catch(err){framed=true;}
|
|
713
|
+
// COPY LINK (owner, 2026-11-25). A card's "Copy link" is drawn hidden; inside the portal this marks the page so the
|
|
714
|
+
// stylesheet shows it, and a press asks the portal, which alone knows its own address and may write the clipboard, to
|
|
715
|
+
// copy the address of its report screen at this card. The card is named by its id; a card copied into the conflict
|
|
716
|
+
// panel carries its original's id as data-card-of. Un-framed nobody can answer, so the page is not marked.
|
|
717
|
+
// THE CONFLICT PANEL MOVES THE PAGE. Narrowing the column beside it reflows everything, and the pressed number has to
|
|
718
|
+
// stay at the same height on screen. The page cannot scroll the portal, so it asks: un-framed it scrolls itself. Any
|
|
719
|
+
// reflow it makes re-posts the height and the section tops.
|
|
720
|
+
document.addEventListener('rep-shift',function(e){
|
|
721
|
+
if(!framed)return;
|
|
722
|
+
e.preventDefault();
|
|
723
|
+
try{parent.postMessage({source:TAG,type:'scrollBy',dy:Math.round((e.detail&&e.detail.dy)||0)},'*');}catch(err){}
|
|
724
|
+
});
|
|
725
|
+
document.addEventListener('rep-reflow',function(){schedule();});
|
|
726
|
+
var copyBtn=null, copyLive=null, copyTimer=null;
|
|
727
|
+
if(framed){
|
|
728
|
+
try{document.documentElement.classList.add('rep-portal');}catch(err){}
|
|
729
|
+
copyLive=document.createElement('span'); copyLive.className='copy-said'; copyLive.setAttribute('role','status');
|
|
730
|
+
copyLive.style.cssText='position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap';
|
|
731
|
+
document.body.appendChild(copyLive);
|
|
732
|
+
}
|
|
733
|
+
document.addEventListener('click',function(e){
|
|
734
|
+
var b=e.target.closest?e.target.closest('.copy-fi'):null;
|
|
735
|
+
if(!b||!framed)return;
|
|
736
|
+
var card=b.closest('.card'); if(!card)return;
|
|
737
|
+
var id=card.id||card.getAttribute('data-card-of')||'';
|
|
738
|
+
var whole=function(v){var n=parseInt(v,10);return String(n)===String(v)&&n>=0?n:null;};
|
|
739
|
+
var koOrd=card.getAttribute('data-ko-ord'), koMark=card.getAttribute('data-ko-mark');
|
|
740
|
+
var ord=koOrd!==null?whole(koOrd):(id.charAt(0)==='c'?whole(id.slice(1)):null);
|
|
741
|
+
copyBtn=b;
|
|
742
|
+
try{parent.postMessage({source:TAG,type:'copyLink',card:id,ordinal:ord,markIndex:koMark!==null?whole(koMark):null},'*');}
|
|
743
|
+
catch(err){try{console.warn('Copy link could not reach the page: '+(err&&err.message||err));}catch(e2){}}
|
|
744
|
+
});
|
|
704
745
|
function revealTarget(el){var p=el.parentElement;while(p){if(p.tagName==='DETAILS'&&!p.open)p.open=true;p=p.parentElement;}}
|
|
705
746
|
document.addEventListener('click',function(e){
|
|
706
747
|
var a=e.target.closest?e.target.closest('a[href^="#"]'):null;
|
|
@@ -731,7 +772,9 @@ const EMBED_JS = `
|
|
|
731
772
|
var card=b.closest('.card');
|
|
732
773
|
var whole=function(v){var n=parseInt(v,10);return String(n)===String(v)&&n>=0?n:null;};
|
|
733
774
|
var koOrd=card?card.getAttribute('data-ko-ord'):null;
|
|
734
|
-
|
|
775
|
+
// A card copied into the conflict panel has no id of its own; it carries its original's as data-card-of.
|
|
776
|
+
var cid=card?(card.id||card.getAttribute('data-card-of')||''):'';
|
|
777
|
+
var idOrd=cid.charAt(0)==='c'?cid.slice(1):null;
|
|
735
778
|
var ord=koOrd!==null?whole(koOrd):(idOrd!==null?whole(idOrd):null);
|
|
736
779
|
var koMark=card?card.getAttribute('data-ko-mark'):null;
|
|
737
780
|
var mi=koMark!==null?whole(koMark):null;
|
|
@@ -18,8 +18,9 @@ import { quoteForJob } from "../run-quote.mjs";
|
|
|
18
18
|
import { readJson } from "../run-record.mjs";
|
|
19
19
|
import { countJobMarks, coverageDisclosure, kebabCollisions, policyFor, productAvailability, UNAVAILABLE_NOTE } from "../search-policy.mjs";
|
|
20
20
|
import { accountUsage, DEFAULT_CLIENT_DAILY_RUNS } from "../usage-ledger.mjs";
|
|
21
|
+
import { admittedSearches, oneLeftRefusal } from "../urgent-count.mjs"; // what an order counts against its allowance, as the runner's wall counts it
|
|
21
22
|
|
|
22
|
-
export async function runRoutes({ poolRoot, workspaceRoot, secret, queueDirs, trigger, stopRun, demo, orderRefusal, audit, upstream, readBuilt, readCanCount, readTerritories, loadProfilesImpl, usedJtis, sweepJtis, jobFor, selectorOf, refusalFor, allowanceExhaustedLine }, { method, parts, principal, body, query }) {
|
|
23
|
+
export async function runRoutes({ poolRoot, workspaceRoot, secret, queueDirs, trigger, stopRun, demo, orderRefusal, urgentAvailable = () => false, audit, upstream, readBuilt, readCanCount, readTerritories, loadProfilesImpl, usedJtis, sweepJtis, jobFor, selectorOf, refusalFor, allowanceExhaustedLine }, { method, parts, principal, body, query }) {
|
|
23
24
|
// shared plan-time gates — run at BOTH doors so a body that would 422 at plan can never be
|
|
24
25
|
// submitted at run behind a token minted for a clean body (review 2026-07-18)
|
|
25
26
|
const planGates = (job) => {
|
|
@@ -132,10 +133,13 @@ export async function runRoutes({ poolRoot, workspaceRoot, secret, queueDirs, tr
|
|
|
132
133
|
const resolveFor = resolveForDoor;
|
|
133
134
|
const effortFrom = ({ job, profile, resolved }) => {
|
|
134
135
|
if (!profile || !resolved || resolved.clarify) return null;
|
|
135
|
-
|
|
136
|
+
// Quoted as admission will count it: an Urgent order this installation cannot run fast is a Standard one.
|
|
137
|
+
const asAdmitted = job?.urgent === true && urgentAvailable() !== true ? { ...job, urgent: false } : job;
|
|
138
|
+
try { return quoteForJob({ job: asAdmitted, profile, searchPolicy: resolved }); } catch { return null; }
|
|
136
139
|
};
|
|
137
140
|
|
|
138
|
-
|
|
141
|
+
// `searches` is what the order counts (urgent-count.mjs admittedSearches), the number the runner's wall charges.
|
|
142
|
+
const quotaRefusal = async (account, organisation = null, searches = 1) => {
|
|
139
143
|
if (seesEverything(principal) || !upstream) return null;
|
|
140
144
|
let caps = null, capsRead = false;
|
|
141
145
|
try {
|
|
@@ -173,8 +177,11 @@ export async function runRoutes({ poolRoot, workspaceRoot, secret, queueDirs, tr
|
|
|
173
177
|
audit({ event: "quota-precheck-blind", by: principal.email, account, basis: used.basis });
|
|
174
178
|
return null;
|
|
175
179
|
}
|
|
176
|
-
if (used.today +
|
|
177
|
-
|
|
180
|
+
if (used.today + searches <= limit) return null;
|
|
181
|
+
// One left and an order that counts two is not an account that has used everything: it is told so in the
|
|
182
|
+
// order screen's own words, the same the runner's wall gives (urgent-count.mjs oneLeftRefusal).
|
|
183
|
+
const oneLeft = oneLeftRefusal({ used: used.today, limit, searches });
|
|
184
|
+
return { status: 429, json: { ok: false, errors: [oneLeft ?? allowanceExhaustedLine(limit, BRAND.name)] } };
|
|
178
185
|
};
|
|
179
186
|
|
|
180
187
|
// ── AN INSTALL THAT CANNOT SEARCH REFUSES HERE, WHERE THE PERSON IS ─────────────────────────
|
|
@@ -206,7 +213,7 @@ export async function runRoutes({ poolRoot, workspaceRoot, secret, queueDirs, tr
|
|
|
206
213
|
if (notConfigured) return notConfigured;
|
|
207
214
|
const gates = planGates(job);
|
|
208
215
|
if (gates.fail) return gates.fail;
|
|
209
|
-
const overQuota = await quotaRefusal(account, job.tenant ?? null);
|
|
216
|
+
const overQuota = await quotaRefusal(account, job.tenant ?? null, admittedSearches(job, { runsHere: urgentAvailable }));
|
|
210
217
|
if (overQuota) return overQuota;
|
|
211
218
|
// ONE resolution, and the name, the stage, the turnaround and the effort all come off it.
|
|
212
219
|
const { profile: planProfile, resolved: planResolved, scope: planScope } = resolveFor(job);
|
|
@@ -261,7 +268,7 @@ export async function runRoutes({ poolRoot, workspaceRoot, secret, queueDirs, tr
|
|
|
261
268
|
if (gates.fail) return gates.fail;
|
|
262
269
|
// re-checked for the same reason the gates are: a token minted while the account still had
|
|
263
270
|
// allowance must not spend it after another tab has used the last one.
|
|
264
|
-
const overQuota = await quotaRefusal(account, job.tenant ?? null);
|
|
271
|
+
const overQuota = await quotaRefusal(account, job.tenant ?? null, admittedSearches(job, { runsHere: urgentAvailable }));
|
|
265
272
|
if (overQuota) return overQuota;
|
|
266
273
|
sweepJtis();
|
|
267
274
|
const bad = verifyConfirmation({ secret, token: body.confirmationToken, account, email: principal.email,
|
|
@@ -384,8 +391,11 @@ export async function runRoutes({ poolRoot, workspaceRoot, secret, queueDirs, tr
|
|
|
384
391
|
: `The run could not be started just now. Nothing was started, and nothing was charged — ${BRAND.name} can see what happened.`);
|
|
385
392
|
return { status: 502, json: { ok: false, error, unwired } };
|
|
386
393
|
}
|
|
387
|
-
|
|
388
|
-
|
|
394
|
+
// THE REFERENCE THE ORDER IS FILED UNDER, as the engine door filed it: a door that does not see every account files
|
|
395
|
+
// an order under its account's own reference (mcp-server/lib/ops.mjs filedReference), not the one minted here.
|
|
396
|
+
const filed = typeof r?.id === "string" && r.id ? r.id : job.id;
|
|
397
|
+
audit({ event: "trigger", by: principal.email, account, selector, id: filed, ok: Boolean(r?.ok ?? r?.queued) });
|
|
398
|
+
return { status: 200, json: { ok: true, queued: true, id: filed, upstream: r ?? null } };
|
|
389
399
|
}
|
|
390
400
|
|
|
391
401
|
// ── STOPPING ───────────────────────────────────────────────────────────────────────────────
|
package/driver/portal-runs.mjs
CHANGED
|
@@ -17,6 +17,7 @@ import { orderedQueueFiles } from "./queue-order.mjs";
|
|
|
17
17
|
import { paths, readJson } from "./run-record.mjs";
|
|
18
18
|
import { policyFor, reportIdentityFor } from "./search-policy.mjs";
|
|
19
19
|
import { drainingState } from "./worker-heartbeat.mjs";
|
|
20
|
+
import { config } from "./driver.config.mjs";
|
|
20
21
|
|
|
21
22
|
// A run in one of these has finished; its step is the one its terminal write set, not the stage it last entered.
|
|
22
23
|
const TERMINAL_STATES = new Set(["delivered", "failed", "cancelled"]);
|
|
@@ -39,6 +40,94 @@ function ladderOf(meta) {
|
|
|
39
40
|
return { bands, toneFor };
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
// ── ONE LIST OF STATES, AND THE PORTAL'S PAUSED STATE AS A PROJECTION OF IT ────────────────────────
|
|
44
|
+
//
|
|
45
|
+
// The engine writes these words into a run's status, and the connector passes them through as written. The portal
|
|
46
|
+
// folds the three waits into one paused state with a kind, and this is the one place that fold is written, so the
|
|
47
|
+
// two faces cannot disagree about which wait a run is in. `queued` is an order no worker has claimed yet.
|
|
48
|
+
export const RUN_STATES = Object.freeze(["running", "delivered", "failed", "postponed", "recovering", "parked-for-human", "cancelled", "queued"]);
|
|
49
|
+
const PAUSED_KINDS = Object.freeze({ postponed: "rate-limit", recovering: "recovering", "parked-for-human": "operator" });
|
|
50
|
+
/** The portal's paused kind for an engine state, or null for a state that is not a wait. */
|
|
51
|
+
export const pausedKindOf = (state) => PAUSED_KINDS[state] ?? null;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* WHAT AN UNCLAIMED ORDER IS DOING, in the words the portal has always shown. "Waiting to start" is true of a job
|
|
55
|
+
* behind other work and of a job nothing will pick up; the second says which. `draining` is read once per walk:
|
|
56
|
+
* a queued job cannot answer it itself, and two rows of one answer must agree about whether a worker exists.
|
|
57
|
+
* `null` means not known, which is every install except a local one whose launcher supervises the worker.
|
|
58
|
+
*/
|
|
59
|
+
export const queuedStep = (draining) => (draining === false ? "Waiting for a worker" : "Waiting to start");
|
|
60
|
+
|
|
61
|
+
// ── THE WALK: WHICH RUNS EXIST, READ ONCE FOR BOTH FACES ───────────────────────────────────────────────
|
|
62
|
+
//
|
|
63
|
+
// The portal's list and the connector's tools both answer "which runs are there, for whom, in what state", and
|
|
64
|
+
// each used to make its own walk of the same folders, with its own rules about which folders count. Two walks
|
|
65
|
+
// gave two answers. This is the only walk: each face projects its own rows from what it read, and keeps only
|
|
66
|
+
// what is its own, its row shape and its access filter.
|
|
67
|
+
//
|
|
68
|
+
// WHAT IT READS, AND NOTHING MORE. `records` reads the pool's delivered records (the portal's delivered rows);
|
|
69
|
+
// `archive` reads the status of runs moved into the archive (the connector's delivered rows); `orders` reads the
|
|
70
|
+
// queue. A face asks only for what it shows, so a connector lookup never pays for the pool or the queue, and a
|
|
71
|
+
// portal poll never walks the archive.
|
|
72
|
+
//
|
|
73
|
+
// records [{ name, meta }] — <pool>/<name>/meta.json
|
|
74
|
+
// runs [{ dir, agent, where, status }] — studio/<slug>/<run> ("live"), archive/<month>/<slug>/<run>
|
|
75
|
+
// queued [{ lane, laneIdx, file, job, mtimeMs }] — every pending `<id>.json` in every queue lane, in admission order
|
|
76
|
+
// retired the run ids the portal's list leaves out (the pool's archive tags)
|
|
77
|
+
// draining whether a worker is draining the queue: true, false, or null for not known
|
|
78
|
+
//
|
|
79
|
+
// A folder whose name starts with `_` or `.` holds no run: history, what-if shadows, a run's own working files.
|
|
80
|
+
export function walkRuns({ poolRoot = null, workspaceRoot = null, queueDirs = [], records = false, archive = false, orders = true } = {}) {
|
|
81
|
+
const walk = { records: [], runs: [], queued: [], retired: poolRoot ? readArchivedSet(poolRoot) : new Set(), draining: orders ? drainingState() : null };
|
|
82
|
+
if (records && poolRoot) {
|
|
83
|
+
let names = []; try { names = readdirSync(poolRoot); } catch { /* no pool yet */ }
|
|
84
|
+
for (const name of names) {
|
|
85
|
+
const metaPath = join(poolRoot, name, "meta.json");
|
|
86
|
+
if (!existsSync(metaPath)) continue;
|
|
87
|
+
try { walk.records.push({ name, meta: readJson(metaPath) }); } catch { /* unreadable meta — skip */ }
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const statusAt = (dir, agent, where) => {
|
|
91
|
+
try { walk.runs.push({ dir, agent, where, status: readJson(join(dir, "status.json")) }); } catch { /* not a run dir */ }
|
|
92
|
+
};
|
|
93
|
+
const subdirs = (dir) => { try { return readdirSync(dir).filter((n) => !n.startsWith("_") && !n.startsWith(".")); } catch { return []; } };
|
|
94
|
+
const lanes = [], laneKeys = new Set();
|
|
95
|
+
const lane = (dir) => { const key = pathResolve(dir); if (!laneKeys.has(key)) { laneKeys.add(key); lanes.push(dir); } };
|
|
96
|
+
// THE CANONICAL INTAKE FIRST: the configured queue is where the enqueue CLI and the connector's `start_run`
|
|
97
|
+
// write, and a headless install may have no workspace at all. The workspace lanes are a union with it, so a
|
|
98
|
+
// deployment whose queue is not configured keeps working: this adds a place to look, never removes one.
|
|
99
|
+
for (const d of Array.isArray(queueDirs) ? queueDirs : []) if (typeof d === "string" && d) lane(d);
|
|
100
|
+
let workspaces = []; try { workspaces = readdirSync(workspaceRoot); } catch { /* no workspace */ }
|
|
101
|
+
for (const ws of workspaces) {
|
|
102
|
+
const agent = config.agentIdFromWorkspaceName(ws);
|
|
103
|
+
if (agent == null) continue;
|
|
104
|
+
const studio = studioDirFor(join(workspaceRoot, ws));
|
|
105
|
+
for (const slug of subdirs(studio)) {
|
|
106
|
+
if (slug === "queue") { lane(join(studio, slug)); continue; }
|
|
107
|
+
if (slug === "archive") {
|
|
108
|
+
if (!archive) continue;
|
|
109
|
+
for (const month of subdirs(join(studio, slug)))
|
|
110
|
+
for (const aSlug of subdirs(join(studio, slug, month)))
|
|
111
|
+
for (const r of subdirs(join(studio, slug, month, aSlug))) statusAt(join(studio, slug, month, aSlug, r), agent, "archive");
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
for (const r of subdirs(join(studio, slug))) statusAt(join(studio, slug, r), agent, "live");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// A PENDING job is `<id>.json` with no suffix; the runner renames it `.done` or `.failed` when it is through, and
|
|
118
|
+
// those are history the pool and the status files already own. The order is the order the runner admits them
|
|
119
|
+
// (queue-order.mjs, the same function the drain sorts with), so a list and the engine can never disagree.
|
|
120
|
+
for (const dir of orders ? lanes : []) {
|
|
121
|
+
let files = []; try { files = readdirSync(dir); } catch { continue; }
|
|
122
|
+
const ordered = orderedQueueFiles(dir, files.filter((f) => f.endsWith(".json") && !f.startsWith(".")));
|
|
123
|
+
for (const [laneIdx, f] of ordered.entries()) {
|
|
124
|
+
try { walk.queued.push({ lane: dir, laneIdx, file: f, job: readJson(join(dir, f)), mtimeMs: statSync(join(dir, f)).mtimeMs }); }
|
|
125
|
+
catch { /* not a job file */ }
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return walk;
|
|
129
|
+
}
|
|
130
|
+
|
|
42
131
|
// ── run listing: delivered (pool metas) + live (workspace status + frozen profile sidecar) ─────────
|
|
43
132
|
//
|
|
44
133
|
// `account` null means EVERY account — the staff "All brand owners" view. Every row carries its own
|
|
@@ -102,13 +191,11 @@ export function scanAccountRuns({ poolRoot, workspaceRoot, account = null, gener
|
|
|
102
191
|
// rewrite exists precisely so those keep resolving — 404ing them here would rot them from a curation
|
|
103
192
|
// command, which is not what "archive" means to the person typing it. Ownership is still enforced at
|
|
104
193
|
// that route, unchanged; retirement is about what the pool ADVERTISES, not about who may read what.
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (!existsSync(metaPath)) continue;
|
|
194
|
+
const walk = walkRuns({ poolRoot, workspaceRoot, queueDirs, records: true });
|
|
195
|
+
const retired = walk.retired;
|
|
196
|
+
{
|
|
197
|
+
for (const { name, meta } of walk.records) {
|
|
110
198
|
try {
|
|
111
|
-
const meta = readJson(metaPath);
|
|
112
199
|
const owner = meta.customerKey || "generic";
|
|
113
200
|
if (!mine(owner, meta.organisation ?? null)) continue;
|
|
114
201
|
// Tagged by runId — the same key pool-admin writes, which is the pool DIRECTORY name. Checking
|
|
@@ -218,13 +305,12 @@ export function scanAccountRuns({ poolRoot, workspaceRoot, account = null, gener
|
|
|
218
305
|
// row, on every surface that has ever consumed this listing; a `retired: false` on all of
|
|
219
306
|
// them would be a new field for every reader to ignore.
|
|
220
307
|
...(isRetired ? { retired: true } : {}) });
|
|
221
|
-
} catch { /*
|
|
308
|
+
} catch { /* a row that cannot be built — skip */ }
|
|
222
309
|
}
|
|
223
|
-
}
|
|
310
|
+
}
|
|
224
311
|
// live runs: status.json + the frozen profile sidecar (freezeProfile writes `profileKey`)
|
|
225
|
-
const readRun = (dir) => {
|
|
312
|
+
const readRun = ({ dir, status: s }) => {
|
|
226
313
|
try {
|
|
227
|
-
const s = readJson(join(dir, "status.json"));
|
|
228
314
|
// A DELIVERED RUN IS SKIPPED BEFORE ITS PROFILE IS READ: the pool row is its face, and every path
|
|
229
315
|
// below returns for it either way, so reading the profile first only cost a file per delivered run.
|
|
230
316
|
if (s.state === "delivered") return; // the pool row is the delivered face
|
|
@@ -268,7 +354,8 @@ export function scanAccountRuns({ poolRoot, workspaceRoot, account = null, gener
|
|
|
268
354
|
// with the run in flight. Mapped HERE, like the other two, so the wire NEVER carries the raw
|
|
269
355
|
// value: the portal contract would coerce an unknown state to "running", which is exactly the
|
|
270
356
|
// zombie face this state exists to end. pausedKind "operator" tells the UI which words to use.
|
|
271
|
-
const
|
|
357
|
+
const pausedKind = pausedKindOf(s.state);
|
|
358
|
+
const paused = pausedKind !== null;
|
|
272
359
|
out.push({ ...(liveRetired ? { retired: true } : {}),
|
|
273
360
|
runId: s.runId, account: owner, ...(owner === "generic" ? { organisation: p.organisation ?? null } : {}), title: s.markName ?? s.slug,
|
|
274
361
|
// THE RUN’S OWN PIPELINE, off the frozen policy sidecar this branch already reads — the same
|
|
@@ -291,7 +378,7 @@ export function scanAccountRuns({ poolRoot, workspaceRoot, account = null, gener
|
|
|
291
378
|
product: sp?.level ?? null, stageLabel: stageLabelOf(sp?.level) ?? sp?.stageLabel ?? null,
|
|
292
379
|
productName: productNameOf(sp?.level),
|
|
293
380
|
state: paused ? "paused" : (s.state ?? "running"),
|
|
294
|
-
pausedKind
|
|
381
|
+
pausedKind,
|
|
295
382
|
// The ONE honest ETA this system possesses. The engine computes it from the provider's own
|
|
296
383
|
// reset header and has always written it; it reached the ops surface and stopped one hop short
|
|
297
384
|
// of the browser. Absent for a recovery park, which backs off on a schedule rather than to a
|
|
@@ -304,6 +391,10 @@ export function scanAccountRuns({ poolRoot, workspaceRoot, account = null, gener
|
|
|
304
391
|
...(TERMINAL_STATES.has(s.state)
|
|
305
392
|
? { step: s.stepLabel ?? null, stepN: s.stepN ?? null, stepTotal: s.stepTotal ?? null }
|
|
306
393
|
: stageNow(s)),
|
|
394
|
+
// EVERY STEP THE RUN WALKS, by name and in order, as the run wrote its own list (progress.mjs
|
|
395
|
+
// displayStepsFor; the Knockout lane's koSteps). Home lists them on a running card; the browser
|
|
396
|
+
// keeps no copy. Null for a run recorded before the field, which keeps today's single step line.
|
|
397
|
+
steps: Array.isArray(s.steps) && s.steps.length && s.steps.every((x) => typeof x === "string") ? s.steps : null,
|
|
307
398
|
// — a requested stop is a state the screen shows. Stamped by stop_run,
|
|
308
399
|
// preserved by writeRunStatus's spread-merge, replaced by the terminal when the honour check
|
|
309
400
|
// fires. The UI derives "Stopping…" from this beside a non-terminal state.
|
|
@@ -384,25 +475,15 @@ export function scanAccountRuns({ poolRoot, workspaceRoot, account = null, gener
|
|
|
384
475
|
// tenants have queued, which is the same thing the 404-never-403 rule exists to prevent. Staff
|
|
385
476
|
// reading across every account see the true lane depth anyway, because for them every row is visible.
|
|
386
477
|
const queuedRows = []; // { row, lane, laneIdx } — positions assigned once the whole scan is in
|
|
387
|
-
//
|
|
388
|
-
//
|
|
389
|
-
//
|
|
390
|
-
//
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
// drains through the systemd path/timer units, which run `main({once:true})` and write no heartbeat — so
|
|
394
|
-
// a service that read a missing heartbeat as "no worker" would put a false alarm on every queued row in
|
|
395
|
-
// production. Only the launcher that actually supervises a worker claims to know, and it is the same
|
|
396
|
-
// launcher that sets the lock dir, so the two can never be set without each other.
|
|
397
|
-
const draining = drainingState();
|
|
398
|
-
const readQueued = (dir) => {
|
|
399
|
-
let files = []; try { files = readdirSync(dir); } catch { return; }
|
|
400
|
-
const ordered = orderedQueueFiles(dir, files.filter((f) => f.endsWith(".json") && !f.startsWith(".")));
|
|
401
|
-
for (const [laneIdx, f] of ordered.entries()) {
|
|
478
|
+
// Whether a worker is draining is read once, by the walk (`walk.draining`), so every row of one answer agrees.
|
|
479
|
+
// `null` means NOT KNOWN, the default everywhere except a local install: a deployed instance drains through the
|
|
480
|
+
// systemd path/timer units, which write no heartbeat, and reading a missing heartbeat as "no worker" would put a
|
|
481
|
+
// false alarm on every queued row in production (queuedStep).
|
|
482
|
+
const readQueued = ({ lane: dir, laneIdx, file: f, job: j, mtimeMs }) => {
|
|
483
|
+
{
|
|
402
484
|
try {
|
|
403
|
-
const j = readJson(join(dir, f));
|
|
404
485
|
const owner = j.profileKey ?? "generic";
|
|
405
|
-
if (!mine(owner, j.tenant ?? null))
|
|
486
|
+
if (!mine(owner, j.tenant ?? null)) return;
|
|
406
487
|
// ALL the names, spelled the way the run's own status.json and its delivered meta.json spell
|
|
407
488
|
// them — this took `marks[0].name` and named ONE mark of N, so a client who had just ordered a
|
|
408
489
|
// three-name knockout screen saw a single name on the row that tells them it went in.
|
|
@@ -431,16 +512,16 @@ export function scanAccountRuns({ poolRoot, workspaceRoot, account = null, gener
|
|
|
431
512
|
// — "Waiting to start" is true of both a job behind other work and a job nothing will
|
|
432
513
|
// ever pick up, and those are not the same thing to whoever just pressed Start. The position
|
|
433
514
|
// still says where it sits in the line; this says whether the line is moving at all.
|
|
434
|
-
state: "queued", step: draining
|
|
515
|
+
state: "queued", step: queuedStep(walk.draining), stepN: null, stepTotal: null,
|
|
435
516
|
reason: null, failedStage: null,
|
|
436
517
|
// Part of the row contract now; a job that has not started has none of them.
|
|
437
518
|
pausedKind: null, resetsAt: null, startedAt: null,
|
|
438
519
|
// A job file has no updatedAt — it has not run. Its MTIME is when it was queued, which is a
|
|
439
520
|
// real fact rather than a fabricated one, sorts a just-queued run to the top where the
|
|
440
521
|
// person who pressed Start will look, and is deterministic under test.
|
|
441
|
-
date: new Date(
|
|
522
|
+
date: new Date(mtimeMs).toISOString().slice(0, 10), overall: null,
|
|
442
523
|
// Queued: its mtime, at full precision, for the same reason the day-level `date` uses it.
|
|
443
|
-
issuedAt: new Date(
|
|
524
|
+
issuedAt: new Date(mtimeMs).toISOString(),
|
|
444
525
|
// The names the job was submitted with — no bands, because nothing has been rated. Same rule as
|
|
445
526
|
// the live row: this array answers "which names", and only the delivered row can answer "at
|
|
446
527
|
// what band".
|
|
@@ -456,37 +537,11 @@ export function scanAccountRuns({ poolRoot, workspaceRoot, account = null, gener
|
|
|
456
537
|
// EVERY QUEUE ONCE. A directory can be reached both ways — `config.queueDirs`
|
|
457
538
|
// lists the workspace queues too — and reading one twice would list every job in it twice and give
|
|
458
539
|
// each row two positions in the line.
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
readQueued(dir);
|
|
465
|
-
};
|
|
466
|
-
// THE CANONICAL INTAKE FIRST, and it is why this parameter exists. `CLEAROTRON_QUEUE_DIR` is where the
|
|
467
|
-
// enqueue CLI and ops-MCP `start_run` write — which is where the PORTAL's own submissions land, since
|
|
468
|
-
// its `trigger` is an ops-MCP hop. The walk below finds only `workspace-*/studio/clearance-search/queue`,
|
|
469
|
-
// and a documented headless install has no workspaces at all: measured on a test deployment, the only queue
|
|
470
|
-
// under the whole tree is the configured one, and it holds portal-prefixed jobs. So this scan ran ZERO
|
|
471
|
-
// times there, and a submitted search was invisible on the dashboard from submit until claim — a
|
|
472
|
-
// minute and a half of a client believing their order was lost.
|
|
473
|
-
for (const d of Array.isArray(queueDirs) ? queueDirs : []) {
|
|
474
|
-
if (typeof d === "string" && d) scanQueue(d);
|
|
475
|
-
}
|
|
476
|
-
try {
|
|
477
|
-
for (const ws of readdirSync(workspaceRoot).filter((n) => n.startsWith("workspace-"))) {
|
|
478
|
-
const studio = studioDirFor(join(workspaceRoot, ws));
|
|
479
|
-
let slugs = []; try { slugs = readdirSync(studio); } catch { continue; }
|
|
480
|
-
for (const slug of slugs) {
|
|
481
|
-
// Still walked, so a deployment whose queue is not in `queueDirs` keeps working. The union is
|
|
482
|
-
// deliberate: this must add a place to look, never remove one.
|
|
483
|
-
if (slug === "queue") { scanQueue(join(studio, slug)); continue; }
|
|
484
|
-
if (slug === "archive" || slug.startsWith("_") || slug.startsWith(".")) continue;
|
|
485
|
-
let runs = []; try { runs = readdirSync(join(studio, slug)); } catch { continue; }
|
|
486
|
-
for (const r of runs) readRun(join(studio, slug, r));
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
} catch { /* no workspace */ }
|
|
540
|
+
// The walk's runs in the order it read them, then the queued orders: the same rows, in the same order, the
|
|
541
|
+
// portal's own walk produced before the connector and the portal shared one.
|
|
542
|
+
for (const run of walk.runs) readRun(run);
|
|
543
|
+
// An order is active work, so it belongs in the ordinary list; the retired index lists retired runs and nothing else.
|
|
544
|
+
if (!includeRetired) for (const q of walk.queued) readQueued(q);
|
|
490
545
|
// Assign the ordinals last, across every lane at once. Cross-lane order is genuinely undefined —
|
|
491
546
|
// the lanes are per-agent and drain concurrently against one shared pair of slots — so lanes are
|
|
492
547
|
// ordered by path purely to make the result STABLE. An ordinal that reshuffled between two polls
|
|
@@ -146,6 +146,7 @@ import { makeUpstream } from "./portal-upstream.mjs";
|
|
|
146
146
|
import { flagView } from "./portal-config-view.mjs";
|
|
147
147
|
import { livePosture } from "./flag-snapshot.mjs"; // — for the capture-vs-box comparison only, never for a value
|
|
148
148
|
import { DEFAULT_CLIENT_DAILY_RUNS, accountUsage } from "./usage-ledger.mjs";
|
|
149
|
+
import { urgentRunsHere } from "./urgent-count.mjs";
|
|
149
150
|
import { SOURCE_REPO } from "../shared/product-identity.mjs"; // AGPL §13 — one answer, three surfaces
|
|
150
151
|
import { engineCommit } from "./engine-build.mjs"; // — the SAME stamp pool meta records
|
|
151
152
|
// — siblings, on their own line: the guard pins the line above and its subject is the JOIN
|
|
@@ -292,6 +293,9 @@ export const PORTAL_JOB_FIELDS = Object.freeze({
|
|
|
292
293
|
"tenant",
|
|
293
294
|
"jurisdictions", "platforms", "geography",
|
|
294
295
|
"product", "recipeKey", "nativeLanguage", "caseLaw", "searchLevel", "deliveryRoute",
|
|
296
|
+
// An Urgent order, carried only as `true`: New clearance offers it with its count of searches, and
|
|
297
|
+
// admission counts it (urgent-count.mjs).
|
|
298
|
+
"urgent",
|
|
295
299
|
"upfrontInstructions", "commercialFlexibility", "priorUse", "campaignShape", "deadline",
|
|
296
300
|
// stamped by the ROUTE rather than copied by jobFor, and on the stored job all the same:
|
|
297
301
|
// `clientPrincipal` from the verified principal's role. It can only ever ADD a cap to the run that
|
|
@@ -656,6 +660,9 @@ export function makePortalService({
|
|
|
656
660
|
// injected for the reason `demo` is: the bootstrap below is the only place that reads the environment for it,
|
|
657
661
|
// and a fixture can drive both answers. The default refuses nothing, which is every fixture that does not ask.
|
|
658
662
|
orderRefusal = async () => null,
|
|
663
|
+
// — CAN AN URGENT ORDER RUN FAST HERE? The answer the run records when it starts (urgent-count.mjs `urgentRunsHere`),
|
|
664
|
+
// injected for the reason `orderRefusal` is. The default is no, so a fixture that does not ask offers Standard only.
|
|
665
|
+
urgentAvailable = () => false,
|
|
659
666
|
audit = () => {},
|
|
660
667
|
// The audit log's PATH, for the one surface that reads it back rather than writing to it
|
|
661
668
|
// (/portal/admin/observed). Separate from `audit` above because that is a sink and this is a source,
|
|
@@ -856,6 +863,9 @@ export function makePortalService({
|
|
|
856
863
|
// Whether the Describe-it half of the composer can actually read. Rides the capability payload
|
|
857
864
|
// the composer already fetches rather than getting its own probe: one round trip decides what the
|
|
858
865
|
// whole screen offers, and a second one would be a second thing to go stale.
|
|
866
|
+
// Whether an Urgent order runs on the faster setting here. New clearance offers Urgent only where it does,
|
|
867
|
+
// and says why not where it does not.
|
|
868
|
+
urgent: { available: urgentAvailable() === true },
|
|
859
869
|
read: {
|
|
860
870
|
available: Boolean(composeRead),
|
|
861
871
|
maxBrief: MAX_BRIEF,
|
|
@@ -929,6 +939,9 @@ export function makePortalService({
|
|
|
929
939
|
// carries verbatim for exactly that reason. A hand-rolled POST sending `false` believed it had
|
|
930
940
|
// switched the investigation off; validateJob now refuses it, in products.mjs's own words.
|
|
931
941
|
...("nativeLanguage" in body && body.nativeLanguage != null ? { nativeLanguage: body.nativeLanguage } : {}),
|
|
942
|
+
// AN URGENT ORDER travels only as `true`, the run's own reading of the field. It is in the review's job hash,
|
|
943
|
+
// so a review confirmed at Standard cannot start an Urgent order (portal-confirmation.mjs).
|
|
944
|
+
...(body.urgent === true ? { urgent: true } : {}),
|
|
932
945
|
// `deliveryRoute` IS CARRIED, and its absence here was THE defect of this round.
|
|
933
946
|
//
|
|
934
947
|
// It is a DECLARED job field with a refusal sentence of its own (enqueue-schema PORTAL_ROUTE_-
|
|
@@ -1013,7 +1026,7 @@ export function makePortalService({
|
|
|
1013
1026
|
// own constants a group prints or answers with, and what the request carries (`request`). A group answers a request it serves and returns undefined for any other, and the dispatcher asks the
|
|
1014
1027
|
// groups in the order its routes have always been matched, so a request is answered by the route that answered it before.
|
|
1015
1028
|
const svc = { poolRoot, workspaceRoot, secret, grants, localSignIn, writeGrants, revokeConnectorKeys, queueDirs, trigger,
|
|
1016
|
-
stopRun, stopControl, demo, orderRefusal, audit, auditPath, auditLog, feedbackCapture, readBuilt, readCanCount,
|
|
1029
|
+
stopRun, stopControl, demo, orderRefusal, urgentAvailable, audit, auditPath, auditLog, feedbackCapture, readBuilt, readCanCount,
|
|
1017
1030
|
readTerritories, upstream, composeRead, readBudget, loadProfilesImpl, usedJtis, sweepJtis, searchesFor, jobFor, selectorOf,
|
|
1018
1031
|
engineProgramDisputed, connectCaches, INSTALL_ROOT, INSTALL_CHANNEL, READ_OFF_NOTE, refusalFor, allowanceExhaustedLine };
|
|
1019
1032
|
|
|
@@ -2859,7 +2872,9 @@ const PORT = PORT_CHOICE.port;
|
|
|
2859
2872
|
// demo out of one. Anything but the literal "1" is not a demo.
|
|
2860
2873
|
demo: isDemo(process.env), // — one name, shared with the MCP door
|
|
2861
2874
|
// The runner's own order-time test, asked of the runner's own tables: the portal refuses what the runner would.
|
|
2862
|
-
orderRefusal: async () => portalOrderRefusal({ tables: await runTables() })
|
|
2875
|
+
orderRefusal: async () => portalOrderRefusal({ tables: await runTables() }),
|
|
2876
|
+
// Whether an Urgent order runs fast here: the same answer the runner counts by and the run records.
|
|
2877
|
+
urgentAvailable: urgentRunsHere });
|
|
2863
2878
|
const { RateLimiter } = await import("../mcp-server/lib/ratelimit.mjs");
|
|
2864
2879
|
const limiter = new RateLimiter({ perMinute: Number(process.env.PORTAL_RATE_PER_MIN || 120) });
|
|
2865
2880
|
const { createServer } = await import("node:http");
|
|
@@ -215,12 +215,12 @@ export function templateChecks({ headerName, ratedNames, searchedNames }) {
|
|
|
215
215
|
|
|
216
216
|
// THE LINES THE DELIVERED PAGE DRAWS FROM THE RECORD, OUTSIDE report.md, THAT CAN NAME A PARTY. The page (render.mjs)
|
|
217
217
|
// draws the coverage rows that are not clean under "What was searched", less a driver-composed follow-up row that another
|
|
218
|
-
// row already restates, and
|
|
218
|
+
// row already restates, and every web and marketplace name under "Also considered" (search-depth.mjs's clearedNames
|
|
219
|
+
// decides which blocks are names, so the page and this read one list). A party
|
|
219
220
|
// named only in a row the page hides is not shown to the reader, so the page's rules are applied here exactly. They are
|
|
220
221
|
// copied rather than imported: importing the page renderer would hand every tool server that loads this lint the
|
|
221
222
|
// branding settings the renderer reads. The test a-party-the-page-shows-is-introduced-to-the-reader renders a page and
|
|
222
223
|
// holds this copy to it, the hidden follow-up row included.
|
|
223
|
-
export const PAGE_WEB_NAMES_SHOWN = 8;
|
|
224
224
|
const PAGE_FOLLOW_UP_PREFIX = "Follow-up / ";
|
|
225
225
|
const PAGE_AXIS_LABELLED = /\s\/\s/;
|
|
226
226
|
const PAGE_COV_STOPWORDS = new Set(["the", "a", "an", "as", "for", "of", "in", "on", "and", "or", "to", "is",
|
|
@@ -249,7 +249,7 @@ function pageDrawnCoverage(coverage, followUpKinds = null) {
|
|
|
249
249
|
export function pageNameLines({ coverage = [], webNames = [], followUpKinds = null } = {}) {
|
|
250
250
|
return [
|
|
251
251
|
...pageDrawnCoverage(coverage, followUpKinds).map((c) => `${c.area ?? ""} ${c.note ?? ""}`),
|
|
252
|
-
...(Array.isArray(webNames) ? webNames : []).
|
|
252
|
+
...(Array.isArray(webNames) ? webNames : []).map((w) => String(w?.title ?? "")),
|
|
253
253
|
];
|
|
254
254
|
}
|
|
255
255
|
/** The parties a step names, read as the check below reads the step's line on the page: its text and condition. PURE. */
|
package/driver/progress.mjs
CHANGED
|
@@ -20,6 +20,7 @@ import { isStopReason, stopReason } from "../shared/stop-reason.mjs"; // a sto
|
|
|
20
20
|
import { DRIVER_DIR, atomicWrite, readJson } from "./run-record.mjs";
|
|
21
21
|
import { config } from "./driver.config.mjs";
|
|
22
22
|
import { batchMarkName } from "./mark-name.mjs";
|
|
23
|
+
import { productSpec } from "./products.mjs"; // which products read case law, which names the sixth step
|
|
23
24
|
import { runLog, note } from "./log.mjs";
|
|
24
25
|
// — the seed's pid stamp. claim-liveness.mjs is the real home of the /proc reader (runner.mjs
|
|
25
26
|
// imports and re-exports it rather than owning it), so this takes it from the source and adds no
|
|
@@ -42,6 +43,28 @@ export const DISPLAY_STEPS = [
|
|
|
42
43
|
"Sending to you", // 9 notify, notify-chat → .delivered
|
|
43
44
|
];
|
|
44
45
|
|
|
46
|
+
// THE SIXTH STEP OF A SEARCH THAT DOES NOT READ CASE LAW. Global preliminary and Multi-country focus run
|
|
47
|
+
// the same stages, and their sixth step is the review of the conclusions: they do not search case law
|
|
48
|
+
// (`caseLaw: false` in products.mjs). Named "Case law & refutation" there, a list that ticks it tells the
|
|
49
|
+
// reader case law was covered. Approved wording, 2026-11-25.
|
|
50
|
+
export const CONCLUSIONS_STEP = "Checking the conclusions";
|
|
51
|
+
const CASE_LAW_STEP_INDEX = 5;
|
|
52
|
+
const CONCLUSIONS_STEPS = Object.freeze(DISPLAY_STEPS.map((s, i) => (i === CASE_LAW_STEP_INDEX ? CONCLUSIONS_STEP : s)));
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The display steps of a clearance of this product, in order: the ONE home of every name a person reads
|
|
56
|
+
* for a clearance's progress. A product that does not read case law names its sixth step
|
|
57
|
+
* CONCLUSIONS_STEP; every other product, and one this build cannot place, keeps DISPLAY_STEPS. PURE.
|
|
58
|
+
*/
|
|
59
|
+
export function displayStepsFor(product) {
|
|
60
|
+
return productSpec(product)?.caseLaw === false ? CONCLUSIONS_STEPS : DISPLAY_STEPS;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The display steps a clearance run walks, from its frozen search policy. */
|
|
64
|
+
function runDisplaySteps(ctx) {
|
|
65
|
+
return displayStepsFor(ctx?.searchPolicy?.product ?? ctx?.searchPolicy?.level ?? null);
|
|
66
|
+
}
|
|
67
|
+
|
|
45
68
|
// Real STAGES key (no axis suffix) → 0-based DISPLAY_STEPS index.
|
|
46
69
|
//
|
|
47
70
|
// — this map, STAGE_NO_STEP and NON_STAGE_STEPS below are a CLOSED PARTITION of Object.keys(STAGES),
|
|
@@ -91,12 +114,13 @@ export const NON_STAGE_STEPS = {
|
|
|
91
114
|
};
|
|
92
115
|
|
|
93
116
|
// rawStageKey may carry an axis suffix ("register-unit:primary-sweep") — strip it. Returns null for an
|
|
94
|
-
// unknown key so callers can no-op (an unmapped stage must never touch the displayed step).
|
|
95
|
-
|
|
117
|
+
// unknown key so callers can no-op (an unmapped stage must never touch the displayed step). `steps` is
|
|
118
|
+
// the run's own list (displayStepsFor); the index is the same in every list, only a name differs.
|
|
119
|
+
export function stepForStage(rawStageKey, steps = DISPLAY_STEPS) {
|
|
96
120
|
const key = String(rawStageKey ?? "").split(":")[0];
|
|
97
121
|
const index = STAGE_TO_STEP[key];
|
|
98
122
|
if (index == null) return null;
|
|
99
|
-
return { index, label:
|
|
123
|
+
return { index, label: steps[index], n: index + 1, total: steps.length };
|
|
100
124
|
}
|
|
101
125
|
|
|
102
126
|
/**
|
|
@@ -397,7 +421,8 @@ export function resumeRecord(runDir, resume) {
|
|
|
397
421
|
|
|
398
422
|
export function seedRunStatus(ctx, { resume = false } = {}) {
|
|
399
423
|
const { job, run, agent } = ctx;
|
|
400
|
-
const
|
|
424
|
+
const steps = runDisplaySteps(ctx);
|
|
425
|
+
const first = stepForStage("matter-frame", steps);
|
|
401
426
|
const pass = resumeRecord(run.runDir, resume);
|
|
402
427
|
writeRunStatus(ctx, {
|
|
403
428
|
schema: 1,
|
|
@@ -426,6 +451,9 @@ export function seedRunStatus(ctx, { resume = false } = {}) {
|
|
|
426
451
|
...identitySeed(),
|
|
427
452
|
stepIndex: first.index, stepLabel: first.label, stepN: first.n, stepTotal: first.total,
|
|
428
453
|
currentStep: currentStepOf(first),
|
|
454
|
+
// EVERY STEP THIS RUN WALKS, by name and in order, so a surface that lists them reads the run's own
|
|
455
|
+
// list rather than keeping a copy. The Knockout lane writes its own list the same way.
|
|
456
|
+
steps: [...steps],
|
|
429
457
|
lastStage: null,
|
|
430
458
|
review: null,
|
|
431
459
|
url: null,
|
|
@@ -452,7 +480,7 @@ export function seedRunStatus(ctx, { resume = false } = {}) {
|
|
|
452
480
|
// raw key; this is the same moment in the stepper's own words, for a surface that shows where the run is.
|
|
453
481
|
// A stage with no display step leaves it where it was: those stages run inside the step already shown.
|
|
454
482
|
export function recordTransition(ctx, rawStageKey) {
|
|
455
|
-
const step = stepForStage(rawStageKey);
|
|
483
|
+
const step = stepForStage(rawStageKey, runDisplaySteps(ctx));
|
|
456
484
|
writeRunStatus(ctx, {
|
|
457
485
|
...(step ? { stepIndex: step.index, stepLabel: step.label, stepN: step.n, stepTotal: step.total, currentStep: currentStepOf(step) } : {}),
|
|
458
486
|
lastStage: rawStageKey,
|