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: detect Vite config in unlisted subdirs (e.g. admin/) so Dev-UI host warning stops firing falsely
Adam Eivy3979127bc0c9
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 12e0e0cb2e..348740b100 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -125,3 +125,4 @@- **Fix Element Flash: pressing Enter/Return after answering now advances to the next question.** In the Element Flash recall test (`ElementsSong.jsx`), the Enter-to-submit handler lived only on the answer `<input>`, which unmounts once the result is shown — so a second Enter did nothing and the user had to click "Next" to continue. `ElementFlashMode` now binds a window `keydown` listener while a result is showing (input unmounted) that advances on Enter/Return, mirroring the "Next" button; the `next()` handler was hoisted above the completion early-return so the effect can reference it without breaking hook order. The listener ignores auto-repeat (`e.repeat`) and any Enter that a focused control or open overlay already owns (`e.target.closest('button, a, input, textarea, select, [role="dialog"], [role="menu"], [contenteditable]')`) — so a keyboard user tabbed to the Back/Next button doesn't double-advance, and an Enter meant for the command palette doesn't leak through to the quiz. Tests drive answer → Enter (submit) → Enter (advance) asserting the counter increments, and pin that an Enter fired from the focused Next button is not hijacked by the window listener.- **[issue-2657] Autonomous Creation Engine (Phase 1) — schedule the Creative Director with a recurring, feedback-ready creative brief.** New first-class `CreativeCommission` entity: a standing brief (`{ name, enabled, targetAbility, brief, schedule, generation }`) that fires on a cron cadence and drives the existing Creative Director *directive* pipeline unattended — "every night at 2am, make me something surreal." Commissions are `db-primary` (per `docs/STORAGE.md`): one row per commission in the machine-local `creative_commissions` PostgreSQL table (full record in `data` JSONB, adapter `server/services/creativeCommissions/db.js`, selected pg-vs-file exactly like universeBuilder so a `NODE_ENV=test`/`MEMORY_BACKEND=file` install keeps a file escape hatch). No `sync_sequence`/tombstone — deletes are hard deletes, mirroring `tribe`. They are deliberately **not** federated in Phase 1 — the same rationale as `seriesAutopilotScheduler`'s settings-based schedules, since a schedule that synced across peers would double-run on every machine (federation with a per-peer "home" gate is Phase 2). A new `commissionScheduler.js` (modeled on `seriesAutopilotScheduler`) arms one `eventScheduler` cron per enabled commission; on fire it re-reads the commission + creative-autonomy config, builds a CD directive from the brief via the pure `buildCommissionDirective` (which already folds a last-N feedback digest so Phase 2 only needs the rate surface), mints a directive-driven CD video project, and nudges `advanceAfterPlanStepSettled` so each plan step runs through the gated `dispatchCreativeTool`. Cold-bootstrap compliant per the AI Provider Usage Policy: boot only *arms* crons (nothing fires until a cadence elapses), and every fire gates on creative autonomy `execute` **and** the daily `cos` budget before spawning anything — an `off`/`dry-run` or over-budget install records a `skipped` run and generates nothing. Full REST CRUD at `/api/creative-commission` (Zod-validated create/update, DAILY/WEEKLY/CUSTOM schedules composed to cron with an authoritative `isValidCron` check in the service, `generation` schema with no object-level default so an empty PATCH still 400s the "at least one field" refine), a scheduler re-sync after every mutation, and a new `/creative-commission` Create-suite page: list + deep-linked create/edit Drawer (`/creative-commission/:id`, `/new`) with pause/resume, inline-confirm delete, and per-run history — registered in `NAV_COMMANDS` (⌘K + voice) and the sidebar. Phase 1 restricts `targetAbility` to `video` (the enum widens with the ability adapter in Phase 3/4) so a user can't create a commission that silently never runs. Refs #2657 — Phases 2–5 (feedback loop, all-ability adapter, music tool, genre taxonomy) remain. New unit + route + PG-adapter tests cover cron composition, the feedback digest, the store CRUD/sanitizer, the autonomy/budget gates, the no-boot-generation guarantee, the route contract, and the `creative_commissions` row round-trip (verbatim readback / upsert with created_at preserved / list order / hard delete). Scheduler-vs-request writes serialize on the facade's shared per-id write queue (`createRecordWriteQueue`), identical to universeBuilder/storyBuilder.+- **Fix the Dev-UI "Vite host will be blocked" warning firing for apps whose vite config lives in an unlisted subdir.** `findViteConfig` only probed a hardcoded subdir allowlist (`client/`, `frontend/`, `web/`, …) plus each managed process's `cwd`. Apps that keep their Vite client elsewhere — e.g. an `admin/` dir — and whose stored process records carry no `cwd` produced a false "no vite.config was found" banner even though the config already set `allowedHosts: true` and the Dev UI opened fine over Tailscale. `findViteConfig` now falls back to a bounded breadth-first scan of the repo (depth ≤3, skipping `node_modules`/`.git`/build/vendor dirs, shallowest match wins) when the fast-path subdirs miss, so a config in any reasonable location is detected and the host-allow check reflects reality. `admin` also added to the fast-path list. New tests cover root, unlisted-subdir (`admin/`), nested, `node_modules`-ignore, and the end-to-end host-allowed status.diff --git a/server/lib/viteAllowedHosts.js b/server/lib/viteAllowedHosts.jsindex b649e074f2..023d39ccf7 100644--- a/server/lib/viteAllowedHosts.js+++ b/server/lib/viteAllowedHosts.js@@ -15,6 +15,7 @@* can fall back to an LLM-assisted fix instead of corrupting the file.*/import { join } from 'path';+import { readdir } from 'fs/promises';import { tryReadFile } from './fileUtils.js';// Vite resolves its config from any of these (TS variants included). Order@@ -96,8 +97,49 @@ export function hostIsAllowed(parsed, hostname) {// Common locations a vite config sits in relative to an app's repo root. Many// PortOS-managed apps are monorepos whose Vite client lives under `client/`-// (PortOS itself does), so the repo root alone misses them.-const VITE_CONFIG_SUBDIRS = ['', 'client', 'frontend', 'web', 'app', 'ui', 'apps/web', 'packages/client'];+// (PortOS itself does), so the repo root alone misses them. This is only a+// fast-path ordering hint — `findViteConfig` falls back to a bounded recursive+// scan (`discoverViteConfig`) so a config in an unlisted subdir (e.g. `admin/`)+// is still found instead of reporting a false "no vite.config" warning.+const VITE_CONFIG_SUBDIRS = ['', 'client', 'frontend', 'web', 'app', 'ui', 'admin', 'apps/web', 'packages/client'];++// Directories that never hold an app's own vite config but are expensive to walk+// (or would surface a dependency's config). Skipped by the recursive fallback.+const VITE_SCAN_IGNORE_DIRS = new Set([+ 'node_modules', '.git', '.hg', '.svn', 'dist', 'build', 'out', 'coverage',+ '.next', '.nuxt', '.cache', '.turbo', '.vite', 'tmp', 'temp', 'vendor', '.venv'+]);++/**+ * Breadth-first scan for a vite config under `root`, skipping heavy/vendor dirs.+ * Breadth-first so the shallowest (most likely the app's own) config wins, and+ * bounded by `maxDepth` so a deep monorepo can't turn this into a full-tree walk.+ * Returns the same `{ path, filename, dir }` shape as `findViteConfig` (content+ * read by the caller), or `null` when nothing is found within the depth budget.+ */+async function discoverViteConfig(root, { maxDepth = 3 } = {}) {+ let level = [root];+ for (let depth = 0; depth <= maxDepth && level.length; depth++) {+ const next = [];+ for (const dir of level) {+ const entries = await readdir(dir, { withFileTypes: true }).catch(() => null);+ if (!entries) continue;+ // Match a config file at this level before descending, so shallower wins.+ for (const filename of VITE_CONFIG_FILENAMES) {+ if (entries.some((e) => e.isFile() && e.name === filename)) {+ return { path: join(dir, filename), filename, dir };+ }+ }+ for (const e of entries) {+ if (e.isDirectory() && !e.name.startsWith('.') && !VITE_SCAN_IGNORE_DIRS.has(e.name)) {+ next.push(join(dir, e.name));+ }+ }+ }+ level = next;+ }+ return null;+}/*** Locate an app's vite config on disk. Returns `{ path, filename, content, dir }`@@ -123,6 +165,16 @@ export async function findViteConfig(repoPath, { extraDirs = [] } = {}) {if (content != null) return { path, filename, content, dir };}}+ // Fast-path subdirs missed it — fall back to a bounded recursive scan so a+ // config in an unlisted subdir (critical-mass keeps its Vite client in+ // `admin/`) is still detected instead of a false "no vite.config" warning.+ if (repoPath) {+ const found = await discoverViteConfig(repoPath);+ if (found) {+ const content = await tryReadFile(found.path);+ if (content != null) return { ...found, content };+ }+ }return null;}diff --git a/server/lib/viteAllowedHosts.test.js b/server/lib/viteAllowedHosts.test.jsindex 003d783f83..a625b48f6b 100644--- a/server/lib/viteAllowedHosts.test.js+++ b/server/lib/viteAllowedHosts.test.js@@ -1,8 +1,13 @@-import { describe, it, expect } from 'vitest';+import { describe, it, expect, beforeEach, afterEach } from 'vitest';+import { mkdtemp, mkdir, writeFile, rm } from 'fs/promises';+import { tmpdir } from 'os';+import { join } from 'path';import {parseAllowedHosts,hostIsAllowed,- rewriteAllowedHosts+ rewriteAllowedHosts,+ findViteConfig,+ checkViteHost} from './viteAllowedHosts.js';describe('parseAllowedHosts', () => {@@ -156,3 +161,60 @@ export default defineConfig(({ mode }) => ({expect(out.ok).toBe(false);});});++describe('findViteConfig', () => {+ let repo;+ const ALLOW_ALL = `import { defineConfig } from 'vite';+export default defineConfig({ server: { allowedHosts: true } });`;++ beforeEach(async () => {+ repo = await mkdtemp(join(tmpdir(), 'vite-cfg-'));+ });+ afterEach(async () => {+ await rm(repo, { recursive: true, force: true });+ });++ it('finds a config at the repo root', async () => {+ await writeFile(join(repo, 'vite.config.js'), ALLOW_ALL);+ const cfg = await findViteConfig(repo);+ expect(cfg?.filename).toBe('vite.config.js');+ expect(cfg?.dir).toBe(repo);+ });++ it('finds a config in an unlisted subdir via recursive fallback (critical-mass admin/)', async () => {+ // `admin` is the critical-mass Vite client dir — the false-negative that+ // produced a bogus "no vite.config was found" warning.+ await mkdir(join(repo, 'admin'), { recursive: true });+ await writeFile(join(repo, 'admin', 'vite.config.js'), ALLOW_ALL);+ const cfg = await findViteConfig(repo);+ expect(cfg?.path).toBe(join(repo, 'admin', 'vite.config.js'));+ });++ it('finds a config nested two levels deep', async () => {+ await mkdir(join(repo, 'packages', 'dashboard'), { recursive: true });+ await writeFile(join(repo, 'packages', 'dashboard', 'vite.config.ts'), ALLOW_ALL);+ const cfg = await findViteConfig(repo);+ expect(cfg?.path).toBe(join(repo, 'packages', 'dashboard', 'vite.config.ts'));+ });++ it('ignores configs inside node_modules', async () => {+ await mkdir(join(repo, 'node_modules', 'some-dep'), { recursive: true });+ await writeFile(join(repo, 'node_modules', 'some-dep', 'vite.config.js'), ALLOW_ALL);+ const cfg = await findViteConfig(repo);+ expect(cfg).toBeNull();+ });++ it('returns null when no config exists', async () => {+ const cfg = await findViteConfig(repo);+ expect(cfg).toBeNull();+ });++ it('reports host allowed for an admin/ config that allows all hosts', async () => {+ await mkdir(join(repo, 'admin'), { recursive: true });+ await writeFile(join(repo, 'admin', 'vite.config.js'), ALLOW_ALL);+ const status = await checkViteHost(repo, 'void.taile8179.ts.net');+ expect(status.hasViteConfig).toBe(true);+ expect(status.allowsAll).toBe(true);+ expect(status.hostAllowed).toBe(true);+ });+});