Skip to content

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

refactor: make the untrusted-content source list one definition both sides import

[._.]/ Adam Eivy7e976fc607eb
diff --git a/client/src/components/models/UntrustedContentPolicyPanel.jsx b/client/src/components/models/UntrustedContentPolicyPanel.jsx
index fc1c07c0bb..bd1883e614 100644
--- a/client/src/components/models/UntrustedContentPolicyPanel.jsx
+++ b/client/src/components/models/UntrustedContentPolicyPanel.jsx
@@ -3,13 +3,17 @@ import { getSettings, updateSettings } from '../../services/api';
import useProviderModels from '../../hooks/useProviderModels';
import ProviderModelSelector from '../ProviderModelSelector';
import toast from '../ui/Toast';
+import {
+ PRIVATE_UNTRUSTED_CONTENT_SOURCES,
+ UNTRUSTED_CONTENT_SOURCES,
+ UNTRUSTED_CONTENT_SOURCE_LABELS,
+} from '../../lib/untrustedContentSources';
const SOURCES = [
- ['defaults', 'Shared defaults'], ['github-issue', 'GitHub issues'], ['github-pr', 'GitHub pull requests'],
- ['stacker-news', 'Stacker News'],
- ['messages', 'Messages'], ['email', 'Email'], ['imessage', 'iMessage'], ['signal', 'Signal'],
+ ['defaults', 'Shared defaults'],
+ ...UNTRUSTED_CONTENT_SOURCES.map(source => [source, UNTRUSTED_CONTENT_SOURCE_LABELS[source] || source]),
];
-const PRIVATE_SOURCES = ['messages', 'email', 'imessage', 'signal'];
+const PRIVATE_SOURCES = PRIVATE_UNTRUSTED_CONTENT_SOURCES;
const apiProvider = provider => provider.type === 'api';
const localApiProvider = provider => {
if (!apiProvider(provider) || !URL.canParse(provider.endpoint)) return false;
diff --git a/client/src/lib/README.md b/client/src/lib/README.md
index 1b452a826d..c979e45b90 100644
--- a/client/src/lib/README.md
+++ b/client/src/lib/README.md
@@ -47,6 +47,7 @@ grep -i "what you want to do" client/src/lib/README.md
| `sheetPointers.js` | Mirror of the character-sheet pointer helpers from `server/lib/storyBible.js`. `LEGACY_SHEET_VARIANT_ID` + `readSheetPointer` / `listSheetPointers` / `applySheetPointer` for traversing both the legacy `referenceSheetImageRef` field and the `referenceSheets` map. |
| `shotContinuity.js` | The storyboards / episode-video stages' INLINE pre-render continuity warnings (#1468). `findAxisReversals` / `findShotTypeMonotony` are re-exported from `server/lib/editorial/shotContinuity.js`, the same detectors the authoritative `visual.shot-continuity` check runs; `sceneShotWarnings(scene, opts)` is the client-only composer (the server emits findings in a different shape). Pure/DOM-free. |
| `shotGrammar.js` | Storyboard shot-grammar display labels. `SHOT_TYPES` / `SCREEN_DIRECTIONS` are re-exported from `server/lib/shotGrammar.js`, so a hand-set value in the editor always passes `storyboardShotSchema`; `SHOT_TYPE_LABELS` / `SCREEN_DIRECTION_LABELS` are the client-only selects (#1468). |
+| `untrustedContentSources.js` | Untrusted-content source display labels. `UNTRUSTED_CONTENT_SOURCES` / `PRIVATE_UNTRUSTED_CONTENT_SOURCES` are re-exported from `server/lib/untrustedContentSources.js`, so the Abuse Guard panel always offers every source the server screens; `UNTRUSTED_CONTENT_SOURCE_LABELS` is the client-only select (#7680). |
| `universeStylePreset.js` | Build the client-side style preset that `composeStyledPrompt` layers on top. |
| `universeRunTag.js` | `buildUniverseSectionRenderTag(universe, kindKey, entry)` — the durable `universeRun` job tag the canon-render call sites (UniverseCanonSection, NounsStage, Story Builder characters step) pass to `generateImage` so the server auto-files the render into the universe collection AND appends it to the entry's `imageRefs[]` (no client follow-up PATCH). |
| `autopilotMilestones.js` | Series-Autopilot milestone map. `buildAutopilotMilestones(plan, progress, {terminal})` folds the run's projected plan (the `start` frame) and its live progress snapshot (`progress` frames / the status route) into ordered rows with a `MILESTONE_STATUS` each — a furthest-index cursor, so a gate the run revisits can't un-finish the milestones after it; `summarizeAutopilotMilestones(rows)` rolls them into the header meter (a settled-but-unstepped milestone counts as complete); `describeAutopilotVerification(kind, verification)` renders what a gate actually validated — shared with the panel's `frameLabel`, since the milestone row and the activity log render the same telemetry; `isStoppedTerminal(terminal)` is the one definition of "the run stopped mid-plan"; `autopilotMarkerTerminal(status)` translates a persisted `autopilot.status` into the terminal frame type the fold reads, so a map rebuilt from the marker after a reload (#4140) flags the step a paused run stopped on. Also owns `AUTOPILOT_STEP_LABELS` / `autopilotStepLabel(kind)`, the one set of human labels for conductor step kinds (shared by the map and the panel's live status line). Used by `components/pipeline/AutopilotMilestones.jsx` + `AutopilotPanel.jsx`. |
diff --git a/client/src/lib/index.js b/client/src/lib/index.js
index b8d1db9a73..99a839cfab 100644
--- a/client/src/lib/index.js
+++ b/client/src/lib/index.js
@@ -15,6 +15,7 @@ export * from './seasonStructure.js';
export * from './sheetPointers.js';
export * from './shotContinuity.js';
export * from './shotGrammar.js';
+export * from './untrustedContentSources.js';
export * from './universeBuilderCounts.js';
export * from './universeBuilderShared.js';
export * from './universeGraphLayout.js';
diff --git a/client/src/lib/untrustedContentSources.js b/client/src/lib/untrustedContentSources.js
new file mode 100644
index 0000000000..cde2290b8d
--- /dev/null
+++ b/client/src/lib/untrustedContentSources.js
@@ -0,0 +1,21 @@
+/**
+ * Untrusted-content source display labels, over the ingress vocabulary in
+ * `server/lib/untrustedContentSources.js` (#7680).
+ *
+ * The two lists are re-exported from the server leaf rather than copied, so a
+ * source the server screens is always offered by the Abuse Guard panel. A
+ * source missing from the panel is stuck on the shipped defaults with no way
+ * to reach its policy, which is how `stacker-news` shipped screened but
+ * unconfigurable. The label map below is client-only presentation.
+ */
+export { PRIVATE_UNTRUSTED_CONTENT_SOURCES, UNTRUSTED_CONTENT_SOURCES } from '../../../server/lib/untrustedContentSources.js';
+
+export const UNTRUSTED_CONTENT_SOURCE_LABELS = Object.freeze({
+ 'github-issue': 'GitHub issues',
+ 'github-pr': 'GitHub pull requests',
+ 'stacker-news': 'Stacker News',
+ messages: 'Messages',
+ email: 'Email',
+ imessage: 'iMessage',
+ signal: 'Signal',
+});
diff --git a/server/lib/README.md b/server/lib/README.md
index 6b4da29287..ede6a7fb84 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -651,6 +651,7 @@ pm` default, `NPM_CONFIG_PREFIX`, nvm/Volta) installed `codex` successfully and
| `repoIntakeActions.js` | `REPO_INTAKE_KEYS` + `normalizeRepoIntake(input)` — the opt-in post-clone agent actions a Brain capture can request for a GitHub repo URL (`malwareScan` → `/do:scan`, `learn` → a `repo-study` review). Pure half of `services/repoIntake.js` (which pulls the CoS task graph), so the link write path and the Zod schemas can import it freely. Normalizes to null when nothing was ticked, so "no intake" is never persisted onto a link. |
| `tombstones.js` | Generic timestamped tombstones (`{ <keyField>, deletedAt }`) that let an otherwise add-only peer merge represent a DELETE, so a record removed on one machine is not resurrected by a peer that still has it (#3530). `normalizeTombstones` / `recordTombstone` / `clearTombstone` / `tombstoneTimestamp` maintain the list; `mergeTombstones` unions it in both directions (newest deletion per key wins) so a delete propagates rather than only defending locally; `isTombstoned(list, key, createdAt)` suppresses a record unless its own creation stamp is strictly NEWER than the deletion; `pruneTombstones(list, records)` drops tombstones a re-created record has superseded (otherwise a stale peer copy keeps reaping it); `supersedingTimestamp(deletedAt)` stamps a re-create that lands in the same millisecond (or behind a skewed peer clock). Comparison goes through `lwwTimestamp.js`, so polarity matches every other sync merge. Key on a field that means the same thing on every machine — locally-minted ids usually do not. `DEFAULT_TOMBSTONE_LIMIT` (200) caps growth. |
| `untrustedContent.js` | Shared source policies, strict settings schema, data framing and API-only/local-private provider eligibility for untrusted GitHub and messaging content. |
+| `untrustedContentSources.js` | The ingress vocabulary alone — `UNTRUSTED_CONTENT_SOURCES` and `PRIVATE_UNTRUSTED_CONTENT_SOURCES`. Split out of `untrustedContent.js` (which reaches `zod` and `node:crypto`) so the browser can import it: the Abuse Guard panel offers exactly the sources the server screens, instead of restating them and drifting (#7680). |
| `uploadLimits.js` | Single source of truth for upload size caps — `JSON_BODY_LIMIT`/`JSON_BODY_LIMIT_BYTES` (the express.json limit applied in `index.js`), `MAX_BASE64_UPLOAD_BYTES` derived from it (base64 ×4/3, so a bigger per-route cap is unreachable), `MAX_SCREENSHOT_BYTES`. Mirrored client-side as `JSON_UPLOAD_MAX_FILE_SIZE`. |
| `userActionTypes.js` | Closed vocabulary for the operator-action ledger (`user_action_events`, #5594 / #5596): `USER_ACTION_TYPES` (CoS task/feedback/schedule + settings + instance-feature toggles + event-only creative/Brain pointers), `USER_ACTION_ACTORS` (`user` / `mind` / `schedule` / `system`), and the `isUserActionType` / `isUserActionActor` predicates. `recordUserAction` (`services/userActions.js`) throws on a type absent from the list, so a typo fails a test instead of writing a row nothing can filter on. |
| `uuid.js` | `v4()` thin wrapper over the global `crypto.randomUUID()`. Import-free, so a leaf the browser imports may reach it without a Node built-in — importable, not browser-callable: `randomUUID` needs a secure context there, so client code mints through `client/src/lib/uuid.js`. |
diff --git a/server/lib/index.js b/server/lib/index.js
index fc781beefe..8c8e0a0c2c 100644
--- a/server/lib/index.js
+++ b/server/lib/index.js
@@ -635,6 +635,7 @@ export * from './repoIntakeActions.js';
export * from './repoLinkFields.js';
export * from './tombstones.js';
export * from './untrustedContent.js';
+export * from './untrustedContentSources.js';
export * from './uploadLimits.js';
export * from './userActionTypes.js';
export * from './uuid.js';
diff --git a/server/lib/untrustedContent.js b/server/lib/untrustedContent.js
index 93961ae4e3..07adc46471 100644
--- a/server/lib/untrustedContent.js
+++ b/server/lib/untrustedContent.js
@@ -1,9 +1,10 @@
import { z } from 'zod';
import { MODEL_ABUSE_GUARD_MAX_INPUT_CHARS } from './modelAbuseGuard.js';
+import { PRIVATE_UNTRUSTED_CONTENT_SOURCES, UNTRUSTED_CONTENT_SOURCES } from './untrustedContentSources.js';
-// Channel names identify ingress, never a trust decision made by a model.
-export const UNTRUSTED_CONTENT_SOURCES = Object.freeze(['github-issue', 'github-pr', 'stacker-news', 'messages', 'email', 'imessage', 'signal']);
-export const PRIVATE_UNTRUSTED_CONTENT_SOURCES = Object.freeze(['messages', 'email', 'imessage', 'signal']);
+// Re-exported so every existing importer keeps working; the lists live in
+// their own browser-importable leaf (see untrustedContentSources.js).
+export { PRIVATE_UNTRUSTED_CONTENT_SOURCES, UNTRUSTED_CONTENT_SOURCES } from './untrustedContentSources.js';
export const DEFAULT_UNTRUSTED_CONTENT_POLICY = Object.freeze({
classifierMode: 'required', minBenignScore: 0.9,
maxInputChars: MODEL_ABUSE_GUARD_MAX_INPUT_CHARS, maxOutputChars: 32_000,
diff --git a/server/lib/untrustedContentSources.js b/server/lib/untrustedContentSources.js
new file mode 100644
index 0000000000..c57eb2d156
--- /dev/null
+++ b/server/lib/untrustedContentSources.js
@@ -0,0 +1,16 @@
+/**
+ * The untrusted-content ingress vocabulary.
+ *
+ * Its own leaf so the browser can import it: `untrustedContent.js` reaches
+ * `zod` and, through `modelAbuseGuard.js`, `node:crypto`, and the settings
+ * panel needs nothing but these two lists. A source the server screens but
+ * the panel never offers is stuck on the shipped defaults forever — its
+ * `classifierMode`, limits and provider pin are all unreachable — which is
+ * exactly how `stacker-news` was screened but unconfigurable (#7680). One
+ * definition, imported by both sides, makes that drift impossible rather
+ * than merely tested for.
+ */
+
+// Channel names identify ingress, never a trust decision made by a model.
+export const UNTRUSTED_CONTENT_SOURCES = Object.freeze(['github-issue', 'github-pr', 'stacker-news', 'messages', 'email', 'imessage', 'signal']);
+export const PRIVATE_UNTRUSTED_CONTENT_SOURCES = Object.freeze(['messages', 'email', 'imessage', 'signal']);
diff --git a/server/lib/untrustedContentSources.test.js b/server/lib/untrustedContentSources.test.js
deleted file mode 100644
index 9870ab9dba..0000000000
--- a/server/lib/untrustedContentSources.test.js
+++ /dev/null
@@ -1,39 +0,0 @@
-import { readFileSync } from 'node:fs';
-import { describe, expect, it } from 'vitest';
-import { PRIVATE_UNTRUSTED_CONTENT_SOURCES, UNTRUSTED_CONTENT_SOURCES } from './untrustedContent.js';
-
-// A source the server screens but the panel never lists is screened under the
-// shipped defaults FOREVER: `maxInputChars`, the classifier mode and the
-// provider pin are all unreachable for it. That is how `stacker-news` could be
-// added to the boundary and still be unconfigurable (#7680), so the two lists
-// are pinned to each other here rather than by eye. Read as text on purpose —
-// a server suite importing a `.jsx` component drags the client's test deps
-// into the node environment.
-const panelSource = readFileSync(new URL('../../client/src/components/models/UntrustedContentPolicyPanel.jsx', import.meta.url), 'utf8');
-const literalArray = (name) => {
- const body = panelSource.match(new RegExp(`const ${name} = \\[([\\s\\S]*?)\\];`))?.[1];
- expect(body, `${name} is no longer a literal array in the panel`).toBeTruthy();
- return [...body.matchAll(/'([^']+)'/g)].map(([, value]) => value);
-};
-
-describe('untrusted-content source parity', () => {
- it('offers every screened source in the policy panel', () => {
- const offered = literalArray('SOURCES');
- expect(offered).toContain('defaults');
- // Every id in the panel is a label/value pair, so filter to the ones the
- // server actually knows rather than asserting on the display strings.
- expect(offered.filter((value) => UNTRUSTED_CONTENT_SOURCES.includes(value)))
- .toEqual(expect.arrayContaining([...UNTRUSTED_CONTENT_SOURCES]));
- });
-
- it('mirrors the private-source set the panel gates loopback analysis on', () => {
- expect(literalArray('PRIVATE_SOURCES')).toEqual([...PRIVATE_UNTRUSTED_CONTENT_SOURCES]);
- });
-
- it('keeps public community content out of the private set', () => {
- // `stacker-news` is public: restricting it to a loopback classifier would
- // deny it the cloud providers `github-issue` is allowed to use.
- expect(UNTRUSTED_CONTENT_SOURCES).toContain('stacker-news');
- expect(PRIVATE_UNTRUSTED_CONTENT_SOURCES).not.toContain('stacker-news');
- });
-});
diff --git a/server/services/stackerNews.js b/server/services/stackerNews.js
index 985856ad1d..efb2cec52a 100644
--- a/server/services/stackerNews.js
+++ b/server/services/stackerNews.js
@@ -452,7 +452,7 @@ export async function analyzeItem(itemId) {
injectionRisk: injectionMatches.length ? 'high' : 'low', injectionMatches, sourceTrusted: false, contentLength: content.length,
// The local regexes stay a SECOND signal; `screeningCode` is what the
// policy escalates on, so an absent key means phase 1 actually passed.
- ...(screening.ok ? {} : { screeningCode: screening.code, screeningMessage: screening.message }),
+ ...(screening.ok ? {} : { screeningCode: screening.code }),
};
await persistAnalysis({ item, stage: 'ingress', provider: 'deterministic', rulesHash, result: deterministic });
diff --git a/server/services/stackerNewsScreening.test.js b/server/services/stackerNewsScreening.test.js
index 672cb21606..b9d6f09900 100644
--- a/server/services/stackerNewsScreening.test.js
+++ b/server/services/stackerNewsScreening.test.js
@@ -58,12 +58,12 @@ beforeEach(() => {
describe('Stacker News phase-1 screening', () => {
it('reaches no model — text or vision — when screening blocks the item', async () => {
screenUntrustedContent.mockResolvedValue({ ok: false, safe: false, code: 'untrusted-content-blocked', message: 'flagged' });
- const analysis = await analyzeItem('item');
+ await analyzeItem('item');
+ // Two distinct egress channels: the chat POST, and the remote image fetch
+ // the vision path performs BEFORE it posts. A block that only skipped the
+ // POST would still pull attacker-chosen media.
expect(fetchWithTimeout).not.toHaveBeenCalled();
- // The vision path fetches remote image bytes BEFORE it posts them, so a
- // block that only skipped the POST would still pull attacker-chosen media.
expect(fetchAndNormalizeStackerNewsImage).not.toHaveBeenCalled();
- expect(analysis).toMatchObject({ text: null, vision: null });
});
it('persists the screening code and escalates instead of returning allowed', async () => {