Commit Graph
1304 Commits
Author SHA1 Message Date
g-butandClaude Sonnet 4.6 474038834a fix(captures): scope delete WHERE to userId — prevent cross-user deletion
feat(projects): surface health badge in agent run history for quality trend visibility

deleteCapture now filters by both id AND userId atomically; the previous
post-hoc ownership check deleted the row before verifying it belonged to the caller.

ProjectHistorySection now shows the health badge (good/needs attention/critical)
from each run's parsed session summary — scanning the list reveals whether project
quality is improving or degrading over time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 15:55:56 +02:00
g-butandClaude Sonnet 4.6 1405e332c9 feat(today): add quick capture — textarea → DB save from any device
New captures table (uuid pk, user_id, body, created_at) with cascade delete.
API: GET/POST /api/captures, DELETE /api/captures/[id].
QuickCaptureButton sits beside LogConversationButton on Today, expands inline,
saves on ⌘↵ or click, shows last 5 captures with swipe-to-delete affordance.
Closes the mobile quick-capture gap — any thought, any device, always in the system.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 15:44:45 +02:00
g-butandClaude Sonnet 4.6 1c4992c211 refactor(auth): replace inline user queries with db/queries/ functions
getDefaultUser() now returns the full row (authorize and signIn callbacks
need passwordHash, email, image). updateUser() gains email/image fields.
jwt callback uses getUserById(). DrizzleAdapter still receives db directly
— that import is unavoidable by NextAuth's adapter contract.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 15:18:51 +02:00
g-butandClaude Sonnet 4.6 29c42602a2 refactor(pages): replace inline db queries in 4 server components with db/queries/ functions
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 14:52:26 +02:00
g-butandClaude Sonnet 4.6 cd1f31a477 refactor(db): extract getProjectDetail to db/queries/projects — eliminate last direct db import from API routes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 14:45:01 +02:00
g-butandClaude Sonnet 4.6 79d2ca4a56 refactor(db): add db/queries/users.ts — extract user queries from 3 inline routes and fix lib/→db layering violation in daemon-auth
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 14:37:49 +02:00
g-butandClaude Sonnet 4.6 8ad626379e refactor(auth): extract daemon-auth helpers — eliminate 3-site duplication of token check and default-user lookup
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 14:28:37 +02:00
g-butandClaude Sonnet 4.6 09f1336c76 fix(auth): replace raw fetch() in PrivatePinGate with postJson wrapper
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 14:18:28 +02:00
g-butandClaude Sonnet 4.6 4cc854a239 fix(inject): eliminate double-inject race and prompt content duplication
- Clear handshake files unconditionally after every Claude adapter inject,
  not only on hard_stop — prevents the beacon from firing a second inject
  because the ready sentinel was never removed
- Skip Intent/Project header and execution rules in renderTaskForAdapter for
  the Claude adapter — CLAUDE.md is always loaded in every Claude Code session
  and already provides these; removes ~100 tokens of redundant context per inject
- Remove trailing "When done, update the session file:" epilogues from all
  prompts in agent-prompts.json — buildPromptWithSession already appends the
  exact session-file path; the vague duplicate in prompt bodies caused Claude
  to receive two conflicting update instructions
- Rewrite next_best prompt body to reference the session context already
  prepended by buildPromptWithSession instead of re-reading it via grep
- Fix continue prompt — remove stale update-block tail

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 13:44:38 +02:00
g-butandClaude Sonnet 4.6 96bfbeede2 fix(prompts): remove redundant 'TODOs' word from session handoff templates
agent-config.ts and orchestration/renderers.ts both generated
'todos: <count> TODOs' — the field name already communicates what
it is. Now generates 'todos: <count>'. DevLogList normalises legacy
DB entries (which stored 'N TODOs') so history renders cleanly too.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 13:23:09 +02:00
g-butandClaude Sonnet 4.6 b5d9263b26 feat(control): local→cloud state push — daemon heartbeat keeps Vercel in sync
- Add agentRunning, activeAgents, lockAt columns to project_states schema
- New POST /api/control/runtime-state endpoint (daemon bearer auth)
  accepts per-project runtime patches and upserts to DB
- control/route.ts: use DB agentRunning/activeAgents/currentPrompt
  when isRuntimeAvailable()=false (Vercel sees live fleet state)
- stream/route.ts: DB polling path when !isRuntimeAvailable()
  maps project_states rows → FastProjectState for SSE clients
- cockpit-daemon.sh: _push_loop runs in background every 2s,
  reads /proc + /tmp sentinels + current-prompt files and pushes
  all 7 tab states to the new endpoint

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 12:46:34 +02:00
g-butandClaude Sonnet 4.6 c293032e69 fix(beacon): close two races that allow auto-inject to fire while user is composing
Race 1 — async mic permission gap: setListening(true) was called only after
await getUserMedia(), leaving a window where isComposing=false even while
the browser was showing the permission dialog. Now setListening(true) fires
synchronously on mic button click, with a rollback to false on error.

Race 2 — cross-window blind spot: the control panel's ReadyBanner had no way
to know the beacon popup was mid-composition. It relied on display.isBeaconActive
which reads /tmp (unavailable on Vercel). Added beaconComposingKey to
control-storage so the popup writes a localStorage flag when isComposing;
ReadyBanner reads it synchronously before firing, blocking the inject.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 12:10:40 +02:00
g-butandClaude Sonnet 4.6 d74a88e08a refactor(control): centralize auto-continue API sync in hook — eliminate 2-site duplication
Both ProjectCard and ProjectCommanderCard were duplicating the same
postJson side-effects alongside the hook toggle. Moving them into
useAutoContinue means the beacon cancel and /tmp sentinel sync
happen wherever the toggle fires, including from beacon and
orchestration paths that bypass the card components.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 11:54:42 +02:00
g-butandClaude Sonnet 4.6 b8cf52dfa8 fix(control): match SSE stream patches by liveTab first — prevent merge miss when canonical and zellij casing differ
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 07:01:47 +02:00
g-butandClaude Sonnet 4.6 7b973f6316 fix(ssot): use AGENT_DEFAULT_MODELS in orchestration run route — remove last hardcoded model fallbacks
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 06:50:06 +02:00
g-butandClaude Sonnet 4.6 d64801706e refactor(agents): extract AGENT_DEFAULT_MODELS constant — eliminate 3-site duplication of fallback model strings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 06:42:20 +02:00
g-butandClaude Sonnet 4.6 f1d19de679 refactor(beacon): replace local agentLabel with getAdapterLabel from control-intents — eliminate duplicated adapter label logic
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 06:33:35 +02:00
g-butandClaude Sonnet 4.6 97d4c253fc refactor(adapters): use ORCHESTRATION_ADAPTER_IDS as SSOT — replace hardcoded enum and adapter array check
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 06:29:19 +02:00
g-butandClaude Sonnet 4.6 f7dc26ff52 refactor(groq): extract shared callGroqText — eliminate duplicated fetch boilerplate and GROQ_FAST_MODEL constant
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 06:27:06 +02:00
g-butandClaude Sonnet 4.6 ebdac2d404 fix(ssot): centralise SWITCH_CHOICE_PREFIX wire constant across all three languages
SWITCH_CHOICE_PREFIX="switch:" was defined locally in beacon/[id]/page.tsx
(TypeScript) and _beacon_popups.py (Python), while its sibling CUSTOM_CHOICE_PREFIX
already lived in src/lib/constants/control.ts and _beacon_config.py respectively.

- Add SWITCH_CHOICE_PREFIX to constants/control.ts alongside CUSTOM_CHOICE_PREFIX
- Remove local const from beacon/[id]/page.tsx; import from constants instead
- Move SWITCH_CHOICE_PREFIX from _beacon_popups.py into _beacon_config.py; import it
- Update shell script comment to cover both prefixes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 06:15:09 +02:00
g-butandClaude Sonnet 4.6 01a1fa051d fix(ssot): extract MIN/MAX_BEACON_COUNTDOWN_S constants — eliminate 3-site duplication
The countdown bounds (min=5, max=300) were hardcoded in beacon/[id]/page.tsx,
BeaconSettings.tsx, and beacon-settings/route.ts. Centralised to control.ts so
changing the allowed range requires one edit instead of three.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 06:02:15 +02:00
g-butandClaude Sonnet 4.6 141483271c fix(commander): persist view mode + handle closed state
- ControlPanel: use useLocalStorageState for viewMode so commander/full
  preference survives page refreshes (critical for phone use)
- ProjectCommanderCard: show Continue + Talk buttons when isClosed — closed
  projects were actionless in commander view; now match full card behaviour

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 05:52:01 +02:00
g-butandClaude Sonnet 4.6 d2defc0380 refactor(control): eliminate DRY violations in route, stream, and panel
- control/route.ts: extract rowToProfile() helper — matchProfile and
  matchProfileById both built the same 7-field object; now share one source
- control/stream/route.ts: extract scanProjects() — initial snapshot and
  tick loop duplicated the confProjects.map + readFastState computation;
  stream handler shrinks from 149 → 140 lines
- ControlPanel.tsx: call cardProps(project) once per commander card instead
  of twice (separate .onInject and .onRunWithBrain destructures)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 05:43:42 +02:00
g-butandClaude Sonnet 4.6 6005415594 feat(control): add commander view — one-click advance, talk panel, auto-roll toggle
Adds a compact mobile-first ProjectCommanderCard showing project state at a
glance with a single Continue button (fires next_best), a collapsible talk
panel for custom prompts, and a Let-it-roll auto-continue toggle. ControlPanel
gets a view-mode toggle (⊞/≡) to switch between full and commander views.

Also includes the session todos field in the Groq dispatch prompt so the
strategist has the full handoff picture when deciding queue vs next_best.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 05:23:33 +02:00
g-butandClaude Sonnet 4.6 3ea75dccad refactor(control-types): use OrchestrationTaskSummary instead of inline duplicate
The 5-field summary shape was defined inline in ProjectState.latestOrchestrationRun,
duplicating the canonical OrchestrationTaskSummary from lib/orchestration. Import and
reuse the SSOT type.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 04:56:07 +02:00
g-butandClaude Sonnet 4.6 5d83e9fa7a fix(control): use shellEscape for dir paths in git-state bash script
Directory paths from userProjects.dirPath were embedded with bare single-quote
wrapping, breaking for paths that contain single quotes (e.g. user home dirs
with apostrophes). shellEscape handles the full single-quote escape sequence.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 04:51:42 +02:00
g-butandClaude Sonnet 4.6 108fdd541c refactor(queries): eliminate duplicate select/map patterns in prompt-history and user-projects
prompt-history: extract DISPATCH_COLS + toHistoryItem/toActivityItem — remove
3 copy-pasted select shapes and row mappers; HistoryItem now derives from ActivityItem
via Omit+intersection so the type relationship is explicit.

user-projects: extract writeDevLog — remove duplicated append+cap+save logic from
appendProjectDevLog and appendProjectDevLogByEntityProjectId.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 04:38:02 +02:00
g-butandClaude Sonnet 4.6 658e118975 chore(auth): rename middleware.ts to proxy.ts per Next.js 16 convention
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 04:23:24 +02:00
g-butandClaude Sonnet 4.6 fb6da12fea refactor(agent-config): defer HOME-based path evaluation to request time
Module-level path.join(process.env.HOME, …) causes Turbopack's NFT tracer
to walk from HOME (parent of project root) and accidentally include
next.config.ts in /api/orchestration/run route bundle. Converting SESSIONS_DIR
and PROMPTS_FILE to lazy accessor functions defers evaluation to request time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 04:17:29 +02:00
g-butandClaude Sonnet 4.6 5fcefb5351 fix(control): use semantic status-negative tokens for commit-error state
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 20:45:14 +02:00
g-butandClaude Sonnet 4.6 81825e6577 fix(private-zone): use semantic ui-error class instead of hardcoded text-red-400
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 20:43:34 +02:00
g-butandClaude Sonnet 4.6 577d6a4bc9 fix(sign-in): move GitHub button visibility to server component
process.env vars are undefined in "use client" components on the client,
so githubEnabled was always false after hydration — the GitHub button
flashed in SSR HTML then disappeared. Split into a server component page
that reads env vars and passes githubEnabled as a prop to the client form.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 20:39:07 +02:00
g-butandClaude Sonnet 4.6 f12e4f150e fix(auth): use x-forwarded-host for sign-in redirect on Vercel
NextAuth v5 middleware builds the redirect URL from request.url which
in the Edge Runtime is the deployment URL (cockpit-orangecat.vercel.app),
not the cockpitapp.vercel.app alias. Vercel sets x-forwarded-host to the
original alias, so we construct the redirect Response manually using it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 20:28:47 +02:00
g-butandClaude Sonnet 4.6 5a2afaea3a feat(sidebar): add Lock private zone button to footer
Shows a Lock icon + label in the sidebar footer only when the private
zone is unlocked. Clicking calls lock() which clears sessionStorage and
re-renders the PIN gate on the next private page visit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 20:17:31 +02:00
g-butandClaude Sonnet 4.6 be2542002b fix(middleware): use default export for Turbopack compatibility
Turbopack requires middleware to be a default export. The previous
`export const { auth: middleware }` destructured named export was not
recognized. Switch to `const { auth } = NextAuth(authConfig); export default auth`.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 19:59:02 +02:00
g-butandClaude Sonnet 4.6 500656d781 fix(middleware): remove proxy.ts conflict, expand public route exclusions
proxy.ts and middleware.ts can't coexist in Next.js. Delete the old
Node.js-dependent proxy.ts and extend the edge-safe middleware matcher
to exclude beacon, thoughts, and invite paths (public routes).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 19:51:28 +02:00
g-butandClaude Sonnet 4.6 69d3a62c6d feat(private-zone): PIN-gate people/money/goals/habits/events
Moves sensitive pages into an (app)/(private) route group with a shared
layout that renders PrivatePinGate before any content. The gate posts to
/api/auth/pin (scrypt verify, 5-attempt rate limit per IP), stores a
30-min sessionStorage token on success, and shows nothing until unlocked.
Uses useSyncExternalStore to read sessionStorage without an effect.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 19:32:12 +02:00
g-butandClaude Sonnet 4.6 946597b950 fix(auth): correct signIn page path and exclude it from middleware matcher
auth.config.ts had '/auth/signin' but actual route is '/sign-in' — logged-out
users would hit a 404 instead of the sign-in page. Also excluded 'sign-in'
from the middleware matcher to prevent an infinite redirect loop when
NextAuth redirects unauthenticated users to the sign-in page.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 19:12:23 +02:00
g-butandClaude Sonnet 4.6 d9abe646ee fix(auth): split NextAuth config for Edge Runtime compatibility
Middleware runs in the Edge Runtime (no Node.js APIs). Created auth.config.ts
with a JWT-only, no-adapter config that is Edge-safe. middleware.ts now uses
NextAuth(authConfig) from auth.config.ts instead of importing the full auth.ts
(which uses Node crypto via password.ts and breaks the edge runtime).

Full auth with DrizzleAdapter + password hashing stays in auth.ts for server
components, which run in the Node.js runtime.

Fixes: "The edge runtime does not support Node.js 'crypto' module" on localhost.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 17:56:55 +02:00
g-butandClaude Sonnet 4.6 0efcf77c69 feat(dispatch): enrich Groq context with recent git commits (Step 4)
Pass recentCommits (last 3, SHA stripped) from GitState to the dispatch
prompt so the model can reason about commit history when deciding QUEUE vs
NEXTBEST — e.g. if the last 3 commits and the next queue item all touch
the same subsystem, QUEUE is the stronger choice over an unrelated nextbest.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 17:28:08 +02:00
g-butandClaude Sonnet 4.6 3ad6890365 feat(dispatch): wire Groq dispatch into auto-continue (Step 3)
handleAutoInject now pre-fetches /api/control/dispatch when the ready
banner appears — the Groq strategist decides QUEUE vs NEXTBEST based on
the session handoff + pending queue. The dispatch reason surfaces in the
ready banner as an "AI: <reason>" hint so the operator sees why a given
item was selected before the countdown fires.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 17:19:55 +02:00
g-butandClaude Sonnet 4.6 009bebd96c fix(auth): add missing middleware.ts — fixes Turbopack parse error on local dev
NextAuth v5 requires src/middleware.ts to re-export auth as default.
Without it, Next.js 16 Turbopack fails to parse the module tree locally.
Deployed Vercel builds were unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 17:09:46 +02:00
g-butandClaude Sonnet 4.6 89339006cb feat(dispatch): add Groq-powered QUEUE vs NEXTBEST dispatch route
POST /api/control/dispatch classifies whether auto-continue should drain
the queue or let the agent follow its own suggested next step, using
llama-3.3-70b-versatile via Groq. Falls back to queue-drain order when
GROQ_API_KEY is absent, preserving existing behavior. Includes defence-in-
depth health gate mirroring the client-side sessionHealthBlocksQueue check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 17:05:22 +02:00
g-butandClaude Sonnet 4.6 2b51bd2ecb feat(dispatch): health-gate queue drain when session is critical or tests failing
When handoff reports health:critical or tests:failing, auto-continue no longer
drains the queue. Both handleAutoInject and sendIntent("next_best") check the
session state before shifting a queue item — if blocked, next_best runs instead
so the agent stays focused on recovery rather than pivoting to an unrelated task.

The ready banner reflects this: shows "AI picks recovery task — health critical,
queue paused" instead of the queued item label, so the human knows why their
queued work was held back.

This is Step 1 of the dispatch intelligence path (rule-based, no AI call).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 16:55:47 +02:00
g-butandClaude Sonnet 4.6 a7f81e834e feat(control): agent switch injection + commit & push from status chips
- Switching agent now injects quit command into terminal then launches new agent
  (e.g. Claude → Codex: injects /exit, waits 900ms, injects codex launch cmd)
- Agent chip shows Switching… spinner during injection
- Pending-changes chip expands to show Commit & push button
  (stages all, commits as wip: checkpoint, pushes — shows sha on success)
- quitCommand added to each agent in registry (claude:/exit, codex/gemini: q)
- New API routes: POST /api/control/switch-agent, POST /api/project/commit

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 16:41:17 +02:00
g-butandClaude Sonnet 4.6 d57e520ea0 fix(build): remove middleware.ts — proxy.ts already handles auth routing
Next.js/Vercel rejects having both middleware.ts and proxy.ts. The existing
proxy.ts already protected all app routes and handles the onboarding redirect.
Extended it with /sign-out and /thoughts as public paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 15:52:25 +02:00
g-butandClaude Sonnet 4.6 564bf05d45 feat(ux): queued-mode feedback + hide GitHub button when OAuth not configured
- ControlPanel shows a 6s "Command queued — local daemon will execute it for <tab>"
  notice when inject returns mode=queued (cloud dispatch flow)
- inject() in use-control-data now returns { mode } so callers can branch on it
- Sign-in page hides GitHub button unless GITHUB_CLIENT_ID + GITHUB_CLIENT_SECRET
  are both set — prevents confusing OAuth error for unconfigured deployments

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 15:46:36 +02:00
g-butandClaude Sonnet 4.6 f40bd13e91 feat(auth): add middleware to protect all UI routes — redirect to sign-in when unauthenticated
Without a middleware, anyone who knows the URL could access /control, /today,
/projects etc. on the public Vercel deployment. Now all app pages require a
session; API routes handle their own auth (some use bearer tokens for the daemon).
Public paths: /, /sign-in, /sign-out, /setup, /thoughts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 15:40:11 +02:00
g-butandClaude Sonnet 4.6 46983ffb88 fix(runtime): guard ai-brief and sync routes against cloud execution
Both routes use child_process to run claude CLI and git pull respectively —
neither is available on Vercel. Returns 503 with descriptive message.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 15:28:12 +02:00
g-butandClaude Sonnet 4.6 ee6811b773 fix(runtime): guard orchestration/run route — returns 503 in cloud mode
spawn() and zellij inject are not available on Vercel.
The orchestration run endpoint now returns a clear 503 instead of crashing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 15:24:10 +02:00