Turn document

# Add repository typecheck command

Added a root `bun run typecheck` command that scans the monorepo workspaces and runs TypeScript checks for every workspace with a `tsconfig.json`. The command now passes across apps, packages, and services.

Created: 2026-05-29 02:18 EDT Beads: islandflow-wvz Validation: typecheck and test suite passed

## Summary

The repository now has a first-class typecheck gate. Running `bun run typecheck` checks every workspace TypeScript project under `apps`, `services`, and `packages`, reports failures per workspace, and exits non-zero if any project fails.

## Changes Made

- Added `scripts/typecheck.ts`, a Bun runner that discovers workspace `tsconfig.json` files.
- Added the root `typecheck` package script.
- Added root development dependencies for `typescript`, `@types/bun`, and `@types/ws`.
- Updated workspace `tsconfig.json` files to include Bun runtime types instead of stripping all globals.
- Fixed type errors exposed by the new gate in tests, JetStream config, storage JSON decoding, API live fanout, and WebSocket payload decoding.

## Context

Before this change, the desktop app had a local typecheck script, but the repository did not have a single command for checking the whole Bun and TypeScript monorepo. The first run surfaced both configuration issues and real type mismatches that were not visible from existing validation commands.

## Important Implementation Details

The typecheck runner intentionally discovers workspace projects from the existing folder structure rather than maintaining a hard-coded list. It passes `--incremental false` so checking the Next.js workspace does not leave tracked `tsconfig.tsbuildinfo` churn behind.

Workspace configs now use `"types": ["bun"]`. This matches the runtime and test environment used by the repo while preserving explicit control over global types.

## Relevant Diff Snippets

Attempted to use `@pierre/diffs` as requested by the repository instructions, but the installed package exposes library exports and no executable CLI. The snippets below are therefore the documented plain diff fallback.

    diff --git a/package.json b/package.json
    @@
         "deploy:current-branch": "./deploy current-branch",
    +    "typecheck": "bun run scripts/typecheck.ts",
    @@
       "devDependencies": {
    +    "@types/bun": "^1.3.3",
    +    "@types/ws": "^8.18.1",
    +    "typescript": "^5.9.3",
         "typescript-language-server": "^5.1.3"
       }

    diff --git a/scripts/typecheck.ts b/scripts/typecheck.ts
    +const workspaceRoots = ["apps", "services", "packages"];
    +const tsconfigs = workspaceRoots.flatMap((root) => findTsconfigs(root)).sort();
    +
    +for (const tsconfig of tsconfigs) {
    +  const result = Bun.spawnSync([
    +    "bunx",
    +    "tsc",
    +    "-p",
    +    tsconfig,
    +    "--noEmit",
    +    "--incremental",
    +    "false",
    +    "--pretty",
    +    "false"
    +  ]);
    +}

    diff --git a/packages/bus/src/jetstream.ts b/packages/bus/src/jetstream.ts
    @@
    -  retention: "limits",
    -  storage: "file",
    -  discard: "old",
    +  retention: RetentionPolicy.Limits,
    +  storage: StorageType.File,
    +  discard: DiscardPolicy.Old,

    diff --git a/packages/bus/tsconfig.json b/packages/bus/tsconfig.json
    @@
    -    "types": []
    +    "types": ["bun"]

## Expected Impact for End-Users

Developers now have one obvious command to validate TypeScript correctness before handoff or deployment: `bun run typecheck`. This should catch drift across shared packages and services earlier, especially when changes cross workspace boundaries.

## Validation

- `bun run typecheck` passed across all discovered workspace `tsconfig.json` files.
- `bun test` passed: 250 tests, 0 failures, 994 assertions.
- Confirmed the typecheck script no longer modifies `apps/web/tsconfig.tsbuildinfo`.

## Issues, Limitations, and Mitigations

The command checks workspace TypeScript projects that already have a `tsconfig.json`. If a new workspace is added without a config file, it will not be checked until that config exists. The runner prints each checked config path to make coverage visible during validation.

## Follow-up Work

No required follow-up remains for this task. A useful future improvement would be adding the new typecheck command to CI once the Forgejo pipeline is ready for a broader quality gate.