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

Merge remote-tracking branch 'origin/main' into claim/issue-2264

Adam Eivy126c8540dd31
diff --cc .changelog/NEXT.md
index f882095628,94d9a7c3a1..0a220717d6
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@@ -152,6 -152,8 +152,10 @@@
- **[issue-2175] Generation-side character framework + structure doctrine (CWQE Phase 10 remainder).** Following the worldbuilding-doctrine slice (#2219), the character-generation and structure-planning prompts now teach the craft up front. The character bible gains the Ghost → Wound → Lie → Want → Need chain (with interlock checks: state the Lie in one sentence; the Need/Truth is its direct opposite; the Ghost causally explains the Lie), a declared arc type (positive/negative/flat), the Three Sliders (proactivity/likability/competence 1–10, rule: HIGH on ≥2 or one-with-growth; all-low = boring, all-high = Mary Sue), and a secrets list — all OPTIONAL so pre-#2175 records round-trip unchanged (`server/lib/storyBible.js` sanitizer + Zod-shape parity via the existing `canonArrayField` sanitize-on-write, client mirror in `client/src/lib/bibleLimits.js`, character-sheet UI in `CharacterDetailEditor.jsx` with `htmlFor`/`id` pairing, and no-clobber merge in `universeCharacterExpand.js` for the AI-expand path). The `character.consistency` / `arc.*` editorial checks now receive the authored Lie/Want/Need/arc-type when present (via `canonCharacterTraitsSummary`) so they reconcile plan-vs-delivery instead of inferring both. Structure prompts gain lean doctrine: `pipeline-season-episodes.md` a try-fail mandate (60%+ of middle episodes end "Yes, but"/"No, and"), beat rules (Catalyst external; Break Into Two a protagonist choice; All Is Lost includes a death — literal or of a hope/relationship/identity) and an active-climax rule; `pipeline-arc-overview.md` MICE-style thread nesting (threads close in reverse order of opening; name the opening/closing thread per season). Shipped-template edits ship to existing installs via hash-keyed migrations 171/172/173 (with the drift-cross-sync of prior owners 003/005/019/027/166). Remaining Phase 10 items (Le Guin style doctrine into the style-guide flow) stay tracked on #2175.
+ - **[issue-2160] Bulk-history importer for Google Takeout Location History → `place.visit` events, on the shared import seam.** The `/timeline` page gains a collapsible "Import Google location history" panel alongside the Spotify one: upload the Takeout "Location History (Timeline)" ZIP (or a single `Semantic Location History` JSON) → preview parsed visit/place counts + date-range + top places → confirm, and every place visit lands as an idempotent `place.visit` event (source `location`) via the existing `recordEvents()` infra (dedupe on place identity + visit start, so re-imports and overlapping exports never double-count). Both export vintages parse: classic server-side Timeline (`timelineObjects[].placeVisit` with E7 coords and ISO or epoch-ms durations) and the 2024+ on-device export (`semanticSegments[].visit.topCandidate` with `latLng` strings). Travel/activity segments carry no "where was I" signal and are dropped; the raw `Records.json` GPS dump is deliberately skipped. The two importers now share ONE seam: a generic `ActivityImportPanel` (pick → preview → confirm, stale-response-guarded) that Spotify + location wrap thinly, one `importHandler` route factory on `/api/timeline`, and one `importFile` client wrapper — so the remaining sources are small follow-ups. (`server/services/takeoutLocationImport.js`, `server/routes/timeline.js`, `client/src/services/apiTimeline.js`, `client/src/components/timeline/{ActivityImportPanel,TakeoutLocationImportPanel,SpotifyImportPanel}.jsx`, `client/src/pages/Timeline.jsx`)
+
- **[issue-2160] Bulk-history importer for Spotify extended streaming history + shared import seam.** The `/timeline` page gains a collapsible "Import Spotify history" panel: upload the privacy-download ZIP (or a single `Streaming_History_Audio_*.json`) → preview parsed counts/date-range/top-artists → confirm, and every play lands as an idempotent `media.listen` event via the existing `recordEvents()` infra (dedupe on track-uri + played-at, so re-imports and overlapping exports never double-count). Both the modern extended-history shape (`ts`/`ms_played`/`master_metadata_*`) and the legacy `StreamingHistory*.json` shape (`endTime`/`artistName`/`trackName`/`msPlayed`) are parsed; legacy offset-less UTC timestamps are anchored to UTC so a server west of UTC can't shift the listen into the wrong day. The route reuses the streaming `multipart.js` parser + `zipStream.js` (no new deps; the JSON parser is hand-written), Zod-validates the `preview` flag, and always unlinks the temp upload. This is one slice of the larger backfill issue. (`server/services/spotifyImport.js`, `server/routes/timeline.js`, `client/src/services/apiTimeline.js`, `client/src/components/timeline/SpotifyImportPanel.jsx`, `client/src/pages/Timeline.jsx`)
+- **[issue-2264] Image Cleaner GPU FLUX diffusion round-trip + resolution-aware options + save-to-gallery.** Completes the composable Image Cleaner (predecessor #1763): the `/devtools/image-clean` page can now run the higher-reliability GPU FLUX img2img round-trip, not just the CPU light pass. The GPU render is GPU-serialized through `mediaJobQueue` (two concurrent FLUX renders OOM the box), so for `?diffusion=gpu` the route stages the already-sync-cleaned bytes to a non-gallery temp dir, enqueues a job through the SAME regen seam the lightbox `/regenerate` flow uses (`resolveRegenBackend` / `buildRegenParams` / `clampRegenDimensions` / `enqueueJob`), and returns HTTP 202 + a `jobId`; the client tracks progress via the existing media-job channel (`useMediaJobProgress`), then GETs the finished bytes from a result endpoint. A non-gallery render seam was factored out of `generateImage` (`resolveOutputPlacement` + an `outputTarget` param): the cleaner renders to `data/image-clean-tmp/` with **no sidecar** and the gallery `completed` index/federate hooks suppressed, so a clean pass never pollutes the gallery by default — the lightbox gallery-write + lineage/variant behavior is untouched. The finished result is ephemeral; an explicit "Save to gallery" action promotes it via `saveUploadedGalleryImage`. Resolution-aware diffusion options land in the page: a GPU/CPU sub-mode selector auto-picked by hardware (`getRegenAvailability()`), a strength slider bounded by the server's `strengthMin`/`strengthMax`, an optional max-render-MP override, a render-budget warning when the source exceeds the FLUX attention budget, and a resolution-squeeze note. The ignore-zone preserve-region mask (#1763) applies to the GPU sub-mode too — the original (oriented) pixels are composited back over the diffused frame after the render. A short-grace age-gated GC (`imageCleanTmpGc.js`) sweeps the temp working files. (`server/routes/imageClean.js`, `server/services/imageGen/cleanGpu.js`, `server/services/imageGen/local.js`, `server/services/imageGen/regen.js`, `server/services/imageCleanTmpGc.js`, `server/lib/fileUtils.js`, `client/src/pages/ImageClean.jsx`, `client/src/services/apiMedia.js`)
++
+ - **[issue-2262] Layered Intelligence Loop — deterministic backbone (server slice).** A perpetual, per-managed-app self-improvement loop that runs as an Engine-B autonomous script job (`job-layered-intelligence`, off by default). On its schedule the handler sweeps `getActiveApps()` and, for each app whose `layeredIntelligence.enabled === true` and whose per-app interval has elapsed, runs four layers: GATHER (reads enabled sources — GOALS.md, CoS `learning.json` metrics, HEALTH_REPORT.md, PLAN.md, open tracker issues, plus app-declared `file` custom sources), REASON (`callProviderAISimple` against the active/overridden provider with a JSON-only prompt), DECIDE (deterministic scope-gate + slug/label dedup against live tracker state), and ACT (files exactly ONE issue via the app's resolved work tracker, and optionally pauses the app on a blocking issue). The reasoning model never touches code — it returns structured JSON and every side effect is deterministic handler code, so the "model must not make direct code changes" contract holds by construction. Dedup and pause are fully tracker-derived (a `<!-- lil-slug: … -->` marker + `layered-intelligence` / `layered-intelligence:blocking` labels; closed-issue suppression pinned at 30 days) — the only local state is per-app `lastRunAt` bookkeeping. Meta/self proposal scopes (`loop-meta` / `portos-self`) are double-enforced to PortOS-only so a hallucinated or hand-edited scope can't file against the loop from someone else's app. GitHub (`gh`) and GitLab (`glab`) forge filing + `plan`-tracker PLAN.md append are implemented; ships via the `DEFAULT_JOBS` catalog (merged into existing installs on boot by `applyAdditiveFields`) and the per-app config accessor's default (all sources on; PortOS gets the meta/self scopes) — so no seed file or migration is needed. Off by default; only runs as a user-enabled scheduled automation (no cold-bootstrap LLM calls). (`server/services/layeredIntelligence.js`, `server/services/autonomousJobs/layeredIntelligenceHandler.js`, `server/services/autonomousJobs/scriptHandlers.js`, `server/services/autonomousJobs/defaults.js`, `server/services/apps.js`, `server/lib/validation.js`)