Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: own the scope-adherence failure labels in server/lib instead of mirroring them into the client (#7643)
[._.]/ Adam Eivy361292e79ab7
diff --git a/client/src/lib/README.md b/client/src/lib/README.mdindex 3824e021d8..6bf00017e3 100644--- a/client/src/lib/README.md+++ b/client/src/lib/README.md@@ -266,7 +266,7 @@ grep -i "what you want to do" client/src/lib/README.md| `mindBundle.js` | Persistent Mind portable-bundle format vocabulary, re-exported from the `server/lib/mindBundleFormat.js` leaf (never copied): file extension, passphrase floor, size cap, export scopes, and the import group ids / source scopes / choice values the import panel renders. The sealing code stays server-side — that module imports node `crypto`. || `publicGuestRoutes.js` | `isPublicGuestRoute` identifies standalone guest pages that skip private app bootstrap. || `riggingReasons.js` | Client mirror of the character-rigging readiness reason labels in `server/services/rigging/readiness.js`: `RIGGING_UNAVAILABLE_REASONS` (reason code -> user-facing label), `RIGGING_REASON_FALLBACK`, and `riggingReasonLabel(code, fallback?)`. Render these anywhere a `GET /api/rigging/readiness` reason is shown; never re-declare the codes. Parity + code coverage enforced by `server/services/rigging/unavailableReasons.parity.test.js`. |-| `scopeAdherenceReasons.js` | Client mirror of the failure codes `POST /api/apps/:id/scope-adherence` can return instead of a verdict: `SCOPE_ADHERENCE_REASONS` (code -> operator-facing label), `SCOPE_ADHERENCE_REASON_FALLBACK`, and `scopeAdherenceReasonLabel(code, fallback?)` (own-property lookup, so a code naming an `Object.prototype` key cannot render as a function). Every label reads as "no advisory", never as a verdict. Coverage of the server codes is enforced by `server/services/scopeAdherence.reasons.parity.test.js`. |+| `scopeAdherenceReasons.js` | Re-export of `server/lib/scopeAdherenceReasons.js` — operator-facing labels for a scope-adherence failure code (`SCOPE_ADHERENCE_REASONS`, `SCOPE_ADHERENCE_REASON_FALLBACK`, `scopeAdherenceReasonLabel`). Every label reads as "no advisory", never as a verdict. One definition, no mirror to keep in parity. || `usagePeriods.js` | The report windows every usage-cost surface offers — `USAGE_PERIOD_OPTIONS`, `DEFAULT_USAGE_PERIOD` (what a URL with no `?period` means) and `resolveUsagePeriod`. Shared because `?period` is a URL param the user carries between the Usage and Subscriptions pages; two copies had already disagreed on the default. || `usdzExport.js` | AR Quick Look (USDZ) export for the 3D viewer (#5756): `exportSceneToUsdz(scene, { maxTextureSize })` lazy-loads three's `USDZExporter` and serializes the already-decoded scene to bytes, `countSceneTriangles(object3d)` measures an object graph against `AR_TRIANGLE_BUDGET`, and `supportsArQuickLook()` feature-detects the `<a rel="ar">` handoff (Safari on iOS/iPadOS only — never sniff the user agent) so a desktop is offered a download instead of a button that does nothing. `AR_MAX_TEXTURE_SIZE` bounds the file: USDZ stores every texel raw, with no Draco/meshopt equivalent. || `installFailureTask.js` | Build the CoS task payload behind the installer-failure "Queue agent to investigate" button (#5981): `buildInstallFailureTask({ label, stage, error, logs, surface })` → `{ description, prompt }` carrying the installer name, failing stage, error text and a bounded log tail, and `installLogTail(logs)` (the `useInstallStream` `{ kind, text }` entries rendered as text, capped at `INSTALL_FAILURE_LOG_TAIL_LINES` / `INSTALL_FAILURE_LOG_TAIL_CHARS` so a 1000-line pip stream cannot push a huge body through `POST /api/cos/tasks`, cutting on a line boundary, redacting the home-directory paths pip/git echo, and neutralizing a log line that would close the prompt fence). Shared by both install modals and `LocalSetupPanel` so every surface queues the same reproducible context. |diff --git a/client/src/lib/scopeAdherenceReasons.js b/client/src/lib/scopeAdherenceReasons.jsindex e6ca18d382..75a5bdcc75 100644--- a/client/src/lib/scopeAdherenceReasons.js+++ b/client/src/lib/scopeAdherenceReasons.js@@ -1,47 +1,15 @@/**- * Operator-facing labels for the codes `scoreAdherence` can return instead of- * a verdict (`server/services/scopeAdherence.js`).+ * Re-export of `server/lib/scopeAdherenceReasons.js` — the one definition of+ * the operator-facing labels for a scope-adherence failure code.*- * The client can't import the server module — it reaches `node:fs` and, past- * the jev router, the sidecar lifecycle — so this is a hand-maintained mirror,- * the same shape as `riggingReasons.js`. Coverage is asserted by- * `server/services/scopeAdherence.reasons.parity.test.js`, which fails when a- * code the service can return has no label here and would therefore render as- * the generic fallback with a fully green suite.- *- * Names are prefixed (`SCOPE_ADHERENCE_…`) because every module in this- * directory is a flat `export *` member of one barrel, where a shared- * identifier is a collision.- *- * Every label reads as "no advisory", never as a verdict. A scorer that could- * not answer has said nothing about the change.+ * A re-export rather than a mirror: a mirror would need a parity test, and a+ * parity test would need a server file importing a client file, which+ * `scripts/server-imports-no-client.test.js` forbids. The server leaf has no+ * imports of its own, so it is safe to pull into the browser bundle.*/-export const SCOPE_ADHERENCE_REASONS = Object.freeze({- // Reachable only in a race — the panel hides itself when the feature is off,- // but the toggle can move between render and response.- 'scope-adherence-disabled': 'The local scope scorer is turned off for this install.',- 'scope-adherence-change-empty': 'This row has no title or description to score.',- 'scope-adherence-corpus-missing': 'This repository has no PRD.md or GOALS.md to score against.',- 'scope-adherence-corpus-unreadable': 'This repository\'s PRD.md / GOALS.md could not be read.',- 'scope-adherence-no-clause': 'No stated goal in this repository is close enough to score against.',- 'jev-not-installed': 'The local scorer is not installed yet — see Models > LLMs > jev.',- 'jev-start-failed': 'The local scorer could not start. Check Models > LLMs > jev.',- 'jev-timeout': 'The local scorer did not answer in time.',- 'jev-request-invalid': 'The local scorer rejected the request for this change.',- 'jev-response-invalid': 'The local scorer returned an answer PortOS could not read.',- 'jev-premise-too-large': 'This change is too large for the local scorer to read at once.',-});--export const SCOPE_ADHERENCE_REASON_FALLBACK = 'The local scorer could not answer for this change.';--/**- * Label for a reason code.- *- * Own-property lookup only: `REASONS[code] || fallback` on a code that happens- * to name an `Object.prototype` key (`toString`, `constructor`) returns a- * function, and React throws when one is rendered as a child.- */-export function scopeAdherenceReasonLabel(reason, fallback = SCOPE_ADHERENCE_REASON_FALLBACK) {- return Object.hasOwn(SCOPE_ADHERENCE_REASONS, reason ?? '') ? SCOPE_ADHERENCE_REASONS[reason] : fallback;-}+export {+ SCOPE_ADHERENCE_REASONS,+ SCOPE_ADHERENCE_REASON_FALLBACK,+ scopeAdherenceReasonLabel,+} from '../../../server/lib/scopeAdherenceReasons.js';diff --git a/docs/features/scope-adherence.md b/docs/features/scope-adherence.mdindex c81c6c8aa5..9c30f54a8e 100644--- a/docs/features/scope-adherence.md+++ b/docs/features/scope-adherence.md@@ -92,4 +92,4 @@ Each reads as "no advisory" in the UI, never as a verdict.| The ladder (screen → retrieve → decide) | `server/services/scopeAdherence.js` || HTTP surface | `server/routes/apps/scopeAdherence.js` || UI | `client/src/components/apps/ScopeAdherenceCheck.jsx` |-| Failure labels (client mirror) | `client/src/lib/scopeAdherenceReasons.js` |+| Failure labels | `server/lib/scopeAdherenceReasons.js` (re-exported to the client) |diff --git a/server/lib/README.md b/server/lib/README.mdindex 701e3382ee..0421802783 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -505,6 +505,7 @@ pm` default, `NPM_CONFIG_PREFIX`, nvm/Volta) installed `codex` successfully and| `jevDecisions.js` | `JEV_DECISIONS` — the closed-set decisions PortOS may answer with the local scorer instead of a chat completion, each with its frozen hypothesis wording and its abstention floor. `getJevDecision` / `jevHypotheses` / `jevValueForHypothesis` map between an enum value and the hypothesis that stands for it; `jevMinMarginFor` composes the per-decision floor, the per-OPTION floor (a destructive `delete` clears a far wider margin than the `archive` beside it), and the operator setting, which can only RAISE the bar. `isValidJevDecision` is the contract every shipped descriptor is tested against. `source` names the ingress CHANNEL and is `null` for a decision that has none (`scope-adherence` asks about the operator's own product documents). Pure. Routing, mode resolution and the counts-only agreement store live in `services/jevRouter.js`. || `prdClauses.js` | Chops `PRD.md` / `GOALS.md` into addressable clauses — one per paragraph, top-level list item, blockquote or table data row — each carrying its heading path, source file and line. Clause ids are `<file>#<heading-slug>:<content-hash>` with NO line number and NO document ordinal, so a clause keeps its id when an unrelated paragraph is inserted above it. `indexClausesById` / `formatClauseCitation` render a verdict back to a citation a human can go read. Pure; the files are read by `services/scopeAdherence.js`. || `scopeAdherence.js` | The retrieval and premise half of "does this change advance the stated product goal?" — the QUESTION itself is the `scope-adherence` entry in `jevDecisions.js`. `selectCandidateClauses` fuses two BM25 views of the change (prose, changed files) with `fuseRankingsRRF`, so scoring is bounded by k rather than the whole corpus; `buildClauseIndex` is exported so a caller can cache the index beside the corpus. `formatChangeEvidence` builds the change half ONCE — the same string is screened and scored, so the two cannot drift — and `composeAdherencePremise` puts the clause first and in full. Also the route-input `scopeAdherenceRequestSchema`. ADVISORY ONLY: nothing here returns a gateable boolean. Pure; the ladder lives in `services/scopeAdherence.js`. |+| `scopeAdherenceReasons.js` | Operator-facing labels for the codes `scoreAdherence` returns instead of a verdict: `SCOPE_ADHERENCE_REASONS`, `SCOPE_ADHERENCE_REASON_FALLBACK`, and `scopeAdherenceReasonLabel(code, fallback?)` (own-property lookup, so a code naming an `Object.prototype` key cannot render as a function). Re-exported by `client/src/lib/scopeAdherenceReasons.js` rather than mirrored — a mirror would need a parity test, and that would need the server→client import `scripts/server-imports-no-client.test.js` forbids. Keep it import-free so it stays bundleable. || `pythonRuntimeDiagnosis.js` | `diagnosePythonRuntimeText(text, { subject, repairLabel, imports, fallback })` — maps raw pip/interpreter output onto the fixed operator-facing diagnosis vocabulary (`package-missing`, `certificate-failed`, `wheel-unavailable`, `dependency-conflict`, `disk-full`, `network-failed`), naming the specific pinned import when one is missing. Evidence is matched and DISCARDED: nothing from the subprocess output (tokens, authenticated index URLs, local paths) is ever returned. Shared by the Prompt Guard and jev installers. Pure. || `modelAbuseGuard.js` | Pinned model-abuse boundary contract: Prompt Guard metadata, deterministic abuse signals (`hiddenCodePointSummary` for invisible/direction-control/C0-C1 code points, `invisibleClusterSummary` for a dense cluster of the exempt ones, `describeEncodedPayload` for compressed/opaque blobs — the last scoped to `CODE_CONTENT_SOURCES` so a private message carrying base64 is not model abuse — plus hidden HTML comments/collapsed markup that address a model), complete classifier-window coverage validation, chunk/timeout limits, fixed dependency versions (`MODEL_ABUSE_GUARD_PYTHON_PACKAGES`), and `MODEL_ABUSE_GUARD_STAGES` / `modelAbuseGuardStageReadiness` for the operator-facing install checklist. Pure. || `diffHiddenContentScan.js` | Pre-LLM gate over a unified diff — `scanDiffForHiddenContent(diff)` reports invisible/direction-control Unicode (added lines and filenames), dense clusters of the invisible characters the rules otherwise exempt, compressed or opaque encoded payloads, a new symlink that leaves the repository or a new git submodule, a non-media binary patch, and inline script in SVG/HTML/XML, keyed `path:line`; `formatHiddenContentFindings` renders them for a CI log. Detectors for the Unicode/encoded rules are shared with `modelAbuseGuard.js` (same rules, applied to external PR content). Lockfiles skip the encoded rule but never the Unicode ones, a leading BOM is allowed, and `portos-allow-hidden-content` on the line itself opts out of the added-line rules. Driven by `scripts/scan-diff-hidden-content.js`, which CI runs on every pull request before any reviewer reads the diff (`core.quotepath=false` so a stealth filename is not octal-escaped past the detector). Pure. |diff --git a/server/lib/index.js b/server/lib/index.jsindex 07116f9202..6e11a01f25 100644--- a/server/lib/index.js+++ b/server/lib/index.js@@ -465,6 +465,7 @@ export * from './jev.js';export * from './jevDecisions.js';export * from './prdClauses.js';export * from './scopeAdherence.js';+export * from './scopeAdherenceReasons.js';export * from './modelAbuseGuard.js';export * from './pythonRuntimeDiagnosis.js';export * from './diffHiddenContentScan.js';diff --git a/server/lib/scopeAdherenceReasons.js b/server/lib/scopeAdherenceReasons.jsnew file mode 100644index 0000000000..2d51398410--- /dev/null+++ b/server/lib/scopeAdherenceReasons.js@@ -0,0 +1,47 @@+/**+ * Operator-facing labels for the codes `scoreAdherence` can return instead of+ * a verdict (`server/services/scopeAdherence.js`).+ *+ * ONE definition, here, re-exported by `client/src/lib/scopeAdherenceReasons.js`+ * — not a hand-maintained mirror with a parity test. The client may import a+ * pure `server/lib` leaf; the reverse edge is what+ * `scripts/server-imports-no-client.test.js` forbids, and a mirror would have+ * needed exactly that edge to be checked. This module keeps itself importable+ * from the browser by having no imports at all.+ *+ * Coverage of the code vocabulary is asserted by the sibling test, so a code+ * added to the service without a label fails rather than silently rendering as+ * the generic fallback.+ *+ * Every label reads as "no advisory", never as a verdict. A scorer that could+ * not answer has said nothing about the change.+ */++export const SCOPE_ADHERENCE_REASONS = Object.freeze({+ // Reachable only in a race — the panel hides itself when the feature is off,+ // but the toggle can move between render and response.+ 'scope-adherence-disabled': 'The local scope scorer is turned off for this install.',+ 'scope-adherence-change-empty': 'This row has no title or description to score.',+ 'scope-adherence-corpus-missing': 'This repository has no PRD.md or GOALS.md to score against.',+ 'scope-adherence-corpus-unreadable': 'This repository\'s PRD.md / GOALS.md could not be read.',+ 'scope-adherence-no-clause': 'No stated goal in this repository is close enough to score against.',+ 'jev-not-installed': 'The local scorer is not installed yet — see Models > LLMs > jev.',+ 'jev-start-failed': 'The local scorer could not start. Check Models > LLMs > jev.',+ 'jev-timeout': 'The local scorer did not answer in time.',+ 'jev-request-invalid': 'The local scorer rejected the request for this change.',+ 'jev-response-invalid': 'The local scorer returned an answer PortOS could not read.',+ 'jev-premise-too-large': 'This change is too large for the local scorer to read at once.',+});++export const SCOPE_ADHERENCE_REASON_FALLBACK = 'The local scorer could not answer for this change.';++/**+ * Label for a reason code.+ *+ * Own-property lookup only: `REASONS[code] || fallback` on a code that happens+ * to name an `Object.prototype` key (`toString`, `constructor`) returns a+ * function, and React throws when one is rendered as a child.+ */+export function scopeAdherenceReasonLabel(reason, fallback = SCOPE_ADHERENCE_REASON_FALLBACK) {+ return Object.hasOwn(SCOPE_ADHERENCE_REASONS, reason ?? '') ? SCOPE_ADHERENCE_REASONS[reason] : fallback;+}diff --git a/server/services/scopeAdherence.reasons.parity.test.js b/server/lib/scopeAdherenceReasons.test.jssimilarity index 57%rename from server/services/scopeAdherence.reasons.parity.test.jsrename to server/lib/scopeAdherenceReasons.test.jsindex 29f63d67b1..a6b1931885 100644--- a/server/services/scopeAdherence.reasons.parity.test.js+++ b/server/lib/scopeAdherenceReasons.test.js@@ -1,29 +1,25 @@/**- * Cross-package coverage for the scope-adherence failure labels.+ * Coverage for the scope-adherence failure labels.*- * `server/services/scopeAdherence.js` owns the CODES; the labels live in- * `client/src/lib/scopeAdherenceReasons.js` because nothing on the server- * renders them. The mirror exists for the same reason `riggingReasons.js` does- * — the client cannot import the server module — and this suite is what stops- * a code added on one side from rendering as the generic fallback with a fully- * green suite.- *- * It asserts COVERAGE, not label equality: there is no server-side label map- * to compare against, and inventing one nothing renders would be the thing the- * reuse rule warns about.+ * `services/scopeAdherence.js` owns the CODES and the labels live beside them+ * in `lib/scopeAdherenceReasons.js`, so there is nothing to keep in parity —+ * the client re-exports this module rather than copying it. What still needs+ * guarding is the vocabulary: a code the service can return with no label here+ * renders as the generic fallback with a fully green suite.*/import { describe, it, expect } from 'vitest';-import { JEV_FAILURE_CODES } from '../lib/jev.js';-import { SCOPE_ADHERENCE_FAILURE_CODES } from './scopeAdherence.js';+import { JEV_FAILURE_CODES } from './jev.js';+import { SCOPE_ADHERENCE_FAILURE_CODES } from '../services/scopeAdherence.js';import {SCOPE_ADHERENCE_REASONS,SCOPE_ADHERENCE_REASON_FALLBACK,scopeAdherenceReasonLabel,-} from '../../client/src/lib/scopeAdherenceReasons.js';+} from './scopeAdherenceReasons.js';describe('scope-adherence failure labels', () => {it('labels every code the service adds', () => {+ expect(SCOPE_ADHERENCE_FAILURE_CODES.length).toBeGreaterThan(0);for (const code of SCOPE_ADHERENCE_FAILURE_CODES) {expect(Object.hasOwn(SCOPE_ADHERENCE_REASONS, code), `${code} has no operator-facing label`).toBe(true);}@@ -31,7 +27,7 @@ describe('scope-adherence failure labels', () => {it('labels every failure the scorer itself can report', () => {// `scoreAdherence` forwards a `jev-*` code verbatim, so a new one in- // `lib/jev.js` silently degrades this surface to the generic fallback.+ // `lib/jev.js` would silently degrade this surface to the generic fallback.for (const code of JEV_FAILURE_CODES) {expect(Object.hasOwn(SCOPE_ADHERENCE_REASONS, code), `${code} has no operator-facing label`).toBe(true);}@@ -53,4 +49,13 @@ describe('scope-adherence failure labels', () => {expect(scopeAdherenceReasonLabel(probe), `label for ${String(probe)}`).toBe(SCOPE_ADHERENCE_REASON_FALLBACK);}});++ it('stays importable from the browser bundle', async () => {+ // The client re-exports this leaf. A single import added here (a settings+ // read, a path helper) would drag `node:` built-ins into the bundle, and+ // the failure would surface as a Vite build error, not a test.+ const { readFile } = await import('fs/promises');+ const source = await readFile(new URL('./scopeAdherenceReasons.js', import.meta.url), 'utf8');+ expect(source).not.toMatch(/^\s*import\s/m);+ });});