CommitmentItem.save() had no catch so network errors propagated silently —
now surfaces "Network error — try again" in the form. FulfillCommitment,
AbandonGoal, and DismissAlert all called server actions with try/finally
but no catch, producing unhandled rejections; added silent catch since state
stays correct and the button correctly ungates for retry.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
commitTitle and commitDesc used ie.commit() but ignored the boolean return,
leaving users with no feedback when saves fail. Now shows a timed error below
the relevant field. toggleComplete, toggleAbandon, and all milestone operations
lacked catch blocks, creating unhandled promise rejections on API failures.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
onCancel() had no error handling — if the server action threw, setCancelling
stayed true forever with no recovery path. Added try/catch/finally, cancelError
state, Loader2 spinner on the Yes button, and error clearing on dialog re-open.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
commit() previously called setEditing(false) in finally, so any failed save
(network error or non-OK API response) silently closed the editor — user saw
the old value and couldn't tell whether the save succeeded or failed.
Now commit() closes only on success and returns a boolean. Callers stay in
edit mode on failure, preserving the draft so users can retry or cancel.
Updated HabitRow to check the boolean return instead of .catch().
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
If createCronJob threw (network error), setSaving was never called and the
button stayed in "Creating…" forever. If the API returned non-OK, the modal
still showed "Scheduled!" as if the job was created.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The toggle handler was optimistically setting streak ±1, but streak is
computed from consecutive history — it isn't simply current ± 1. More
critically, the error rollback only reset doneToday, leaving streak at
the wrong value permanently if the API call failed.
Removing the streak mutation fixes the rollback bug and eliminates the
inaccurate flash. The server-side value is already corrected immediately
by router.refresh() on success.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
agentRunning is derived independently from activeAgents (process CWD scan
vs. per-project agent ID array), so they can diverge when one agent stops
and another starts simultaneously. The control panel would show a stale
agent identity for the tick window until the next agentRunning transition.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
PostgreSQL sorts booleans ascending (false < true), so the previous
orderBy(habits.active, ...) put inactive habits at the top. Inactive
habits are dimmed with opacity-50 — they should appear below active ones.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The money page fetched active subs and all subs separately — 2 DB
queries for data that's a strict subset. Now fetches getAllSubscriptions
once and filters active in memory. Removes getActiveSubscriptions from
the query layer entirely. Also drops dead getCurrentUserId() from
session.ts (deprecated, had zero callers).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Filesystem-based essays are site-wide content, not per-user writing.
On multi-user deployments, team member profiles incorrectly showed the
owner's essays as if they authored them. Gate on user.isDefault so
only the owner's profile renders the Writing section.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Both functions fetched all habit_goals rows for the user, then filtered
in memory — wasting bandwidth proportional to total goal/habit count.
Now the WHERE clause includes an inArray on the relevant FK so only
matching rows travel the wire.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
generateMetadata and the page component both called getUserByUsername with
the same argument in the same request, firing two DB queries. Wrapping the
function with React cache() collapses them to one — no other changes.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
getOrgProjects and getOrgEntityProjects both ran the same two-step
sequential query to find org peer IDs: fetch the caller's orgIds, then
fetch peer userIds from those orgs. Extract this as getOrgPeerIds() in
utils.ts using a single self-join on org_memberships, and update both
callers. Reduces 3 sequential round-trips to 2 per call, and eliminates
the duplicated lookup logic.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Next.js 16 uses proxy.ts as the middleware file — creating middleware.ts caused
a startup conflict ("Both middleware file and proxy file detected"). Removed it.
The ^/...\$ regex anchor was also invalid for Next.js matchers (must start with /).
Reverted to original form. The authorized() belt-and-suspenders check added to
auth.config.ts in the prior commit is the definitive fix for invitation paths.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Three related issues:
- proxy.ts rename broke production: Next.js requires middleware.ts; the build
manifest was empty meaning no middleware ran in production. New middleware.ts
re-exports from proxy.ts so logic stays in one place.
- Unanchored regex: /((?!...api/invitations/...).+) matched at substring
position 4 in /api/invitations/<token>, so Turbopack ran the middleware on
invitation routes despite the exclusion. Fixed with ^/...$ anchoring.
- Belt-and-suspenders: authorized() callback in auth.config.ts now explicitly
returns true for /api/invitations/<token> paths regardless of regex behavior.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
beacon-settings PATCH had no auth guard and the middleware regex (api/beacon) accidentally
excluded it as a prefix match. stripe/checkout had two identical auth checks (dead code).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
POST /api/agent/launch (starts AI agent processes in Zellij tabs) and
POST /api/orchestration/run/execute (runs OpenClaw against a project path)
were reachable by any valid bearer token without user verification,
completing the same bearer-passthrough gap fixed in the previous commit.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Six handlers that the middleware passes through for bearer-token
requests had no in-handler auth check, allowing any valid ck_* agent
token to call them regardless of the owning user:
POST /api/project/commit — commits to any git dir on the server
POST /api/ivy — calls OpenClaw on behalf of the server
POST /api/control/auto-continue — writes /tmp sentinel files
POST /api/control/focus-tab — switches Zellij tabs
POST /api/control/merge-prompts — calls Groq/OpenClaw
POST /api/control/dispatch — calls Groq
All now require getApiUserId() (accepts cookie session + daemon token
+ ck_* agent tokens), consistent with the rest of the fleet API.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
POST /api/crons, PATCH /api/crons, and POST /api/crons/run were
excluded from the auth middleware (so the daemon can GET job configs
without a session) but had no in-handler auth checks, leaving them
open to unauthenticated job creation, modification, and execution.
Uses getApiUserId() so daemon bearer tokens remain valid for these ops.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Org members see team-owner projects in the control fleet view but cannot
write to the owner's entity project or user-project rows (ownership-gated
APIs return 404). QuickProfileForm and RemoveSection were showing for
team projects with no profile, leading to confusing "Failed to save /
remove" errors when clicked.
Fix:
- Add readonly?: boolean to ProjectState type
- Set readonly: true for team-project entries in GET /api/control
- Gate QuickProfileForm behind !project.readonly
- Gate RemoveSection behind !project.readonly
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Stripe's webhook POSTs carry no session cookie — the auth middleware was
returning 401 before the route handler's Stripe-Signature verification ran,
silently dropping all billing events (subscription created, cancelled, etc.).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
/api/invitations/[token] (validate) and /api/invitations/[token]/accept
were not excluded from the middleware, causing unauthenticated invitation
recipients to receive a 401 before the route handler ran. The trailing-slash
exclusion (api/invitations/) covers only token sub-routes; the root
GET/POST /api/invitations (list/create) stays protected.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Extends the readonly gating from the previous commit to the Prompts tab:
org members can read linked autopilot jobs but cannot toggle them or create
new ones for a project they don't own.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Org members opening a team owner's project detail were silently getting 404
on every PATCH/DELETE because those routes are ownership-gated. Now the API
surfaces readonly=true when the viewer doesn't own the project, and every
edit control (name, description, status, maturity, attrs, add-attr, log-activity,
delete) is suppressed or rendered as non-interactive text for read-only views.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Previously, org project cards on /projects were non-clickable and "View Project"
in the prompts RunModal was suppressed because the detail API scoped by userId,
returning 404 for any project the viewer didn't own.
Added resolveProjectDetailWithOrgFallback() that verifies shared org membership
then fetches the detail under the owner's userId. The GET /api/projects/[id]
handler now falls back to this when the direct ownership check fails.
Cards and "View Project" are fully re-enabled. PATCH/DELETE still require
ownership and correctly return 404 for non-owned entities.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Team members saw an empty project dropdown in the RunModal when running
project-scoped prompt templates. Now fetches own + org entity projects in
parallel. Org projects are marked readonly so the 'View Project' button
(which would hang — detail API scopes by userId) is suppressed for them.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The applyToOpenTabs helper in /api/control/agent duplicated the raw
query-tab-names call that was fixed in getZellijTabs (9c6df29). Without
the fix, stale ZELLIJ_SESSION_NAME caused query-tab-names to emit session
list entries with ANSI codes, which never matched any project tab name —
silently marking all tabs as "skipped" when switching agent models.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Team members landing on /projects saw an empty page despite having org project
access in the control panel. Now fetches both own projects and org peers'
entity profiles in parallel. Org projects render with a 'team' kicker badge
and are read-only (no inline edit, no delete, no detail drawer).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Team members who belong to an org already have projects accessible in the
control panel. The "Register your first project" prompt was incorrectly shown
to any user with no personal projects, including invited members. Now checks
both own projects and org projects before showing the banner.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Team members invited to an org already have projects shared with them.
Showing "Add your first project" was confusing — this detects org membership
after the username step and routes them directly to /today instead.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
dbProjects (per-user entity projects) was stored in the module-level SlowCache
keyed by dirsKey. When a member user built the cache first (dbProjects=[]),
the owner's subsequent request hit the same dirsKey and got empty profiles
despite having their own entity projects. Now all user-specific project data
is fetched per-request in the existing Promise.all alongside teamOwnerIds,
so each user always resolves against their own + team owners' entity projects.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Members viewing team project cards always got profile:{description:'',status:''}
because dbProjects only contained the requesting user's own entity projects —
empty for org members. Now teamOwnerIds' projects are fetched in the same
Promise.all and merged, giving member users the same profile visibility as owners.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When called from the production server process, zellij action query-tab-names
emits session-list output with ANSI colour codes instead of bare tab names.
Strip escape sequences and drop "[Created ...]" lines so the tab-name check
passes correctly and inject reaches the target pane.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The initial poll() checked document.hidden before fetching, so the
control panel stayed stuck in skeleton state when a tab was backgrounded
(e.g. opened in background, browser automation). Now the first fetch
always fires; subsequent interval/visibility polls still skip when
hidden to avoid unnecessary background requests.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Members were only receiving live-state updates for own projects;
org-peer team projects were missing from the watched tab list.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
/api/inject was gating on own-projects only; a member dispatching to an
org-peer project got a 404 "Unknown tab". Now falls back to getOrgProjects
so team project tabs resolve correctly. DB events are still recorded under
the dispatching member's userId.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Include org-peer projects in the Control panel so members can dispatch
agents to the owner's projects. Own projects take precedence on tab-name
collision; DB session states are fetched from each team owner's userId so
progress is visible regardless of who last ran the agent.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
getOrgProjects previously queried by orgId on the project row, but no
projects had orgId set so it always returned empty. Fixed to query via
org membership user IDs instead — works with all existing data.
createUserProject now auto-sets orgId to the user's primary org so future
projects are org-linked at creation time.
Settings page fetches both own and team projects in parallel and renders
a read-only "Team projects" section below the user's own list. Members
can now see the fleet of projects they have access to dispatch agents on.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Without an email on the invite, accepted users had email=null and no way
to authenticate after their initial session expired. Now open-link accept
forms require an email field; email-targeted invites keep the pre-filled
(disabled) display. Passed email flows through the API into acceptInvitation
which prefers invite.email and falls back to the user-supplied value.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Transient popup windows should not control app-wide theme — removing
ThemeToggle from the beacon header prevents the next session from
waking up in light mode when the user clicked the toggle there.
Smoke test gains /api/orgs, /api/agent-tokens, /api/agent/register
(all three new multi-tenancy + agent-token endpoints).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- AgentTokenSettings: fetch GET /api/agent-tokens on mount to populate list
- agent/register: remove unused NextRequest import/param
- agent-tokens/route: suppress intentional token omission lint warning
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- /api/orgs GET: returns all orgs the user belongs to with full member list
- TeamSettings: shows current members (avatar, name, role) before invite form
- getOrgProjects(): query for active projects shared via org (other members' projects)
- invitations.acceptInvitation: atomically adds new user to inviter's org on accept
- orgs.ts: getOwnerOrgId helper
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- New orgs and org_memberships tables (Drizzle schema + raw DDL applied)
- org_id FK added to user_projects and orchestration_runs for team scoping
- Org auto-create on sign-in: every new user gets a personal org; backfilled existing user
- db/queries/orgs.ts: getOrgMembershipCount, createPersonalOrg, getOrgsByUserId, addOrgMember
- Auto-continue now defaults to false (was true); beacon popup no longer force-enables it on mount — auto-inject is fully opt-in, preventing interference with in-progress multi-step plans
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds /api/github/repos that reads the stored OAuth access_token and
fetches the user's 50 most-recently-updated non-fork repos from GitHub.
Onboarding step 2 shows a scrollable visual picker with language badges,
star counts, and descriptions. Selecting a repo fills name + gitUrl
automatically. Manual entry is still available as a fallback ("Enter
details manually instead"). Users who signed up with email/password see
the original form unchanged (hasGithub: false path).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Root surface: bg-surface-page → bg-surface-base so the popup window
IS the card, not a page containing a card
- Header: rewritten using ui-card-header / ui-card-header-main /
ui-card-actions with the status-dot + project-name + tag pattern
from ProjectTile
- Primary prompt button: ui-btn-primary (white) → ui-btn-ready-primary
(accent) to match the control panel ready-banner style
- Section divider: border-t border-border-subtle separates header from
body, consistent with card section pattern
- Submitted state: same card surface + header, no separate full-page wrapper
- Dismiss button: ui-link-muted → ui-btn-ghost for system consistency
- Loading / standby states: bg-surface-page → bg-surface-base
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>