0e927c914d
* feat(desktop): port guided onboarding substrate Add seeded session creation, transcript directives, profile routing, and the shared window and pane primitives needed by the guided flow. Keep later-step mounts deferred and exclude provider selection and retry machinery. * refactor(desktop): anti-slop cleanup for substrate Assemble seed parameters in the existing create helper and use the owning transcript attribute type. Read the guaranteed gateway and connection contracts directly to remove runtime type probes and unchecked assertions. * test(desktop): create-overrides invariants Verify that reasoning and title overrides do not select a provider or model. Empty overrides and seeds add no parameters. * feat(desktop): port first-run cinematic window Play the cinematic behind the guest onboarding launch flag using bundled Collapse and JetBrains Mono. Give the native window its own controller and restore the app on skip, renderer deadman or native watchdog. Drop the perf scenario because it depends on the removed replay hook. Guided chat kickoff and app-shell gate wiring remain with their later steps. * refactor(desktop): anti-slop cleanup for cinematic Preserve audio and canvas behavior through named types and inferred results. Split the viewport node and frame drawing to keep control flow bounded. Cut comments that only repeat the code. * feat(desktop): add onboarding gate and answers stores Track cinematic, guided chat, handoff and completion in one phase record. Queue the guide after the intro and share pending kickoff work between callers. Keep existing saved answers while dropping retired preferences. Leave intro seen-state ownership with the cinematic store. * feat(desktop): port guided onboarding chat Add guided setup cards, runbooks, machine context, and onboarding presence. Connect transcript rendering and first-build progress to the desktop behind the onboarding flag. Leave session kickoff and handoff execution for the next step. * refactor(desktop): anti-slop cleanup for guided chat Keep directive and layout lookups typed. Remove unsafe test casts and isolate onboarding transcript calculations without changing the flow. * feat(desktop): connect guided onboarding to durable first-build handoff Start the guide only after its profile backend confirms bootstrap readiness. Seed or adopt the welcome chat, then transfer the first build to default with a durable receipt and explicit retry. Wire cinematic completion, screen stand-down, layout growth and progress check-ins. Save agreed preferences before creating the build and release prompt slots after storage refusal. * refactor(desktop): anti-slop cleanup for onboarding handoff Reuse the gateway request and error contracts. Isolate guide adoption and snapshot validation while preserving receipt recovery and reasoning overrides. Validate persisted receipt fields at the JSON boundary without coercion. Keep corrupt identities rejected and retain only the permitted test mocks. * fix(desktop): guided chat review fixes Wire the native machine probe so guided setup can suggest a name and offer the right first task. Restore the comments that explain the flow boundaries. The directive registration uses the launch flag to preserve ordinary chat. Ruling 6 folds active.ts into assembly to keep activity ownership together and removes the second greeting source so the seeded and visible greetings agree. * fix(desktop): handoff review fixes Probe the guide backend before switching profiles so a readiness refusal keeps classic onboarding on the current backend. Restore list-valued personalization coverage and routing rationale. Remove the obsolete setup status fixture. * chore(desktop): onboarding script cull and rehearsal recipe Document a temporary-state rehearsal using the existing onboarding flag and optional portal stand-in. Keep the main scripts unchanged and retain window growth for the guided chat. * fix(connectors): reject incomplete catalog responses * feat(gateway): scope connector controls to the owning session * feat(desktop): connect apps through native session-owned controls * feat(desktop): gate connector cards and enable free-tier access Use the launch flag before mounting connector controls so classic transcripts add no status requests. Allow existing free-tier identities through the read-only tool gateway gate and test the owning-profile RPC path with A’s launch gate. Keep authorization links out of previews. * style(desktop): format connector translations Apply Prettier to the connector copy blocks while preserving upstream translations and free-tier wording. * refactor(desktop): anti-slop cleanup for connector card Use the transcript JSON contract and concrete RPC parameters. Preserve malformed-value filtering at one string boundary and make the fixture and row types explicit. Keep connector execution and cancellation behavior unchanged. * feat(desktop): detect initial language from the OS Use the native machine locale when no supported language is saved. Preserve explicit choices and leave inferred languages out of config. * refactor(desktop): anti-slop cleanup for initial locale detection Keep unvalidated config values at the existing validation boundary. Pass no saved choice after that boundary has ruled it out, preserving locale precedence. * test(desktop): onboarding port test set Make native window tests reject duplicate IPC handlers and isolate disabled onboarding. Assert the active gate mock when onboarding re-enables. Keep the test set limited to behavior carried by the port. * fix(desktop): recover failed guide kickoff and reveal once The review found that a failed guide create stranded the solo shell and draft profile, and solo boot faded an already visible window a second time. Restore the prior route and layout, release onboarding through its existing phase record, and surface create failures. Let the film own the reveal while solo boot animates the visible resize. * fix(desktop): preserve transcript ownership across cards and handoff The review reproduced answers submitted to the focused chat, repeated questions disabled across sessions, handoff recovery using foreground identity, and mount-dependent progress history. Target each card’s own composer, scope settlement to its message and session, carry the issuing guide through handoff, and derive progress from its transcript with streaming activity. Reuse the existing owner ladder for exact and profile-only routes. * fix(gateway): preserve connector ownership with profile routing The review found that shared-primary profile metadata was rejected before connector dispatch, while desktop controls treated a missing registry id as missing ownership. Accept profile only as routing metadata and keep the live transport as authorization. Resolve card ownership through the existing exact/profile ladder, retaining ambient routing only for the single-backend case. * fix(desktop): resolve plugin roots and gate the Basic layout The review found that the first plugin build was seeded with a different installation’s fixed path, and the director ruled that flag-off layouts must match main. Resolve the running desktop’s plugin root before seeding a plugin build and register Basic only when onboarding is enabled. Keep the runbook wording and the ordinary four layout presets intact. * fix(desktop): clear review-fix slop findings The slop gate flagged an undocumented layout-data assertion and unknown-return types in the new test selectors. Record the layout registry invariant and preserve each selector’s return type. The only remaining production finding is the accepted connector-tools baseline. * fix(desktop): detect the OS language on a fresh install The review found that the merged English config default prevented the desktop from probing the OS language on a fresh install. Add an opt-in saved-values read so an absent choice remains distinct from saved English. Preserve default-valued English only for explicit language saves; unrelated settings saves must not turn a merged default into a language choice. Older backends ignore the new query options and keep returning merged English, preserving their existing desktop behavior. * test(desktop): make the flag-off layout registry test deterministic The flag-off test awaited the full controller import, pulling in the UI graph and installing application watchers just to read layout presets. That import took 9.5 seconds locally and timed out in the director's run. Move the existing trees and registration into a small layout-presets module. Production and the synchronous test use the same flag-gated registration, without starting the controller in the test. Keep the real registry invariant and dispose the test's contributions after completion. * fix(desktop): keep the transcript parser and ::ask behind the onboarding flag Register the guided chat's question card only with onboarding enabled. Restore main's whole-paragraph parser and contribution rendering when the flag is off, including its streaming prose behavior. Keep segmentation for the guided flow until B4 decides the parser's wider use. Restore main's two parser test files so its existing product and plugin contracts remain the flag-off check. * test: drop the onboarding and connector tests pending a later ticket Apply the director's ruling to remove B1's added test files and restore main's existing suites. Keep only the gateway route-reader mock contract that main's profile tests need against the shipped activation behavior; their cases and assertions stay intact. The flow's shape is not settled and B3/B4 rewrite it. The connector layer will also be reworked. The live CDP run is the flow check until a follow-up ticket brings tests back. --------- Co-authored-by: brooklyn! <brooklyn.bb.nicholson@gmail.com>
243 lines
11 KiB
TypeScript
243 lines
11 KiB
TypeScript
import { defineConfig } from 'vite'
|
|
import babel from '@rolldown/plugin-babel'
|
|
import react, { reactCompilerPreset } from '@vitejs/plugin-react'
|
|
|
|
/** React Compiler preset scoped to modules that can actually contain
|
|
* components/hooks (JSX syntax or a react-ish import). The preset's default
|
|
* code filter matches any PascalCase/use* declaration — effectively every TS
|
|
* module — which made the babel pass parse all ~1.5k source files when only
|
|
* ~750 are React-bearing. */
|
|
function compilerPreset() {
|
|
const preset = reactCompilerPreset()
|
|
preset.rolldown.filter.code = /\/>|<\/|from\s*['"][^'"]*react/
|
|
return preset
|
|
}
|
|
import tailwindcss from '@tailwindcss/vite'
|
|
import path from 'path'
|
|
import fs from 'fs'
|
|
import { createRequire } from 'module'
|
|
|
|
// `hgui` symlinks a worktree's node_modules to the main checkout. Vite realpaths
|
|
// those before enforcing server.fs.allow, so codicon/font assets resolve outside
|
|
// the worktree root and 404. Whitelist the real node_modules locations.
|
|
const real = (p: string): string | null => {
|
|
try {
|
|
return fs.realpathSync(p)
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
const fsAllow = [
|
|
...new Set(
|
|
[
|
|
path.resolve(__dirname, '../..'),
|
|
real(path.resolve(__dirname, 'node_modules')),
|
|
real(path.resolve(__dirname, '../../node_modules'))
|
|
].filter((p): p is string => p !== null)
|
|
)
|
|
]
|
|
|
|
// React refuses to run when `react` and `react-dom` come from two different
|
|
// installed copies ("Minified React error #527" — a blank window, since it
|
|
// throws before the first paint). Both packages are pinned to one version in
|
|
// this workspace's package.json, but npm hoists whatever *it* considers
|
|
// compatible to the monorepo root: a root dependency whose react peer is a
|
|
// loose range (e.g. `^18 || ^19`) pulls the newest react up there, while
|
|
// react-dom stays at the pinned one. `^19.2.7` accepts `19.2.8`, so npm never
|
|
// warns. Resolving from this workspace instead of a hardcoded root path yields
|
|
// the versions declared here — npm nests a copy under the workspace exactly
|
|
// when the hoisted one differs, so the pair can only ever match.
|
|
const requireFromApp = createRequire(path.join(__dirname, 'vite.config.ts'))
|
|
const reactDir = path.dirname(requireFromApp.resolve('react/package.json'))
|
|
const reactDomDir = path.dirname(requireFromApp.resolve('react-dom/package.json'))
|
|
|
|
// The dev-only render/state churn counters (src/debug) must be imported
|
|
// STATICALLY above react-dom — react-dom captures the devtools hook at module
|
|
// init, so a dynamic import lands too late and observes zero commits. A static
|
|
// side-effect import can't be tree-shaken, so instead the whole graph is
|
|
// aliased out of any non-dev build. `command === 'serve'` covers `vite dev`;
|
|
// the perf harness opts a production build back in with VITE_PERF_PROBE=1.
|
|
const debugEntry = (command: string, env: Record<string, string>) =>
|
|
command === 'serve' || env.VITE_PERF_PROBE === '1'
|
|
? path.resolve(__dirname, './src/debug/dev-only.ts')
|
|
: path.resolve(__dirname, './src/debug/dev-only.noop.ts')
|
|
|
|
// The emoji picker (frimousse) fetches `<emojibaseUrl>/<locale>/data.json` at
|
|
// runtime. Its default is a CDN; Electron must work offline, so serve the
|
|
// bundled emojibase-data package at a stable local path instead — middleware
|
|
// in dev, emitted assets in the build. Only the files a locale actually needs.
|
|
const emojibaseDir =
|
|
real(path.resolve(__dirname, 'node_modules/emojibase-data')) ??
|
|
real(path.resolve(__dirname, '../../node_modules/emojibase-data'))
|
|
|
|
const EMOJIBASE_PATH = /^[a-z-]+\/(data|messages|shortcodes\/emojibase)\.json$/
|
|
|
|
const emojibaseAssets = () => ({
|
|
name: 'hermes:emojibase-assets',
|
|
configureServer(server: {
|
|
middlewares: { use: (route: string, handler: (req: any, res: any, next: () => void) => void) => void }
|
|
}) {
|
|
server.middlewares.use('/emojibase', (req, res, next) => {
|
|
const rel = (req.url ?? '').split('?')[0].replace(/^\/+/, '')
|
|
if (!emojibaseDir || !EMOJIBASE_PATH.test(rel)) return next()
|
|
fs.readFile(path.join(emojibaseDir, rel), (err: unknown, buf: Buffer) => {
|
|
if (err) return next()
|
|
res.setHeader('Content-Type', 'application/json')
|
|
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable')
|
|
res.end(buf)
|
|
})
|
|
})
|
|
},
|
|
generateBundle(this: { emitFile: (asset: { type: 'asset'; fileName: string; source: Uint8Array }) => void }) {
|
|
if (!emojibaseDir) return
|
|
for (const rel of ['en/data.json', 'en/messages.json', 'en/shortcodes/emojibase.json']) {
|
|
this.emitFile({
|
|
type: 'asset',
|
|
fileName: `emojibase/${rel}`,
|
|
source: fs.readFileSync(path.join(emojibaseDir, rel))
|
|
})
|
|
}
|
|
}
|
|
})
|
|
|
|
export default defineConfig(({ command }) => ({
|
|
base: './',
|
|
plugins: [react(), babel({ presets: [compilerPreset()] }), tailwindcss(), emojibaseAssets()],
|
|
css: {
|
|
// Pin an explicit (empty) PostCSS config. Tailwind is handled entirely by
|
|
// `@tailwindcss/vite`, so the renderer needs no PostCSS plugins — and
|
|
// without this, Vite's `postcss-load-config` walks UP the filesystem
|
|
// looking for a stray `postcss.config.*` / `tailwind.config.*`. The desktop
|
|
// build runs from inside the user's home tree (e.g.
|
|
// `C:\Users\<name>\AppData\Local\hermes\hermes-agent\apps\desktop`), so an
|
|
// unrelated Tailwind v3 config higher up the tree gets picked up and
|
|
// reprocesses our v4 stylesheet, failing the build with
|
|
// "`@layer base` is used but no matching `@tailwind base` directive is
|
|
// present." Pinning the config makes the build hermetic.
|
|
postcss: { plugins: [] }
|
|
},
|
|
build: {
|
|
// The renderer intentionally ships FEW chunks (not one, not thousands):
|
|
// · `codeSplitting: false` (the old setup) inlines every `lazy()` /
|
|
// dynamic import into the entry, so heavyweight lazy-only deps
|
|
// (mermaid, shiki grammars, katex) are parsed + evaluated on every
|
|
// cold start even though nothing rendered them. By the time the
|
|
// bundle hit ~28 MB that eval was ~1s of launch on an M-series.
|
|
// · Default splitting emits a chunk per shiki grammar/theme — thousands
|
|
// of files, which electron-builder OOMs scanning (#38888).
|
|
// `advancedChunks` is the middle ground: heavyweight libraries merge into
|
|
// a handful of named vendor chunks loaded on first use, app-level dynamic
|
|
// imports stay lazy, and the file count stays in the tens.
|
|
chunkSizeWarningLimit: 25000,
|
|
rolldownOptions: {
|
|
output: {
|
|
advancedChunks: {
|
|
groups: [
|
|
// Shared foundations FIRST (first match wins): an unmatched
|
|
// module shared by the entry and a heavy chunk gets merged INTO
|
|
// the heavy chunk, and the entry then statically imports 19 MB of
|
|
// shiki just to reach react/hast utils — putting the heavy chunk
|
|
// right back on the boot path.
|
|
//
|
|
// @tanstack/react-query is here for the same reason react-router
|
|
// is: it carries MODULE-LEVEL context (QueryClientContext) that
|
|
// the entry's QueryClientProvider and every lazy chunk's useQuery
|
|
// must share. Left to rolldown's merge heuristics, an unmatched
|
|
// shared module can be inlined into a lazy chunk — the packaged
|
|
// app then runs TWO react-query runtimes, the provider's context
|
|
// is invisible to the other copy, and useQuery throws "No
|
|
// QueryClient set, use QueryClientProvider to set one" on the
|
|
// launch path (#95560). Grouping it forces one shared instance.
|
|
{
|
|
name: 'vendor-react',
|
|
test: /node_modules[\\/](react|react-dom|scheduler|react-router|@tanstack[\\/]react-query)[\\/]/
|
|
},
|
|
{
|
|
name: 'vendor-md',
|
|
test: /node_modules[\\/](property-information|hast-util-[^\\/]+|mdast-util-[^\\/]+|micromark[^\\/]*|unist-util-[^\\/]+|vfile[^\\/]*|unified|stringify-entities|space-separated-tokens|comma-separated-tokens|zwitch|html-void-elements|devlop|style-to-js|style-to-object|clsx)[\\/]/
|
|
},
|
|
// Shared utility packages the entry ALSO uses — kept out of the
|
|
// heavy groups for the same boot-path reason.
|
|
{
|
|
name: 'vendor-util',
|
|
test: /node_modules[\\/](lodash-es|es-toolkit|uuid|dayjs|d3-array|d3-color|d3-force|d3-interpolate|d3-time[^\\/]*|dompurify|stylis)[\\/]/
|
|
},
|
|
// One chunk per heavyweight, lazy-only library family.
|
|
// @streamdown/code lives WITH shiki because it statically imports
|
|
// the full shiki bundle.
|
|
{
|
|
name: 'mermaid',
|
|
test: /node_modules[\\/](mermaid|cytoscape|dagre|khroma|elkjs|d3|d3-[^\\/]+|@mermaid-js)[\\/]/
|
|
},
|
|
{
|
|
name: 'shiki',
|
|
test: /node_modules[\\/](shiki|@shikijs|react-shiki|@streamdown[\\/]code|oniguruma-to-es|oniguruma-parser|regex(-[^\\/]+)?)[\\/]/
|
|
},
|
|
{ name: 'katex', test: /node_modules[\\/]katex[\\/]/ }
|
|
]
|
|
}
|
|
}
|
|
}
|
|
},
|
|
// driver.js only enters the graph through the tour's DYNAMIC import chain
|
|
// (lib/tour/run-tour.ts), so the dep scanner never sees it at startup. Left
|
|
// alone, first use registers it as a missing dep at runtime — which (a)
|
|
// esbuild-prebundles the `?raw` IIFE import as a JS module, breaking the
|
|
// raw-text transform ("does not provide an export named 'default'"), and
|
|
// (b) triggers Vite's "new dependencies optimized" full page reload mid-
|
|
// session. It's pure ESM with no CJS deps, so serving it unoptimized is
|
|
// free. Query and bare forms all listed — exclusion matches exact ids.
|
|
optimizeDeps: {
|
|
exclude: [
|
|
'driver.js',
|
|
'driver.js/dist/driver.js.iife.js',
|
|
'driver.js/dist/driver.js.iife.js?raw',
|
|
'driver.js/dist/driver.css?raw'
|
|
]
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@/debug/dev-only': debugEntry(command, process.env as Record<string, string>),
|
|
'@': path.resolve(__dirname, './src'),
|
|
'@hermes/plugin-sdk': path.resolve(__dirname, './src/sdk/index.ts'),
|
|
'@hermes/shared/billing': path.resolve(__dirname, '../shared/src/billing-types.ts'),
|
|
'@hermes/shared': path.resolve(__dirname, '../shared/src'),
|
|
// The tour tool's preview surface injects driver.js's prebuilt IIFE into
|
|
// the pane's guest page as raw source; the package's exports map doesn't
|
|
// expose that dist file (nor ./package.json), so resolve the main entry
|
|
// (dist/driver.js.cjs) and point at its sibling. Both keys on purpose:
|
|
// alias matching is exact, and the id reaches it with the `?raw` query
|
|
// still attached in dev but stripped in some build paths.
|
|
'driver.js/dist/driver.js.iife.js?raw': `${path.join(
|
|
path.dirname(requireFromApp.resolve('driver.js')),
|
|
'driver.js.iife.js'
|
|
)}?raw`,
|
|
'driver.js/dist/driver.js.iife.js': path.join(
|
|
path.dirname(requireFromApp.resolve('driver.js')),
|
|
'driver.js.iife.js'
|
|
),
|
|
react: reactDir,
|
|
'react-dom': reactDomDir,
|
|
'react/jsx-dev-runtime': path.join(reactDir, 'jsx-dev-runtime.js'),
|
|
'react/jsx-runtime': path.join(reactDir, 'jsx-runtime.js')
|
|
},
|
|
dedupe: ['react', 'react-dom', 'react-router', '@tanstack/react-query']
|
|
},
|
|
server: {
|
|
host: '127.0.0.1',
|
|
port: 5174,
|
|
strictPort: true,
|
|
warmup: {
|
|
clientFiles: ['./src/components/intro-reveal/intro-root.tsx']
|
|
},
|
|
fs: {
|
|
allow: fsAllow
|
|
}
|
|
},
|
|
preview: {
|
|
host: '127.0.0.1',
|
|
port: 4174
|
|
}
|
|
}))
|