Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .agents/skills/skills-lock.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
".agents/skills/sweet-mode": {
"repo": "https://github.com/SweetRetry/skills",
"path": "web-design/sweet-mode",
"commit": "879e51e249f2c3ef02e5a1b7b2b3c04be3599c48",
"repo": "https://github.com/SweetRetry/retry-kit",
"path": "skills/web-design/sweet-mode",
"commit": "4b750407f344128a22d4b28acdc7c619e3ffdd04",
"hash": "030f7311e814f696265e4747f09804177e7b7c011c845b542f69c74e8ac2c010"
}
}
5 changes: 5 additions & 0 deletions .agents/skills/void/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ the app's existing saved destination, including when the target project is new.
guides and use `void info` to preserve resource names and instance keys.
- Declare application environment keys in `env.ts` and access them through
`void/env`; follow `docs/guide/env-vars.md` for local and production values.
- In Pages navigation, style the current link with `Link`'s `aria-current` and `data-void-active`
attributes (`activeMatch="prefix"` for sections) instead of comparing `useRouter().path`; see
`docs/guide/pages-routing/overview.md#active-links`. Show a loading state on
the clicked link with `data-void-pending` instead of matching `useNavigation().location`
yourself; see `docs/guide/pages-routing/overview.md#pending-links`.
- For platform setup, follow the pages linked from
`docs/guide/self-hosted-platform.md`. Use `void platform list` to find the
installation slug for maintenance. For recovery, use its documented resume
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ coverage
.tanstack
.void
.wrangler
.cloudflare
.void-wrangler.jsonc
*.tsbuildinfo

Expand Down
18 changes: 9 additions & 9 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@
},
"dependencies": {
"@tanstack/react-router": "^1.170.46",
"@tanstack/react-start": "^1.169.4",
"@tanstack/react-start": "^1.169.5",
"@workspace/ui": "workspace:*",
"lucide-react": "^1.66.0",
"motion": "^14.9.0",
"lucide-react": "^1.70.0",
"motion": "^14.10.1",
"react": "^19.3.1",
"react-dom": "^19.3.1",
"sonner": "^2.0.8",
"streamdown": "^2.7.1",
"zod": "^4.6.7"
},
"devDependencies": {
"@tailwindcss/vite": "^4.3.3",
"@tailwindcss/vite": "^4.3.5",
"@types/react": "^19.3.0",
"@types/react-dom": "^19.3.0",
"@vitejs/plugin-react": "^6.1.2",
"@vitejs/plugin-react": "^6.2.1",
"@workspace/typescript-config": "workspace:*",
"tailwindcss": "^4.3.3",
"tailwindcss": "^4.3.5",
"typescript": "^7.0.2",
"vite": "npm:@voidzero-dev/vite-plus-core@^1.4.0",
"vite-plus": "^1.4.0",
"void": "1.4.0"
"vite": "npm:@voidzero-dev/vite-plus-core@^1.5.0",
"vite-plus": "^1.5.0",
"void": "1.6.2"
}
}
9 changes: 3 additions & 6 deletions apps/web/src/components/blog/toc.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { cn } from "@workspace/ui/lib/utils"
import { useEffect, useState } from "react"

import { frameThrottle } from "@/lib/frame"
import type { Heading } from "@/lib/toc"

/** How far below the viewport top a heading counts as the one being read: the header plus air. */
Expand All @@ -19,24 +20,20 @@ export function Toc({
const [current, setCurrent] = useState(headings[0]?.id)

useEffect(() => {
let frame = 0
const update = () => {
frame = 0
let active = headings[0]?.id
for (const heading of headings) {
const node = document.getElementById(heading.id)
if (node && node.getBoundingClientRect().top <= READING_LINE) active = heading.id
}
setCurrent(active)
}
const schedule = () => {
if (!frame) frame = requestAnimationFrame(update)
}
const { schedule, cancel } = frameThrottle(update)
update()
window.addEventListener("scroll", schedule, { passive: true })
window.addEventListener("resize", schedule)
return () => {
cancelAnimationFrame(frame)
cancel()
window.removeEventListener("scroll", schedule)
window.removeEventListener("resize", schedule)
}
Expand Down
17 changes: 5 additions & 12 deletions apps/web/src/components/ui/conversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import type { ComponentProps, ReactNode, RefObject } from "react"
import { Button } from "@workspace/ui/components/button"
import { cn } from "@workspace/ui/lib/utils"

import { frameThrottle } from "@/lib/frame"

type ButtonProps = ComponentProps<typeof Button>

/* -- The thread ----------------------------------------------------------------
Expand Down Expand Up @@ -126,18 +128,11 @@ export const Conversation = ({ children, className, ...props }: ConversationProp
return
}

let frame = 0
const pin = () => {
frame = 0
const { schedule, cancel } = frameThrottle(() => {
if (following.current) {
node.scrollTop = node.scrollHeight
}
}
const schedule = () => {
if (frame === 0) {
frame = requestAnimationFrame(pin)
}
}
})

// Text arrives without a scroll event and a box changes size without a mutation:
// a webfont swapping in re-wraps every line, an image decodes, Streamdown's styles
Expand Down Expand Up @@ -165,9 +160,7 @@ export const Conversation = ({ children, className, ...props }: ConversationProp
window.addEventListener("resize", schedule)

return () => {
if (frame !== 0) {
cancelAnimationFrame(frame)
}
cancel()
content.disconnect()
box.disconnect()
window.removeEventListener("resize", schedule)
Expand Down
21 changes: 21 additions & 0 deletions apps/web/src/lib/frame.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Coalesces calls into one `run` on the next animation frame. Scroll, resize and observer
* callbacks fire many times a frame, and a layout read needs only the latest state.
*/
export function frameThrottle(run: () => void) {
let frame = 0
return {
schedule() {
if (frame === 0) {
frame = requestAnimationFrame(() => {
frame = 0
run()
})
}
},
cancel() {
cancelAnimationFrame(frame)
frame = 0
},
}
}
18 changes: 5 additions & 13 deletions apps/web/src/lib/hooks/use-scroll-focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { MotionValue } from "motion/react"
import { useEffect, useRef } from "react"
import type { RefObject } from "react"

import { frameThrottle } from "@/lib/frame"

/** Where the reading line sits inside the viewport: halfway down. */
const READING_LINE = 0.5

Expand Down Expand Up @@ -32,16 +34,8 @@ const useScrollReader = (
return
}

let frame = 0
const measure = () => {
frame = 0
focus.set(readRef.current(container))
}
const schedule = () => {
if (frame === 0) {
frame = requestAnimationFrame(measure)
}
}
const measure = () => focus.set(readRef.current(container))
const { schedule, cancel } = frameThrottle(measure)

measure()
container.addEventListener("scroll", schedule, { passive: true })
Expand All @@ -60,9 +54,7 @@ const useScrollReader = (
})

return () => {
if (frame !== 0) {
cancelAnimationFrame(frame)
}
cancel()
container.removeEventListener("scroll", schedule)
window.removeEventListener("resize", schedule)
resize.disconnect()
Expand Down
8 changes: 2 additions & 6 deletions apps/web/src/server/api.server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { logger } from "void/log"
import type { z } from "zod"

import type { chatId } from "@/lib/chat"
Expand Down Expand Up @@ -37,14 +38,9 @@ export function chatRoute<Params extends z.output<typeof chatId>>(
return errorResponse({ code: "NOT_FOUND", message: "Chat not found." })
return await handler({ request, params: parsed.data, visitor, access })
} catch (error) {
// An Error serializes to {} in Workers Logs; keep its name, message and stack.
const cause =
error instanceof Error
? { name: error.name, message: error.message, stack: error.stack }
: error
// The edge's ray id when there is one, so Workers Logs finds the request by it.
const traceId = request.headers.get("cf-ray") ?? crypto.randomUUID()
console.error("api.failed", { traceId, path: new URL(request.url).pathname, error: cause })
logger.error("api.failed", { traceId, path: new URL(request.url).pathname, error })
return errorResponse({
code: "INTERNAL_SERVER_ERROR",
message: "Something went wrong on our side.",
Expand Down
7 changes: 2 additions & 5 deletions apps/web/src/server/chat.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { waitUntil } from "cloudflare:workers"
import { ai } from "void/ai"
import { and, asc, db, desc, eq, gt } from "void/db"
import { UsageLimit } from "void/limits"
import { logger } from "void/log"
import { storage } from "void/storage"

import { attachment, chat, message } from "../../db/schema"
Expand Down Expand Up @@ -93,11 +94,7 @@ async function readable(file: File, bytes: ArrayBuffer): Promise<string | null>
})
return result.format === "error" ? null : result.data
} catch (error) {
console.warn("chat.to_markdown_failed", {
name: file.name,
type: file.type,
error: String(error),
})
logger.warn("chat.to_markdown_failed", { name: file.name, type: file.type, error })
return null
}
}
Expand Down
9 changes: 7 additions & 2 deletions apps/web/test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,13 @@ describe("POST /api/chats/:chatId/messages", () => {
message: "Something went wrong on our side.",
traceId: "8f1c2d3b4a5e6f70-SJC",
})
expect(log.mock.calls[0]?.[0]).toBe("api.failed")
expect(log.mock.calls[0]?.[1]).toMatchObject({ traceId: "8f1c2d3b4a5e6f70-SJC" })
const entry = JSON.parse(String(log.mock.calls[0]?.[0]))
expect(entry).toMatchObject({
msg: "api.failed",
traceId: "8f1c2d3b4a5e6f70-SJC",
error: { name: "Error", message: "D1_ERROR: no such table: chat" },
})
expect(entry.error.stack).toContain("D1_ERROR: no such table: chat")
})
})

Expand Down
48 changes: 48 additions & 0 deletions apps/web/test/frame.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"

import { frameThrottle } from "../src/lib/frame.ts"

describe("frameThrottle", () => {
let frames: Map<number, FrameRequestCallback>
const flush = () => {
const pending = [...frames.values()]
frames.clear()
for (const callback of pending) callback(0)
}

beforeEach(() => {
frames = new Map()
let id = 0
vi.stubGlobal("requestAnimationFrame", (callback: FrameRequestCallback) => {
frames.set(++id, callback)
return id
})
vi.stubGlobal("cancelAnimationFrame", (handle: number) => frames.delete(handle))
})

afterEach(() => {
vi.unstubAllGlobals()
})

it("runs once per frame however often it is scheduled", () => {
const run = vi.fn()
const { schedule } = frameThrottle(run)
schedule()
schedule()
schedule()
flush()
expect(run).toHaveBeenCalledTimes(1)
schedule()
flush()
expect(run).toHaveBeenCalledTimes(2)
})

it("drops the pending frame on cancel", () => {
const run = vi.fn()
const { schedule, cancel } = frameThrottle(run)
schedule()
cancel()
flush()
expect(run).toHaveBeenCalledTimes(0)
})
})
2 changes: 1 addition & 1 deletion docs/guardrails.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Both are dev-only and never reach the Worker. `minimumReleaseAge` keeps pnpm's o
Fix the cause the message names. Every scan prints the file, the rule and the replacement.

- Don't silence a check to get green. No `--no-verify`, no new `ignorePatterns`, no `oxlint-disable` comment, no rule turned off. A rule that is wrong for a whole area is a config change to propose, as the component-library override above shows.
- Copied skills are never edited here. Drift after a `void` upgrade is expected, so run `pnpm skills:update` and commit the copy with the upgrade. A change to sweet-mode goes to [SweetRetry/skills](https://github.com/SweetRetry/skills) first, then `pnpm skills:update` pulls it.
- Copied skills are never edited here. Drift after a `void` upgrade is expected, so run `pnpm skills:update` and commit the copy with the upgrade. A change to sweet-mode goes to [SweetRetry/retry-kit](https://github.com/SweetRetry/retry-kit/tree/main/skills) first, then `pnpm skills:update` pulls it.
- A hook skip with `git commit --no-verify` or `LEFTHOOK=0` is for a human who knows why. CI still runs the full gate.

## What no tool checks
Expand Down
8 changes: 5 additions & 3 deletions docs/observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ The Worker's logs and traces are the record of what a request did. The `traceId`

## Logging

- Log with `console.log`, `console.warn` and `console.error`. Workers Logs captures them and attaches them to the request's trace.
- Name events with a short dotted key and put the data in an object: `console.error("api.failed", { path, error })`.
- Log an `Error` as `{ name, message, stack }`. A raw `Error` serializes to `{}`.
- Log server events with `logger` from `void/log`. Each call writes one JSON line, which Workers Logs captures, indexes by field and attaches to the request's trace.
- Name events with a short dotted key and put the data in fields: `logger.error("api.failed", { path, error })`. The event name lands in the `msg` field.
- Pass an `Error` as is. `logger` keeps its `name`, `message`, `stack` and `cause`.
- `logger.child(fields)` binds fields shared by a group of calls, such as `{ chatId }`.
- Browser code keeps `console`; its logs never reach Workers Logs.
- Never log secrets, cookies, session tokens, passwords or full request bodies.

## Local dev
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
"verify": "pnpm format:check && pnpm md:check && pnpm lint && pnpm rules:check && pnpm typecheck && pnpm test && pnpm build && pnpm knip"
},
"devDependencies": {
"@shadcn/lint": "^0.2.3",
"@shadcn/lint": "^0.2.5",
"@workspace/typescript-config": "workspace:*",
"knip": "^6.44.1",
"knip": "^6.44.2",
"lefthook": "^2.2.2",
"markdownlint-cli2": "^0.24.0",
"playwright": "^1.64.1",
"playwright": "^1.65.0",
"turbo": "^2.11.10",
"typescript": "^7.0.2",
"vite": "npm:@voidzero-dev/vite-plus-core@^1.4.0",
"vite-plus": "^1.4.0"
"vite": "npm:@voidzero-dev/vite-plus-core@^1.5.0",
"vite-plus": "^1.5.0"
},
"engines": {
"node": ">=24"
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"@base-ui/react": "^1.9.0",
"class-variance-authority": "^0.7.1",
"cmdk": "^1.1.1",
"cn": "^0.5.1",
"cn": "^0.5.2",
"embla-carousel-react": "^8.6.0",
"input-otp": "^1.5.0",
"lucide-react": "^1.66.0",
"lucide-react": "^1.70.0",
"react-day-picker": "^10.0.2",
"react-resizable-panels": "^4.15.3",
"react-resizable-panels": "^4.19.1",
"recharts": "3.10.1",
"sonner": "^2.0.8",
"tw-animate-css": "^1.4.0"
Expand All @@ -33,7 +33,7 @@
"@workspace/typescript-config": "workspace:*",
"react": "^19.3.1",
"shadcn": "4.23.0",
"tailwindcss": "^4.3.3",
"tailwindcss": "^4.3.5",
"typescript": "^7.0.2"
},
"peerDependencies": {
Expand Down
Loading
Loading