Commit Graph
873 Commits
Author SHA1 Message Date
g-butandClaude Sonnet 4.6 bbf45c9a21 fix(hooks): guard Notification auto-inject behind idle check; surface continue prompt in UI
The Notification hook was unconditionally injecting "Resolve the pending
question..." whenever Claude Code sent a notification event — even if the
user was actively at the keyboard typing their own reply. This caused the
double-prompt problem independently of the Stop hook fix.

Two changes:
1. handle_notification now applies the same 60s idle gate as handle_stop.
   If the user is active, the hook plays the attention sound only and exits —
   the user responds themselves. Auto-inject only fires when they're away.

2. The "continue" prompt entry in agent-prompts.json had style "internal"
   and slot null, making it invisible in the prompt library UI despite being
   the SSOT for this behavior. Changed to style "more" / slot 14 so it
   appears under the More button and can be read, used, and edited from the
   same place as every other prompt.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 17:38:38 +02:00
g-butandClaude Sonnet 4.6 d966e906f1 feat(beacon): two-layer parallel popup — OS notification + browser beacon race
Layer 1 (< 100ms): notify-choice.py shows a native KDE notification with
action buttons built from the first 3 prompt slots. Uses gi.repository.Notify
+ GLib event loop so actions are properly wired (plain notify-send --action
is not supported by the KDE notification server). When clicked:
  - prints the slot number (choice)
  - patches /tmp/cockpit-beacon/{id}.json so the browser beacon sees
    choice != null and window.close()s itself within 500ms

Layer 2 (1-4s): beacon_python opens the full browser beacon in parallel.

Both layers write to a shared tempfile via atomic mv — first write wins.
The main loop polls every 200ms, kills both processes on first result.
If neither layer produces a choice (user is at keyboard, typing manually),
the hook exits cleanly without injecting anything.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 17:33:58 +02:00
g-butandClaude Sonnet 4.6 795f4b9974 fix(beacon): SSR initial session load + prefer Brave for popup
Two fixes to make the beacon popup work without requiring the browser to
be logged into Cockpit:

1. Server-side initial session read — page.tsx is now a Server Component
   that reads the beacon session directly from /tmp/cockpit-beacon/{id}.json
   before sending HTML to the browser.  The client receives a fully-populated
   initialSession prop and shows session content immediately — no client-side
   GET /api/beacon/{id} needed on page load.  The PATCH (recording the user's
   choice) and the cancel-detection poll still go through the API, which
   works as long as the browser that opens the popup has a Cockpit session.

2. Prefer Brave browser for the popup — beacon.py now checks for brave-browser
   before google-chrome in the candidate list.  The user's Cockpit session
   lives in Brave (the primary browser), so opening there means API calls
   from the beacon page are authenticated automatically.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 17:21:09 +02:00
g-butandClaude Sonnet 4.6 5978bcf0f8 fix(beacon): add /dev/pts fallback for idle detection without xprintidle
The XScreenSaver extension is unavailable on this machine's X11 display.
Add /dev/pts youngest-atime as a fallback: the most recently accessed
pseudo-terminal is a reliable proxy for 'user is active in a terminal'
and needs no extra packages or group membership.

Detection order: libXss (XScreenSaver) → /dev/pts atime → 9999 (show beacon).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 17:11:48 +02:00
g-butandClaude Sonnet 4.6 45835c9ee3 fix(beacon): stop auto-injecting on timeout; add idle gate + instant notify
Three targeted fixes for the "prompt injection even when at keyboard" problem:

1. Remove the `choice="1"` fallback — when the beacon times out or Chrome fails
   to open, the hook now exits cleanly instead of auto-injecting slot 1 on top of
   whatever the user typed manually.

2. X11 idle gate — skip beacon entirely when the user has been active within the
   last 60 s (uses xprintidle if installed, falls back to libXss via ctypes, falls
   back to 9999 = always show beacon when neither is available).  Install
   xprintidle with `sudo apt install xprintidle` to enable on systems without the
   MIT-SCREEN-SAVER X11 extension.

3. Instant notify-send notification fires before Chrome launches so the user gets
   immediate visual feedback while the browser beacon popup loads (1–4 s on first
   Chrome launch, near-instant when Chrome is already running).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 17:05:09 +02:00
g-butandClaude Sonnet 4.6 604c84ed49 fix(beacon): bypass API auth — write/poll session files directly
beacon.py now writes sessions to /tmp/cockpit-beacon/{uuid}.json
directly instead of POSTing to /api/beacon, and polls the file instead
of GET /api/beacon/{id}. No API auth is needed — the browser popup (which
has the user's session cookie) still calls the API to load the beacon UI
and write the choice. Works immediately without any dev server restart.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 16:45:32 +02:00
g-butandClaude Sonnet 4.6 77aec7eca5 fix(today): surface habit toggle errors in HabitsList instead of silent revert
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 16:38:34 +02:00
g-butandClaude Sonnet 4.6 5b35c8b6f3 fix(beacon): unblock /api/beacon from middleware + fix PyQt crash
Two bugs preventing the popup from working:
1. /api/beacon was matched by the auth middleware (401 for unauthenticated
   beacon.py). Added api/beacon to the middleware exclusion list — sessions
   are /tmp UUIDs with no sensitive data.
2. FocusCancelTextEdit(QPlainTextEdit) called setAcceptRichText which does
   not exist on QPlainTextEdit (it's a QTextEdit method). Removed the
   redundant call — QPlainTextEdit is plain-text-only by definition.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 16:32:50 +02:00
g-butandClaude Sonnet 4.6 b739b6f02f fix(people): replace bare 'Loading...' name in PersonDetail sticky header with skeleton pill
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 16:26:59 +02:00
g-butandClaude Sonnet 4.6 8b750d9666 fix(control): replace bare 'Loading…' with structural skeletons
Header loading text becomes a pulse pill; sidepanel shows 4 skeleton
metric cards while useControlData fetches, matching the real 2×2 grid.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 16:24:47 +02:00
g-butandClaude Sonnet 4.6 fd70127e6e feat(beacon): make web beacon primary popup, PyQt fallback
Browser popup (Chrome --app= frameless window) is now the default when
Cockpit is running. PyQt native widget is used only when no browser is
found or Cockpit is not running. The confirm dialog still uses PyQt.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 16:21:22 +02:00
g-butandClaude Sonnet 4.6 bdf60a9086 fix(ui): replace bare loading text with structural skeletons in GitHubStatus and PersonDetail
GitHubStatus showed 'Checking repos...' text; now shows 3 repo-row
skeletons (status icon circle + name bar / PR count + CI name bars).

PersonDetail drawer showed 'Loading...' text; now shows description
block, 2x2 attribute grid, and 3 interaction-row placeholders — matching
the actual drawer body layout.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 16:12:35 +02:00
g-butandClaude Sonnet 4.6 ae77749c8a fix(today): replace bare 'Loading...' text with structural skeletons in CalendarCard and WeatherCard
Both cards showed unstyled loading text while every other card on /today
used animate-pulse placeholder blocks. CalendarCard now shows 3 event-row
skeletons (time col + title/location); WeatherCard shows the icon + temp
+ condition block layout, keeping visual structure consistent during load.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 16:08:33 +02:00
g-butandClaude Sonnet 4.6 f6cb0dc681 fix: remove duplicate auth check in stripe portal, drop stale date, expand smoke to 36
- stripe/portal: remove copy-paste duplicate if (!userId) guard (dead code)
- money page: remove hardcoded Apr 2026 verification date that was already
  stale and would keep rotting; label remains without the date
- smoke.sh: add /api/setup (public), /api/checkout/personal, and
  /api/stripe/portal (accepts 401 + 503 when Stripe not configured);
  extend check_route with extra_ok_code param for integration-gated routes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 16:04:35 +02:00
g-butandClaude Sonnet 4.6 ad70f4f793 fix(habits): surface mutation errors in HabitCard instead of silent failure
All four operations (frequency change, active toggle, done toggle, delete)
previously swallowed errors silently after reverting optimistic state.
Now flash a 3-second inline error message below the card on failure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 15:59:40 +02:00
g-butandClaude Sonnet 4.6 e6c65d3778 fix(auth): gate owner-key tab on LOCAL_AUTH_PASSWORD, move sign-up link into form
The owner key tab was always visible even when LOCAL_AUTH_PASSWORD is not
set, confusing users who don't use local auth. Now conditional on the env
var (passed server-side to avoid hydration mismatch).

Also moves the "No account?" link inside the email AuthCard instead of
using AuthFooterLink below, which visually associates it with the form.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 15:58:50 +02:00
g-butandClaude Sonnet 4.6 260f33250d test(smoke): expand coverage from 28 to 33 routes
Added /api/health (public), /api/control/agent, /api/control/commands,
/api/captures, and /api/beacon-settings to smoke coverage. All return
expected status codes (200 for public, 401 for auth-required routes).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 12:19:15 +02:00
g-butandClaude Sonnet 4.6 5a815ceaba fix(people): surface search fetch errors with retry instead of silent failure
PeopleGrid was rethrowing non-abort errors into a discarded promise, leaving
users looking at stale results or an empty list with no indication that the
search failed. Now sets fetchError state, shows an inline error banner with a
Retry button, and clears the error on the next successful fetch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 12:10:09 +02:00
g-butandClaude Sonnet 4.6 dc791e5134 fix(ux): add SummaryBar loading skeleton, surface silent errors, fix reorder revert
- SummaryBar: add SummaryBarSkeleton (5 animated pills) as Suspense fallback
  instead of null — /today no longer shows blank space during DB queries
- ProfileSettings: show actual window.location.host instead of hardcoded
  'cockpit.app' in the username prefix — correct on localhost and Vercel
- BeaconSettings: surface load failure with an error message instead of
  silently rendering defaults when /api/beacon-settings is unreachable
- ProjectsSettings: reorder now reverts UI and shows error if any PATCH
  fails — previously silent failure left UI and server out of sync

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 12:00:24 +02:00
g-butandClaude Sonnet 4.6 632fcc16c8 feat(health): expose runtime and version in /api/health; purge stale beacon sessions
/api/health now returns { ok, runtime, version } — runtime signals whether this
is the local machine instance (RUNTIME_AVAILABLE=true) vs a cloud deployment,
enabling scripts and monitoring to distinguish the two without auth.

Beacon POST purges sessions older than 10 minutes from /tmp/cockpit-beacon/
on each new creation, preventing unbounded accumulation over time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 11:47:12 +02:00
g-butandClaude Sonnet 4.6 c54858345a fix(middleware): rename to proxy.ts, return 401 for unauthenticated API requests, exclude public API routes
- Renamed src/middleware.ts → src/proxy.ts (Next.js 16 convention)
- Removed stale src/middleware.ts that conflicted with proxy.ts
- authorized() callback now returns JSON 401 for /api/* routes instead
  of redirecting to sign-in (clients expect JSON, not HTML redirect)
- Added api/crons and api/system to matcher exclusions — these are
  intentionally public endpoints used by the daemon and monitoring

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 11:32:43 +02:00
g-butandClaude Sonnet 4.6 4e40609387 fix(security): guard /api/sessions and /api/prompts/agent against unauthenticated access
Both routes use fs.readFileSync without any Next.js dynamic API call, so
Next.js could statically pre-render them and bypass middleware. Added
`export const dynamic = "force-dynamic"` plus explicit getSessionUserId()
checks — /api/sessions also allows daemon bearer-token requests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 11:14:44 +02:00
g-butandClaude Sonnet 4.6 20b7a9dd49 feat(auth): add middleware.ts to activate global auth and onboarding gate
auth.config.ts had a complete authorized() callback (unauthenticated →
/sign-in, not-onboarded → /onboarding, daemon bearer token pass-through)
but no middleware.ts to wire it up — it was dead code.

Uses NextAuth(authConfig).auth, an edge-safe instance with no DB adapter
or Node.js crypto. The matcher uses .+ (not .*) so the bare / path
(public landing page) is excluded without needing extra matcher logic.

Matcher explicitly excludes all public surfaces: landing (/), auth pages
(sign-in, sign-up, forgot-password, reset-password, setup, invite),
public content (whitepaper, thoughts, u/, beacon), NextAuth internals
(api/auth), and infrastructure endpoints (api/health, api/setup).

Verified: landing 200, /today unauthenticated → /sign-in?callbackUrl=%2Ftoday,
sign-in 200, whitepaper 200. All 28 smoke routes green.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 11:01:03 +02:00
g-butandClaude Sonnet 4.6 1416315bc9 fix(smoke): add missing nav routes and API endpoints to coverage
PAGE_ROUTES was missing /history, /thoughts, /settings (all in
NAV_ITEMS per the comment's own rule) and /whitepaper (public page).
Routes match navigation.ts NAV_ITEMS order for easier diffing.

AUTH_API_ROUTES grows from 5 to 10 — adds /api/me, /api/user-projects,
/api/invitations, /api/sessions, /api/prompts/agent. Each confirmed to
have a GET handler before adding. /api/subscriptions omitted (POST-only).

All 28 routes verified green against the running dev server.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 10:53:49 +02:00
g-butandClaude Sonnet 4.6 f33d8dbcd1 feat(security): rate-limit register and forgot-password endpoints
Adds a sliding-window in-memory rate limiter (lib/rate-limit.ts).

- /api/auth/register:       10 requests / IP / hour  → 429 + Retry-After: 3600
- /api/auth/forgot-password: 5 requests / IP / 15 min → 429 + Retry-After: 900

Works correctly for the local-server deployment (single long-lived process).
On Vercel serverless, limits within a warm invocation — still raises the cost
of rapid-fire attacks without requiring Redis or external infrastructure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 10:45:28 +02:00
g-butandClaude Sonnet 4.6 5c82f81d0c fix(auth): move onboarding to public surface, auto-fire sign-out, fix copy
Onboarding was inside (app) and rendered wrapped in the full AppShell
(sidebar visible). Moved to top-level app/onboarding/ so it uses
AuthShell → PublicSurface — same clean layout as sign-in/sign-up.

Sign-out no longer shows a confirmation page; it fires signOut()
immediately on mount and shows a spinner. The confirmation added
friction without protecting anything meaningful in a personal tool.

Sign-up description updated from generic filler to copy that matches
the landing page voice.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 10:41:32 +02:00
g-butandClaude Sonnet 4.6 daa264286d feat(public): x.ai-style nav, owner-key tab, redesigned landing
- PublicSurface now accepts navLinks prop; renders desktop link row
  with a subtle border-bottom separating nav from content
- Landing page gets Features | Pricing | Whitepaper nav links with
  scroll anchors; hero drops the badge, adds dual CTAs (Sign in +
  Get started →) matching the x.ai pattern
- All auth pages inherit the same nav via AuthShell automatically
- Sign-in replaces the hidden "Use owner key" text link with a visible
  Email / Owner key tab switcher — owner password is no longer buried

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 10:27:28 +02:00
g-butandClaude Sonnet 4.6 78ace3d904 chore(hooks): add pre-push smoke test gate
Runs npm run smoke before push when the local server is detected.
Silent skip when server is down so offline pushes are never blocked.
Supports COCKPIT_SESSION_TOKEN for fully authenticated smoke runs.
pre-commit now documents that authenticated smoke lives in pre-push.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 10:26:42 +02:00
g-butandClaude Sonnet 4.6 6c32560377 fix(smoke): accept 401 for auth-protected API routes, add COCKPIT_SESSION_TOKEN support
smoke.sh was always exiting 1 because auth-required API routes correctly
return 401 without a session — but the script treated anything ≥400 as a
failure. Splits routes into PUBLIC_API_ROUTES (must 2xx) and AUTH_API_ROUTES
(200 or 401 both pass), so the check meaningfully detects 500s without
requiring a live session. When COCKPIT_SESSION_TOKEN is set, all requests
are authenticated and the full DB/query layer is exercised (20/20 routes).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 22:26:55 +02:00
g-butandClaude Sonnet 4.6 07f0c20cf0 fix(scripts): remove dead should_skip_native_popup and fix cp -r nesting
Removes the should_skip_native_popup() function and its call site from
agent-hook-bridge.sh — prefer_browser_ready_ui was removed from the UI
and API, leaving this code checking a setting that no longer exists.

Fixes a repeated-install bug in install-cockpit-app.sh where cp -r into
an existing directory nests the source as a subdirectory instead of
overwriting. Now removes target dirs before copying.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 22:01:18 +02:00
g-butandClaude Sonnet 4.6 b8fa8b89e9 fix(auth): trust localhost in production standalone server
Auth.js v5 in production rejects unrecognized hosts by default, causing
every session check at localhost:3000 to throw UntrustedHost and spam
the journal. The error prevented sign-in from working at all on the local
production server.

Fix: set trustHost from AUTH_TRUST_HOST env var (sourced from .env.local
by cockpit-app.sh at startup). Vercel keeps working via the existing
VERCEL=1 auto-trust. Local .env.local has AUTH_TRUST_HOST=true added.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 21:50:53 +02:00
g-butandClaude Sonnet 4.6 837ecb6f1d feat(daemon): auto-detect local server, prefer it over Vercel
When the local Next.js app (cockpit-app.service) is running, the daemon
now routes all runtime-state pushes and command polls to localhost:3000
instead of cockpitapp.vercel.app. This makes the Control panel on the
local machine show live agent state (via local PostgreSQL) rather than
always showing idle.

Detection logic:
- At startup: probe localhost:3000/api/health up to 8 times (1 s apart)
  so the daemon doesn't race past the app during boot.
- During operation: re-check every 30 s via a shared tmpfile cache so
  both the poll loop and the background push loop agree on the URL.
- Falls back to COCKPIT_BASE_URL (Vercel) when localhost is unreachable.

Updated cockpit-daemon.service to soft-depend on cockpit-app.service
(Wants= / After=) so systemd starts the app before the daemon.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 21:35:05 +02:00
g-butandClaude Sonnet 4.6 d973ad63a8 feat(local): add production server installer and systemd user service
Adds two scripts to run Cockpit locally as a production-grade service
instead of relying on `npm run dev`:

- scripts/cockpit-app.sh: wrapper that sources .env.local and launches
  the Next.js standalone server at localhost:3000. Unsets the bash
  HOSTNAME builtin so the server binds to 0.0.0.0 (not the machine's
  hostname which resolves to 127.0.1.1).

- scripts/install-cockpit-app.sh: one-shot installer that builds the
  production bundle, copies static assets into .next/standalone, writes
  ~/.config/systemd/user/cockpit-app.service, and enables + starts it.
  Accepts --skip-build to reinstall without rebuilding.

Run: npm run install-app  (or npm run build && npm run install-app --skip-build)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 21:27:56 +02:00
g-butandClaude Sonnet 4.6 c8a0d6b7c4 fix(build): remove duplicate middleware.ts that conflicts with proxy.ts
Next.js 16 renamed middleware.ts → proxy.ts. The old file was never
deleted, causing the build to fail with "both middleware and proxy file
detected." Merged the missing public-route exclusions (sign-up,
forgot-password, reset-password) into proxy.ts and deleted middleware.ts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 21:04:11 +02:00
g-butandClaude Sonnet 4.6 b7c2bea591 fix(commands): drain queue for all user IDs, not just isDefault user
The daemon was calling claimNextPendingCommand(getDaemonUserId()), which
only claimed commands stored under the isDefault user's row. Commands
enqueued by a session authenticated via GitHub OAuth (a different DB row
for the same person) were silently ignored and never executed.

Fix: daemon now fetches all distinct userIds from user_projects and
claims commands for any of them. Also makes the claim atomic via a
transaction with FOR UPDATE SKIP LOCKED, preventing a theoretical
double-claim race if two pollers hit the endpoint simultaneously.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 20:52:40 +02:00
g-butandClaude Sonnet 4.6 793957a824 fix(beacon): add missing input_bg token to dark and light palettes
ContinuePopup._build_summary used C['input_bg'] but neither palette
defined it, causing a KeyError crash on every stop hook — popup fell
back to slot-1 auto-continue silently instead of showing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 20:46:01 +02:00
g-butandClaude Sonnet 4.6 2eda5b77cd fix: harden runtime-state lookup + remove dead prefer_browser_ready_ui setting
getUserIdsByProjectNames: replace case-sensitive inArray with lower()-based
equality so conf-file tab names with different casing still resolve the
right user. Also fixes potential LIKE-wildcard injection via ilike.

prefer_browser_ready_ui: the old "open browser window" beacon mode was
replaced by PyQt-primary months ago. The toggle has been a no-op ever
since — remove it from BeaconSettings and the API to stop misleading users.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 20:36:52 +02:00
g-butandClaude Sonnet 4.6 6291bc609b fix(control): resolve actual project owner in runtime-state push
getDaemonUserId() returns the isDefault user's ID, but the owner may be
logged in as a different user (e.g. GitHub OAuth creates a separate row
when the setup user has no email). This caused project_states to be stored
under user A while the SSE read for user B — showing all 20 projects idle
even with Claude running in multiple zellij tabs.

Fix: look up which user actually owns each project via user_projects, fall
back to daemonUserId only for unregistered projects.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 20:24:09 +02:00
g-butandClaude Sonnet 4.6 618a6cde1f fix(control): remove readProjectsMap fallback from clear-context route
Resolves canonical tab name from the user's own DB projects only,
consistent with the same fix applied to agent and inject routes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 20:16:53 +02:00
g-butandClaude Sonnet 4.6 f80cdccf33 fix(control): remove parseProjectsConf leaks from agent and inject routes
applyToOpenTabs in /api/control/agent was merging the owner's conf-file
projects with the current user's DB projects, allowing any authenticated
user to force-restart the owner's Claude sessions.

/api/inject was resolving canonical tab names and project paths from the
owner's conf file before falling back to DB — now DB-only for both.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 20:00:49 +02:00
g-butandClaude Sonnet 4.6 bd7929786b fix(middleware): exclude beacon and health routes from auth
beacon.py calls /api/health (to detect if Cockpit is up) and /api/beacon
(to create/poll/patch sessions) without a session cookie. With these
routes protected the calls were silently redirected to /sign-in, causing
_create_web_session() to always return None and breaking two-way sync
between the PyQt popup and the Control panel ReadyBanner.

/api/beacon writes only ephemeral /tmp data — no user-sensitive state.
/api/health is a no-op check. Both are safe to expose publicly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 19:53:18 +02:00
g-butandClaude Sonnet 4.6 bd0dfe4ddf chore: remove dead DEFAULT_USER_ID constant
No longer referenced in any application code after the data isolation
audit replaced all user-resolution paths with getSessionUserId().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 19:43:21 +02:00
g-butandClaude Sonnet 4.6 ce74277d1d fix(control): remove conf-file fallback that leaked owner projects to all users
Both /api/control and /api/control/stream fell back to parseProjectsConf()
when the authenticated user had no DB projects yet. The conf file contains
the owner's personal project list, so any signed-in user with no projects
of their own would see all of the owner's projects in their control panel.

Fix: drop the fallback entirely. Each user now sees only the projects in
their own user_projects rows. The owner already has their projects there,
so backward compatibility is unaffected. New users who skip onboarding
or haven't added projects yet see an empty control panel — correct.

Also removes the now-dead parseProjectsConf import from both routes and
collapses the usingUserProjects conditional into a single filter+map.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 19:35:52 +02:00
g-butandClaude Sonnet 4.6 fc6282e1fb feat(auth): enforce onboarding flow for new self-registered users
Three-part fix:

1. auth.config.ts — add session callback to propagate onboardedAt from
   the JWT payload so the middleware can check it without a DB lookup;
   add authorized() gate that redirects authenticated-but-not-onboarded
   users to /onboarding for all page routes (API routes pass through so
   the /api/me and /api/user-projects calls from the onboarding page work).

2. sign-up/page.tsx — redirect to /onboarding after registration instead
   of /today, so new users immediately enter the username + first-project
   setup flow.

3. db/queries/users.ts — remove the premature onboardedAt: new Date()
   from createUser(). New self-registered users now have onboardedAt=null
   until they complete /onboarding. createInitialUser() (owner account)
   and the invite flow keep their immediate onboardedAt, since those users
   don't need guided setup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 19:25:21 +02:00
g-butandClaude Sonnet 4.6 4d17f2a928 fix(control): don't label projects idle when daemon state is unknown
When accessing the control panel from Vercel (or any remote browser)
and the local daemon is offline or has never connected, the DB shows
agentRunning=false for every project — not because they're idle, but
because there's no live signal. This caused the Cockpit project itself
(with an active Claude session) to appear in the "Idle projects" section.

Fix: when daemon is offline/never-seen, collapse the active/idle split
entirely and show all projects in the main list. The DaemonStatusBanner
already explains why state is stale; the fleet view no longer claims
projects are idle when it simply doesn't know.

Also made ControlMetricCard.note optional so the "N idle" note can be
suppressed in the stat card when daemon state is unknown.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 19:16:19 +02:00
g-butandClaude Sonnet 4.6 fe282bf761 fix(auth): GitHub OAuth creates separate accounts per user
Replaced the hard-coded default-user link in the signIn callback.
Previously, every new GitHub login was linked to the default user.
Now allowDangerousEmailAccountLinking lets the DrizzleAdapter link
GitHub accounts to existing Cockpit users by email match (safe: GitHub
verifies email addresses). New users get their own account; returning
users continue via existing account lookup. signIn callback reduced to
profile field updates only.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 18:59:23 +02:00
g-butandClaude Sonnet 4.6 689a315ca7 fix(auth): complete data isolation — remove DEFAULT_USER_ID fallback, add daemon bypass
Security fixes:
- auth.config.ts: middleware now allows COCKPIT_DAEMON_TOKEN bearer requests through,
  so the local daemon works correctly after middleware was added in the previous commit.
  Individual daemon routes still enforce their own auth; middleware is the first gate.
- lib/session.ts: removed DEFAULT_USER_ID fallback that silently returned the owner's
  data for unauthenticated requests. Replaced with:
    requirePageUserId()  — server components/actions: redirects to /sign-in if no session
    getSessionUserId()   — API routes: returns null for explicit 401 handling
  getCurrentUserId() is now a deprecated alias for requirePageUserId().

Call-site migrations:
- 22 server component files (pages + today/* + system/*): getCurrentUserId → requirePageUserId
- 35 API route files: getCurrentUserId → getSessionUserId + explicit 401 guard
  (one exception: beacon appendDevLog helper silently skips on no session to avoid
  breaking the beacon response for an internal logging side-effect)
- project-states/[key]: fixed concurrent Promise.all that mixed data fetch with auth

Result: every data-access path now explicitly enforces authentication. Unauthenticated
requests to server components redirect to /sign-in; API calls return 401 JSON. No path
silently falls back to owner data.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 18:47:51 +02:00
g-butandClaude Sonnet 4.6 9650985d97 fix(auth): remove unused imports in sign-up and reset-password pages
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 18:31:05 +02:00
g-butandClaude Sonnet 4.6 bbe92fae7a feat(auth): multi-user registration, email sign-in, forgot/reset password
Self-service registration flow:
- POST /api/auth/register — creates account (email+name+password)
- /sign-up — registration form; auto-signs-in after creation

Email+password sign-in:
- New 'email-password' Credentials provider in auth.ts
- SignInForm updated: email+password primary, 'forgot password?' link,
  'Create account →' footer; owner key accessible via collapsible fallback

Forgot/reset password flow:
- password_reset_tokens table (2-hr expiry, single-use, auto-invalidates)
- POST /api/auth/forgot-password — creates token, sends via Resend REST API
  (falls back to console log when RESEND_API_KEY is unset)
- POST /api/auth/reset-password — validates + consumes token, hashes new password
- /forgot-password — email input; always shows 'check your email' (no user enumeration)
- /reset-password/[token] — new password form, redirects to sign-in on success

Infrastructure:
- src/middleware.ts — NextAuth edge middleware protecting all app routes;
  excludes sign-in, sign-up, forgot-password, reset-password, invite, API auth
- src/lib/email.ts — thin Resend REST wrapper (no package dep)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 18:25:20 +02:00
g-butandClaude Sonnet 4.6 e9e85447cf feat(settings): transcription provider selector — local / groq / auto
Adds a per-setting choice between local Whisper and Groq cloud so the
operator can force local when Groq rate-limits hit, or force Groq when
the runtime isn't active. 'auto' preserves the old behavior.
Stored in ~/.config/agent-dashboard-settings.json alongside whisper_model.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 18:03:22 +02:00