clearotron 0.5.1 → 0.6.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/.env.example +7 -7
- package/INSTALL.md +10 -10
- package/QUICKSTART.md +6 -6
- package/README.md +2 -2
- package/THIRD-PARTY-NOTICES.md +4 -4
- package/bin/README.md +2 -2
- package/bin/clearotron.mjs +1 -1
- package/bin/connect.mjs +1 -1
- package/bin/disconnect.mjs +1 -1
- package/bin/example.mjs +2 -2
- package/bin/grant.mjs +1 -1
- package/bin/onboard.mjs +78 -23
- package/bin/start.mjs +49 -18
- package/bin/update.mjs +13 -3
- package/build-info.json +2 -2
- package/docs/DELIVERY.md +1 -1
- package/docs/PORTAL.md +1 -1
- package/docs/RELEASES.md +1 -1
- package/docs/architecture/02-architecture.md +10 -2
- package/docs/architecture/03-run-lifecycle.md +6 -2
- package/docs/architecture/04-configuration-reference.md +3 -3
- package/docs/architecture/05-config-governance.md +5 -4
- package/docs/architecture/08-development-guide.md +4 -4
- package/docs/architecture/09-security-and-data.md +1 -1
- package/{driver/skills/clearance-search/SKILL.md → docs/architecture/retired-manuals/clearance-search-spine.md} +17 -30
- package/{driver/skills/clearance-search/templates/email/generic.md → docs/architecture/retired-manuals/email-generic.md} +1 -1
- package/{driver/skills/clearance-search → docs/architecture/retired-manuals}/template-formatting.md +3 -4
- package/docs/configuration.md +1 -1
- package/docs/decisions/0002-no-dark-functionality.md +5 -0
- package/driver/CHANGELOG.md +60 -0
- package/driver/README.md +11 -1
- package/driver/accepted-order.mjs +13 -5
- package/driver/attempt-rows.mjs +64 -0
- package/driver/attributed-span.mjs +1 -1
- package/driver/authority-trees.mjs +1 -1
- package/driver/best-draft.mjs +3 -3
- package/driver/blind-frame-record.mjs +2 -2
- package/driver/cancel.mjs +3 -2
- package/driver/carry-through.mjs +2 -2
- package/driver/citation-census.json +3 -3
- package/driver/clearance-variants-record.mjs +4 -10
- package/driver/common-law-coverage-status.mjs +3 -3
- package/driver/common-law-receipts.mjs +2 -2
- package/driver/compare.mjs +1 -1
- package/driver/config-inventory.mjs +6 -79
- package/driver/consumption-ledger.mjs +2 -1
- package/driver/contract-dictation-registry.mjs +5 -0
- package/driver/contract-e3-backlog.mjs +45 -66
- package/driver/contract-e3-baseline.json +16 -16
- package/driver/contract-vocabulary.mjs +8 -6
- package/driver/corrections-feedforward.mjs +3 -1
- package/driver/coverage-form-io.mjs +7 -8
- package/driver/coverage-tool.mjs +1 -1
- package/driver/declination-tool.mjs +2 -2
- package/driver/degraded-parts.mjs +9 -9
- package/driver/demo-container.mjs +5 -4
- package/driver/deploy-live-run-guard.mjs +19 -7
- package/driver/derived-state.mjs +2 -2
- package/driver/dev-portal.mjs +2 -1
- package/driver/dispatch-record.mjs +1 -1
- package/driver/disposition-tool.mjs +2 -1
- package/driver/doubt-closure-tool.mjs +2 -2
- package/driver/driver.config.mjs +35 -724
- package/driver/e2e-rounds.mjs +3 -4
- package/driver/engine/CONTRACT.md +3 -0
- package/driver/engine/README.md +2 -0
- package/driver/engine/anthropic-agent.mjs +8 -37
- package/driver/engine/auth.mjs +74 -0
- package/driver/engine/child-record.mjs +1 -1
- package/driver/engine/deny-authority-write.mjs +2 -2
- package/driver/engine/jx-turn.mjs +10 -2
- package/driver/engine/mcp/README.md +1 -1
- package/driver/engine/mcp/band-server.mjs +6 -6
- package/driver/engine/mcp/codex-config.mjs +1 -1
- package/driver/engine/mcp/declination-server.mjs +2 -3
- package/driver/engine/mcp/dispositions-server.mjs +3 -3
- package/driver/engine/mcp/gather-config.mjs +24 -19
- package/driver/engine/mcp/grid-provenance.mjs +1 -1
- package/driver/engine/mcp/held-answers.mjs +5 -5
- package/driver/engine/mcp/perplexity-server.mjs +16 -7
- package/driver/engine/mcp/recording-server.mjs +7 -6
- package/driver/engine/mcp/register-server.mjs +29 -0
- package/driver/engine/mcp/stdio-server.mjs +5 -5
- package/driver/engine/mcp/supplemental.mjs +9 -9
- package/driver/engine/openai-agent.mjs +5 -2
- package/driver/engine/registry.mjs +103 -0
- package/driver/engine/run-choices.mjs +162 -0
- package/driver/engine/stamps.mjs +35 -0
- package/driver/enqueue-schema.mjs +4 -4
- package/driver/envelope-settle.mjs +3 -2
- package/driver/feedback-issues.mjs +1 -1
- package/driver/feedback-mint.mjs +3 -2
- package/driver/feedback-store.mjs +3 -2
- package/driver/findings-model.mjs +1 -1
- package/driver/flag-snapshot.mjs +5 -4
- package/driver/floor-duty.mjs +3 -3
- package/driver/foreign-record-links.mjs +1 -1
- package/driver/frame-diff-record.mjs +2 -8
- package/driver/framework.mjs +1 -1
- package/driver/gate-metrics.mjs +10 -11
- package/driver/gateway.mjs +220 -839
- package/driver/goods-evidence.mjs +10 -6
- package/driver/jx-lanes.mjs +3 -3
- package/driver/jx-units.mjs +31 -37
- package/driver/jx.mjs +44 -59
- package/driver/knockout-assess-record.mjs +3 -3
- package/driver/knockout-caveats.mjs +21 -0
- package/driver/knockout-correction-record.mjs +58 -28
- package/driver/knockout-frame-record.mjs +2 -2
- package/driver/knockout-register-read.mjs +38 -21
- package/driver/knockout-register-record.mjs +5 -6
- package/driver/knockout-review-record.mjs +12 -11
- package/driver/ladder/model-gauge.mjs +88 -0
- package/driver/ladder/next-rung.mjs +296 -0
- package/driver/ladder/rescue.mjs +146 -0
- package/driver/ladder/stage-tools.mjs +57 -0
- package/driver/ladder/turn-failure.mjs +166 -0
- package/driver/log.mjs +2 -2
- package/driver/matter-frame-record.mjs +4 -4
- package/driver/methodology-witness.mjs +2 -2
- package/driver/narrative-refutation-record.mjs +145 -42
- package/driver/one-build-per-run.mjs +62 -0
- package/driver/outbox-backoff.mjs +4 -4
- package/driver/owner-screen.mjs +0 -10
- package/driver/owner-use-check.mjs +2 -28
- package/driver/package.json +1 -1
- package/driver/partial-payload-baseline.json +1 -1
- package/driver/parts-not-completed.mjs +1 -1
- package/driver/pipeline-knockout.mjs +1015 -1001
- package/driver/pipeline.mjs +511 -9265
- package/driver/placement-decisions.mjs +2 -2
- package/driver/placement-form-io.mjs +7 -9
- package/driver/placement-union.mjs +0 -6
- package/driver/plan-stability.mjs +7 -10
- package/driver/portal-acks.mjs +3 -2
- package/driver/portal-confirmation.mjs +48 -0
- package/driver/portal-families.mjs +3 -2
- package/driver/portal-local-auth.mjs +1 -2
- package/driver/portal-routes/README.md +24 -0
- package/driver/portal-routes/admin.mjs +425 -0
- package/driver/portal-routes/compose.mjs +66 -0
- package/driver/portal-routes/config.mjs +118 -0
- package/driver/portal-routes/connect.mjs +283 -0
- package/driver/portal-routes/feedback.mjs +178 -0
- package/driver/portal-routes/me.mjs +165 -0
- package/driver/portal-routes/queue.mjs +64 -0
- package/driver/portal-routes/report.mjs +106 -0
- package/driver/portal-routes/run.mjs +508 -0
- package/driver/portal-routes/runs.mjs +127 -0
- package/driver/portal-routes/usage.mjs +82 -0
- package/driver/portal-runs.mjs +588 -0
- package/driver/portal-service.mjs +78 -2592
- package/driver/portal-static.mjs +3 -1
- package/driver/predelivery-lint.mjs +92 -9
- package/driver/production-pool-guard.mjs +1 -1
- package/driver/profiles.mjs +5 -4
- package/driver/progress.mjs +29 -24
- package/driver/publish/README.md +10 -5
- package/driver/publish/archive-tags.mjs +3 -2
- package/driver/publish/demo-marking.mjs +2 -2
- package/driver/publish/index.mjs +215 -140
- package/driver/publish/knockout.mjs +153 -107
- package/driver/publish/office-record-links.mjs +22 -0
- package/driver/publish/parse.mjs +20 -5
- package/driver/publish/pool-admin.mjs +9 -3
- package/driver/publish/render.mjs +11 -3
- package/driver/publish/report-dates.mjs +3 -4
- package/driver/publish/report-registry.mjs +7 -10
- package/driver/publish/seed-pool.mjs +3 -2
- package/driver/publish/shell.mjs +106 -0
- package/driver/publish/templates/report.css +3 -1
- package/driver/queue-order.mjs +4 -3
- package/driver/record-carry.mjs +0 -9
- package/driver/record-discard.mjs +1 -4
- package/driver/record-fold.mjs +3 -3
- package/driver/record-goods.mjs +5 -5
- package/driver/reference-score.mjs +2 -3
- package/driver/register-capabilities.mjs +0 -6
- package/driver/register-count.mjs +3 -2
- package/driver/register-digest-record.mjs +7 -7
- package/driver/register-fixture-marker.mjs +3 -3
- package/driver/register-plan.mjs +2 -2
- package/driver/register-records.mjs +2 -2
- package/driver/register-taint.mjs +3 -3
- package/driver/register-unit-record.mjs +48 -9
- package/driver/register-unreachable.mjs +4 -3
- package/driver/registry-fidelity.mjs +79 -34
- package/driver/repair-composers.mjs +14 -9
- package/driver/repair-digest.mjs +4 -6
- package/driver/repair-scope.mjs +3 -3
- package/driver/repair-targets.mjs +24 -9
- package/driver/repairs.mjs +44 -58
- package/driver/replay-archive.mjs +7 -7
- package/driver/report-card-record.mjs +3 -3
- package/driver/report-overview-record.mjs +4 -4
- package/driver/research-answers.mjs +38 -6
- package/driver/research-checks.mjs +4 -4
- package/driver/result-noun-fields.mjs +28 -11
- package/driver/review-addresses.mjs +163 -0
- package/driver/rule-shape.mjs +1 -1
- package/driver/run-delivered.mjs +340 -0
- package/driver/run-economics.mjs +8 -26
- package/driver/run-failed.mjs +545 -0
- package/driver/run-integrity.mjs +1 -1
- package/driver/run-outcome.mjs +314 -0
- package/driver/run-park.mjs +23 -0
- package/driver/run-quote.mjs +32 -0
- package/driver/run-record.mjs +352 -0
- package/driver/run-requirements.mjs +22 -0
- package/driver/run-shell.mjs +55 -0
- package/driver/runner.mjs +71 -33
- package/driver/saved-register-pages.mjs +4 -4
- package/driver/score-redaction.mjs +2 -2
- package/driver/search-policy.mjs +12 -13
- package/driver/settle-stamp.mjs +4 -3
- package/driver/skeptic-record.mjs +2 -2
- package/driver/skeptic-search.mjs +1 -1
- package/driver/skills/README.md +7 -7
- package/driver/skills/blind-frame/SKILL.md +1 -2
- package/driver/skills/case-law-citation/SKILL.md +9 -37
- package/driver/skills/case-law-citation/sources/courtlistener.md +1 -3
- package/driver/skills/case-law-citation/sources/eurlex.md +8 -11
- package/driver/skills/case-law-citation/sources/legaldatahunter.md +1 -1
- package/driver/skills/clearance-common-law/SKILL.md +45 -111
- package/driver/skills/clearance-common-law/perplexity-prompts.md +7 -79
- package/driver/skills/clearance-register/SKILL.md +15 -33
- package/driver/skills/clearance-register/digest.md +31 -92
- package/driver/skills/clearance-register/providers/clarivate.md +2 -2
- package/driver/skills/clearance-register/providers/corsearch.md +5 -5
- package/driver/skills/clearance-register/providers/euipo.md +1 -2
- package/driver/skills/clearance-register/providers/free-tier.md +0 -19
- package/driver/skills/clearance-register/providers/signa.md +6 -25
- package/driver/skills/clearance-register/providers/uspto-local.md +0 -24
- package/driver/skills/clearance-register/register-recipes.md +8 -15
- package/driver/skills/clearance-register/status-rules.md +6 -24
- package/driver/skills/clearance-register/unit.md +11 -20
- package/driver/skills/clearance-search/delivery-contract.md +24 -120
- package/driver/skills/clearance-search/field-doctrine-pharma.md +1 -5
- package/driver/skills/clearance-search/firm-wide-reasoning.md +24 -43
- package/driver/skills/clearance-search/phase2-execution.md +29 -77
- package/driver/skills/clearance-search/report-prose.md +3 -4
- package/driver/skills/clearance-search/risk-framework-demo.md +1 -1
- package/driver/skills/clearance-search/risk-framework-triage.manifest.json +3 -3
- package/driver/skills/clearance-search/risk-framework-triage.md +7 -9
- package/driver/skills/clearance-search/risk-framework.manifest.json +1 -1
- package/driver/skills/clearance-search/risk-framework.md +1 -1
- package/driver/skills/clearance-search/synthesis-rules.md +30 -107
- package/driver/skills/clearance-search/worked-examples.md +5 -5
- package/driver/skills/clearance-variants/SKILL.md +46 -45
- package/driver/skills/clearance-variants/transliteration-scripts.md +4 -4
- package/driver/skills/frame-diff/SKILL.md +1 -1
- package/driver/skills/knockout-assess/SKILL.md +6 -14
- package/driver/skills/knockout-frame/SKILL.md +1 -1
- package/driver/skills/matter-frame/SKILL.md +7 -12
- package/driver/skills/matter-frame/watchlist-reference.md +1 -4
- package/driver/skills/narrative-refutation/SKILL.md +20 -30
- package/driver/skills/placement-inquiry/SKILL.md +8 -18
- package/driver/skills-store-provenance.mjs +1 -1
- package/driver/stage-context.mjs +32 -35
- package/driver/stage-freshness.mjs +127 -11
- package/driver/stages-knockout.mjs +49 -22
- package/driver/stages.mjs +88 -283
- package/driver/status-snapshot.mjs +2 -1
- package/driver/steps/correction-cycle.mjs +311 -0
- package/driver/steps/corrections.mjs +644 -0
- package/driver/steps/delivery.mjs +1287 -0
- package/driver/steps/frame-comparison.mjs +922 -0
- package/driver/steps/intake.mjs +84 -0
- package/driver/steps/open-run.mjs +419 -0
- package/driver/steps/overview-and-cards.mjs +899 -0
- package/driver/steps/placement-and-digest.mjs +23 -0
- package/driver/steps/register-sweep.mjs +1563 -0
- package/driver/steps/skeptic-and-follow-up.mjs +831 -0
- package/driver/steps/synthesis.mjs +261 -0
- package/driver/steps/verdict-gate.mjs +968 -0
- package/driver/suite-census.json +403 -91
- package/driver/surface-exit-verdict.mjs +0 -8
- package/driver/synthesis-record.mjs +72 -6
- package/driver/terminal-clamp.mjs +10 -0
- package/driver/tokens.mjs +8 -62
- package/driver/tool-calls.mjs +2 -2
- package/driver/unit-state-verdict.mjs +1 -1
- package/driver/usage-ledger.mjs +2 -1
- package/driver/verify-knockout.mjs +20 -35
- package/driver/verify.mjs +47 -36
- package/driver/web-grid.mjs +3 -4
- package/driver/whatif-memo-run.mjs +2 -2
- package/driver/whatif-queue.mjs +4 -3
- package/driver/withheld-families.mjs +14 -15
- package/driver/worker-heartbeat.mjs +3 -2
- package/driver/write-up-form.mjs +0 -3
- package/mcp-server/CHANGELOG.md +4 -0
- package/mcp-server/http-server.mjs +1 -1
- package/mcp-server/lib/brief.mjs +22 -4
- package/mcp-server/lib/events.mjs +2 -2
- package/mcp-server/lib/evidence.mjs +3 -2
- package/mcp-server/lib/findings.mjs +2 -1
- package/mcp-server/lib/knockout.mjs +9 -10
- package/mcp-server/lib/ops.mjs +9 -9
- package/mcp-server/lib/runs.mjs +9 -10
- package/mcp-server/lib/trace.mjs +1 -1
- package/mcp-server/lib/whatif.mjs +2 -3
- package/mcp-server/package.json +1 -1
- package/mcp-server/server.mjs +5 -5
- package/package.json +2 -1
- package/portal-ui/dist/assets/{index-fPqAU0sx.js → index-D5rkCjDc.js} +26 -14
- package/portal-ui/dist/index.html +1 -1
- package/portal-ui/package.json +3 -3
- package/providers/README.md +1 -1
- package/providers/_shared/answer-memory.mjs +4 -5
- package/providers/_shared/execute-plan.mjs +48 -1
- package/providers/_shared/records-from-search.mjs +46 -0
- package/providers/clarivate/README.md +2 -2
- package/providers/clarivate/src/adapter.js +147 -0
- package/providers/clarivate/src/core.js +1 -14
- package/{driver/engine/mcp/clarivate-server.mjs → providers/clarivate/src/mount.js} +5 -10
- package/providers/corsearch/README.md +3 -3
- package/providers/corsearch/src/adapter.js +80 -0
- package/providers/corsearch/src/core.js +14 -11
- package/{driver/engine/mcp/corsearch-server.mjs → providers/corsearch/src/mount.js} +5 -10
- package/providers/euipo/README.md +2 -2
- package/providers/euipo/src/adapter.js +85 -0
- package/providers/euipo/src/core.js +1 -1
- package/providers/euipo/src/euipo-client.js +1 -2
- package/{driver/engine/mcp/euipo-server.mjs → providers/euipo/src/mount.js} +5 -10
- package/providers/free-tier/README.md +2 -2
- package/providers/free-tier/src/adapter.js +127 -0
- package/{driver/engine/mcp/free-tier-server.mjs → providers/free-tier/src/mount.js} +5 -10
- package/providers/jx-subclass/coverage.mjs +1 -6
- package/providers/jx-subclass/score-truth.mjs +2 -1
- package/providers/oauth-mcp-bridge/CHANGELOG.md +4 -0
- package/providers/oauth-mcp-bridge/package.json +1 -1
- package/providers/perplexity/src/core.js +2 -2
- package/providers/signa/README.md +2 -2
- package/providers/signa/src/adapter.js +157 -0
- package/providers/signa/src/capabilities.js +0 -3
- package/providers/signa/src/core.js +2 -2
- package/{driver/engine/mcp/signa-server.mjs → providers/signa/src/mount.js} +7 -12
- package/providers/signa/src/offices.generated.js +17 -15
- package/providers/uspto-local/README.md +1 -1
- package/providers/uspto-local/bin/verify-index.mjs +1 -1
- package/providers/uspto-local/src/adapter.js +75 -0
- package/{driver/engine/mcp/uspto-local-server.mjs → providers/uspto-local/src/mount.js} +5 -10
- package/scripts/band-shape-probe.mjs +2 -2
- package/scripts/citation-line-check.mjs +7 -7
- package/scripts/compare.mjs +1 -1
- package/scripts/dead-names.mjs +2 -2
- package/scripts/e2e-first-time.mjs +19 -7
- package/scripts/e2e.mjs +13 -13
- package/scripts/engine-probe.mjs +1 -1
- package/scripts/env-audit.mjs +7 -4
- package/scripts/env-classify.mjs +5 -1
- package/scripts/feedback-mint.mjs +1 -1
- package/scripts/freeze-example-run.mjs +7 -7
- package/scripts/mint-suite-census.mjs +2 -2
- package/scripts/nightly-notice.mjs +1 -1
- package/scripts/release-cut-decision.mjs +7 -2
- package/scripts/release-note-required.mjs +26 -9
- package/scripts/release-notes-lint.mjs +3 -2
- package/scripts/release-version-pr-checks.mjs +1 -1
- package/scripts/settings-render-check.mjs +23 -3
- package/scripts/test-run.mjs +5 -5
- package/scripts/travelling-predicates.mjs +1 -1
- package/scripts/undeclared-field-census.mjs +1 -1
- package/scripts/unexecuted-asserts.mjs +1 -1
- package/scripts/verify-publishable.mjs +1 -1
- package/shared/client-door.mjs +1 -1
- package/shared/connect-clients.mjs +1 -1
- package/shared/connector-signin-probe.mjs +1 -1
- package/shared/env-aliases.mjs +1 -1
- package/shared/invocation.mjs +14 -2
- package/shared/names-in-force.mjs +2 -0
- package/shared/register-selection.mjs +2 -2
- package/shared/store-in-repo.mjs +3 -3
- package/shared/summary-blocks.mjs +0 -3
- package/shared/trigger-lane.mjs +1 -1
- package/shared/vacuous-pass.mjs +2 -2
- package/shared/verb-shim.mjs +4 -2
- package/node_modules/exceljs/README.md +0 -3023
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
// portal-routes/runs.mjs — the runs list a reader sees, and acknowledging a run that needed attention.
|
|
5
|
+
//
|
|
6
|
+
// One of the portal service's route groups, moved out of its dispatcher unchanged; makePortalService says how it asks them.
|
|
7
|
+
import { assertPrincipal, genericOrgOf, seesEverything } from "../portal-access.mjs";
|
|
8
|
+
import { ACKNOWLEDGEABLE, readAcks, setAck, withAcks } from "../portal-acks.mjs";
|
|
9
|
+
import { forRole, scanAccountRuns, scanAllRuns } from "../portal-runs.mjs";
|
|
10
|
+
|
|
11
|
+
export async function runsRoutes({ poolRoot, workspaceRoot, queueDirs }, { method, parts, principal, body, query }) {
|
|
12
|
+
// /portal/api/runs
|
|
13
|
+
if (parts[1] === "api" && parts[2] === "runs" && method === "GET") {
|
|
14
|
+
// — THE VIEWER'S OWN DISMISSALS, stamped per request because the listing does not know who
|
|
15
|
+
// is asking and must not learn: scanAccountRuns is shared with the staff index and the fold, and
|
|
16
|
+
// a per-reader flag computed inside it would be one reader's preference baked into a cache every
|
|
17
|
+
// other surface reads. So the scan answers "what is there" and this answers "what has THIS
|
|
18
|
+
// reader put down". Every branch below goes through it — a route that stamped only the scope=mine
|
|
19
|
+
// path would leave the same run acknowledged on one screen and not on another.
|
|
20
|
+
const mine = (runs) => withAcks(runs, readAcks(poolRoot, principal?.email));
|
|
21
|
+
// "All brand owners". ONLY FOR A PERSON WHO SEES EVERYTHING, and it is a distinct code path rather
|
|
22
|
+
// than a wildcard passed to assertPrincipal — nobody else may reach a branch that skips the account
|
|
23
|
+
// resolution, even by accident. Anyone else who asks for it gets the same 404 as any account not theirs.
|
|
24
|
+
if (query.account === "*") {
|
|
25
|
+
// THE DOOR FIRST. This branch once read a field off `principal` directly, and `principal` is null
|
|
26
|
+
// for an identity with no access anywhere — the exact caller this route most needs to refuse.
|
|
27
|
+
// Reading a field off null threw a TypeError, which is not a PortalDeny, so the
|
|
28
|
+
// catch at the bottom of route() rethrew it and the handler answered 500 "internal". An
|
|
29
|
+
// unenrolled prober therefore got a SERVER ERROR from the one route that lists every customer,
|
|
30
|
+
// while every other surface refused them cleanly — and a 500 is both the wrong answer and a
|
|
31
|
+
// more interesting one than a refusal. Resolving the principal before checking whether there
|
|
32
|
+
// IS one is the bug; the fix is ordering, not a null-guard.
|
|
33
|
+
//
|
|
34
|
+
// door:true is the same admission check /portal/api/me makes and deliberately resolves NO
|
|
35
|
+
// account (portal-access.mjs), so the staff-only rule below is untouched: a client still gets
|
|
36
|
+
// the plain 404 on the line after this one.
|
|
37
|
+
assertPrincipal(principal, { door: true });
|
|
38
|
+
if (!seesEverything(principal)) return { status: 404, json: { error: "not_found" } };
|
|
39
|
+
// One pass over the pool, not one request per account. The alternative — the browser fanning
|
|
40
|
+
// out across the roster — would spend a roster-sized chunk of the 120/min rate limit on every
|
|
41
|
+
// poll, which is exactly what the limiter is there to stop.
|
|
42
|
+
return { status: 200, json: { account: "*", runs: mine(forRole(scanAllRuns({ poolRoot, workspaceRoot, queueDirs: queueDirs() }), principal)) } };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ?scope=mine — EVERY BRAND OWNER THIS IDENTITY HOLDS, in one call.
|
|
46
|
+
//
|
|
47
|
+
// Home is account-scoped: it shows what is in flight across every brand owner the account
|
|
48
|
+
// holds, and the sidebar's brand-owner switcher must not empty it. A law firm clearing for
|
|
49
|
+
// three of its own clients cannot have that while "all of mine" costs one request per owner
|
|
50
|
+
// against a 120/min limit.
|
|
51
|
+
//
|
|
52
|
+
// IT IS DELIBERATELY NOT `account=*`. The wildcard means one thing — every account in the
|
|
53
|
+
// deployment, staff only — and it stays that way. Letting a client's `*` quietly resolve to
|
|
54
|
+
// "mine" would teach the browser that `*` is a harmless default worth sending everywhere, and
|
|
55
|
+
// the next path that forgets to re-check it becomes a cross-tenant read. Two capabilities,
|
|
56
|
+
// two names. (The two portal-service tests that pin the wildcard say exactly this.)
|
|
57
|
+
//
|
|
58
|
+
// One request shape for everyone: staff get every account, a client gets its own. Home never
|
|
59
|
+
// has to ask who is looking, which is the whole point — there is no staff layout.
|
|
60
|
+
if (parts[1] === "api" && parts[2] === "runs" && method === "GET" && query.scope === "mine") {
|
|
61
|
+
assertPrincipal(principal, { door: true });
|
|
62
|
+
if (seesEverything(principal)) {
|
|
63
|
+
return { status: 200, json: { account: "*", runs: mine(forRole(scanAllRuns({ poolRoot, workspaceRoot, queueDirs: queueDirs() }), principal)) } };
|
|
64
|
+
}
|
|
65
|
+
// Resolved from `principal.accounts`, NEVER from the query — this is the same set
|
|
66
|
+
// assertPrincipal hands back one key at a time, so it widens no boundary.
|
|
67
|
+
//
|
|
68
|
+
// `accounts === "*"` is the grants-file-absent posture (enforcement OFF). That is a
|
|
69
|
+
// SENTINEL, NOT A LIST: expanding it here would turn a missing config file into a
|
|
70
|
+
// cross-tenant read, so it falls through to the same refusal as holding nothing.
|
|
71
|
+
// Their companies, and the Generic of each organisation they hold whole.
|
|
72
|
+
if (Array.isArray(principal.accounts) && (principal.accounts.length || principal.genericOrgs?.length)) {
|
|
73
|
+
return { status: 200, json: { account: "*", runs: mine(forRole(scanAccountRuns({ poolRoot, workspaceRoot, account: principal.accounts,
|
|
74
|
+
generic: { orgs: principal.genericOrgs ?? [] }, queueDirs: queueDirs() }), principal)) } };
|
|
75
|
+
}
|
|
76
|
+
return { status: 404, json: { error: "not_found" } };
|
|
77
|
+
}
|
|
78
|
+
const account = assertPrincipal(principal, { account: query.account ?? null, tenant: query.tenant ?? null });
|
|
79
|
+
if (!account) return { status: 400, json: { error: "name an account (?account=)" } };
|
|
80
|
+
// GENERIC IS LISTED PER ORGANISATION. assertPrincipal has already refused an organisation whose
|
|
81
|
+
// Generic this person does not see. A named or implied organisation lists its own Generic runs,
|
|
82
|
+
// and a person who sees everything also gets the ones filed under none — on a one-organisation
|
|
83
|
+
// install those are that organisation's. Unnamed, with several organisations, a person who sees
|
|
84
|
+
// everything lists every Generic run, which is what they saw before organisations existed.
|
|
85
|
+
if (account === "generic") {
|
|
86
|
+
const org = genericOrgOf(principal, query.tenant ?? null);
|
|
87
|
+
const generic = org == null ? { all: true } : { orgs: [org], unfiled: seesEverything(principal) };
|
|
88
|
+
return { status: 200, json: { account, tenant: org, runs: mine(forRole(scanAccountRuns({ poolRoot, workspaceRoot, account: [], generic, queueDirs: queueDirs() }), principal)) } };
|
|
89
|
+
}
|
|
90
|
+
return { status: 200, json: { account, runs: mine(forRole(scanAccountRuns({ poolRoot, workspaceRoot, account, queueDirs: queueDirs() }), principal)) } };
|
|
91
|
+
}
|
|
92
|
+
// ── /portal/api/ack — "I have seen that one" ─────────────────────────────────────────────
|
|
93
|
+
//
|
|
94
|
+
// The Home dashboard accumulated failed runs with no way to clear them; on the test instance they
|
|
95
|
+
// were the dominant content, crowding out the work actually running. This dismisses one, FOR THE
|
|
96
|
+
// VIEWER ONLY.
|
|
97
|
+
//
|
|
98
|
+
// NOT STAFF-GATED, and that is the point rather than an oversight — it is the one curation act on
|
|
99
|
+
// this service that changes nothing anybody else can see, so every reader gets it for their own
|
|
100
|
+
// dashboard. Compare /portal/admin/retired: that hides a run from everyone including the
|
|
101
|
+
// brand owner, so it is staff-only and audited. This is neither, because there is nothing to
|
|
102
|
+
// audit: no state moves, no other reader is affected, and the run is untouched in Clearances.
|
|
103
|
+
//
|
|
104
|
+
// NO OWNERSHIP SCAN. Acking an id you cannot see writes one line to your own file and matches
|
|
105
|
+
// nothing on any listing you can reach — the stamp is applied by comparing against rows the scan
|
|
106
|
+
// already decided you may have. Proving ownership here would put a pool walk on a click, to
|
|
107
|
+
// prevent a caller from filling their own 500-entry file with ids that do nothing. The id is
|
|
108
|
+
// shape-checked all the same: it is a key in a file we write.
|
|
109
|
+
if (parts[1] === "api" && parts[2] === "ack" && method === "POST") {
|
|
110
|
+
assertPrincipal(principal, { door: true });
|
|
111
|
+
const runId = String(body?.runId ?? "");
|
|
112
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,180}$/.test(runId) || runId.includes("..")) {
|
|
113
|
+
return { status: 400, json: { error: "unknown run" } };
|
|
114
|
+
}
|
|
115
|
+
const acknowledged = body?.acknowledged !== false;
|
|
116
|
+
const state = String(body?.state ?? "");
|
|
117
|
+
// The rule at the door as well as in the key: a paused or recovering run is one somebody still
|
|
118
|
+
// needs to see. Keying on (runId, state) already makes a lie inert — the stamp only lands while
|
|
119
|
+
// the run still reads that way — but a refusal here is what a caller can act on.
|
|
120
|
+
if (acknowledged && !ACKNOWLEDGEABLE.includes(state)) {
|
|
121
|
+
return { status: 400, json: { error: `only a ${ACKNOWLEDGEABLE.join(" or ")} run can be acknowledged` } };
|
|
122
|
+
}
|
|
123
|
+
const acks = setAck(poolRoot, principal.email, { runId, state, acknowledged });
|
|
124
|
+
return { status: 200, json: { acknowledged, runId, count: acks.size } };
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
// portal-routes/usage.mjs — /portal/api/usage, what an account has used against its allowance.
|
|
5
|
+
//
|
|
6
|
+
// One of the portal service's route groups, moved out of its dispatcher unchanged; makePortalService says how it asks them.
|
|
7
|
+
import { assertPrincipal, genericOrgOf, seesEverything } from "../portal-access.mjs";
|
|
8
|
+
import { accountUsage, DEFAULT_CLIENT_DAILY_RUNS } from "../usage-ledger.mjs";
|
|
9
|
+
|
|
10
|
+
export async function usageRoutes({ queueDirs, upstream, loadProfilesImpl }, { method, parts, principal, query }) {
|
|
11
|
+
// /portal/api/usage — what this account has used against its allowance.
|
|
12
|
+
//
|
|
13
|
+
// Its own route rather than a field on /portal/api/me, because it is per-ACCOUNT and `me` is
|
|
14
|
+
// per-identity: a staff member acting for three clients has three different answers, and one of
|
|
15
|
+
// them is never "yours". Cheap enough to fetch beside the composer and the run list.
|
|
16
|
+
if (parts[1] === "api" && parts[2] === "usage" && method === "GET") {
|
|
17
|
+
const account = assertPrincipal(principal, { account: query.account ?? null, tenant: query.tenant ?? null });
|
|
18
|
+
if (!account) return { status: 400, json: { error: "name an account (?account=)" } };
|
|
19
|
+
// Generic is counted per organisation — the lane the wall caps (runner.mjs checkRunCaps).
|
|
20
|
+
const organisation = account === "generic" ? genericOrgOf(principal, query.tenant ?? null) : null;
|
|
21
|
+
// Caps live on the customer profile and are code-owned (never client-editable). A deployment
|
|
22
|
+
// with no config surface still answers, with counts and no caps — "we cannot tell you your
|
|
23
|
+
// limit" is a better answer than a fabricated one.
|
|
24
|
+
let caps = null, capsRead = false;
|
|
25
|
+
if (upstream) {
|
|
26
|
+
try {
|
|
27
|
+
if (account === "generic") { caps = (await loadProfilesImpl()).get("generic")?.runCaps ?? null; capsRead = true; }
|
|
28
|
+
else {
|
|
29
|
+
const r = await upstream.getProfile(principal, account);
|
|
30
|
+
if (r.status === 200) { caps = r.json?.readOnly?.runCaps ?? null; capsRead = true; }
|
|
31
|
+
}
|
|
32
|
+
} catch { /* a settings surface fault must not take the counter down */ }
|
|
33
|
+
}
|
|
34
|
+
// `complete` rides out with the counts (see usage-ledger.mjs): false means no ledger was read and
|
|
35
|
+
// these numbers are a floor. The UI can render that as "—" the way it already renders an
|
|
36
|
+
// unreadable cap as null, instead of a confident 0 nobody counted.
|
|
37
|
+
//
|
|
38
|
+
// `basis` is dropped here on purpose. What a client is owed is "we could not count", which
|
|
39
|
+
// `complete` says; WHICH kind of nothing it was is an operator's diagnosis of our deployment and
|
|
40
|
+
// belongs in the audit trail, where the quota pre-check puts it.
|
|
41
|
+
const { basis: _basis, ...used } = accountUsage({ queueDirs: queueDirs(), account, organisation });
|
|
42
|
+
return { status: 200, json: { account, ...(account === "generic" ? { tenant: organisation } : {}), ...used,
|
|
43
|
+
// The EFFECTIVE daily allowance: the profile's value, else the default the wall applies — a
|
|
44
|
+
// client reading "—" while the wall enforces 2 is the same lie as a wrong count. But a profile
|
|
45
|
+
// we could NOT read still reports null: "we cannot tell you your limit" is a different
|
|
46
|
+
// statement from "your limit is 2", and only one of them is honest when settings are down.
|
|
47
|
+
dailyRuns: Number.isInteger(caps?.dailyRuns) ? caps.dailyRuns : (capsRead ? DEFAULT_CLIENT_DAILY_RUNS : null),
|
|
48
|
+
monthlyRuns: caps?.monthlyRuns ?? null, maxQueued: caps?.maxQueued ?? null,
|
|
49
|
+
// A person who sees everything is not capped, and the UI needs to know that to avoid showing an
|
|
50
|
+
// allowance to someone it does not bind. See checkRunCaps for why it is decided here and nowhere else.
|
|
51
|
+
capped: !seesEverything(principal) } };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// /portal/api/mcp-access — the connection details for driving the engine from your own assistant.
|
|
55
|
+
//
|
|
56
|
+
// The Use-your-AI screen shipped deliberately EMPTY: there was no API that reported a host, so the
|
|
57
|
+
// page said so rather than printing a plausible placeholder (a genericised host has gone out of this
|
|
58
|
+
// codebase before and had to be chased). This is that API, and it keeps the same discipline: the URL
|
|
59
|
+
// comes from configuration and is null when unset. A deployment that has not wired the client MCP
|
|
60
|
+
// says "not available here", which is true, instead of showing an address that will not connect.
|
|
61
|
+
//
|
|
62
|
+
// There is no credential in this response, and that is the design rather than an omission: client
|
|
63
|
+
// MCP access is the caller's OWN Cloudflare Access login plus the grants entry that already governs
|
|
64
|
+
// this portal. Nothing to mint, nothing to paste, nothing to leak — and revoking portal access
|
|
65
|
+
// revokes the connector with it.
|
|
66
|
+
//
|
|
67
|
+
// `keyUrl` is the SECOND address: the API-key door, for assistants that cannot do a browser sign-in
|
|
68
|
+
// (a fixed "API key" box, a headless agent). It is a different HOST, never the same one with a key
|
|
69
|
+
// bolted on, and it is reported separately so the page can be honest about which is which. It stays
|
|
70
|
+
// null until that door is deployed — and a key itself is never in this response: keys are issued to a
|
|
71
|
+
// named person out of band, not handed to whoever loads the page.
|
|
72
|
+
// DOOR CHECK, not an account check — and the distinction is the whole bug this once had. Nothing in
|
|
73
|
+
// this answer is per-account: the connector address is one host for the deployment, and the identity
|
|
74
|
+
// to sign in with is the caller's own. Asking assertPrincipal to resolve an ACCOUNT made the route
|
|
75
|
+
// depend on something it never uses, and the failure was silent in the worst way — `assertPrincipal`
|
|
76
|
+
// returns null for STAFF with no acting-for account (portal-access.mjs: "caller decides"), that null
|
|
77
|
+
// became a 400, and the screen fell back to its "not shown here" empty state. So every staff user and
|
|
78
|
+
// every multi-account client was told the connector did not exist yet, while single-account clients
|
|
79
|
+
// saw it. `door:true` is the mode for exactly this question — may this identity enter — and it is what
|
|
80
|
+
// /portal/api/me already uses.
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|