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,425 @@
|
|
|
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/admin.mjs — the staff pages under /portal/admin: the roster, settings, run families, retired runs,
|
|
5
|
+
// access and people, and who has used this installation.
|
|
6
|
+
//
|
|
7
|
+
// One of the portal service's route groups, moved out of its dispatcher unchanged; makePortalService says how it asks them.
|
|
8
|
+
import { statSync } from "node:fs";
|
|
9
|
+
import { basename, join } from "node:path";
|
|
10
|
+
import { envFrom } from "../../shared/env-aliases.mjs";
|
|
11
|
+
import { personPoints, withoutPerson, withPerson } from "../../shared/grants-edit.mjs";
|
|
12
|
+
import { resolvePerson } from "../../shared/scope.mjs";
|
|
13
|
+
import { livePosture } from "../flag-snapshot.mjs";
|
|
14
|
+
import { assertPrincipal, mayRun, reachCovers, seesEverything } from "../portal-access.mjs";
|
|
15
|
+
import { accessView, authView, flagView, observedView } from "../portal-config-view.mjs";
|
|
16
|
+
import { familiesView, groupRuns, ungroupRuns } from "../portal-families.mjs";
|
|
17
|
+
import { forRole, resolveRunAccount, scanAccountRuns } from "../portal-runs.mjs";
|
|
18
|
+
import { updateArchived } from "../publish/archive-tags.mjs";
|
|
19
|
+
import { readJson } from "../run-record.mjs";
|
|
20
|
+
|
|
21
|
+
export async function adminRoutes({ poolRoot, workspaceRoot, grants, localSignIn, writeGrants, revokeConnectorKeys, queueDirs, audit, auditPath, loadProfilesImpl }, { method, parts, principal, grantsHere, body, query }) {
|
|
22
|
+
// /portal/admin/* — the install-wide surfaces, for a person who sees everything, and People, for a
|
|
23
|
+
// person with Manage. Everyone else gets 404: the surface does not exist for them.
|
|
24
|
+
if (parts[1] === "admin") {
|
|
25
|
+
assertPrincipal(principal, parts[2] === "access" || parts[2] === "people"
|
|
26
|
+
? { door: true, manage: true } : { door: true, everything: true });
|
|
27
|
+
if (parts[2] === "roster" && method === "GET") {
|
|
28
|
+
const profiles = await loadProfilesImpl();
|
|
29
|
+
// `generic` IS in the roster — this route is staff-only (asserted above), and untagged runs
|
|
30
|
+
// are real work that staff have to be able to select. Excluding it made those runs reachable
|
|
31
|
+
// by typing ?account=generic but invisible in the switcher, which is how they stop being
|
|
32
|
+
// looked at. The client-facing boundary is unchanged: /portal/api/runs and the report route
|
|
33
|
+
// both 404 `generic` for a non-staff principal.
|
|
34
|
+
// THE FACTS RIDE WITH THE NAME. The pick panel tells companies apart by industry, marketplace
|
|
35
|
+
// count and territories, and it renders for staff from here and for a client from /me. Shaping
|
|
36
|
+
// both through `companyFactsOf` is what stops the same company reading two ways depending on
|
|
37
|
+
// who signed in. Dynamic import deliberately: `profiles.mjs` captures the store directory at
|
|
38
|
+
// MODULE LOAD (see this file's note above), so it is never pulled in at our own load time.
|
|
39
|
+
const { companyFactsOf } = await import("../profiles.mjs");
|
|
40
|
+
// A company whose file would not load is named with its reason (staff-only route), never left out
|
|
41
|
+
// in silence: a switcher with one company where there were twenty-five reads as deleted work.
|
|
42
|
+
const unreadable = Array.isArray(profiles?.unreadable) ? profiles.unreadable.map((u) => ({ key: u.key, reason: u.reason })) : [];
|
|
43
|
+
return { status: 200, json: { customers: [...profiles.values()].map((p) => ({ key: p.key, name: p.name, ...companyFactsOf(p) })), ...(unreadable.length ? { unreadable } : {}) } };
|
|
44
|
+
}
|
|
45
|
+
// /portal/admin/config — what this deployment actually has switched on. Read from the SNAPSHOT,
|
|
46
|
+
// never from process.env: this process has no engine environment, so asking its own env would
|
|
47
|
+
// report every switch as off on a box where they are on — and this page, of all pages, would be
|
|
48
|
+
// believed.
|
|
49
|
+
if (parts[2] === "config" && method === "GET") {
|
|
50
|
+
// THE AUTH ROW IS READ LIVE, HERE, and not from the snapshot (ruled 2026-08-21).
|
|
51
|
+
// Everything else on this page is RENDERED from the snapshot. The reason recorded here used
|
|
52
|
+
// to be "because this process has no engine environment", and that has not been true since
|
|
53
|
+
// the owner's 2026-08-26 one-configuration-per-server-box ruling gave every unit the same
|
|
54
|
+
// `EnvironmentFile=%h/.env`. The rule stands on a better reason: the snapshot records what
|
|
55
|
+
// the ENGINE last ran under, and that is the fact this page reports. The portal's OWN door is
|
|
56
|
+
// the opposite case: this process reads PORTAL_AUTH_MODE and acts on it a few hundred lines
|
|
57
|
+
// below, so it is the authoritative source. Fed from process.env at the seam rather than
|
|
58
|
+
// inside authView, so the one process entitled to answer is visibly the one reading.
|
|
59
|
+
//
|
|
60
|
+
// AND THE ENVIRONMENT IS READ ONCE MORE, FOR ONE PURPOSE: to say whether
|
|
61
|
+
// the capture still DESCRIBES this box, never to supply a value. A deployment being
|
|
62
|
+
// configured runs nothing, so its capture cannot age into a warning while its contents drift
|
|
63
|
+
// — the disagreement is the signal the age never was. Degraded rather than fatal: a page that
|
|
64
|
+
// refused to render because it could not derive the live posture would be a worse answer than
|
|
65
|
+
// one that reports the capture and says it could not check it.
|
|
66
|
+
let live = null;
|
|
67
|
+
try { live = await livePosture(); } catch { live = null; }
|
|
68
|
+
return {
|
|
69
|
+
status: 200,
|
|
70
|
+
json: {
|
|
71
|
+
...flagView(poolRoot, { live }),
|
|
72
|
+
auth: authView({
|
|
73
|
+
mode: process.env.PORTAL_AUTH_MODE,
|
|
74
|
+
oidcIssuer: process.env.PORTAL_OIDC_ISSUER,
|
|
75
|
+
team: process.env.CF_ACCESS_TEAM,
|
|
76
|
+
}),
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// /portal/admin/families — the mark families a person has asserted.
|
|
81
|
+
//
|
|
82
|
+
// STAFF ONLY, and by construction rather than by filtering: it hangs off /portal/admin, which
|
|
83
|
+
// asserted staffOnly above and 404s for everyone else. That is a decision, not an oversight. A
|
|
84
|
+
// family name is staff shorthand for a brand line — "Aqua range" can name a launch a client has
|
|
85
|
+
// not announced — and a grouping a client can see but not edit or explain raises more questions
|
|
86
|
+
// than it answers. Revisit when clients have a reason to care; until then the client's list is
|
|
87
|
+
// exactly the mark list, which is what the browser falls back to when this 404s.
|
|
88
|
+
if (parts[2] === "families") {
|
|
89
|
+
const acct = query.account ?? null;
|
|
90
|
+
if (method === "GET") {
|
|
91
|
+
return { status: 200, json: familiesView(poolRoot, acct && acct !== "*" ? acct : null) };
|
|
92
|
+
}
|
|
93
|
+
if (method === "POST") {
|
|
94
|
+
const runIds = Array.isArray(body?.runIds) ? body.runIds.map(String) : [];
|
|
95
|
+
if (!runIds.length) return { status: 400, json: { error: "no runs given" } };
|
|
96
|
+
|
|
97
|
+
// THE ACCOUNT COMES FROM THE RUNS, NEVER FROM THE BODY.
|
|
98
|
+
//
|
|
99
|
+
// Same rule as jobFor() above and for the same reason: a body-supplied owner is a body-supplied
|
|
100
|
+
// tenancy claim. Each run's account is read from its own meta.json, and a request naming runs
|
|
101
|
+
// from two owners is refused rather than silently filed under one of them — a family's band is
|
|
102
|
+
// rolled up across its marks, and bands are only comparable inside one framework.
|
|
103
|
+
const owners = new Set();
|
|
104
|
+
for (const runId of runIds) {
|
|
105
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,180}$/.test(runId) || runId.includes("..")) {
|
|
106
|
+
return { status: 400, json: { error: "unknown run" } };
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
const meta = readJson(join(poolRoot, runId, "meta.json"));
|
|
110
|
+
owners.add(meta.customerKey || "generic");
|
|
111
|
+
} catch { return { status: 400, json: { error: "unknown run" } }; }
|
|
112
|
+
}
|
|
113
|
+
if (owners.size > 1) {
|
|
114
|
+
return { status: 400, json: { error: "those runs belong to different brand owners — a family covers one" } };
|
|
115
|
+
}
|
|
116
|
+
const account = [...owners][0];
|
|
117
|
+
|
|
118
|
+
const r = body?.action === "ungroup"
|
|
119
|
+
? ungroupRuns(poolRoot, { runIds })
|
|
120
|
+
: groupRuns(poolRoot, { name: body?.name, runIds, account });
|
|
121
|
+
if (r.error) return { status: 400, json: { error: r.error } };
|
|
122
|
+
// `status` so the success row and the refusal row above answer the same question the same
|
|
123
|
+
// way: reading down this log, every admin write now says how it ended.
|
|
124
|
+
audit({ event: `family-${body?.action === "ungroup" ? "ungroup" : "group"}`, by: principal.email,
|
|
125
|
+
account, family: r.familyId ?? null, runs: runIds.length, status: 200 });
|
|
126
|
+
return { status: 200, json: r };
|
|
127
|
+
}
|
|
128
|
+
return { status: 404, json: { error: "not_found" } };
|
|
129
|
+
}
|
|
130
|
+
// ── /portal/admin/retired — RETIRE, AND THE WAY BACK ──────────────────────────────────
|
|
131
|
+
//
|
|
132
|
+
// Staff could hide a run from every screen and had no way to do it except a terminal on the pool
|
|
133
|
+
// host. The sidecar, its reader and its semantics were all already here (scanAccountRuns, ~line
|
|
134
|
+
// 168); the only missing piece was a writer that is not a CLI.
|
|
135
|
+
//
|
|
136
|
+
// RETIRE, NEVER DELETE, and the issue is explicit about why: the pool is the published copy of
|
|
137
|
+
// real client matter, so an irreversible control does not belong on a staff screen. This route
|
|
138
|
+
// writes ONE file — archive-tags.json — and touches neither the run directory, the artifacts,
|
|
139
|
+
// nor the matter ledger. Removing the id brings the run back exactly as it was, which is what
|
|
140
|
+
// makes putting the control on the screen safe in the first place.
|
|
141
|
+
//
|
|
142
|
+
// The REPORT ROUTE STAYS OPEN on a retired run, deliberately and as before: retiring changes
|
|
143
|
+
// what the pool advertises, not who may read what, and the link is in mail we have already sent.
|
|
144
|
+
//
|
|
145
|
+
// STAFF ONLY BY CONSTRUCTION — it hangs off /portal/admin, which asserted staffOnly above. That
|
|
146
|
+
// is load-bearing here rather than incidental: retiring hides a run from the brand owner too, so
|
|
147
|
+
// it is a curation act by the firm, not a per-reader preference. The per-reader one is, and
|
|
148
|
+
// it deliberately uses a different store.
|
|
149
|
+
if (parts[2] === "retired") {
|
|
150
|
+
const acct = query.account ?? null;
|
|
151
|
+
const scoped = acct && acct !== "*" ? acct : null;
|
|
152
|
+
if (method === "GET") {
|
|
153
|
+
return { status: 200, json: { account: acct ?? "*",
|
|
154
|
+
runs: forRole(scanAccountRuns({ poolRoot, workspaceRoot, account: scoped, includeRetired: true, queueDirs: queueDirs() }), principal) } };
|
|
155
|
+
}
|
|
156
|
+
if (method === "POST") {
|
|
157
|
+
const runIds = Array.isArray(body?.runIds) ? body.runIds.map(String) : [];
|
|
158
|
+
if (!runIds.length) return { status: 400, json: { error: "no runs given" } };
|
|
159
|
+
const restore = body?.action === "restore";
|
|
160
|
+
// THE ACCOUNT COMES FROM THE RUNS, NEVER FROM THE BODY — the families rule above, for the
|
|
161
|
+
// same reason. Reading each run's own meta.json is also what proves the id names a real pool
|
|
162
|
+
// run: an unchecked id would let a typo write a tag for a run that does not exist, and that
|
|
163
|
+
// tag would sit in the sidecar for ever with nothing to explain it.
|
|
164
|
+
//
|
|
165
|
+
// A RESTORE MUST NOT REQUIRE A READABLE META. It is the way back, and the case where you
|
|
166
|
+
// most want it is the run whose directory has gone strange. So the id is validated as a
|
|
167
|
+
// shape, and the meta read is best-effort on that path.
|
|
168
|
+
//
|
|
169
|
+
// ── — RESOLVED THE WAY THE LIST RESOLVES IT ────────────────────
|
|
170
|
+
//
|
|
171
|
+
// This read `<pool>/<runId>/meta.json` directly, and a run that was STOPPED never publishes
|
|
172
|
+
// into the pool. So every press on a stopped run answered `400 unknown run` — the owner's
|
|
173
|
+
// report, twice in his own audit log — while the list that drew the button had read the
|
|
174
|
+
// run from the workspace. The endpoint and the screen were asking different questions about
|
|
175
|
+
// the same id.
|
|
176
|
+
//
|
|
177
|
+
// `resolveRunAccount` asks the LIST's question, pool first and the wider scan only when the
|
|
178
|
+
// pool cannot answer. The tenancy rule below is untouched: the account still comes from the
|
|
179
|
+
// run, never from the body.
|
|
180
|
+
const owners = new Set();
|
|
181
|
+
for (const runId of runIds) {
|
|
182
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,180}$/.test(runId) || runId.includes("..")) {
|
|
183
|
+
return { status: 400, json: { error: "unknown run" } };
|
|
184
|
+
}
|
|
185
|
+
const found = resolveRunAccount({ poolRoot, workspaceRoot, queueDirs: queueDirs(), runId });
|
|
186
|
+
if (found) owners.add(found.account);
|
|
187
|
+
// A RESTORE MUST NOT REQUIRE A RESOLVABLE RUN — it is the way back, and the case you most
|
|
188
|
+
// want it in is the run whose directory has gone strange. Unchanged from what shipped.
|
|
189
|
+
else if (!restore) return { status: 400, json: { error: "unknown run" } };
|
|
190
|
+
}
|
|
191
|
+
const archived = updateArchived(poolRoot, (set) => {
|
|
192
|
+
for (const id of runIds) { if (restore) set.delete(id); else set.add(id); }
|
|
193
|
+
return set;
|
|
194
|
+
});
|
|
195
|
+
audit({ event: restore ? "run-restore" : "run-retire", by: principal.email,
|
|
196
|
+
account: owners.size === 1 ? [...owners][0] : null, runs: runIds.length, status: 200 });
|
|
197
|
+
return { status: 200, json: { retired: !restore, runs: runIds.length, archived: archived.size } };
|
|
198
|
+
}
|
|
199
|
+
return { status: 404, json: { error: "not_found" } };
|
|
200
|
+
}
|
|
201
|
+
// /portal/admin/access — who is granted what, and where an enrolment is half done.
|
|
202
|
+
if (parts[2] === "access" && method === "GET") {
|
|
203
|
+
const { loadProfiles } = await import("../profiles.mjs");
|
|
204
|
+
const companies = Object.fromEntries([...loadProfiles({ force: true }).values()].map((p) => [p.key, p.name ?? p.key]));
|
|
205
|
+
// Where to go to change this. The stat is done HERE rather than inside accessView because
|
|
206
|
+
// that function is pure and its tests call it with no filesystem at all; giving it IO would
|
|
207
|
+
// cost that for a filename and a date.
|
|
208
|
+
//
|
|
209
|
+
// BASENAME, never the full path. This route is staff-only, so it is not a leak to a client —
|
|
210
|
+
// but a full path bakes a deployment's layout into a JSON body that ends up in browser
|
|
211
|
+
// caches, screenshots and support tickets, and the filename is the whole useful part.
|
|
212
|
+
let grantsFile = null;
|
|
213
|
+
try {
|
|
214
|
+
const p = envFrom(process.env, "CLEAROTRON_ACCESS_FILE");
|
|
215
|
+
if (p) grantsFile = { name: basename(p), modifiedAt: new Date(statSync(p).mtimeMs).toISOString() };
|
|
216
|
+
} catch { /* reported as unknown; a failed stat must not take down the page that explains access */ }
|
|
217
|
+
// WHETHER AN ISSUED KEY CAN BE WITHDRAWN AT ALL. This used to be whether a revocation list was
|
|
218
|
+
// named in this process's environment, because a door with none named checked no list. Every door
|
|
219
|
+
// now reads the install's default list when none is named (isRevoked, shared/scope.mjs), and that
|
|
220
|
+
// is where a revocation from here is written, so keys can be withdrawn whenever this process has
|
|
221
|
+
// a revoker at all.
|
|
222
|
+
const keysRevocable = Boolean(revokeConnectorKeys);
|
|
223
|
+
return { status: 200, json: accessView({ grants: grantsHere, viewer: principal, companies, grantsFile, localSignIn, keysRevocable }) };
|
|
224
|
+
}
|
|
225
|
+
// /portal/admin/people — give someone access. Manage-gated above; everything else is decided here.
|
|
226
|
+
//
|
|
227
|
+
// THE ADDER'S OWN REACH BOUNDS WHAT THEY GIVE. A point outside it is a 404, exactly as asking to
|
|
228
|
+
// see it would be. Switches belong to the person, not to a point, so they are set only when the
|
|
229
|
+
// person's whole access sits inside the adder's; otherwise the points are added, the switches stay
|
|
230
|
+
// as they were, and the answer says which happened. Nobody sets their own switches, and nobody
|
|
231
|
+
// gives Run without holding it.
|
|
232
|
+
if (parts[2] === "people" && parts.length === 3 && method === "POST") {
|
|
233
|
+
// CODE AS ITS OWN FIELD. `error` carries a sentence on most routes here and a token on a few, so
|
|
234
|
+
// a client cannot tell the two apart by looking at it — and the one that reached the page as page
|
|
235
|
+
// copy was a token. A code the client reads as a FIELD is decidable; prose never is.
|
|
236
|
+
if (localSignIn) return { status: 409, json: { error: "local_sign_in", code: "local_sign_in" } };
|
|
237
|
+
if (!writeGrants) return { status: 503, json: { error: "cannot_write_grants" } };
|
|
238
|
+
const email = String(body?.email ?? "").trim().toLowerCase();
|
|
239
|
+
if (!email || email.indexOf("@") <= 0 || email.indexOf("@") !== email.lastIndexOf("@"))
|
|
240
|
+
return { status: 400, json: { error: "Enter one email address." } };
|
|
241
|
+
// ACCESS TO EVERYTHING IS NOT A POINT, and the handler used to treat it as one. The form draws
|
|
242
|
+
// "Everything on this Clearotron" only to somebody who holds it, and sent it as
|
|
243
|
+
// `{kind:"everything"}` alongside the organisation and company points; nothing here matched
|
|
244
|
+
// that kind, so it fell to the 404 below and the page rendered the refusal it keeps for a
|
|
245
|
+
// point outside the adder's reach — "You can only give access to what you have access to
|
|
246
|
+
// yourself" — to the one person on the install for whom that is false. The control had never
|
|
247
|
+
// worked. It lives under `people` as a switch, not in any organisation, so it is read as one.
|
|
248
|
+
const points = [];
|
|
249
|
+
let wantsEverything = false;
|
|
250
|
+
for (const a of Array.isArray(body?.access) ? body.access : []) {
|
|
251
|
+
const key = typeof a?.key === "string" ? a.key : "";
|
|
252
|
+
if (a?.kind === "everything" && seesEverything(principal)) wantsEverything = true;
|
|
253
|
+
else if (a?.kind === "organisation" && (principal.genericOrgs ?? []).includes(key)) points.push({ tenant: key });
|
|
254
|
+
else if (a?.kind === "company" && principal.accountOrgs?.[key]) points.push({ tenant: principal.accountOrgs[key], account: key });
|
|
255
|
+
else return { status: 404, json: { error: "not_found" } };
|
|
256
|
+
}
|
|
257
|
+
if (!points.length && !wantsEverything) return { status: 400, json: { error: "Choose at least one organisation or company this person may see." } };
|
|
258
|
+
const want = { run: body?.permissions?.run === true, manage: body?.permissions?.manage === true, everything: wantsEverything };
|
|
259
|
+
if (want.run && !mayRun(principal)) return { status: 400, json: { error: "You cannot give Run clearances without holding it yourself." } };
|
|
260
|
+
const existing = resolvePerson(email, grantsHere);
|
|
261
|
+
const setSwitches = email !== principal.email && (!existing || reachCovers(principal, existing));
|
|
262
|
+
// THE SWITCHES ARE WHERE ACCESS TO EVERYTHING IS WRITTEN, so a grant of it that cannot write
|
|
263
|
+
// them writes nothing at all — and `withPerson` would return unchanged grants and this route a
|
|
264
|
+
// 201 naming a person who gained nothing. Said instead of returned.
|
|
265
|
+
if (wantsEverything && !setSwitches)
|
|
266
|
+
return { status: 400, json: { error: "Access to everything is part of what a person may do, and that cannot be set from here for this address. Nothing was saved." } };
|
|
267
|
+
let next;
|
|
268
|
+
try { next = withPerson(grantsHere, { email, points, switches: want, setSwitches }); }
|
|
269
|
+
catch (e) { return { status: 400, json: { error: String(e?.message ?? e).slice(0, 300) } }; }
|
|
270
|
+
try { await writeGrants(next); }
|
|
271
|
+
catch (e) {
|
|
272
|
+
audit({ event: "person-add", by: principal.email, person: email, ok: false, error: String(e?.message ?? e).slice(0, 200) });
|
|
273
|
+
return { status: 500, json: { error: "The guest list could not be written, so nobody was added." } };
|
|
274
|
+
}
|
|
275
|
+
audit({ event: "person-add", by: principal.email, person: email, points: points.length, switchesApplied: setSwitches, ok: true, status: 201 });
|
|
276
|
+
const { loadProfiles } = await import("../profiles.mjs");
|
|
277
|
+
const companies = Object.fromEntries([...loadProfiles({ force: true }).values()].map((p) => [p.key, p.name ?? p.key]));
|
|
278
|
+
const person = accessView({ grants: next, viewer: principal, companies }).people.find((p) => p.email === email) ?? null;
|
|
279
|
+
return { status: 201, json: { person, switchesApplied: setSwitches } };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// /portal/admin/people/change — change what somebody may do and see.
|
|
283
|
+
//
|
|
284
|
+
// THE DIFF IS COMPUTED HERE, FROM THE FILE, and never taken from the request. The page sends the
|
|
285
|
+
// state it wants; this reads what the file holds right now, narrows that to the part of the
|
|
286
|
+
// person the caller can see, and works out what to add and what to take away between the two. A
|
|
287
|
+
// page that had been open while somebody else was edited would otherwise write its own stale
|
|
288
|
+
// copy back over them — and the half it would overwrite is the half outside its own view, which
|
|
289
|
+
// nobody looking at either screen could see happen.
|
|
290
|
+
//
|
|
291
|
+
// NOBODY CHANGES THEMSELVES. The Add form already refuses to set the adder's own switches; this
|
|
292
|
+
// refuses the whole act, because a manager who can take their own Manage away can lock the
|
|
293
|
+
// install's last manager out of it with one press, and the way back is a text editor on the box.
|
|
294
|
+
if (parts[2] === "people" && parts[3] === "change" && parts.length === 4 && method === "POST") {
|
|
295
|
+
// CODE AS ITS OWN FIELD. `error` carries a sentence on most routes here and a token on a few, so
|
|
296
|
+
// a client cannot tell the two apart by looking at it — and the one that reached the page as page
|
|
297
|
+
// copy was a token. A code the client reads as a FIELD is decidable; prose never is.
|
|
298
|
+
if (localSignIn) return { status: 409, json: { error: "local_sign_in", code: "local_sign_in" } };
|
|
299
|
+
if (!writeGrants) return { status: 503, json: { error: "cannot_write_grants" } };
|
|
300
|
+
const email = String(body?.email ?? "").trim().toLowerCase();
|
|
301
|
+
if (email === principal.email) return { status: 400, json: { error: "You cannot change your own access. Somebody else who manages this install can." } };
|
|
302
|
+
const existing = resolvePerson(email, grantsHere);
|
|
303
|
+
const held = personPoints(grantsHere, email);
|
|
304
|
+
if (!existing && !held.listed && !held.points.length) return { status: 404, json: { error: "not_found" } };
|
|
305
|
+
|
|
306
|
+
// What the caller can see of this person, and what they asked for — both in the same shape, so
|
|
307
|
+
// the difference between them is the change.
|
|
308
|
+
const inReach = (pt) => pt.account == null
|
|
309
|
+
? (principal.genericOrgs ?? []).includes(pt.tenant)
|
|
310
|
+
: principal.accountOrgs?.[pt.account] === pt.tenant;
|
|
311
|
+
const mine = held.points.filter(inReach);
|
|
312
|
+
const want = [];
|
|
313
|
+
for (const a of Array.isArray(body?.access) ? body.access : []) {
|
|
314
|
+
const key = typeof a?.key === "string" ? a.key : "";
|
|
315
|
+
if (a?.kind === "organisation" && (principal.genericOrgs ?? []).includes(key)) want.push({ tenant: key, account: null });
|
|
316
|
+
else if (a?.kind === "company" && principal.accountOrgs?.[key]) want.push({ tenant: principal.accountOrgs[key], account: key });
|
|
317
|
+
else return { status: 404, json: { error: "not_found" } };
|
|
318
|
+
}
|
|
319
|
+
const id = (pt) => `${pt.tenant}/${pt.account ?? "*"}`;
|
|
320
|
+
const wanted = new Set(want.map(id));
|
|
321
|
+
const kept = new Set(mine.map(id));
|
|
322
|
+
const drop = mine.filter((pt) => !wanted.has(id(pt)));
|
|
323
|
+
const add = want.filter((pt) => !kept.has(id(pt)));
|
|
324
|
+
// TAKING THE WHOLE OF SOMEBODY'S VISIBLE ACCESS AWAY IS REMOVAL, and it has its own route, its
|
|
325
|
+
// own confirmation and its own revocation. Reaching it by unticking every row would do half of
|
|
326
|
+
// that act under the word "save".
|
|
327
|
+
if (!want.length) return { status: 400, json: { error: "Leave them at least one organisation or company, or remove them instead." } };
|
|
328
|
+
|
|
329
|
+
const switches = { run: body?.permissions?.run === true, manage: body?.permissions?.manage === true,
|
|
330
|
+
everything: held.switches.everything };
|
|
331
|
+
if (switches.run && !held.switches.run && !mayRun(principal))
|
|
332
|
+
return { status: 400, json: { error: "You cannot give Run clearances without holding it yourself." } };
|
|
333
|
+
// Switches belong to the person and not to a point, so they are set only when the whole of this
|
|
334
|
+
// person sits inside the caller's reach. Otherwise the points move and the switches stay, and
|
|
335
|
+
// the answer says which happened — the same contract adding already has.
|
|
336
|
+
const setSwitches = reachCovers(principal, existing);
|
|
337
|
+
let next;
|
|
338
|
+
try {
|
|
339
|
+
next = drop.length ? withoutPerson(grantsHere, { email, points: drop }) : grantsHere;
|
|
340
|
+
next = withPerson(next, { email, points: add, switches, setSwitches });
|
|
341
|
+
} catch (e) { return { status: 400, json: { error: String(e?.message ?? e).slice(0, 300) } }; }
|
|
342
|
+
try { await writeGrants(next); }
|
|
343
|
+
catch (e) {
|
|
344
|
+
audit({ event: "person-change", by: principal.email, person: email, ok: false, error: String(e?.message ?? e).slice(0, 200) });
|
|
345
|
+
return { status: 500, json: { error: "The guest list could not be written, so nothing was changed." } };
|
|
346
|
+
}
|
|
347
|
+
audit({ event: "person-change", by: principal.email, person: email, added: add.length, removed: drop.length,
|
|
348
|
+
switchesApplied: setSwitches, ok: true, status: 200 });
|
|
349
|
+
const { loadProfiles } = await import("../profiles.mjs");
|
|
350
|
+
const companies = Object.fromEntries([...loadProfiles({ force: true }).values()].map((p) => [p.key, p.name ?? p.key]));
|
|
351
|
+
const person = accessView({ grants: next, viewer: principal, companies }).people.find((p) => p.email.toLowerCase() === email) ?? null;
|
|
352
|
+
return { status: 200, json: { person, switchesApplied: setSwitches, added: add.length, removed: drop.length } };
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// /portal/admin/people/remove — take their access away.
|
|
356
|
+
//
|
|
357
|
+
// HOW FAR IT REACHES IS THE SERVER'S ANSWER, NOT THE REQUEST'S. A caller who can see the whole of
|
|
358
|
+
// this person removes them from the install; a caller who can see one organisation's worth of
|
|
359
|
+
// them takes away that organisation and nothing else. The page draws a different button for each
|
|
360
|
+
// — it reads the same `covered` the view computes — but the request carries no scope to get
|
|
361
|
+
// wrong, so a stale page cannot ask for more than the person pressing it can see.
|
|
362
|
+
if (parts[2] === "people" && parts[3] === "remove" && parts.length === 4 && method === "POST") {
|
|
363
|
+
// CODE AS ITS OWN FIELD. `error` carries a sentence on most routes here and a token on a few, so
|
|
364
|
+
// a client cannot tell the two apart by looking at it — and the one that reached the page as page
|
|
365
|
+
// copy was a token. A code the client reads as a FIELD is decidable; prose never is.
|
|
366
|
+
if (localSignIn) return { status: 409, json: { error: "local_sign_in", code: "local_sign_in" } };
|
|
367
|
+
if (!writeGrants) return { status: 503, json: { error: "cannot_write_grants" } };
|
|
368
|
+
const email = String(body?.email ?? "").trim().toLowerCase();
|
|
369
|
+
if (email === principal.email) return { status: 400, json: { error: "You cannot remove your own access. Somebody else who manages this install can." } };
|
|
370
|
+
const existing = resolvePerson(email, grantsHere);
|
|
371
|
+
const held = personPoints(grantsHere, email);
|
|
372
|
+
if (!existing && !held.listed && !held.points.length) return { status: 404, json: { error: "not_found" } };
|
|
373
|
+
const whole = reachCovers(principal, existing);
|
|
374
|
+
const inReach = (pt) => pt.account == null
|
|
375
|
+
? (principal.genericOrgs ?? []).includes(pt.tenant)
|
|
376
|
+
: principal.accountOrgs?.[pt.account] === pt.tenant;
|
|
377
|
+
const mine = held.points.filter(inReach);
|
|
378
|
+
if (!whole && !mine.length) return { status: 404, json: { error: "not_found" } };
|
|
379
|
+
|
|
380
|
+
let next;
|
|
381
|
+
try { next = withoutPerson(grantsHere, whole ? { email, all: true } : { email, points: mine }); }
|
|
382
|
+
catch (e) { return { status: 400, json: { error: String(e?.message ?? e).slice(0, 300) } }; }
|
|
383
|
+
|
|
384
|
+
// THE KEYS, AND ONLY ON A WHOLE REMOVAL. A narrowing leaves the person on the install with
|
|
385
|
+
// access somewhere else, and their connector key is how they reach that.
|
|
386
|
+
let keys = { checked: false };
|
|
387
|
+
if (whole) {
|
|
388
|
+
if (!revokeConnectorKeys) keys = { checked: false, note: "this installation cannot revoke issued keys from here" };
|
|
389
|
+
else {
|
|
390
|
+
try {
|
|
391
|
+
const { grants: written, ...said } = await revokeConnectorKeys({ email, grants: next });
|
|
392
|
+
next = written ?? next;
|
|
393
|
+
keys = { checked: true, ...said };
|
|
394
|
+
}
|
|
395
|
+
// A REVOCATION THAT FAILED MUST NOT LOOK LIKE ONE THAT HAPPENED, and it must not take the
|
|
396
|
+
// removal with it either: the access record is the gate every surface reads, and leaving
|
|
397
|
+
// it in place because a key file could not be appended would be the larger failure.
|
|
398
|
+
catch (e) { keys = { checked: true, failed: true, note: String(e?.message ?? e).slice(0, 200) }; }
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
try { await writeGrants(next); }
|
|
403
|
+
catch (e) {
|
|
404
|
+
audit({ event: "person-remove", by: principal.email, person: email, ok: false, error: String(e?.message ?? e).slice(0, 200) });
|
|
405
|
+
return { status: 500, json: { error: "The guest list could not be written, so nothing was changed." } };
|
|
406
|
+
}
|
|
407
|
+
audit({ event: "person-remove", by: principal.email, person: email, scope: whole ? "install" : "organisations",
|
|
408
|
+
organisations: whole ? null : [...new Set(mine.map((pt) => pt.tenant))].length,
|
|
409
|
+
keysRevoked: keys.revoked ?? 0, keysUnrevokable: keys.lateArm ? (keys.jtis?.length ?? 0) : 0, ok: true, status: 200 });
|
|
410
|
+
return { status: 200, json: { removed: whole ? "install" : "organisations",
|
|
411
|
+
organisations: whole ? [] : [...new Set(mine.map((pt) => pt.tenant))], keys } };
|
|
412
|
+
}
|
|
413
|
+
// /portal/admin/observed — who has actually USED this instance lately, from the audit log.
|
|
414
|
+
//
|
|
415
|
+
// ALWAYS 200, even when the log is missing or unreadable, with an `available` boolean — the
|
|
416
|
+
// same contract flagView already uses for a missing snapshot. An error status here would trip
|
|
417
|
+
// the screen's load gate and blank a page whose real job is explaining access, in order to
|
|
418
|
+
// report that an optional extra was unavailable.
|
|
419
|
+
if (parts[2] === "observed" && method === "GET") {
|
|
420
|
+
return { status: 200, json: observedView({ auditPath }) };
|
|
421
|
+
}
|
|
422
|
+
return { status: 404, json: { error: "not_found" } };
|
|
423
|
+
}
|
|
424
|
+
return undefined;
|
|
425
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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/compose.mjs — reading a pasted brief into a draft search (/portal/api/compose/read). It spends nothing and
|
|
5
|
+
// queues nothing.
|
|
6
|
+
//
|
|
7
|
+
// One of the portal service's route groups, moved out of its dispatcher unchanged; makePortalService says how it asks them.
|
|
8
|
+
import { browserCommand } from "../../shared/invocation.mjs";
|
|
9
|
+
import { assertPrincipal } from "../portal-access.mjs";
|
|
10
|
+
|
|
11
|
+
export async function composeRoutes({ audit, composeRead, readBudget, READ_OFF_NOTE }, { method, parts, principal, body }) {
|
|
12
|
+
// /portal/api/compose/read — turn a pasted brief into a filled-in composer.
|
|
13
|
+
//
|
|
14
|
+
// THE ONE THING TO KEEP TRUE ABOUT THIS ROUTE: it is the only POST under /portal/api that is not
|
|
15
|
+
// a step towards spending money. It mints no confirmation token, writes nothing, queues nothing
|
|
16
|
+
// and returns a draft. If it ever grows a side effect, it stops being safe to leave un-gated
|
|
17
|
+
// behind the composer's first click and belongs beside plan/run instead.
|
|
18
|
+
if (parts[1] === "api" && parts[2] === "compose" && parts[3] === "read" && method === "POST") {
|
|
19
|
+
// Door check only. The read touches no account data, so demanding an account here would be a
|
|
20
|
+
// gate with nothing behind it — and a staff member composing for a client they have not yet
|
|
21
|
+
// picked would be refused a form-filler for no reason.
|
|
22
|
+
assertPrincipal(principal, { door: true });
|
|
23
|
+
// `error` carries the SENTENCE, `code` the machine word — the convention every other route on
|
|
24
|
+
// this service follows, and what portal-ui's decoder reads. A code in `error` reaches a client
|
|
25
|
+
// screen as the literal word "read_failed".
|
|
26
|
+
if (!composeRead) {
|
|
27
|
+
return { status: 501, json: { code: "unavailable", error: READ_OFF_NOTE } };
|
|
28
|
+
}
|
|
29
|
+
if (readBudget && !readBudget.take(principal.email)) {
|
|
30
|
+
return { status: 429, json: { code: "rate_limited", error: "That is a lot of reading in one hour — set this one up below." } };
|
|
31
|
+
}
|
|
32
|
+
let out;
|
|
33
|
+
try {
|
|
34
|
+
out = await composeRead(typeof body?.brief === "string" ? body.brief : "");
|
|
35
|
+
} catch (e) {
|
|
36
|
+
// A provider outage is not a portal fault and must not read as one. The composer shows the
|
|
37
|
+
// sentence and keeps every field the user already typed — the brief is still in the box.
|
|
38
|
+
audit({ event: "compose-read", by: principal.email, ok: false, error: String(e?.message ?? e) });
|
|
39
|
+
// NOT "just now": a throw says nothing about whether it will pass, and that wording sent a reader
|
|
40
|
+
// back to the button for a failure no retry fixes. It names the check instead.
|
|
41
|
+
return { status: 502, json: { code: "read_failed",
|
|
42
|
+
error: `The request could not be read: the reader failed. \`${browserCommand("doctor --probe-engine")}\` finds out why — set the search up below meanwhile.` } };
|
|
43
|
+
}
|
|
44
|
+
// Length, never content. A brief is client material — whose mark, for whose product, before
|
|
45
|
+
// whose deadline — and an audit log is a different disclosure surface from a run store.
|
|
46
|
+
audit({ event: "compose-read", by: principal.email, ok: out.ok === true,
|
|
47
|
+
chars: String(body?.brief ?? "").length, ...(out.ok ? {} : { error: out.error }) });
|
|
48
|
+
if (!out.ok) {
|
|
49
|
+
// "engine" IS AN UPSTREAM FAULT AND KEEPS ITS 502. Before this the reader
|
|
50
|
+
// built its own client and a provider outage THREW, landing in the catch above as a 502. Going
|
|
51
|
+
// through the engine door made it a returned refusal instead — total rather than throwing — and
|
|
52
|
+
// routing that to 422 would have told the user their brief was unprocessable when the engine
|
|
53
|
+
// was simply unreachable. Same fault, same status as before; the reader changed, not the
|
|
54
|
+
// meaning. `unreadable` and `shape` stay 422 beside it: those ARE answers, just untrustworthy
|
|
55
|
+
// ones, and 422 is what this route has always said about them.
|
|
56
|
+
if (out.error === "engine") {
|
|
57
|
+
audit({ event: "compose-read", by: principal.email, ok: false, error: out.cause ?? "engine" });
|
|
58
|
+
return { status: 502, json: { code: "read_failed", error: out.message } };
|
|
59
|
+
}
|
|
60
|
+
const status = out.error === "too_long" || out.error === "empty" ? 400 : 422;
|
|
61
|
+
return { status, json: { code: out.error, error: out.message } };
|
|
62
|
+
}
|
|
63
|
+
return { status: 200, json: { read: out.read } };
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
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/config.mjs — the settings surface, /portal/api/config/*, which reaches the profile service only through
|
|
5
|
+
// portal-upstream, the one tenancy wall in front of it.
|
|
6
|
+
//
|
|
7
|
+
// One of the portal service's route groups, moved out of its dispatcher unchanged; makePortalService says how it asks them.
|
|
8
|
+
import { assertPrincipal } from "../portal-access.mjs";
|
|
9
|
+
|
|
10
|
+
export async function configRoutes({ audit, upstream }, { method, parts, principal, body, query }) {
|
|
11
|
+
// ── /portal/api/config/* — the settings surface ────────────────────────────────────────────
|
|
12
|
+
// Every route here goes through portal-upstream, which is the ONLY tenancy wall in front of
|
|
13
|
+
// profile-service. Nothing in this block resolves an account itself; doing so would create a
|
|
14
|
+
// second implementation of tenancy that has to agree with the first one forever.
|
|
15
|
+
if (parts[1] === "api" && parts[2] === "config") {
|
|
16
|
+
// THE DOOR FIRST — before the wiring check, before the method check, before anything whose
|
|
17
|
+
// answer depends on what this deployment happens to have.
|
|
18
|
+
//
|
|
19
|
+
// This block used to answer 405 method_not_allowed to a caller who had not been admitted at all:
|
|
20
|
+
// POST /portal/api/config/profile from an unenrolled address returned a crisp "that endpoint
|
|
21
|
+
// exists and you used the wrong verb on it", from the one surface that reads and writes tenant
|
|
22
|
+
// configuration. GET on the same path already 403'd (the door check happens inside
|
|
23
|
+
// portal-upstream's resolveAccount), so the surface answered two different ways to the same
|
|
24
|
+
// stranger depending only on the method — and the chattier answer was the one no identity check
|
|
25
|
+
// had run in front of.
|
|
26
|
+
//
|
|
27
|
+
// Now every method behaves identically for an unadmitted identity: the same PortalDeny(403) the
|
|
28
|
+
// rest of the API gives, carrying nothing this caller could not already read off /portal/api/me.
|
|
29
|
+
// 403-at-the-door is the deliberate doctrine here (portal-access.mjs: "an unmapped identity gets
|
|
30
|
+
// NO principal (403 at the door)") and it is what the denial page in makeHttpHandler exists to
|
|
31
|
+
// render; 404 is the doctrine for FOREIGN and NONEXISTENT resources, which is the case handled
|
|
32
|
+
// on the method line below.
|
|
33
|
+
assertPrincipal(principal, { door: true });
|
|
34
|
+
// 404 WITH A NAMED REASON. The status is unchanged and deliberately so —
|
|
35
|
+
// `portal-service.test.mjs` pins "never a 500" for this branch, and a config surface that failed
|
|
36
|
+
// to construct is a clean refusal rather than a fault. What changes is the BODY: `not_found` was
|
|
37
|
+
// the only thing the client had, so the screens rendered "Projects are not available to you" to
|
|
38
|
+
// the owner of the account when the real cause was that `PROFILE_REPO_ROOT` does not contain the
|
|
39
|
+
// customer store. That reason existed only in a boot log, and it cost the owner a morning.
|
|
40
|
+
//
|
|
41
|
+
// The 404-never-403 rule is untouched, and this code cannot weaken it. The rule protects the
|
|
42
|
+
// EXISTENCE of tenant-scoped resources from probing; this answer is tenant-INDEPENDENT — every
|
|
43
|
+
// admitted identity on this deployment gets exactly it, so it separates no account from any
|
|
44
|
+
// other. The door check above still answers 403 first, so an unadmitted caller never reaches
|
|
45
|
+
// this line. A 503 was the other candidate and was rejected: it would have reversed a pinned
|
|
46
|
+
// contract for nothing the reader gains, and it says "try again later" about a condition that
|
|
47
|
+
// needs a configuration change.
|
|
48
|
+
if (!upstream) return { status: 404, json: { error: "config_surface_unavailable" } };
|
|
49
|
+
const acct = query.account ?? body.account ?? null;
|
|
50
|
+
|
|
51
|
+
// /portal/api/config/profile
|
|
52
|
+
if (parts[3] === "profile" && parts.length === 4) {
|
|
53
|
+
if (method === "GET") return await upstream.getProfile(principal, acct);
|
|
54
|
+
// 404, not 405 — the 404-never-403 rule applied to SHAPE as well as ownership. A foreign
|
|
55
|
+
// account already reads here as not-found (portal-upstream rule 2), so answering
|
|
56
|
+
// method_not_allowed for a wrong verb made ONE endpoint distinguishable from an endpoint that
|
|
57
|
+
// does not exist, which is precisely the fact the 404 rule is protecting. The other half of
|
|
58
|
+
// this same block has always fallen through to the not_found below for the identical mistake
|
|
59
|
+
// (a POST to /portal/api/config/projects) — the two halves disagreed, and this was the wrong
|
|
60
|
+
// half. Byte-identical body, so nothing downstream can tell them apart either.
|
|
61
|
+
return { status: 404, json: { error: "not_found" } };
|
|
62
|
+
}
|
|
63
|
+
// /portal/api/config/profile/{validate,save}
|
|
64
|
+
if (parts[3] === "profile" && parts.length === 5 && method === "POST") {
|
|
65
|
+
const r = await upstream.writeProfile(principal, acct, parts[4], body);
|
|
66
|
+
if (parts[4] === "save" && r.status === 200) {
|
|
67
|
+
audit({ event: "profile-save", by: principal.email, account: r.json?.account ?? acct });
|
|
68
|
+
}
|
|
69
|
+
return r;
|
|
70
|
+
}
|
|
71
|
+
// /portal/api/config/companies — CREATE. No account segment, because there is no account yet.
|
|
72
|
+
//
|
|
73
|
+
// It does not hang off `profile` for a reason worth stating: every route under that word acts on
|
|
74
|
+
// ONE company, resolved from the caller, and this one is the act of there not being one. Reusing
|
|
75
|
+
// the noun would put "the company you are in" and "the company you are making" behind the same
|
|
76
|
+
// path, which is the conflation the pick panel exists to remove.
|
|
77
|
+
//
|
|
78
|
+
// The audit row is written upstream by the create route itself, in the same commit as the file,
|
|
79
|
+
// so there is none here. An audit call copied from its neighbours would also be wrong twice: it
|
|
80
|
+
// would test `status === 200` against a 201, and file nothing.
|
|
81
|
+
if (parts[3] === "companies") {
|
|
82
|
+
if (parts.length === 4 && method === "POST") return await upstream.createCompany(principal, body);
|
|
83
|
+
// 404 for a wrong verb, as the profile branch above explains at length: 405 would make this
|
|
84
|
+
// endpoint distinguishable from one that does not exist.
|
|
85
|
+
return { status: 404, json: { error: "not_found" } };
|
|
86
|
+
}
|
|
87
|
+
// /portal/api/config/projects[/:project[/{validate,save}]]
|
|
88
|
+
if (parts[3] === "projects") {
|
|
89
|
+
if (parts.length === 4 && method === "GET") return await upstream.listProjects(principal, acct);
|
|
90
|
+
if (parts.length === 5 && method === "GET") return await upstream.getProject(principal, acct, parts[4]);
|
|
91
|
+
if (parts.length === 6 && method === "POST") {
|
|
92
|
+
const r = await upstream.writeProject(principal, acct, parts[4], parts[5], body);
|
|
93
|
+
if (parts[5] === "save" && r.status === 200) {
|
|
94
|
+
audit({ event: "project-save", by: principal.email, account: acct, project: parts[4] });
|
|
95
|
+
}
|
|
96
|
+
return r;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// /portal/api/config/searches[/:slug[/{validate,save}]] — saved searches, client-authorable.
|
|
100
|
+
// Same shape as projects because it is the same discipline: list, read one, validate, save.
|
|
101
|
+
// Archive is a save carrying archived:true; there is no delete verb to mount.
|
|
102
|
+
if (parts[3] === "searches") {
|
|
103
|
+
if (parts.length === 4 && method === "GET") return await upstream.listSearches(principal, acct);
|
|
104
|
+
if (parts.length === 5 && method === "GET") return await upstream.getSearch(principal, acct, parts[4]);
|
|
105
|
+
if (parts.length === 6 && method === "POST") {
|
|
106
|
+
const r = await upstream.writeSearch(principal, acct, parts[4], parts[5], body);
|
|
107
|
+
if (parts[5] === "save" && r.status === 200) {
|
|
108
|
+
audit({ event: "saved-search-save", by: principal.email, account: acct, slug: parts[4],
|
|
109
|
+
version: r.json?.version ?? null, archived: Boolean(body?.recipe?.archived) });
|
|
110
|
+
}
|
|
111
|
+
return r;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return { status: 404, json: { error: "not_found" } };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|