Compare commits

..

46 Commits

Author SHA1 Message Date
Haileyesus
0595ba8fed refactor: add gemini jsonl session support 2026-04-29 19:21:57 +03:00
Haileyesus
c7d4fa915e refactor: directly use getProjectPathById from projectsDb 2026-04-29 18:40:21 +03:00
Haileyesus
5352582fe5 refactor: remove dead code 2026-04-29 18:33:27 +03:00
Haileyesus
5b9108ac18 fix(codex): preserve reasoning entries as thinking blocks
Codex history normalization was downgrading reasoning into plain assistant text
because of branch ordering, not because the raw data was missing.

Why this mattered:
- Codex reasoning JSONL entries are intentionally mapped to history items with
  type thinking, but they also carry message.role assistant.
- normalizeHistoryEntry evaluated the assistant-role branch before the
  thinking branch.
- As a result, reasoning content matched the assistant-text path first and was
  emitted as kind text instead of kind thinking.
- This collapses semantic intent, so UI and downstream features that rely on
  thinking blocks (separate rendering, filtering, and interpretation of model
  thought process vs final answer) receive the wrong message kind.

What changed:
- Prioritized thinking detection (raw.type === thinking or raw.isReasoning)
  before role-based assistant normalization.
- Kept a non-empty content guard for thinking payloads to avoid emitting empty
  artifacts.

Impact:
- Reasoning entries from persisted Codex JSONL now remain thinking blocks
  end-to-end.
- Regular assistant text normalization behavior remains unchanged.
2026-04-29 18:23:14 +03:00
Haileyesus
cd3e8986d7 refactor(database): make session id the primary key in sessions table 2026-04-29 18:06:58 +03:00
Haileyesus
f175d20c4e refactor: normalize project paths across database and service modules 2026-04-29 18:02:33 +03:00
Haileyesus
0f93ef2781 refactor: improve session limit and offset validation in provider routes 2026-04-29 11:46:53 +03:00
Haileyesus
10f35c238d refactor(session-synchronizer): update last scanned timestamp based on synchronization results 2026-04-29 11:35:59 +03:00
Haileyesus
805e283fb6 fix(migrations,projects,clone): normalize legacy schema before writes and harden conflict detection
Why

- Legacy installs can have a sessions table shape that predates provider/custom_name columns. Running migrateLegacySessionNames first caused its INSERT OR REPLACE INTO sessions (...) to target columns that may not exist and fail during startup migration.

- Some upgraded databases had projects.project_id as plain TEXT instead of a real PRIMARY KEY. That breaks assumptions used by id-based lookups and can allow invalid/duplicate identity semantics over time.

- projectsDb.createProjectPath inferred outcomes from 
ow.isArchived, but the upsert path always returns the post-update row with isArchived=0, so archived-reactivation and fresh-create could be misclassified.

- git clone accepted user-controlled URLs directly in argv position, so inputs beginning with - could be interpreted as options instead of a repository argument.

What

- Added 
ebuildProjectsTableWithPrimaryKeySchema in migrations: detect table shape via getTableInfo('projects'), verify project_id has pk=1, and rebuild when missing.

- Rebuild flow now creates a canonical projects__new table (project_id TEXT PRIMARY KEY), copies rows with transformation, backfills empty ids via SQLITE_UUID_SQL, deduplicates conflicting ids/paths, then swaps tables inside a transaction.

- Replaced the prior ddColumnToTableIfNotExists(...) + UPDATE project_id sequence with PK-aware detection/rebuild logic so legacy DBs converge to the required schema.

- Reordered migration sequence to run 
ebuildSessionsTableWithProjectSchema before migrateLegacySessionNames, ensuring sessions is normalized before legacy session_names merge writes execute.

- Updated projectsDb.createProjectPath to generate an ttemptedId before insert, pass it into the prepared statement, and classify outcomes by comparing returned 
ow.project_id to ttemptedId (created vs 
eactivated_archived), with no-row remaining ctive_conflict.

- Hardened clone execution by inserting -- before clone URL in git argv and rejecting normalized GitHub URLs that start with - in startCloneProject.

Tests

- Added integration coverage for projectsDb.createProjectPath branches: fresh insert, archived reactivation, and active conflict.

- Added clone service test for option-prefixed githubUrl rejection (INVALID_GITHUB_URL).
2026-04-28 17:15:13 +03:00
Haileyesus
8570bd7bab refactor: add handling for internal Codex metadata in conversation search 2026-04-27 22:30:31 +03:00
Haileyesus
5af2b719e2 fix: search performance 2026-04-27 22:23:50 +03:00
Haileyesus
9684aa0941 Merge branch 'refactor/use-database-for-session-managemnet' of https://github.com/siteboon/claudecodeui into refactor/use-database-for-session-managemnet 2026-04-27 21:39:56 +03:00
Haileyesus
50ee3c7548 refactor: move search to module 2026-04-27 21:39:48 +03:00
Haileyesus
9a8fb116ef refactor: implement pagination for project sessions loading 2026-04-27 21:22:56 +03:00
Haileyesus
14e6b5b7b2 refactor(projects/sidebar): remove temp snapshot side-effects and simplify session metadata UX
Why this change was needed:
- Project listing had an implicit side effect: every fetch wrote a debug snapshot under `.tmp/project-dumps`.
  That added unnecessary disk I/O to a hot path, introduced hidden runtime behavior, and created maintenance
  overhead for code that was not part of product functionality.
- Keeping snapshot-specific exports/tests around made the projects module API broader than needed and coupled
  tests to temporary/debug behavior instead of user-visible behavior.
- Codex sessions could remain stuck with a placeholder name (`Untitled Codex Session`) even after a real title
  became available from newer sync data, which degraded session discoverability in the UI.
- Sidebar session rows showed duplicated provider branding and long-form relative times, which added visual noise
  and reduced scan speed when many sessions are listed.

What changed:
- Removed temporary projects snapshot dumping from `projects-with-sessions-fetch.service.ts`:
  - deleted snapshot types/helpers and file-write flow
  - removed the write call from `getProjectsWithSessions`
- Removed snapshot-related surface area from `projects/index.ts`.
- Removed the snapshot-focused test `projects.service.test.ts` that only validated removed debug behavior.
- Updated `codex-session-synchronizer.provider.ts` to upgrade session names when an existing session still has
  the placeholder title but a real parsed name is now available.
- Updated `SidebarSessionItem.tsx`:
  - removed duplicate provider logo rendering in each session row
  - moved age indicator to the right side
  - made age indicator fade on hover to prioritize action controls
  - switched to compact relative time format (`<1m`, `Xm`, `Xhr`, `Xd`) for faster list scanning

Outcome:
- Lower overhead and fewer hidden side effects in project fetches.
- Cleaner module boundaries in projects.
- Better Codex session naming consistency after sync.
- Cleaner sidebar density and clearer hover/action behavior.
2026-04-27 21:07:54 +03:00
Haile
714c9214e6 Potential fix for pull request finding 'Useless assignment to local variable'
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
2026-04-27 15:21:53 +03:00
Haile
c027dc0813 fix: remove unused var
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
2026-04-27 15:21:05 +03:00
Haileyesus
16954c883b refactor: move fetching messages to module 2026-04-27 14:30:09 +03:00
Haileyesus
9663f08fcb refactor: move rename and delete sessions to modules 2026-04-27 14:21:03 +03:00
Haileyesus
7ceaa9e326 refactor: move projects provider specific logic into respective session providers 2026-04-27 13:46:19 +03:00
Haileyesus
d3adc7afb8 refactor: optimize project auto-expand logic 2026-04-25 21:49:09 +03:00
Haileyesus
360aa514f9 fix(projects-state): stop websocket message reprocessing loop
The websocket projects effect in useProjectsState could re-handle the same
latestMessage after local state writes triggered re-renders.

Under bursty websocket traffic, this created an update feedback cycle
that surfaced as 'Maximum update depth exceeded', often from Sidebar.

What changed:
- Added lastHandledMessageRef so each latestMessage object is handled once.
- Added an early return guard when the current message was already handled.
- Made projects updates idempotent by comparing previous and merged payloads
  before calling setProjects.

Result:
- Breaks the effect -> state update -> effect re-entry cycle.
- Reduces redundant renders during rapid projects_updated traffic while
  preserving normal project/session synchronization.
2026-04-25 21:45:30 +03:00
Haileyesus
68123dcc33 feat: optimistic update for session watcher 2026-04-25 21:32:24 +03:00
Haileyesus
edc7d6d184 refactor: implement optimistic UI for project star state management 2026-04-25 21:09:25 +03:00
Haileyesus
113c7631b8 refactor: move project star state from localStorage to backend 2026-04-25 21:08:16 +03:00
Haileyesus
7a82fb54dc refactor: move project deletion to module 2026-04-25 20:45:24 +03:00
Haileyesus
447f352e7b refactor: move project rename to module 2026-04-25 20:28:58 +03:00
Haileyesus
3188ef5fee refactor: remove loading sessions logic from sidebar 2026-04-25 19:56:50 +03:00
Haileyesus
bb86236520 refactor: modularize project services, and wizard create/clone flow
Restructure project creation, listing, GitHub clone progress, and TaskMaster
details behind a dedicated TypeScript module under server/modules/projects/,
and align the client wizard with a single path-based flow.

Server / routing
- Remove server/routes/projects.js and mount server/modules/projects/
  projects.routes.ts at /api/projects (still behind authenticateToken).
- Drop duplicate handlers from server/index.js for GET /api/projects and
  GET /api/projects/:projectId/taskmaster; those live on the new router.
- Import WORKSPACES_ROOT and validateWorkspacePath from shared utils in
  index.js instead of the deleted projects route module.

Projects router (projects.routes.ts)
- GET /: list projects with sessions (existing snapshot behavior).
- POST /create-project: validate body, reject legacy workspaceType and
  mixed clone fields, delegate to createProject service, return distinct
  success copy when an archived path is reactivated.
- GET /clone-progress: Server-Sent Events for clone progress/complete/error;
  requires authenticated user id for token resolution; wires startCloneProject.
- GET /:projectId/taskmaster: delegates to getProjectTaskMaster.

Services (new)
- project-management.service.ts: path validation, workspace directory
  creation, persistence via projectsDb.createProjectPath, mapping to API
  project shape; surfaces AppError for validation, conflict, and not-found
  cases; optional dependency injection for tests.
- project-clone.service.ts: validates workspace, resolves GitHub auth
  (stored token or inline token), runs git clone with progress callbacks,
  registers project via createProject on success; sanitizes errors and
  supports cancellation; injectable dependencies for tests.
- projects-has-taskmaster.service.ts: moves TaskMaster detection and
  normalization out of server/projects.js; resolve-by-id and public
  getProjectTaskMaster with structured AppError responses.

Persistence and shared types
- projectsDb.createProjectPath now returns CreateProjectPathResult
  (created | reactivated_archived | active_conflict) using INSERT … ON
  CONFLICT with selective update when the row is archived; normalizes
  display name from path or custom name; repository row typing moves to
  shared ProjectRepositoryRow.
- getProjectPaths() returns only non-archived rows (isArchived = 0).
- shared/types.ts: ProjectRepositoryRow, CreateProjectPathResult/outcome,
  WorkspacePathValidationResult.
- shared/utils.ts: WORKSPACES_ROOT, forbidden path lists, validateWorkspacePath,
  asyncHandler for Express async routes.

Legacy cleanup
- server/projects.js: remove detectTaskMasterFolder, normalizeTaskMasterInfo,
  and getProjectTaskMasterById (logic lives in the new service).
- server/routes/agent.js: register external API project paths with
  projectsDb.createProjectPath instead of addProjectManually try/catch;
  treat active_conflict as an existing registration and continue.

Tests
- Add Node test suites for project-management, project-clone, and
  projects-has-taskmaster services; update projects.service test import
  for renamed projects-with-sessions-fetch.service.ts.

Rename
- projects.service.ts → projects-with-sessions-fetch.service.ts;
  re-export from modules/projects/index.ts.

Client (project creation wizard)
- Remove StepTypeSelection and workspaceType from form state and types;
  wizard is two steps (configure path/GitHub auth, then review).
- createWorkspaceRequest → createProjectRequest; clone vs create-only
  inferred from githubUrl (pathUtils / isCloneWorkflow).
- Adjust step indices, WizardProgress, StepConfiguration/Review,
  WorkspacePathField, and src/utils/api.js as needed for the new API.

Docs
- Minor websocket README touch-up.

Net: ~1.6k insertions / ~0.9k deletions across 29 files; behavior is
centralized in typed services with explicit HTTP errors and test seams.
2026-04-25 19:36:47 +03:00
Haileyesus
7023a8cf7b refactor: remove unnecessary GitHub cloning logic from create-workspace endpoint 2026-04-25 17:56:14 +03:00
Haileyesus
5d7d6e478e refactor(index.js): fix import order 2026-04-25 16:17:21 +03:00
Haileyesus
1083746df5 refactor(index.js): reorganize code structure 2026-04-25 16:02:35 +03:00
Haileyesus
eec9701679 refactor(sessions-watcher): remove redundant logging after session sync completion 2026-04-25 15:44:26 +03:00
Haileyesus
2323a576a6 refactor(websocket): move websocket logic to its own module 2026-04-25 15:39:22 +03:00
Haileyesus
3fd2353ffe refactor: use updated session watcher
In addition, for projects_updated websocket response, send the sessionId instead
2026-04-24 21:56:19 +03:00
Haileyesus
b3445508e9 refactor: update import path for getProjectsWithSessions to include file extension 2026-04-24 19:09:30 +03:00
Haileyesus
c412aac8fb refactor(projects): rename getProjects with getProjectsWithSessions 2026-04-24 19:08:27 +03:00
Haileyesus
18e5a88c48 refactor(projects): reorganize project-related logic into dedicated modules 2026-04-24 19:06:40 +03:00
Haileyesus
dc5d73936a refactor(projects): identify projects by DB projectId instead of folder-derived name
GET /api/projects used to scan ~/.claude/projects/ on every request, derive
each project's identity from the encoded folder name, and re-parse JSONL
files to build session lists. Using the folder-derived name as the project
identifier leaked the Claude CLI's on-disk encoding into every API route,
forced every downstream endpoint to re-resolve a real path via JSONL
'cwd' inspection, and made the project list endpoint O(projects x sessions)
on disk I/O.

This change switches the entire API surface to identify projects by the
stable primary key from the 'projects' table and drives the listing
straight from the DB:

- Add projectsDb.getProjectPathById as the canonical projectId -> path
  resolver so routes no longer need to touch the filesystem to figure out
  where a project lives.

- Rewrite getProjects so it reads the project list from the 'projects'
  table and the per-project session list from the 'sessions' table (one
  SELECT per project). No filesystem scanning happens for this endpoint
  anymore, which removes the dependency on ~/.claude/projects existing,
  on Cursor's MD5-hashed chat folders being discoverable, and on Codex's
  JSONL history being on disk. Per the migration spec each session now
  exposes 'summary' sourced from sessions.custom_name, 'messageCount' = 0
  (message counting is not implemented), and sessionMeta.hasMore is
  pinned to false since this endpoint doesn't drive session pagination.

- Introduce id-based wrappers (getSessionsById, renameProjectById,
  deleteSessionById, deleteProjectById, getProjectTaskMasterById) so
  every caller can pass projectId and resolve the real path through the
  DB. renameProjectById also writes to projects.custom_project_name so
  the DB-driven getProjects response reflects renames immediately; it
  keeps project-config.json in sync for any legacy reader that still
  consults the JSON file.

- Migrate every /api/projects/:projectName route in server/index.js,
  server/routes/taskmaster.js, and server/routes/messages.js to
  :projectId, and change server/routes/git.js so the 'project'
  query/body parameter carries a projectId that is resolved through the
  DB before any git command runs. TaskMaster WebSocket broadcasts emit
  'projectId' for the same reason so the frontend can match
  notifications against its current selection without another lookup.

- Delete helpers that existed only to feed the old getProjects path
  (getCursorSessions, getGeminiCliSessions, getProjectTaskMaster) along
  with their unused imports (better-sqlite3's Database,
  applyCustomSessionNames). The legacy folder-name helpers (getSessions,
  renameProject, deleteSession, deleteProject, extractProjectDirectory)
  are kept as internal implementation details of the id-based wrappers
  and of destructive cleanup / conversation search, but they are no
  longer re-exported.

- searchConversations still walks JSONL to produce match snippets (that
  data doesn't live in the DB), but it now includes the resolved
  projectId in each result so the sidebar can cross-reference hits with
  its already loaded project list without a second round-trip.

Frontend migration:

- Project.name is replaced by Project.projectId in src/types/app.ts, and
  ProjectSession.__projectName becomes __projectId so session tagging
  and sidebar state keys stay aligned with the backend identifier.
  Settings continues to use SettingsProject.name for legacy consumers,
  but it is populated from projectId by normalizeProjectForSettings.

- All places that previously indexed per-project state by project.name
  (sidebar expanded/starred/loading/deletingProjects sets,
  additionalSessions map, projectHasMoreOverrides, starredProjects
  localStorage, command history and draft-input localStorage,
  TaskMaster caches) now key on projectId so state survives
  display-name edits and is consistent across the app.

- src/utils/api.js renames every endpoint parameter to projectId, the
  unified messages endpoint takes projectId in its query string, and
  useSessionStore forwards projectId on fetchFromServer / fetchMore /
  refreshFromServer. Git panel, file tree, code editor, PRD editor,
  plugins context, MCP server flows and TaskMaster hooks are all
  updated to pass projectId.

- DEFAULT_PROJECT_FOR_EMPTY_SHELL is updated to carry a 'default'
  projectId sentinel so the empty-shell placeholder still satisfies the
  Project contract.

Bug fix bundled in:

- sessionsDb.setName no longer bumps updated_at when a row already
  exists. Renaming is a label change, not activity, so there is no
  reason for it to reset 'last activity' in the sidebar. It also no
  longer relies on SQLite's CURRENT_TIMESTAMP, which stores a naive
  'YYYY-MM-DD HH:MM:SS' value that JavaScript parses as local time and
  caused renamed sessions to appear shifted backwards by the client's
  UTC offset. When an INSERT actually happens it now writes ISO-8601
  UTC with a 'Z' suffix.

- buildSessionsByProviderFromDb normalizes any legacy naive timestamps
  in the sessions table to ISO-8601 UTC on the way out so rows written
  before this change also render correctly on the client.

Other cleanup:

- Removed the filesystem-first project-discovery comment block at the
  top of server/projects.js and replaced it with a short note that
  describes the new DB-driven flow and lists the few remaining
  filesystem-dependent helpers (message reads, search, destructive
  delete, manual project registration).

- server/modules/providers/index.ts is added as a small barrel so the
  providers module exposes a stable public surface.

Made-with: Cursor
2026-04-24 18:12:10 +03:00
Haileyesus
4bd07c3ece refactor: update import paths for database modules and remove legacy db.js and schema.js files 2026-04-24 15:11:25 +03:00
Haileyesus
15171e1428 perf(projects): lazy-load TaskMaster metadata per selected project
Why:

- /api/projects is a hot path (initial load, sidebar refresh, websocket sync).

- Scanning .taskmaster for every project on each call added avoidable fs I/O and payload size.

- TaskMaster metadata is only needed after selecting a specific project.

- Moving it to a project-scoped endpoint makes loading cost match user intent.

- The UI now hydrates TaskMaster state on selection and keeps it across refresh events.

- This prevents status flicker/regression while still removing global scan overhead.

- Selection fetches are sequence-guarded to block stale async responses on fast switching.

- isManuallyAdded was removed from responses to keep the public project contract minimal.

- Project dumps now use incrementing snapshot files to preserve history for debugging.

What changed:

- Added GET /api/projects/:projectName/taskmaster and getProjectTaskMaster().

- Removed TaskMaster detection from bulk getProjects().

- Added api.projectTaskmaster(...) plus selection-time hydration in frontend contexts.

- Merged cached taskmaster values into refreshed project lists for continuity.

- Removed isManuallyAdded from manual project payloads.
2026-04-24 13:30:04 +03:00
Haileyesus
f99af1ff67 feat: added session indexer logic 2026-04-23 17:32:08 +03:00
Haileyesus
7b75ed0b72 refactor(database): move db into typescript
- Implemented githubTokensDb for managing GitHub tokens with CRUD operations.
- Created
otificationPreferencesDb to handle user notification preferences.
- Added projectsDb for project path management and related operations.
- Introduced pushSubscriptionsDb for managing browser push subscriptions.
- Developed scanStateDb to track the last scanned timestamp.
- Established sessionsDb for session management with CRUD functionalities.
- Created userDb for user management, including authentication and onboarding.
- Implemented apidKeysDb for storing and managing VAPID keys.

feat(database): define schema for new database tables

- Added SQL schema definitions for users, API keys, user credentials, notification preferences, VAPID keys, push subscriptions, projects, sessions, scan state, and app configuration.
- Included necessary indexes for performance optimization.

refactor(shared): enhance type definitions and utility functions

- Updated shared types and interfaces for improved clarity and consistency.
- Added new types for credential management and provider-specific operations.
- Refined utility functions for better error handling and message normalization.
2026-04-23 16:59:45 +03:00
Haileyesus
2e326214e1 refactor: rename session_names table and related code to sessions for clarity and consistency 2026-04-22 13:43:16 +03:00
Haileyesus
295b8846a7 refactor: remove unused fields from project and session objects 2026-04-22 13:28:44 +03:00
Haileyesus
80d010126f refactor: remove unused exports 2026-04-22 13:01:55 +03:00
90 changed files with 894 additions and 4748 deletions

View File

@@ -3,32 +3,6 @@
All notable changes to CloudCLI UI will be documented in this file.
## [1.31.5](https://github.com/siteboon/claudecodeui/compare/v1.31.4...v1.31.5) (2026-04-30)
### New Features
* add auto mode to claude code ([3f71d49](https://github.com/siteboon/claudecodeui/commit/3f71d4932b05dfedcdf816e2a3d7d0cd69c4f566))
## [1.31.4](https://github.com/siteboon/claudecodeui/compare/v1.31.3...v1.31.4) (2026-04-30)
### Bug Fixes
* bump codex sdk to latest version ([658421c](https://github.com/siteboon/claudecodeui/commit/658421c1c44ec4eb58b69ec7b1844a9fba11a3f3))
## [1.31.3](https://github.com/siteboon/claudecodeui/compare/v1.31.2...v1.31.3) (2026-04-30)
## [1.31.2](https://github.com/siteboon/claudecodeui/compare/v1.31.0...v1.31.2) (2026-04-30)
### Bug Fixes
* migrations for new sqlite schema ([0753c04](https://github.com/siteboon/claudecodeui/commit/0753c047837dab17b86ae4453027e30b465870f8))
## [1.31.0](https://github.com/siteboon/claudecodeui/compare/v1.30.0...v1.31.0) (2026-04-30)
### Bug Fixes
* **/status:** use CLAUDE_MODELS.DEFAULT instead of stale 'claude-sonnet-4.5' fallback ([#723](https://github.com/siteboon/claudecodeui/issues/723)) ([b4a39c7](https://github.com/siteboon/claudecodeui/commit/b4a39c729710a6294c62eb742e99e05f3e3914e9))
## [1.30.0](https://github.com/siteboon/claudecodeui/compare/v1.29.5...v1.30.0) (2026-04-21)
### New Features

View File

@@ -164,7 +164,7 @@ CloudCLI has a plugin system that lets you add custom tabs with their own fronte
|---|---|
| **[Project Stats](https://github.com/cloudcli-ai/cloudcli-plugin-starter)** | Shows file counts, lines of code, file-type breakdown, largest files, and recently modified files for your current project |
| **[Web Terminal](https://github.com/cloudcli-ai/cloudcli-plugin-terminal)** | Full xterm.js terminal with multi-tab support|
| **[CloudCLI Scheduler](https://github.com/grostim/cloudcli-cron)** | Create workspace-scoped scheduled prompts and execute them through a local CLI such as Codex, Claude Code, or Gemini CLI|
### Build Your Own
**[Plugin Starter Template →](https://github.com/cloudcli-ai/cloudcli-plugin-starter)** — fork this repo to create your own plugin. It includes a working example with frontend rendering, live context updates, and RPC communication to a backend server.

View File

@@ -157,7 +157,7 @@ export default tseslint.config(
},
{
type: "backend-shared-utils", // shared backend runtime helpers that modules may import directly
pattern: ["server/shared/utils.{js,ts}", "server/shared/claude-cli-path.ts"], // classify the shared utils file so modules can depend on it explicitly
pattern: ["server/shared/utils.{js,ts}"], // classify the shared utils file so modules can depend on it explicitly
mode: "file",
},
{

667
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@cloudcli-ai/cloudcli",
"version": "1.31.5",
"version": "1.30.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@cloudcli-ai/cloudcli",
"version": "1.31.5",
"version": "1.30.0",
"hasInstallScript": true,
"license": "AGPL-3.0-or-later",
"dependencies": {
@@ -21,7 +21,7 @@
"@codemirror/theme-one-dark": "^6.1.2",
"@iarna/toml": "^2.2.5",
"@octokit/rest": "^22.0.0",
"@openai/codex-sdk": "^0.125.0",
"@openai/codex-sdk": "^0.101.0",
"@replit/codemirror-minimap": "^0.5.2",
"@tailwindcss/typography": "^0.5.16",
"@uiw/react-codemirror": "^4.23.13",
@@ -36,7 +36,6 @@
"chokidar": "^4.0.3",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
"cors": "^2.8.5",
"cross-spawn": "^7.0.3",
"express": "^4.18.2",
@@ -3307,9 +3306,9 @@
}
},
"node_modules/@openai/codex": {
"version": "0.125.0",
"resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.125.0.tgz",
"integrity": "sha512-GiE9wlgL95u/5BRirY5d3EaRLU1tu7Y1R09R8lCHHVmcQdSmhS809FdPDWH3gIYHS7ZriAPqXwJ3aLA0WKl40Q==",
"version": "0.101.0",
"resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.101.0.tgz",
"integrity": "sha512-H874q5K5I3chrT588BaddMr7GNvRYypc8C1MKWytNUF2PgxWMko2g/2DgKbt5OdajZKMsWdbsPywu34KQGf5Qw==",
"license": "Apache-2.0",
"bin": {
"codex": "bin/codex.js"
@@ -3318,19 +3317,19 @@
"node": ">=16"
},
"optionalDependencies": {
"@openai/codex-darwin-arm64": "npm:@openai/codex@0.125.0-darwin-arm64",
"@openai/codex-darwin-x64": "npm:@openai/codex@0.125.0-darwin-x64",
"@openai/codex-linux-arm64": "npm:@openai/codex@0.125.0-linux-arm64",
"@openai/codex-linux-x64": "npm:@openai/codex@0.125.0-linux-x64",
"@openai/codex-win32-arm64": "npm:@openai/codex@0.125.0-win32-arm64",
"@openai/codex-win32-x64": "npm:@openai/codex@0.125.0-win32-x64"
"@openai/codex-darwin-arm64": "npm:@openai/codex@0.101.0-darwin-arm64",
"@openai/codex-darwin-x64": "npm:@openai/codex@0.101.0-darwin-x64",
"@openai/codex-linux-arm64": "npm:@openai/codex@0.101.0-linux-arm64",
"@openai/codex-linux-x64": "npm:@openai/codex@0.101.0-linux-x64",
"@openai/codex-win32-arm64": "npm:@openai/codex@0.101.0-win32-arm64",
"@openai/codex-win32-x64": "npm:@openai/codex@0.101.0-win32-x64"
}
},
"node_modules/@openai/codex-darwin-arm64": {
"name": "@openai/codex",
"version": "0.125.0-darwin-arm64",
"resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.125.0-darwin-arm64.tgz",
"integrity": "sha512-Gn2fHiSO0XgyHp1OSd5DWUTm66Bv9UEuipW5pVEj1E+hWZCOrdqnYttllKFWtRGj5yiKefNX3JIxONgh/ZwlOQ==",
"version": "0.101.0-darwin-arm64",
"resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.101.0-darwin-arm64.tgz",
"integrity": "sha512-unk4rTRQQ9o0w2Upu35IsJHpoZHJ+tU/myn6LNhUjcP9FrjLnEcAQJ6WIMtdTYVPja1PGhFSO0DNxV79GMvehw==",
"cpu": [
"arm64"
],
@@ -3345,9 +3344,9 @@
},
"node_modules/@openai/codex-darwin-x64": {
"name": "@openai/codex",
"version": "0.125.0-darwin-x64",
"resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.125.0-darwin-x64.tgz",
"integrity": "sha512-TZ5Lek2X/UXTI9LXFxzarvQaJeuTrqVh4POc7soO/8RclVnCxADnCf15sivxLd5eiFW4t0myGoeVoM4lciRiRg==",
"version": "0.101.0-darwin-x64",
"resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.101.0-darwin-x64.tgz",
"integrity": "sha512-+KFi1IapCQGd3vLQp2lI4xI3hu2QffDZYt7Fhfw6NxEFOKhHnTamRtQ5yI8jYQcYF+pQfYF2fyiuXLM1lITLQw==",
"cpu": [
"x64"
],
@@ -3362,9 +3361,9 @@
},
"node_modules/@openai/codex-linux-arm64": {
"name": "@openai/codex",
"version": "0.125.0-linux-arm64",
"resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.125.0-linux-arm64.tgz",
"integrity": "sha512-pPnJoJD6rZ2Iin0zNt/up36bO2/EOp2B+1/rPHu/lSq3PJbT3Fmnfut2kJy5LylXb7bGA2XQbtqOogZzIbnlkA==",
"version": "0.101.0-linux-arm64",
"resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.101.0-linux-arm64.tgz",
"integrity": "sha512-RkDnQeq7M6ZBtD+8i+I5ewjjOf02BcJq6r1kN4RBewfAQBsz6B73Ns3OrI2bHVRsuPtAf8Cf1S4xg/eFZT2Omg==",
"cpu": [
"arm64"
],
@@ -3379,9 +3378,9 @@
},
"node_modules/@openai/codex-linux-x64": {
"name": "@openai/codex",
"version": "0.125.0-linux-x64",
"resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.125.0-linux-x64.tgz",
"integrity": "sha512-K2NTTEeBpz/G+N2x17UGWfauRt3So+ir4f+U/60l5PPnYEJB/w3YZrlXo2G9og8Dm9BqtoBAjoPV74sRv9tWWQ==",
"version": "0.101.0-linux-x64",
"resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.101.0-linux-x64.tgz",
"integrity": "sha512-SJeEdQ4ReEU3nvtceZ1uY3me6oWoB3djr3GnZmAUCEUuYEWD1kRGprAyJB1N0B+8zhSv0SU2e9sX5t3aCV4AwQ==",
"cpu": [
"x64"
],
@@ -3395,12 +3394,12 @@
}
},
"node_modules/@openai/codex-sdk": {
"version": "0.125.0",
"resolved": "https://registry.npmjs.org/@openai/codex-sdk/-/codex-sdk-0.125.0.tgz",
"integrity": "sha512-1xCIHdSbQVF880nJ2aVWdPIsWZbSpKODwuP9y/gvtChDYhYfYEW0DKp2H8ZlctkzIjlzS/WzYmP6ZZPHIvs2Dg==",
"version": "0.101.0",
"resolved": "https://registry.npmjs.org/@openai/codex-sdk/-/codex-sdk-0.101.0.tgz",
"integrity": "sha512-Lrar2pDvGUX64itSbMNKuNBzxh72UwKokY4TPuXJRURwGX0qyDi80n7DiVivC40BwFsQWNs6behSo/9Mr6PoLw==",
"license": "Apache-2.0",
"dependencies": {
"@openai/codex": "0.125.0"
"@openai/codex": "0.101.0"
},
"engines": {
"node": ">=18"
@@ -3408,9 +3407,9 @@
},
"node_modules/@openai/codex-win32-arm64": {
"name": "@openai/codex",
"version": "0.125.0-win32-arm64",
"resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.125.0-win32-arm64.tgz",
"integrity": "sha512-zxoUakw9oIHIFrAyk400XkkLBJFA6nOym0NDq6sQ/jhdcYraKqNSRCII2nsBwZHk+/4zgUvuk52iuutgysY/rQ==",
"version": "0.101.0-win32-arm64",
"resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.101.0-win32-arm64.tgz",
"integrity": "sha512-WQ8QsychjHyvlr+vCSTMbd2/yrBIZre5tRuM79eZi973BJz0CSEiFsNSGg5fvpnJuiHHawZ/8HWeir7nlatamQ==",
"cpu": [
"arm64"
],
@@ -3425,9 +3424,9 @@
},
"node_modules/@openai/codex-win32-x64": {
"name": "@openai/codex",
"version": "0.125.0-win32-x64",
"resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.125.0-win32-x64.tgz",
"integrity": "sha512-ofpOK+OWH5QFuUZ9pTM0d/PcXUXiIP5z5DpRcE9MlucJoyOl4Zy4Nu3NcuHF4YzCkZMQb6x3j0tjDEPHKqNQzw==",
"version": "0.101.0-win32-x64",
"resolved": "https://registry.npmjs.org/@openai/codex/-/codex-0.101.0-win32-x64.tgz",
"integrity": "sha512-H+7h9x0fYrJRUZZHCA62Dzb/CS5Scl1sUw1aamfmHJzzorX+uTFOgGsibzqFpHTd6nRM4q8//fCdSxe5wUpOQQ==",
"cpu": [
"x64"
],
@@ -3464,447 +3463,6 @@
"node": ">=14"
}
},
"node_modules/@radix-ui/primitive": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.1.3.tgz",
"integrity": "sha512-JTF99U/6XIjCBo0wqkU5sK10glYe27MRRsfwoiq5zzOEZLHU3A3KCMa5X/azekYRCJ0HlwI0crAXS/5dEHTzDg==",
"license": "MIT"
},
"node_modules/@radix-ui/react-compose-refs": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@radix-ui/react-compose-refs/-/react-compose-refs-1.1.2.tgz",
"integrity": "sha512-z4eqJvfiNnFMHIIvXP3CY57y2WJs5g2v3X0zm9mEJkrkNv4rDxu+sg9Jh8EkXyeqBkB7SOcboo9dMVqhyrACIg==",
"license": "MIT",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-context": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@radix-ui/react-context/-/react-context-1.1.2.tgz",
"integrity": "sha512-jCi/QKUM2r1Ju5a3J64TH2A5SpKAgh0LpknyqdQ4m6DCV0xJ2HG1xARRwNGPQfi1SLdLWZ1OJz6F4OMBBNiGJA==",
"license": "MIT",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-dialog": {
"version": "1.1.15",
"resolved": "https://registry.npmjs.org/@radix-ui/react-dialog/-/react-dialog-1.1.15.tgz",
"integrity": "sha512-TCglVRtzlffRNxRMEyR36DGBLJpeusFcgMVD9PZEzAKnUs1lKCgX5u9BmC2Yg+LL9MgZDugFFs1Vl+Jp4t/PGw==",
"license": "MIT",
"dependencies": {
"@radix-ui/primitive": "1.1.3",
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-context": "1.1.2",
"@radix-ui/react-dismissable-layer": "1.1.11",
"@radix-ui/react-focus-guards": "1.1.3",
"@radix-ui/react-focus-scope": "1.1.7",
"@radix-ui/react-id": "1.1.1",
"@radix-ui/react-portal": "1.1.9",
"@radix-ui/react-presence": "1.1.5",
"@radix-ui/react-primitive": "2.1.3",
"@radix-ui/react-slot": "1.2.3",
"@radix-ui/react-use-controllable-state": "1.2.2",
"aria-hidden": "^1.2.4",
"react-remove-scroll": "^2.6.3"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-primitive": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-primitive/-/react-primitive-2.1.3.tgz",
"integrity": "sha512-m9gTwRkhy2lvCPe6QJp4d3G1TYEUHn/FzJUtq9MjH46an1wJU+GdoGC5VLof8RX8Ft/DlpshApkhswDLZzHIcQ==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-slot": "1.2.3"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-dismissable-layer": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/@radix-ui/react-dismissable-layer/-/react-dismissable-layer-1.1.11.tgz",
"integrity": "sha512-Nqcp+t5cTB8BinFkZgXiMJniQH0PsUt2k51FUhbdfeKvc4ACcG2uQniY/8+h1Yv6Kza4Q7lD7PQV0z0oicE0Mg==",
"license": "MIT",
"dependencies": {
"@radix-ui/primitive": "1.1.3",
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-primitive": "2.1.3",
"@radix-ui/react-use-callback-ref": "1.1.1",
"@radix-ui/react-use-escape-keydown": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-dismissable-layer/node_modules/@radix-ui/react-primitive": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-primitive/-/react-primitive-2.1.3.tgz",
"integrity": "sha512-m9gTwRkhy2lvCPe6QJp4d3G1TYEUHn/FzJUtq9MjH46an1wJU+GdoGC5VLof8RX8Ft/DlpshApkhswDLZzHIcQ==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-slot": "1.2.3"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-focus-guards": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-focus-guards/-/react-focus-guards-1.1.3.tgz",
"integrity": "sha512-0rFg/Rj2Q62NCm62jZw0QX7a3sz6QCQU0LpZdNrJX8byRGaGVTqbrW9jAoIAHyMQqsNpeZ81YgSizOt5WXq0Pw==",
"license": "MIT",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-focus-scope": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/@radix-ui/react-focus-scope/-/react-focus-scope-1.1.7.tgz",
"integrity": "sha512-t2ODlkXBQyn7jkl6TNaw/MtVEVvIGelJDCG41Okq/KwUsJBwQ4XVZsHAVUkK4mBv3ewiAS3PGuUWuY2BoK4ZUw==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-primitive": "2.1.3",
"@radix-ui/react-use-callback-ref": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-primitive": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-primitive/-/react-primitive-2.1.3.tgz",
"integrity": "sha512-m9gTwRkhy2lvCPe6QJp4d3G1TYEUHn/FzJUtq9MjH46an1wJU+GdoGC5VLof8RX8Ft/DlpshApkhswDLZzHIcQ==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-slot": "1.2.3"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-id": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-id/-/react-id-1.1.1.tgz",
"integrity": "sha512-kGkGegYIdQsOb4XjsfM97rXsiHaBwco+hFI66oO4s9LU+PLAC5oJ7khdOVFxkhsmlbpUqDAvXw11CluXP+jkHg==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-portal": {
"version": "1.1.9",
"resolved": "https://registry.npmjs.org/@radix-ui/react-portal/-/react-portal-1.1.9.tgz",
"integrity": "sha512-bpIxvq03if6UNwXZ+HTK71JLh4APvnXntDc6XOX8UVq4XQOVl7lwok0AvIl+b8zgCw3fSaVTZMpAPPagXbKmHQ==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-primitive": "2.1.3",
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-portal/node_modules/@radix-ui/react-primitive": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-primitive/-/react-primitive-2.1.3.tgz",
"integrity": "sha512-m9gTwRkhy2lvCPe6QJp4d3G1TYEUHn/FzJUtq9MjH46an1wJU+GdoGC5VLof8RX8Ft/DlpshApkhswDLZzHIcQ==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-slot": "1.2.3"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-presence": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/@radix-ui/react-presence/-/react-presence-1.1.5.tgz",
"integrity": "sha512-/jfEwNDdQVBCNvjkGit4h6pMOzq8bHkopq458dPt2lMjx+eBQUohZNG9A7DtO/O5ukSbxuaNGXMjHicgwy6rQQ==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-primitive": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/@radix-ui/react-primitive/-/react-primitive-2.1.4.tgz",
"integrity": "sha512-9hQc4+GNVtJAIEPEqlYqW5RiYdrr8ea5XQ0ZOnD6fgru+83kqT15mq2OCcbe8KnjRZl5vF3ks69AKz3kh1jrhg==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-slot": "1.2.4"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-primitive/node_modules/@radix-ui/react-slot": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.2.4.tgz",
"integrity": "sha512-Jl+bCv8HxKnlTLVrcDE8zTMJ09R9/ukw4qBs/oZClOfoQk/cOTbDn+NceXfV7j09YPVQUryJPHurafcSg6EVKA==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.2"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-slot": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.2.3.tgz",
"integrity": "sha512-aeNmHnBxbi2St0au6VBVC7JXFlhLlOnvIIlePNniyUNAClzmtAUEY8/pBiK3iHjufOlwA+c20/8jngo7xcrg8A==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.2"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-callback-ref": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-callback-ref/-/react-use-callback-ref-1.1.1.tgz",
"integrity": "sha512-FkBMwD+qbGQeMu1cOHnuGB6x4yzPjho8ap5WtbEJ26umhgqVXbhekKUQO+hZEL1vU92a3wHwdp0HAcqAUF5iDg==",
"license": "MIT",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-controllable-state": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-controllable-state/-/react-use-controllable-state-1.2.2.tgz",
"integrity": "sha512-BjasUjixPFdS+NKkypcyyN5Pmg83Olst0+c6vGov0diwTEo6mgdqVR6hxcEgFuh4QrAs7Rc+9KuGJ9TVCj0Zzg==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-use-effect-event": "0.0.2",
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-effect-event": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-effect-event/-/react-use-effect-event-0.0.2.tgz",
"integrity": "sha512-Qp8WbZOBe+blgpuUT+lw2xheLP8q0oatc9UpmiemEICxGvFLYmHm9QowVZGHtJlGbS6A6yJ3iViad/2cVjnOiA==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-escape-keydown": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-escape-keydown/-/react-use-escape-keydown-1.1.1.tgz",
"integrity": "sha512-Il0+boE7w/XebUHyBjroE+DbByORGR9KKmITzbR7MyQ4akpORYP/ZmbhAr0DG7RmmBqoOnZdy2QlvajJ2QA59g==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-use-callback-ref": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-layout-effect": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-layout-effect/-/react-use-layout-effect-1.1.1.tgz",
"integrity": "sha512-RbJRS4UWQFkzHTTwVymMTUv8EqYhOp8dOOviLj2ugtTiXRaRQS7GLGxZTLL1jWhMeoSCf5zmcZkqTl9IiYfXcQ==",
"license": "MIT",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@release-it/conventional-changelog": {
"version": "10.0.5",
"resolved": "https://registry.npmjs.org/@release-it/conventional-changelog/-/conventional-changelog-10.0.5.tgz",
@@ -4553,7 +4111,7 @@
"version": "18.3.7",
"resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.7.tgz",
"integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==",
"devOptional": true,
"dev": true,
"license": "MIT",
"peerDependencies": {
"@types/react": "^18.0.0"
@@ -5526,18 +5084,6 @@
"sprintf-js": "~1.0.2"
}
},
"node_modules/aria-hidden": {
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/aria-hidden/-/aria-hidden-1.2.6.tgz",
"integrity": "sha512-ik3ZgC9dY/lYVVM++OISsaYDeg1tb0VtP5uL3ouh1koGOaUMDPpbFIei4JkFimWUFPn90sbMNMXQAIVOlnYKJA==",
"license": "MIT",
"dependencies": {
"tslib": "^2.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/array-buffer-byte-length": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/array-buffer-byte-length/-/array-buffer-byte-length-1.0.2.tgz",
@@ -6640,22 +6186,6 @@
"node": ">=6"
}
},
"node_modules/cmdk": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/cmdk/-/cmdk-1.1.1.tgz",
"integrity": "sha512-Vsv7kFaXm+ptHDMZ7izaRsP70GgrW9NBNGswt9OZaVBLlE0SNpDq8eu/VGXyF9r7M0azK3Wy7OlYXsuyYLFzHg==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-compose-refs": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.6",
"@radix-ui/react-id": "^1.1.0",
"@radix-ui/react-primitive": "^2.0.2"
},
"peerDependencies": {
"react": "^18 || ^19 || ^19.0.0-rc",
"react-dom": "^18 || ^19 || ^19.0.0-rc"
}
},
"node_modules/codemirror": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/codemirror/-/codemirror-6.0.2.tgz",
@@ -7428,12 +6958,6 @@
"node": ">=8"
}
},
"node_modules/detect-node-es": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/detect-node-es/-/detect-node-es-1.1.0.tgz",
"integrity": "sha512-ypdmJU/TbBby2Dxibuv7ZLW3Bs1QEmM7nHjEANfohJLvE0XVujisn1qPJcZxg+qDucsr+bP6fLD1rPS3AhJ7EQ==",
"license": "MIT"
},
"node_modules/devlop": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/devlop/-/devlop-1.1.0.tgz",
@@ -9150,15 +8674,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-nonce": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-nonce/-/get-nonce-1.0.1.tgz",
"integrity": "sha512-FJhYRoDaiatfEkUK8HKlicmu/3SGFD51q3itKDGoSTysQJBnfOcxU5GxnhE1E6soB76MbT0MBtnKJuXyAx+96Q==",
"license": "MIT",
"engines": {
"node": ">=6"
}
},
"node_modules/get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
@@ -14548,53 +14063,6 @@
"node": ">=0.10.0"
}
},
"node_modules/react-remove-scroll": {
"version": "2.7.2",
"resolved": "https://registry.npmjs.org/react-remove-scroll/-/react-remove-scroll-2.7.2.tgz",
"integrity": "sha512-Iqb9NjCCTt6Hf+vOdNIZGdTiH1QSqr27H/Ek9sv/a97gfueI/5h1s3yRi1nngzMUaOOToin5dI1dXKdXiF+u0Q==",
"license": "MIT",
"dependencies": {
"react-remove-scroll-bar": "^2.3.7",
"react-style-singleton": "^2.2.3",
"tslib": "^2.1.0",
"use-callback-ref": "^1.3.3",
"use-sidecar": "^1.1.3"
},
"engines": {
"node": ">=10"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/react-remove-scroll-bar": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/react-remove-scroll-bar/-/react-remove-scroll-bar-2.3.8.tgz",
"integrity": "sha512-9r+yi9+mgU33AKcj6IbT9oRCO78WriSj6t/cF8DWBZJ9aOGPOTEDvdUDz1FwKim7QXWwmHqtdHnRJfhAxEG46Q==",
"license": "MIT",
"dependencies": {
"react-style-singleton": "^2.2.2",
"tslib": "^2.0.0"
},
"engines": {
"node": ">=10"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/react-router": {
"version": "6.30.1",
"resolved": "https://registry.npmjs.org/react-router/-/react-router-6.30.1.tgz",
@@ -14627,28 +14095,6 @@
"react-dom": ">=16.8"
}
},
"node_modules/react-style-singleton": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/react-style-singleton/-/react-style-singleton-2.2.3.tgz",
"integrity": "sha512-b6jSvxvVnyptAiLjbkWLE/lOnR4lfTtDAl+eUC7RZy+QQWc6wRzIV2CE6xBuMmDxc2qIihtDCZD5NPOFl7fRBQ==",
"license": "MIT",
"dependencies": {
"get-nonce": "^1.0.0",
"tslib": "^2.0.0"
},
"engines": {
"node": ">=10"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/react-syntax-highlighter": {
"version": "15.6.6",
"resolved": "https://registry.npmjs.org/react-syntax-highlighter/-/react-syntax-highlighter-15.6.6.tgz",
@@ -18146,49 +17592,6 @@
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
}
},
"node_modules/use-callback-ref": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/use-callback-ref/-/use-callback-ref-1.3.3.tgz",
"integrity": "sha512-jQL3lRnocaFtu3V00JToYz/4QkNWswxijDaCVNZRiRTO3HQDLsdu1ZtmIUvV4yPp+rvWm5j0y0TG/S61cuijTg==",
"license": "MIT",
"dependencies": {
"tslib": "^2.0.0"
},
"engines": {
"node": ">=10"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/use-sidecar": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/use-sidecar/-/use-sidecar-1.1.3.tgz",
"integrity": "sha512-Fedw0aZvkhynoPYlA5WXrMCAMm+nSWdZt6lzJQ7Ok8S6Q+VsHmHpRWndVRJ8Be0ZbkfPc5LRYH+5XrzXcEeLRQ==",
"license": "MIT",
"dependencies": {
"detect-node-es": "^1.1.0",
"tslib": "^2.0.0"
},
"engines": {
"node": ">=10"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/use-sync-external-store": {
"version": "1.6.0",
"resolved": "https://registry.npmmirror.com/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz",

View File

@@ -1,6 +1,6 @@
{
"name": "@cloudcli-ai/cloudcli",
"version": "1.31.5",
"version": "1.30.0",
"description": "A web-based UI for Claude Code CLI",
"type": "module",
"main": "dist-server/server/index.js",
@@ -76,7 +76,7 @@
"@codemirror/theme-one-dark": "^6.1.2",
"@iarna/toml": "^2.2.5",
"@octokit/rest": "^22.0.0",
"@openai/codex-sdk": "^0.125.0",
"@openai/codex-sdk": "^0.101.0",
"@replit/codemirror-minimap": "^0.5.2",
"@tailwindcss/typography": "^0.5.16",
"@uiw/react-codemirror": "^4.23.13",
@@ -91,7 +91,6 @@
"chokidar": "^4.0.3",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
"cors": "^2.8.5",
"cross-spawn": "^7.0.3",
"express": "^4.18.2",

View File

@@ -18,7 +18,6 @@ import { promises as fs } from 'fs';
import path from 'path';
import os from 'os';
import { CLAUDE_MODELS } from '../shared/modelConstants.js';
import { resolveClaudeCodeExecutablePath } from './shared/claude-cli-path.js';
import {
createNotificationEvent,
notifyRunFailed,
@@ -154,9 +153,11 @@ function mapCliOptionsToSDK(options = {}) {
// Since SDK 0.2.113, options.env replaces process.env instead of overlaying it.
sdkOptions.env = { ...process.env };
// Resolve the executable eagerly on Windows because the SDK uses raw child_process.spawn,
// which does not reliably follow npm's shell wrappers like cross-spawn does.
sdkOptions.pathToClaudeCodeExecutable = resolveClaudeCodeExecutablePath(process.env.CLAUDE_CLI_PATH);
// Use CLAUDE_CLI_PATH if explicitly set, otherwise fall back to 'claude' on PATH.
// The SDK 0.2.113+ looks for a bundled native binary optional dep by default;
// this fallback ensures users who installed via the official installer still work
// even when npm prune --production has removed those optional deps.
sdkOptions.pathToClaudeCodeExecutable = process.env.CLAUDE_CLI_PATH || 'claude';
// Map working directory
if (cwd) {
@@ -526,12 +527,6 @@ async function queryClaudeSDK(command, options = {}, ws) {
}]
};
// Caveat: in 'auto' and 'bypassPermissions' modes the SDK resolves approval
// at the permission-mode step and skips this callback, so interactive tools
// (AskUserQuestion, ExitPlanMode) won't reach the UI — the classifier/bypass
// auto-approves them and the model acts on a generated answer. Move these
// tools to a PreToolUse hook (runs before the mode check) if we need them
// to work in those modes.
sdkOptions.canUseTool = async (toolName, input, context) => {
const requiresInteraction = TOOLS_REQUIRING_INTERACTION.has(toolName);

View File

@@ -150,6 +150,7 @@ async function spawnCursor(command, options = {}, ws) {
try {
const response = JSON.parse(line);
console.log('Parsed JSON response:', response);
// Handle different message types
switch (response.type) {
@@ -158,6 +159,7 @@ async function spawnCursor(command, options = {}, ws) {
// Capture session ID
if (response.session_id && !capturedSessionId) {
capturedSessionId = response.session_id;
console.log('Captured session ID:', capturedSessionId);
// Update process key with captured session ID
if (processKey !== capturedSessionId) {
@@ -195,6 +197,7 @@ async function spawnCursor(command, options = {}, ws) {
case 'result': {
// Session complete — send stream end + lifecycle complete with result payload
console.log('Cursor session result:', response);
const resultText = typeof response.result === 'string' ? response.result : '';
ws.send(createNormalizedMessage({
kind: 'complete',
@@ -210,6 +213,8 @@ async function spawnCursor(command, options = {}, ws) {
// Unknown message types — ignore.
}
} catch (parseError) {
console.log('Non-JSON response:', line);
if (shouldSuppressForTrustRetry(line)) {
return;
}
@@ -223,6 +228,7 @@ async function spawnCursor(command, options = {}, ws) {
// Handle stdout (streaming JSON responses)
cursorProcess.stdout.on('data', (data) => {
const rawOutput = data.toString();
console.log('Cursor CLI stdout:', rawOutput);
// Stream chunks can split JSON objects across packets; keep trailing partial line.
stdoutLineBuffer += rawOutput;
@@ -248,6 +254,8 @@ async function spawnCursor(command, options = {}, ws) {
// Handle process completion
cursorProcess.on('close', async (code) => {
console.log(`Cursor CLI process exited with code ${code}`);
const finalSessionId = capturedSessionId || sessionId || processKey;
activeCursorProcesses.delete(finalSessionId);

View File

@@ -1,123 +1,19 @@
import { spawn } from 'child_process';
import { promises as fs } from 'fs';
import os from 'os';
import path from 'path';
import crossSpawn from 'cross-spawn';
// Use cross-spawn on Windows for correct .cmd resolution (same pattern as cursor-cli.js)
const spawnFunction = process.platform === 'win32' ? crossSpawn : spawn;
import { promises as fs } from 'fs';
import path from 'path';
import os from 'os';
import sessionManager from './sessionManager.js';
import GeminiResponseHandler from './gemini-response-handler.js';
import { notifyRunFailed, notifyRunStopped } from './services/notification-orchestrator.js';
import { providerAuthService } from './modules/providers/services/provider-auth.service.js';
import { createNormalizedMessage } from './shared/utils.js';
// Use cross-spawn on Windows for correct .cmd resolution (same pattern as cursor-cli.js)
const spawnFunction = process.platform === 'win32' ? crossSpawn : spawn;
let activeGeminiProcesses = new Map(); // Track active processes by session ID
function mapGeminiExitCodeToMessage(exitCode) {
switch (exitCode) {
case 42:
return 'Gemini rejected the request input (exit code 42).';
case 44:
return 'Gemini sandbox error (exit code 44). Check local sandbox/container settings.';
case 52:
return 'Gemini configuration error (exit code 52). Check your Gemini settings files for invalid JSON/config.';
case 53:
return 'Gemini conversation turn limit reached (exit code 53). Start a new Gemini session.';
default:
return null;
}
}
const GEMINI_AUTH_ENV_KEYS = [
'GEMINI_API_KEY',
'GOOGLE_API_KEY',
'GOOGLE_CLOUD_PROJECT',
'GOOGLE_CLOUD_PROJECT_ID',
'GOOGLE_CLOUD_LOCATION',
'GOOGLE_APPLICATION_CREDENTIALS'
];
function parseEnvFileContent(content) {
const parsed = {};
for (const rawLine of content.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line || line.startsWith('#')) {
continue;
}
const exportPrefix = 'export ';
const normalizedLine = line.startsWith(exportPrefix) ? line.slice(exportPrefix.length).trim() : line;
const separatorIndex = normalizedLine.indexOf('=');
if (separatorIndex <= 0) {
continue;
}
const key = normalizedLine.slice(0, separatorIndex).trim();
if (!key) {
continue;
}
let value = normalizedLine.slice(separatorIndex + 1).trim();
const hasDoubleQuotes = value.startsWith('"') && value.endsWith('"');
const hasSingleQuotes = value.startsWith('\'') && value.endsWith('\'');
if (hasDoubleQuotes || hasSingleQuotes) {
value = value.slice(1, -1);
} else {
// Support inline comments in unquoted values: KEY=value # comment
value = value.replace(/\s+#.*$/, '').trim();
}
parsed[key] = value;
}
return parsed;
}
async function loadGeminiUserLevelEnv() {
const geminiCliHome = (process.env.GEMINI_CLI_HOME || '').trim() || os.homedir();
const envCandidates = [
path.join(geminiCliHome, '.gemini', '.env'),
path.join(geminiCliHome, '.env')
];
for (const envPath of envCandidates) {
try {
await fs.access(envPath);
const content = await fs.readFile(envPath, 'utf8');
return parseEnvFileContent(content);
} catch {
// Keep scanning for the next candidate.
}
}
return {};
}
async function buildGeminiProcessEnv() {
const processEnv = { ...process.env };
if (processEnv.GEMINI_API_KEY || processEnv.GOOGLE_API_KEY || processEnv.GOOGLE_APPLICATION_CREDENTIALS) {
return processEnv;
}
// Gemini CLI docs recommend ~/.gemini/.env for persistent headless auth settings.
// When the server process was launched without shell profile variables, we still
// want the spawned CLI process to inherit those user-level credentials.
const userEnv = await loadGeminiUserLevelEnv();
for (const key of GEMINI_AUTH_ENV_KEYS) {
if (!processEnv[key] && userEnv[key]) {
processEnv[key] = userEnv[key];
}
}
return processEnv;
}
async function spawnGemini(command, options = {}, ws) {
const { sessionId, projectPath, cwd, toolsSettings, permissionMode, images, sessionSummary } = options;
let capturedSessionId = sessionId; // Track session ID throughout the process
@@ -204,11 +100,6 @@ async function spawnGemini(command, options = {}, ws) {
args.push('--debug');
}
// This integration runs Gemini in headless mode and cannot answer trust prompts.
// Skip folder-trust interactivity so authenticated runs don't fail with
// FatalUntrustedWorkspaceError in previously unseen directories.
args.push('--skip-trust');
// Add MCP config flag only if MCP servers are configured
try {
const geminiConfigPath = path.join(os.homedir(), '.gemini.json');
@@ -263,6 +154,9 @@ async function spawnGemini(command, options = {}, ws) {
// Try to find gemini in PATH first, then fall back to environment variable
const geminiPath = process.env.GEMINI_PATH || 'gemini';
console.log('Spawning Gemini CLI:', geminiPath, args.join(' '));
console.log('Working directory:', workingDir);
let spawnCmd = geminiPath;
let spawnArgs = args;
@@ -274,13 +168,11 @@ async function spawnGemini(command, options = {}, ws) {
spawnArgs = ['-c', 'exec "$0" "$@"', geminiPath, ...args];
}
const spawnEnv = await buildGeminiProcessEnv();
return new Promise((resolve, reject) => {
const geminiProcess = spawnFunction(spawnCmd, spawnArgs, {
cwd: workingDir,
stdio: ['pipe', 'pipe', 'pipe'],
env: spawnEnv
env: { ...process.env } // Inherit all environment variables
});
let terminalNotificationSent = false;
let terminalFailureReason = null;
@@ -384,43 +276,12 @@ async function spawnGemini(command, options = {}, ws) {
}
},
onInit: (event) => {
const discoveredSessionId = event?.session_id;
if (!discoveredSessionId) {
return;
}
// New Gemini sessions announce their canonical ID asynchronously via the
// initial `init` stream event. Avoid synthetic IDs and only register
// the session once that real ID is known (same model used by Claude/Codex).
if (!capturedSessionId) {
capturedSessionId = discoveredSessionId;
sessionManager.createSession(capturedSessionId, cwd || process.cwd());
if (command) {
sessionManager.addMessage(capturedSessionId, 'user', command);
if (capturedSessionId) {
const sess = sessionManager.getSession(capturedSessionId);
if (sess && !sess.cliSessionId) {
sess.cliSessionId = event.session_id;
sessionManager.saveSession(capturedSessionId);
}
if (processKey !== capturedSessionId) {
activeGeminiProcesses.delete(processKey);
activeGeminiProcesses.set(capturedSessionId, geminiProcess);
}
geminiProcess.sessionId = capturedSessionId;
if (ws.setSessionId && typeof ws.setSessionId === 'function') {
ws.setSessionId(capturedSessionId);
}
if (!sessionId && !sessionCreatedSent) {
sessionCreatedSent = true;
ws.send(createNormalizedMessage({ kind: 'session_created', newSessionId: capturedSessionId, sessionId: capturedSessionId, provider: 'gemini' }));
}
}
const sess = sessionManager.getSession(capturedSessionId);
if (sess && !sess.cliSessionId) {
sess.cliSessionId = discoveredSessionId;
sessionManager.saveSession(capturedSessionId);
}
}
});
@@ -431,6 +292,30 @@ async function spawnGemini(command, options = {}, ws) {
const rawOutput = data.toString();
startTimeout(); // Re-arm the timeout
// For new sessions, create a session ID FIRST
if (!sessionId && !sessionCreatedSent && !capturedSessionId) {
capturedSessionId = `gemini_${Date.now()}`;
sessionCreatedSent = true;
// Create session in session manager
sessionManager.createSession(capturedSessionId, cwd || process.cwd());
// Save the user message now that we have a session ID
if (command) {
sessionManager.addMessage(capturedSessionId, 'user', command);
}
// Update process key with captured session ID
if (processKey !== capturedSessionId) {
activeGeminiProcesses.delete(processKey);
activeGeminiProcesses.set(capturedSessionId, geminiProcess);
}
ws.setSessionId && typeof ws.setSessionId === 'function' && ws.setSessionId(capturedSessionId);
ws.send(createNormalizedMessage({ kind: 'session_created', newSessionId: capturedSessionId, sessionId: capturedSessionId, provider: 'gemini' }));
}
if (responseHandler) {
responseHandler.processData(rawOutput);
} else if (rawOutput) {
@@ -496,38 +381,12 @@ async function spawnGemini(command, options = {}, ws) {
notifyTerminalState({ code });
resolve();
} else {
const socketSessionId = typeof ws.getSessionId === 'function' ? ws.getSessionId() : finalSessionId;
// code 127 = shell "command not found" - check installation
// code 127 = shell "command not found" — check installation
if (code === 127) {
const installed = await providerAuthService.isProviderInstalled('gemini');
if (!installed) {
terminalFailureReason = 'Gemini CLI is not installed. Please install it first: https://github.com/google-gemini/gemini-cli';
ws.send(createNormalizedMessage({ kind: 'error', content: terminalFailureReason, sessionId: socketSessionId, provider: 'gemini' }));
}
} else if (code === 41) {
// Gemini CLI documents exit code 41 as FatalAuthenticationError.
// Surface an actionable auth error instead of a generic exit-code message.
let authErrorSuffix = '';
try {
const authStatus = await providerAuthService.getProviderAuthStatus('gemini');
if (!authStatus?.authenticated && authStatus?.error) {
authErrorSuffix = ` Details: ${authStatus.error}`;
}
} catch {
// Keep base remediation text when auth status lookup fails.
}
terminalFailureReason =
'Gemini authentication failed (exit code 41). '
+ 'Run `gemini` in a terminal to choose an auth method, or configure a valid `GEMINI_API_KEY`.'
+ authErrorSuffix;
ws.send(createNormalizedMessage({ kind: 'error', content: terminalFailureReason, sessionId: socketSessionId, provider: 'gemini' }));
} else {
const mappedError = mapGeminiExitCodeToMessage(code);
if (mappedError) {
terminalFailureReason = mappedError;
ws.send(createNormalizedMessage({ kind: 'error', content: terminalFailureReason, sessionId: socketSessionId, provider: 'gemini' }));
const socketSessionId = typeof ws.getSessionId === 'function' ? ws.getSessionId() : finalSessionId;
ws.send(createNormalizedMessage({ kind: 'error', content: 'Gemini CLI is not installed. Please install it first: https://github.com/google-gemini/gemini-cli', sessionId: socketSessionId, provider: 'gemini' }));
}
}
@@ -535,14 +394,7 @@ async function spawnGemini(command, options = {}, ws) {
code,
error: code === null ? 'Gemini CLI process was terminated or timed out' : null
});
reject(
new Error(
terminalFailureReason
|| (code === null
? 'Gemini CLI process was terminated or timed out'
: `Gemini CLI exited with code ${code}`)
)
);
reject(new Error(code === null ? 'Gemini CLI process was terminated or timed out' : `Gemini CLI exited with code ${code}`));
}
});

View File

@@ -65,7 +65,6 @@ const migrateLegacySessionNames = (db: Database): void => {
COALESCE(created_at, CURRENT_TIMESTAMP),
COALESCE(updated_at, CURRENT_TIMESTAMP)
FROM session_names
WHERE true
ON CONFLICT(session_id) DO UPDATE SET
provider = excluded.provider,
custom_name = COALESCE(excluded.custom_name, sessions.custom_name),
@@ -257,10 +256,8 @@ const rebuildSessionsTableWithProjectSchema = (db: Database): void => {
if (!shouldRebuild) {
addColumnToTableIfNotExists(db, 'sessions', columnNames, 'jsonl_path', 'TEXT');
addColumnToTableIfNotExists(db, 'sessions', columnNames, 'isArchived', 'BOOLEAN DEFAULT 0');
addColumnToTableIfNotExists(db, 'sessions', columnNames, 'created_at', 'DATETIME');
addColumnToTableIfNotExists(db, 'sessions', columnNames, 'updated_at', 'DATETIME');
db.exec('UPDATE sessions SET isArchived = COALESCE(isArchived, 0)');
db.exec('UPDATE sessions SET created_at = COALESCE(created_at, CURRENT_TIMESTAMP)');
db.exec('UPDATE sessions SET updated_at = COALESCE(updated_at, CURRENT_TIMESTAMP)');
return;
@@ -286,10 +283,6 @@ const rebuildSessionsTableWithProjectSchema = (db: Database): void => {
? 'jsonl_path'
: 'NULL';
const isArchivedExpression = columnNames.includes('isArchived')
? 'COALESCE(isArchived, 0)'
: '0';
const createdAtExpression = columnNames.includes('created_at')
? 'COALESCE(created_at, CURRENT_TIMESTAMP)'
: 'CURRENT_TIMESTAMP';
@@ -309,7 +302,6 @@ const rebuildSessionsTableWithProjectSchema = (db: Database): void => {
custom_name TEXT,
project_path TEXT,
jsonl_path TEXT,
isArchived BOOLEAN DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (session_id),
@@ -326,7 +318,6 @@ const rebuildSessionsTableWithProjectSchema = (db: Database): void => {
${customNameExpression} AS custom_name,
${projectPathExpression} AS project_path,
${jsonlPathExpression} AS jsonl_path,
${isArchivedExpression} AS isArchived,
${createdAtExpression} AS created_at,
${updatedAtExpression} AS updated_at,
rowid AS source_rowid
@@ -340,7 +331,6 @@ const rebuildSessionsTableWithProjectSchema = (db: Database): void => {
custom_name,
project_path,
jsonl_path,
isArchived,
created_at,
updated_at,
ROW_NUMBER() OVER (
@@ -355,7 +345,6 @@ const rebuildSessionsTableWithProjectSchema = (db: Database): void => {
custom_name,
project_path,
jsonl_path,
isArchived,
created_at,
updated_at
)
@@ -365,7 +354,6 @@ const rebuildSessionsTableWithProjectSchema = (db: Database): void => {
custom_name,
project_path,
jsonl_path,
isArchived,
created_at,
updated_at
FROM ranked_rows
@@ -432,7 +420,6 @@ export const runMigrations = (db: Database) => {
db.exec('CREATE INDEX IF NOT EXISTS idx_session_ids_lookup ON sessions(session_id)');
db.exec('CREATE INDEX IF NOT EXISTS idx_sessions_project_path ON sessions(project_path)');
db.exec('CREATE INDEX IF NOT EXISTS idx_sessions_is_archived ON sessions(isArchived)');
db.exec('CREATE INDEX IF NOT EXISTS idx_projects_is_starred ON projects(isStarred)');
db.exec('CREATE INDEX IF NOT EXISTS idx_projects_is_archived ON projects(isArchived)');

View File

@@ -95,19 +95,6 @@ export const projectsDb = {
`).all() as ProjectRepositoryRow[];
},
/**
* Archived rows are queried separately so archive-focused UIs can present
* hidden workspaces without reintroducing them into the active sidebar list.
*/
getArchivedProjectPaths(): ProjectRepositoryRow[] {
const db = getConnection();
return db.prepare(`
SELECT project_id, project_path, custom_project_name, isStarred, isArchived
FROM projects
WHERE isArchived = 1
`).all() as ProjectRepositoryRow[];
},
getCustomProjectName(projectPath: string): string | null {
const db = getConnection();
const normalizedProjectPath = normalizeProjectPath(projectPath);

View File

@@ -1,72 +0,0 @@
import assert from 'node:assert/strict';
import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';
import test from 'node:test';
import { closeConnection } from '@/modules/database/connection.js';
import { initializeDatabase } from '@/modules/database/init-db.js';
import { sessionsDb } from '@/modules/database/repositories/sessions.db.js';
async function withIsolatedDatabase(runTest: () => void | Promise<void>): Promise<void> {
const previousDatabasePath = process.env.DATABASE_PATH;
const tempDirectory = await mkdtemp(path.join(tmpdir(), 'sessions-db-'));
const databasePath = path.join(tempDirectory, 'auth.db');
closeConnection();
process.env.DATABASE_PATH = databasePath;
await initializeDatabase();
try {
await runTest();
} finally {
closeConnection();
if (previousDatabasePath === undefined) {
delete process.env.DATABASE_PATH;
} else {
process.env.DATABASE_PATH = previousDatabasePath;
}
await rm(tempDirectory, { recursive: true, force: true });
}
}
test('session archive queries hide archived rows from active project views', async () => {
await withIsolatedDatabase(() => {
sessionsDb.createSession('session-active', 'claude', '/workspace/demo-project', 'Active Session');
sessionsDb.createSession('session-archived', 'claude', '/workspace/demo-project', 'Archived Session');
sessionsDb.updateSessionIsArchived('session-archived', true);
const activeSessions = sessionsDb.getAllSessions();
const archivedSessions = sessionsDb.getArchivedSessions();
const activeProjectSessions = sessionsDb.getSessionsByProjectPath('/workspace/demo-project');
const allProjectSessions = sessionsDb.getSessionsByProjectPathIncludingArchived('/workspace/demo-project');
assert.deepEqual(activeSessions.map((session) => session.session_id), ['session-active']);
assert.deepEqual(archivedSessions.map((session) => session.session_id), ['session-archived']);
assert.deepEqual(activeProjectSessions.map((session) => session.session_id), ['session-active']);
assert.deepEqual(
allProjectSessions.map((session) => session.session_id).sort(),
['session-active', 'session-archived'],
);
assert.equal(sessionsDb.countSessionsByProjectPath('/workspace/demo-project'), 1);
});
});
test('createSession reactivates archived rows when the session becomes active again', async () => {
await withIsolatedDatabase(() => {
sessionsDb.createSession('session-reused', 'claude', '/workspace/demo-project', 'First Name');
sessionsDb.updateSessionIsArchived('session-reused', true);
sessionsDb.createSession('session-reused', 'claude', '/workspace/demo-project', 'Updated Name');
const activeSessions = sessionsDb.getAllSessions();
const archivedSessions = sessionsDb.getArchivedSessions();
const restoredSession = sessionsDb.getSessionById('session-reused');
assert.equal(activeSessions.length, 1);
assert.equal(activeSessions[0]?.session_id, 'session-reused');
assert.equal(activeSessions[0]?.custom_name, 'Updated Name');
assert.equal(archivedSessions.length, 0);
assert.equal(restoredSession?.isArchived, 0);
});
});

View File

@@ -8,14 +8,13 @@ type SessionRow = {
project_path: string | null;
jsonl_path: string | null;
custom_name: string | null;
isArchived: number;
created_at: string;
updated_at: string;
};
type SessionMetadataLookupRow = Pick<
SessionRow,
'session_id' | 'provider' | 'project_path' | 'jsonl_path' | 'custom_name' | 'isArchived' | 'created_at' | 'updated_at'
'session_id' | 'provider' | 'project_path' | 'jsonl_path' | 'custom_name' | 'created_at' | 'updated_at'
>;
function normalizeTimestamp(value?: string): string | null {
@@ -54,14 +53,13 @@ export const sessionsDb = {
projectsDb.createProjectPath(normalizedProjectPath);
db.prepare(
`INSERT INTO sessions (session_id, provider, custom_name, project_path, jsonl_path, isArchived, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, 0, COALESCE(?, CURRENT_TIMESTAMP), COALESCE(?, CURRENT_TIMESTAMP))
`INSERT INTO sessions (session_id, provider, custom_name, project_path, jsonl_path, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, COALESCE(?, CURRENT_TIMESTAMP), COALESCE(?, CURRENT_TIMESTAMP))
ON CONFLICT(session_id) DO UPDATE SET
provider = excluded.provider,
updated_at = excluded.updated_at,
project_path = excluded.project_path,
jsonl_path = excluded.jsonl_path,
isArchived = 0,
custom_name = COALESCE(excluded.custom_name, sessions.custom_name)`
).run(
sessionId,
@@ -89,7 +87,7 @@ export const sessionsDb = {
const db = getConnection();
const row = db
.prepare(
`SELECT session_id, provider, project_path, jsonl_path, custom_name, isArchived, created_at, updated_at
`SELECT session_id, provider, project_path, jsonl_path, custom_name, created_at, updated_at
FROM sessions
WHERE session_id = ?
ORDER BY updated_at DESC
@@ -104,25 +102,8 @@ export const sessionsDb = {
const db = getConnection();
return db
.prepare(
`SELECT session_id, provider, project_path, jsonl_path, custom_name, isArchived, created_at, updated_at
FROM sessions
WHERE isArchived = 0`
)
.all() as SessionRow[];
},
/**
* Archived rows are intentionally queried separately so the caller can render
* them in a dedicated view without reintroducing them into active session lists.
*/
getArchivedSessions(): SessionRow[] {
const db = getConnection();
return db
.prepare(
`SELECT session_id, provider, project_path, jsonl_path, custom_name, isArchived, created_at, updated_at
FROM sessions
WHERE isArchived = 1
ORDER BY datetime(COALESCE(updated_at, created_at)) DESC, session_id DESC`
`SELECT session_id, provider, project_path, jsonl_path, custom_name, created_at, updated_at
FROM sessions`
)
.all() as SessionRow[];
},
@@ -132,24 +113,7 @@ export const sessionsDb = {
const normalizedProjectPath = normalizeProjectPath(projectPath);
return db
.prepare(
`SELECT session_id, provider, project_path, jsonl_path, custom_name, isArchived, created_at, updated_at
FROM sessions
WHERE project_path = ?
AND isArchived = 0`
)
.all(normalizedProjectPath) as SessionRow[];
},
/**
* Permanent project deletion must see every session row for the path,
* including archived ones, so their transcript files can be cleaned up.
*/
getSessionsByProjectPathIncludingArchived(projectPath: string): SessionRow[] {
const db = getConnection();
const normalizedProjectPath = normalizeProjectPath(projectPath);
return db
.prepare(
`SELECT session_id, provider, project_path, jsonl_path, custom_name, isArchived, created_at, updated_at
`SELECT session_id, provider, project_path, jsonl_path, custom_name, created_at, updated_at
FROM sessions
WHERE project_path = ?`
)
@@ -161,10 +125,9 @@ export const sessionsDb = {
const normalizedProjectPath = normalizeProjectPath(projectPath);
return db
.prepare(
`SELECT session_id, provider, project_path, jsonl_path, custom_name, isArchived, created_at, updated_at
`SELECT session_id, provider, project_path, jsonl_path, custom_name, created_at, updated_at
FROM sessions
WHERE project_path = ?
AND isArchived = 0
ORDER BY datetime(COALESCE(updated_at, created_at)) DESC, session_id DESC
LIMIT ? OFFSET ?`
)
@@ -178,8 +141,7 @@ export const sessionsDb = {
.prepare(
`SELECT COUNT(*) AS count
FROM sessions
WHERE project_path = ?
AND isArchived = 0`
WHERE project_path = ?`
)
.get(normalizedProjectPath) as { count: number } | undefined;
@@ -205,19 +167,6 @@ export const sessionsDb = {
return row?.custom_name ?? null;
},
/**
* Soft-delete and restore both use the same flag update so callers keep the
* row, metadata, and file path intact while toggling visibility.
*/
updateSessionIsArchived(sessionId: string, isArchived: boolean): void {
const db = getConnection();
db.prepare(
`UPDATE sessions
SET isArchived = ?
WHERE session_id = ?`
).run(isArchived ? 1 : 0, sessionId);
},
deleteSessionById(sessionId: string): boolean {
const db = getConnection();
return db.prepare('DELETE FROM sessions WHERE session_id = ?').run(sessionId).changes > 0;

View File

@@ -86,7 +86,6 @@ CREATE TABLE IF NOT EXISTS sessions (
custom_name TEXT,
project_path TEXT,
jsonl_path TEXT,
isArchived BOOLEAN DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (session_id),

View File

@@ -3,9 +3,9 @@ import express from 'express';
import { createProject, updateProjectDisplayName } from '@/modules/projects/services/project-management.service.js';
import { startCloneProject } from '@/modules/projects/services/project-clone.service.js';
import { getProjectTaskMaster } from '@/modules/projects/services/projects-has-taskmaster.service.js';
import { AppError, asyncHandler, createApiSuccessResponse } from '@/shared/utils.js';
import { getArchivedProjectsWithSessions, getProjectSessionsPage, getProjectsWithSessions } from '@/modules/projects/services/projects-with-sessions-fetch.service.js';
import { deleteOrArchiveProject, restoreArchivedProject } from '@/modules/projects/services/project-delete.service.js';
import { AppError, asyncHandler } from '@/shared/utils.js';
import { getProjectSessionsPage, getProjectsWithSessions } from '@/modules/projects/services/projects-with-sessions-fetch.service.js';
import { deleteOrArchiveProject } from '@/modules/projects/services/project-delete.service.js';
import { applyLegacyStarredProjectIds, toggleProjectStar } from '@/modules/projects/services/project-star.service.js';
const router = express.Router();
@@ -73,14 +73,6 @@ router.get(
}),
);
router.get(
'/archived',
asyncHandler(async (_req, res) => {
const projects = await getArchivedProjectsWithSessions();
res.json(createApiSuccessResponse({ projects }));
}),
);
router.get(
'/:projectId/sessions',
asyncHandler(async (req, res) => {
@@ -238,15 +230,6 @@ router.post(
}),
);
router.post(
'/:projectId/restore',
asyncHandler(async (req, res) => {
const projectId = typeof req.params.projectId === 'string' ? req.params.projectId : '';
restoreArchivedProject(projectId);
res.json(createApiSuccessResponse({ projectId, isArchived: false }));
}),
);
/**
* - `force` not set / false: archive project in DB only (`isArchived` = 1; hidden from active list).
* - `force=true`: remove DB row, delete session rows for that path, remove all `*.jsonl` under the Claude project dir.

View File

@@ -42,7 +42,7 @@ async function unlinkJsonlIfExists(filePath: string): Promise<void> {
* Loads all session rows for the project path and removes each distinct `jsonl_path` file on disk.
*/
export async function deleteSessionJsonlFilesForProjectPath(projectPath: string): Promise<void> {
const sessions = sessionsDb.getSessionsByProjectPathIncludingArchived(projectPath);
const sessions = sessionsDb.getSessionsByProjectPath(projectPath);
const paths = uniqueJsonlPathsFromSessions(sessions);
for (const filePath of paths) {
@@ -73,18 +73,3 @@ export async function deleteOrArchiveProject(projectId: string, force: boolean):
sessionsDb.deleteSessionsByProjectPath(row.project_path);
projectsDb.deleteProjectById(projectId);
}
/**
* Restores one archived project row back into the active project list.
*/
export function restoreArchivedProject(projectId: string): void {
const row = projectsDb.getProjectById(projectId);
if (!row) {
throw new AppError(`Unknown projectId: ${projectId}`, {
code: 'PROJECT_NOT_FOUND',
statusCode: 404,
});
}
projectsDb.updateProjectIsArchivedById(projectId, false);
}

View File

@@ -40,10 +40,6 @@ export type ProjectListItem = {
};
};
export type ArchivedProjectListItem = ProjectListItem & {
isArchived: true;
};
type ProgressUpdate = {
phase: 'loading' | 'complete';
current: number;
@@ -154,16 +150,6 @@ function bucketSessionRowsByProvider(rows: SessionRepositoryRow[]): SessionsByPr
return byProvider;
}
function readProjectSessionsIncludingArchived(projectPath: string): ProjectSessionsPageResult {
const rows = sessionsDb.getSessionsByProjectPathIncludingArchived(projectPath) as SessionRepositoryRow[];
return {
sessionsByProvider: bucketSessionRowsByProvider(rows),
total: rows.length,
hasMore: false,
};
}
/**
* Reads one paginated project session slice from the DB and groups rows by provider.
*/
@@ -269,56 +255,6 @@ export async function getProjectsWithSessions(
return projects;
}
/**
* Reads archived projects from DB and includes every session row for each
* project path, because an archived workspace should surface all preserved
* conversation history in the archive view regardless of each session's flag.
*/
export async function getArchivedProjectsWithSessions(
options: Pick<GetProjectsWithSessionsOptions, 'skipSynchronization'> = {},
): Promise<ArchivedProjectListItem[]> {
if (!options.skipSynchronization) {
await sessionSynchronizerService.synchronizeSessions();
}
const projectRows = projectsDb.getArchivedProjectPaths() as Array<{
project_id: string;
project_path: string;
custom_project_name?: string | null;
isStarred?: number;
}>;
const archivedProjects: ArchivedProjectListItem[] = [];
for (const row of projectRows) {
const displayName =
row.custom_project_name && row.custom_project_name.trim().length > 0
? row.custom_project_name
: await generateDisplayName(path.basename(row.project_path) || row.project_path, row.project_path);
const sessionsPage = readProjectSessionsIncludingArchived(row.project_path);
archivedProjects.push({
projectId: row.project_id,
path: row.project_path,
displayName,
fullPath: row.project_path,
isStarred: Boolean(row.isStarred),
isArchived: true,
sessions: sessionsPage.sessionsByProvider.claude,
cursorSessions: sessionsPage.sessionsByProvider.cursor,
codexSessions: sessionsPage.sessionsByProvider.codex,
geminiSessions: sessionsPage.sessionsByProvider.gemini,
sessionMeta: {
hasMore: sessionsPage.hasMore,
total: sessionsPage.total,
},
});
}
return archivedProjects;
}
/**
* Loads one paginated session slice for a specific project id.
*/

View File

@@ -4,7 +4,6 @@ import path from 'node:path';
import spawn from 'cross-spawn';
import { resolveClaudeCodeExecutablePath } from '@/shared/claude-cli-path.js';
import type { IProviderAuth } from '@/shared/interfaces.js';
import type { ProviderAuthStatus } from '@/shared/types.js';
import { readObjectRecord, readOptionalString } from '@/shared/utils.js';
@@ -21,13 +20,13 @@ export class ClaudeProviderAuth implements IProviderAuth {
* Checks whether the Claude Code CLI is available on this host.
*/
private checkInstalled(): boolean {
const cliPath = resolveClaudeCodeExecutablePath(process.env.CLAUDE_CLI_PATH);
try {
spawn.sync(cliPath, ['--version'], { stdio: 'ignore', timeout: 5000 });
return true;
} catch {
return false;
}
const cliPath = process.env.CLAUDE_CLI_PATH || 'claude';
try {
spawn.sync(cliPath, ['--version'], { stdio: 'ignore', timeout: 5000 });
return true;
} catch {
return false;
}
}
/**

View File

@@ -1,6 +1,5 @@
import os from 'node:os';
import path from 'node:path';
import { readFile } from 'node:fs/promises';
import { sessionsDb } from '@/modules/database/index.js';
import {
@@ -92,7 +91,7 @@ export class ClaudeSessionSynchronizer implements IProviderSessionSynchronizer {
filePath: string,
nameMap: Map<string, string>
): Promise<ParsedSession | null> {
const parsed = await extractFirstValidJsonlData(filePath, (rawData) => {
return extractFirstValidJsonlData(filePath, (rawData) => {
const data = rawData as Record<string, unknown>;
const sessionId = typeof data.sessionId === 'string' ? data.sessionId : undefined;
const projectPath = typeof data.cwd === 'string' ? data.cwd : undefined;
@@ -104,73 +103,8 @@ export class ClaudeSessionSynchronizer implements IProviderSessionSynchronizer {
return {
sessionId,
projectPath,
sessionName: normalizeSessionName(nameMap.get(sessionId), 'Untitled Claude Session'),
};
});
if (!parsed) {
return null;
}
const existingSession = sessionsDb.getSessionById(parsed.sessionId);
const existingSessionName = existingSession?.custom_name;
if (existingSessionName && existingSessionName !== 'Untitled Claude Session') {
return {
...parsed,
sessionName: normalizeSessionName(existingSessionName, 'Untitled Claude Session'),
};
}
let sessionName = nameMap.get(parsed.sessionId);
if (!sessionName) {
sessionName = await this.extractSessionAiTitleFromEnd(filePath, parsed.sessionId);
}
return {
...parsed,
sessionName: normalizeSessionName(sessionName, 'Untitled Claude Session'),
};
}
private async extractSessionAiTitleFromEnd(
filePath: string,
sessionId: string
): Promise<string | undefined> {
try {
const content = await readFile(filePath, 'utf8');
const lines = content.split(/\r?\n/);
for (let index = lines.length - 1; index >= 0; index -= 1) {
const line = lines[index]?.trim();
if (!line) {
continue;
}
let parsed: unknown;
try {
parsed = JSON.parse(line);
} catch {
continue;
}
const data = parsed as Record<string, unknown>;
const eventType = typeof data.type === 'string' ? data.type : undefined;
const eventSessionId = typeof data.sessionId === 'string' ? data.sessionId : undefined;
const aiTitle = typeof data.aiTitle === 'string' ? data.aiTitle : undefined;
const lastPrompt = typeof data.lastPrompt === 'string' ? data.lastPrompt : undefined;
const claudeRenamedTitle = typeof data.customTitle === 'string' ? data.customTitle : undefined;
if (
(eventType === 'ai-title' && eventSessionId === sessionId && aiTitle?.trim()) ||
(eventType === 'last-prompt' && eventSessionId === sessionId && lastPrompt?.trim()) ||
(eventType === "custom-title" && eventSessionId === sessionId && claudeRenamedTitle?.trim())
) {
return aiTitle || lastPrompt || claudeRenamedTitle;
}
}
} catch {
// Ignore missing/unreadable files so sync can continue.
}
return undefined;
}
}

View File

@@ -200,18 +200,17 @@ async function getSessionMessages(
}
/**
* Claude writes a mix of truly internal transcript rows and "UI-hidden" local
* command artifacts into the same JSONL stream.
*
* Important distinction:
* - system reminders / caveats / interruption banners should stay hidden
* - local command payloads (`<command-name>...`) and stdout wrappers
* (`<local-command-stdout>...`) should be remapped into normal chat messages
* instead of being discarded as internal content
* Claude writes internal command and system reminder entries into history.
* Those are useful for the CLI but should not appear in the user-facing chat.
*/
const INTERNAL_CONTENT_PREFIXES = [
'<command-name>',
'<command-message>',
'<command-args>',
'<local-command-stdout>',
'<system-reminder>',
'Caveat:',
'This session is being continued from a previous',
'[Request interrupted',
] as const;
@@ -219,73 +218,6 @@ function isInternalContent(content: string): boolean {
return INTERNAL_CONTENT_PREFIXES.some((prefix) => content.startsWith(prefix));
}
/**
* Claude wraps local slash-command metadata in lightweight XML-like tags inside
* a plain string payload. We intentionally parse only the small tag surface we
* care about instead of introducing a generic XML parser for untrusted history.
*/
function extractTaggedContent(content: string, tagName: string): string | null {
const escapedTagName = tagName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const match = new RegExp(`<${escapedTagName}>([\\s\\S]*?)<\\/${escapedTagName}>`).exec(content);
return match ? match[1] : null;
}
type ClaudeLocalCommandPayload = {
commandName: string;
commandMessage: string;
commandArgs: string;
};
/**
* Converts Claude's hidden local command wrapper into structured metadata.
*
* The three tags often coexist in one string payload. Returning `null` lets the
* normal text path continue untouched for unrelated messages.
*/
function parseLocalCommandPayload(content: string): ClaudeLocalCommandPayload | null {
const commandName = extractTaggedContent(content, 'command-name');
const commandMessage = extractTaggedContent(content, 'command-message');
const commandArgs = extractTaggedContent(content, 'command-args');
if (commandName === null && commandMessage === null && commandArgs === null) {
return null;
}
return {
commandName: commandName ?? '',
commandMessage: commandMessage ?? '',
commandArgs: commandArgs ?? '',
};
}
/**
* Produces the short user-visible command string that should appear in chat.
*
* We prefer the slash-prefixed command name because that most closely matches
* what the user actually typed, and only fall back to the message body when the
* command name is unavailable in older transcript variants.
*/
function buildLocalCommandDisplayText(payload: ClaudeLocalCommandPayload): string {
const commandName = payload.commandName.trim();
const commandMessage = payload.commandMessage.trim();
const commandArgs = payload.commandArgs.trim();
const baseCommand = commandName || commandMessage;
if (!baseCommand) {
return '';
}
return commandArgs ? `${baseCommand} ${commandArgs}` : baseCommand;
}
/**
* Claude local-command stdout may contain ANSI styling codes because it was
* captured from the terminal. The web chat should receive readable plain text.
*/
function stripAnsiFormatting(text: string): string {
return text.replace(/\u001B\[[0-9;?]*[ -/]*[@-~]/g, '');
}
export class ClaudeSessionsProvider implements IProviderSessions {
/**
* Normalizes one Claude JSONL entry or live SDK stream event into the shared
@@ -308,7 +240,7 @@ export class ClaudeSessionsProvider implements IProviderSessions {
const ts = raw.timestamp || new Date().toISOString();
const baseId = raw.uuid || generateMessageId('claude');
if (raw.message?.role === 'user' && raw.message?.content && raw.isMeta !== true) {
if (raw.message?.role === 'user' && raw.message?.content) {
if (Array.isArray(raw.message.content)) {
for (let partIndex = 0; partIndex < raw.message.content.length; partIndex++) {
const part = raw.message.content[partIndex];
@@ -361,80 +293,6 @@ export class ClaudeSessionsProvider implements IProviderSessions {
}
} else if (typeof raw.message.content === 'string') {
const text = raw.message.content;
/**
* Claude stores compact summaries as synthetic "user" rows so the CLI
* can resume the next session turn with the summary in-context.
*
* For the web UI this is much more useful as assistant-authored summary
* text; otherwise it is both filtered by the generic internal-prefix
* check and visually mislabeled as a user message.
*/
if (raw.isCompactSummary === true && text.trim()) {
messages.push(createNormalizedMessage({
id: baseId,
sessionId,
timestamp: ts,
provider: PROVIDER,
kind: 'text',
role: 'assistant',
content: text,
isCompactSummary: true,
}));
return messages;
}
/**
* Local slash commands are serialized as tagged text even though they
* are semantically a user action. Expose the parsed fields to the
* frontend and emit a plain user-visible command string so the command
* no longer disappears from history.
*/
const localCommandPayload = parseLocalCommandPayload(text);
if (localCommandPayload) {
const displayText = buildLocalCommandDisplayText(localCommandPayload);
if (displayText) {
messages.push(createNormalizedMessage({
id: baseId,
sessionId,
timestamp: ts,
provider: PROVIDER,
kind: 'text',
role: 'user',
content: displayText,
commandName: localCommandPayload.commandName,
commandMessage: localCommandPayload.commandMessage,
commandArgs: localCommandPayload.commandArgs,
isLocalCommand: true,
}));
}
return messages;
}
/**
* Local command stdout is also written as a "user" row in Claude's
* transcript, but it is terminal output produced in response to the
* command. Re-label it as assistant text so the chat transcript matches
* the actual conversational flow seen by the user.
*/
const localCommandStdout = extractTaggedContent(text, 'local-command-stdout');
if (localCommandStdout !== null) {
const stdoutText = stripAnsiFormatting(localCommandStdout).trim();
if (stdoutText) {
messages.push(createNormalizedMessage({
id: baseId,
sessionId,
timestamp: ts,
provider: PROVIDER,
kind: 'text',
role: 'assistant',
content: stdoutText,
isLocalCommandStdout: true,
}));
}
return messages;
}
if (text && !isInternalContent(text)) {
messages.push(createNormalizedMessage({
id: baseId,
@@ -556,9 +414,7 @@ export class ClaudeSessionsProvider implements IProviderSessions {
let result: ClaudeHistoryResult;
try {
// Load full history first so `total` reflects frontend-normalized messages,
// not raw JSONL records.
result = await getSessionMessages(sessionId, null, 0);
result = await getSessionMessages(sessionId, limit, offset);
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
console.warn(`[ClaudeProvider] Failed to load session ${sessionId}:`, message);
@@ -566,6 +422,8 @@ export class ClaudeSessionsProvider implements IProviderSessions {
}
const rawMessages = Array.isArray(result) ? result : (result.messages || []);
const total = Array.isArray(result) ? rawMessages.length : (result.total || 0);
const hasMore = Array.isArray(result) ? false : Boolean(result.hasMore);
const toolResultMap = new Map<string, ClaudeToolResult>();
for (const raw of rawMessages) {
@@ -606,31 +464,12 @@ export class ClaudeSessionsProvider implements IProviderSessions {
}
}
const totalNormalized = normalized.length;
let total = 0;
for (const msg of normalized) {
if (msg.kind !== 'tool_result') {
total += 1;
}
}
const normalizedOffset = Math.max(0, offset);
const normalizedLimit = limit === null ? null : Math.max(0, limit);
const messages = normalizedLimit === null
? normalized
: normalized.slice(
Math.max(0, totalNormalized - normalizedOffset - normalizedLimit),
Math.max(0, totalNormalized - normalizedOffset),
);
const hasMore = normalizedLimit === null
? false
: Math.max(0, totalNormalized - normalizedOffset - normalizedLimit) > 0;
return {
messages,
messages: normalized,
total,
hasMore,
offset: normalizedOffset,
limit: normalizedLimit,
offset,
limit,
};
}
}

View File

@@ -1,6 +1,5 @@
import os from 'node:os';
import path from 'node:path';
import { readFile } from 'node:fs/promises';
import { sessionsDb } from '@/modules/database/index.js';
import {
@@ -100,7 +99,7 @@ export class CodexSessionSynchronizer implements IProviderSessionSynchronizer {
filePath: string,
nameMap: Map<string, string>
): Promise<ParsedSession | null> {
const parsed = await extractFirstValidJsonlData(filePath, (rawData) => {
return extractFirstValidJsonlData(filePath, (rawData) => {
const data = rawData as Record<string, unknown>;
const payload = data.payload as Record<string, unknown> | undefined;
const sessionId = typeof payload?.id === 'string' ? payload.id : undefined;
@@ -113,67 +112,8 @@ export class CodexSessionSynchronizer implements IProviderSessionSynchronizer {
return {
sessionId,
projectPath,
sessionName: normalizeSessionName(nameMap.get(sessionId), 'Untitled Codex Session'),
};
});
if (!parsed) {
return null;
}
const existingSession = sessionsDb.getSessionById(parsed.sessionId);
const existingSessionName = existingSession?.custom_name;
if (existingSessionName && existingSessionName !== 'Untitled Codex Session') {
return {
...parsed,
sessionName: normalizeSessionName(existingSessionName, 'Untitled Codex Session'),
};
}
let sessionName = nameMap.get(parsed.sessionId);
if (!sessionName) {
sessionName = await this.extractLastAgentMessageFromEnd(filePath);
}
return {
...parsed,
sessionName: normalizeSessionName(sessionName, 'Untitled Codex Session'),
};
}
private async extractLastAgentMessageFromEnd(filePath: string): Promise<string | undefined> {
try {
const content = await readFile(filePath, 'utf8');
const lines = content.split(/\r?\n/);
for (let index = lines.length - 1; index >= 0; index -= 1) {
const line = lines[index]?.trim();
if (!line) {
continue;
}
let parsed: unknown;
try {
parsed = JSON.parse(line);
} catch {
continue;
}
const data = parsed as Record<string, unknown>;
const eventType = typeof data.type === 'string' ? data.type : undefined;
const payload = data.payload as Record<string, unknown> | undefined;
const payloadType = typeof payload?.type === 'string' ? payload.type : undefined;
const lastAgentMessage = typeof payload?.last_agent_message === 'string'
? payload.last_agent_message
: undefined;
if (eventType === 'event_msg' && payloadType === 'task_complete' && lastAgentMessage?.trim()) {
return lastAgentMessage;
}
}
} catch {
// Ignore missing/unreadable files so sync can continue.
}
return undefined;
}
}

View File

@@ -520,9 +520,7 @@ export class CodexSessionsProvider implements IProviderSessions {
let result: CodexHistoryResult;
try {
// Load full history first so `total` reflects frontend-normalized messages,
// not raw JSONL records.
result = await getCodexSessionMessages(sessionId, null, 0);
result = await getCodexSessionMessages(sessionId, limit, offset);
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
console.warn(`[CodexProvider] Failed to load session ${sessionId}:`, message);
@@ -530,6 +528,8 @@ export class CodexSessionsProvider implements IProviderSessions {
}
const rawMessages = Array.isArray(result) ? result : (result.messages || []);
const total = Array.isArray(result) ? rawMessages.length : (result.total || 0);
const hasMore = Array.isArray(result) ? false : Boolean(result.hasMore);
const tokenUsage = Array.isArray(result) ? undefined : result.tokenUsage;
const normalized: NormalizedMessage[] = [];
@@ -552,31 +552,12 @@ export class CodexSessionsProvider implements IProviderSessions {
}
}
const totalNormalized = normalized.length;
let total = 0;
for (const msg of normalized) {
if (msg.kind !== 'tool_result') {
total += 1;
}
}
const normalizedOffset = Math.max(0, offset);
const normalizedLimit = limit === null ? null : Math.max(0, limit);
const messages = normalizedLimit === null
? normalized
: normalized.slice(
Math.max(0, totalNormalized - normalizedOffset - normalizedLimit),
Math.max(0, totalNormalized - normalizedOffset),
);
const hasMore = normalizedLimit === null
? false
: Math.max(0, totalNormalized - normalizedOffset - normalizedLimit) > 0;
return {
messages,
messages: normalized,
total,
hasMore,
offset: normalizedOffset,
limit: normalizedLimit,
offset,
limit,
tokenUsage,
};
}

View File

@@ -45,28 +45,44 @@ export class CursorSessionSynchronizer implements IProviderSessionSynchronizer {
*/
async synchronize(since?: Date): Promise<number> {
const projectsDir = path.join(this.cursorHome, 'projects');
const projectEntries = await listDirectoryEntriesSafe(projectsDir);
const seenProjectPaths = new Set<string>();
let processed = 0;
const files = await findFilesRecursivelyCreatedAfter(projectsDir, '.jsonl', since ?? null);
for (const filePath of files) {
const parsed = await this.processSessionFile(filePath);
if (!parsed) {
for (const entry of projectEntries) {
if (!entry.isDirectory()) {
continue;
}
const timestamps = await readFileTimestamps(filePath);
sessionsDb.createSession(
parsed.sessionId,
this.provider,
parsed.projectPath,
parsed.sessionName,
timestamps.createdAt,
timestamps.updatedAt,
filePath
);
processed += 1;
const workerLogPath = path.join(projectsDir, entry.name, 'worker.log');
const projectPath = await this.extractProjectPathFromWorkerLog(workerLogPath);
if (!projectPath || seenProjectPaths.has(projectPath)) {
continue;
}
seenProjectPaths.add(projectPath);
const projectHash = this.md5(projectPath);
const chatsDir = path.join(this.cursorHome, 'chats', projectHash);
const files = await findFilesRecursivelyCreatedAfter(chatsDir, '.jsonl', since ?? null);
for (const filePath of files) {
const parsed = await this.processSessionFile(filePath);
if (!parsed) {
continue;
}
const timestamps = await readFileTimestamps(filePath);
sessionsDb.createSession(
parsed.sessionId,
this.provider,
parsed.projectPath,
parsed.sessionName,
timestamps.createdAt,
timestamps.updatedAt,
filePath
);
processed += 1;
}
}
return processed;
@@ -97,6 +113,13 @@ export class CursorSessionSynchronizer implements IProviderSessionSynchronizer {
);
}
/**
* Produces the same project hash Cursor uses in chat directory names.
*/
private md5(input: string): string {
return crypto.createHash('md5').update(input).digest('hex');
}
/**
* Extracts project path from Cursor worker.log.
*/
@@ -126,7 +149,7 @@ export class CursorSessionSynchronizer implements IProviderSessionSynchronizer {
*/
private async processSessionFile(filePath: string): Promise<ParsedSession | null> {
const sessionId = path.basename(filePath, '.jsonl');
const grandparentDir = path.dirname(path.dirname(path.dirname(filePath)));
const grandparentDir = path.dirname(path.dirname(filePath));
const workerLogPath = path.join(grandparentDir, 'worker.log');
const projectPath = await this.extractProjectPathFromWorkerLog(workerLogPath);

View File

@@ -25,167 +25,6 @@ type CursorMessageBlob = {
content: AnyRecord;
};
function isInternalCursorText(value: unknown): boolean {
if (typeof value !== 'string') {
return false;
}
const normalized = value.trim();
return normalized.startsWith('<user_info>') || normalized.startsWith('<system_reminder>');
}
function isInternalCursorPart(part: unknown): boolean {
if (!part || typeof part !== 'object') {
return false;
}
const record = part as AnyRecord;
const type = typeof record.type === 'string' ? record.type : '';
if (type === 'user_info' || type === 'system_reminder') {
return true;
}
return isInternalCursorText(record.text);
}
function unwrapUserQueryText(value: string, role: 'user' | 'assistant'): string {
if (role !== 'user') {
return value;
}
const normalized = value.trimStart();
const openTag = '<user_query>';
const closeTag = '</user_query>';
if (!normalized.startsWith(openTag)) {
return value;
}
const afterOpen = normalized.slice(openTag.length);
const closeIndex = afterOpen.lastIndexOf(closeTag);
const inner = closeIndex >= 0 ? afterOpen.slice(0, closeIndex) : afterOpen;
return inner.trim();
}
function normalizeToolId(value: unknown): string | null {
if (typeof value !== 'string') {
return null;
}
const normalized = value.trim();
return normalized ? normalized : null;
}
function extractCursorToolResultContent(item: AnyRecord): string {
if (typeof item.result === 'string' && item.result.trim()) {
return item.result;
}
if (typeof item.output === 'string' && item.output.trim()) {
return item.output;
}
if (Array.isArray(item.experimental_content)) {
const experimentalText = item.experimental_content
.map((part: unknown) => {
if (typeof part === 'string') {
return part;
}
if (part && typeof part === 'object') {
const record = part as AnyRecord;
if (typeof record.text === 'string') {
return record.text;
}
}
return '';
})
.filter(Boolean)
.join('\n');
if (experimentalText.trim()) {
return experimentalText;
}
}
return typeof item.result === 'string' ? item.result : '';
}
function parseCursorToolInput(rawInput: unknown): unknown {
if (typeof rawInput !== 'string') {
return rawInput;
}
const trimmed = rawInput.trim();
if (!trimmed) {
return rawInput;
}
try {
return JSON.parse(trimmed);
} catch {
return rawInput;
}
}
function normalizeCursorToolInput(toolName: string, rawInput: unknown): unknown {
const parsed = parseCursorToolInput(rawInput);
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
return parsed;
}
const input = parsed as AnyRecord;
const normalized: AnyRecord = { ...input };
const filePath = input.file_path
?? input.filePath
?? input.path
?? input.file
?? input.filename;
if (typeof filePath === 'string' && filePath.trim()) {
normalized.file_path = filePath;
}
if (toolName === 'Write') {
const content = input.content
?? input.text
?? input.value
?? input.contents
?? input.fileContent
?? input.new_string
?? input.newString;
if (typeof content === 'string') {
normalized.content = content;
}
}
if (toolName === 'Edit') {
const oldString = input.old_string
?? input.oldString
?? input.old
?? '';
const newString = input.new_string
?? input.newString
?? input.new
?? input.content
?? '';
if (typeof oldString === 'string') {
normalized.old_string = oldString;
}
if (typeof newString === 'string') {
normalized.new_string = newString;
}
}
if (toolName === 'ApplyPatch') {
const patch = input.patch ?? input.diff ?? input.content;
if (typeof patch === 'string' && !normalized.patch) {
normalized.patch = patch;
}
}
return normalized;
}
function sanitizeCursorSessionId(sessionId: string): string {
const normalized = sessionId.trim();
if (!normalized) {
@@ -386,14 +225,13 @@ export class CursorSessionsProvider implements IProviderSessions {
try {
const blobs = await this.loadCursorBlobs(sessionId, projectPath);
const allNormalized = this.normalizeCursorBlobs(blobs, sessionId);
const renderableMessages = allNormalized.filter((msg) => msg.kind !== 'tool_result');
const total = renderableMessages.length;
const total = allNormalized.length;
if (limit !== null) {
const start = offset;
const page = limit === 0
? []
: renderableMessages.slice(start, start + limit);
: allNormalized.slice(start, start + limit);
const hasMore = limit === 0
? start < total
: start + limit < total;
@@ -407,7 +245,7 @@ export class CursorSessionsProvider implements IProviderSessions {
}
return {
messages: renderableMessages,
messages: allNormalized,
total,
hasMore: false,
offset: 0,
@@ -445,24 +283,11 @@ export class CursorSessionsProvider implements IProviderSessions {
let text = '';
if (Array.isArray(content.message.content)) {
text = content.message.content
.map((part: string | AnyRecord) => {
if (typeof part === 'string') {
if (isInternalCursorText(part)) {
return '';
}
return unwrapUserQueryText(part, role);
}
if (isInternalCursorPart(part)) {
return '';
}
return unwrapUserQueryText(part?.text || '', role);
})
.map((part: string | AnyRecord) => typeof part === 'string' ? part : part?.text || '')
.filter(Boolean)
.join('\n');
} else if (typeof content.message.content === 'string') {
if (!isInternalCursorText(content.message.content)) {
text = unwrapUserQueryText(content.message.content, role);
}
text = content.message.content;
}
if (text?.trim()) {
messages.push(createNormalizedMessage({
@@ -491,14 +316,7 @@ export class CursorSessionsProvider implements IProviderSessions {
if (item?.type !== 'tool-result') {
continue;
}
const cursorOptions = content.providerOptions?.cursor as AnyRecord | undefined;
const highLevelToolCallResult = cursorOptions?.highLevelToolCallResult;
const toolCallId = normalizeToolId(item.toolCallId)
|| normalizeToolId(item.tool_call_id)
|| normalizeToolId(highLevelToolCallResult?.toolCallId)
|| normalizeToolId(highLevelToolCallResult?.tool_call_id)
|| normalizeToolId(content.id)
|| '';
const toolCallId = item.toolCallId || content.id;
messages.push(createNormalizedMessage({
id: `${baseId}_tr`,
sessionId,
@@ -506,9 +324,8 @@ export class CursorSessionsProvider implements IProviderSessions {
provider: PROVIDER,
kind: 'tool_result',
toolId: toolCallId,
content: extractCursorToolResultContent(item),
isError: Boolean(item.isError || item.is_error),
toolUseResult: highLevelToolCallResult,
content: item.result || '',
isError: false,
}));
}
continue;
@@ -519,15 +336,8 @@ export class CursorSessionsProvider implements IProviderSessions {
if (Array.isArray(content.content)) {
for (let partIdx = 0; partIdx < content.content.length; partIdx++) {
const part = content.content[partIdx];
if (isInternalCursorPart(part)) {
continue;
}
if (part?.type === 'text' && part?.text) {
const normalizedPartText = unwrapUserQueryText(part.text, role);
if (!normalizedPartText) {
continue;
}
messages.push(createNormalizedMessage({
id: `${baseId}_${partIdx}`,
sessionId,
@@ -535,7 +345,7 @@ export class CursorSessionsProvider implements IProviderSessions {
provider: PROVIDER,
kind: 'text',
role,
content: normalizedPartText,
content: part.text,
sequence: blob.sequence,
rowid: blob.rowid,
}));
@@ -551,11 +361,7 @@ export class CursorSessionsProvider implements IProviderSessions {
} else if (part?.type === 'tool-call' || part?.type === 'tool_use') {
const rawToolName = part.toolName || part.name || 'Unknown Tool';
const toolName = rawToolName === 'ApplyPatch' ? 'Edit' : rawToolName;
const toolId = normalizeToolId(part.toolCallId)
|| normalizeToolId(part.tool_call_id)
|| normalizeToolId(part.id)
|| `tool_${i}_${partIdx}`;
const normalizedToolInput = normalizeCursorToolInput(rawToolName, part.args ?? part.input);
const toolId = part.toolCallId || part.id || `tool_${i}_${partIdx}`;
const message = createNormalizedMessage({
id: `${baseId}_${partIdx}`,
sessionId,
@@ -563,22 +369,14 @@ export class CursorSessionsProvider implements IProviderSessions {
provider: PROVIDER,
kind: 'tool_use',
toolName,
toolInput: normalizedToolInput,
toolInput: part.args || part.input,
toolId,
});
messages.push(message);
toolUseMap.set(toolId, message);
}
}
} else if (
typeof content.content === 'string'
&& content.content.trim()
&& !isInternalCursorText(content.content)
) {
const normalizedText = unwrapUserQueryText(content.content, role);
if (!normalizedText) {
continue;
}
} else if (typeof content.content === 'string' && content.content.trim()) {
messages.push(createNormalizedMessage({
id: baseId,
sessionId,
@@ -586,7 +384,7 @@ export class CursorSessionsProvider implements IProviderSessions {
provider: PROVIDER,
kind: 'text',
role,
content: normalizedText,
content: content.content,
sequence: blob.sequence,
rowid: blob.rowid,
}));
@@ -603,7 +401,6 @@ export class CursorSessionsProvider implements IProviderSessions {
toolUse.toolResult = {
content: msg.content,
isError: msg.isError,
toolUseResult: msg.toolUseResult,
};
}
}

View File

@@ -15,24 +15,7 @@ type GeminiCredentialsStatus = {
error?: string;
};
type GeminiAuthType =
| 'oauth-personal'
| 'gemini-api-key'
| 'vertex-ai'
| 'compute-default-credentials'
| 'gateway'
| 'cloud-shell'
| null;
export class GeminiProviderAuth implements IProviderAuth {
/**
* Gemini CLI can override its home root via GEMINI_CLI_HOME.
* Use the same resolution so status checks match runtime behavior.
*/
private getGeminiCliHome(): string {
return process.env.GEMINI_CLI_HOME?.trim() || os.homedir();
}
/**
* Checks whether the Gemini CLI is available on this host.
*/
@@ -75,88 +58,6 @@ export class GeminiProviderAuth implements IProviderAuth {
};
}
/**
* Parses dotenv-style key/value pairs.
*/
private parseEnvFile(content: string): Record<string, string> {
const parsed: Record<string, string> = {};
for (const rawLine of content.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line || line.startsWith('#')) {
continue;
}
const normalizedLine = line.startsWith('export ')
? line.slice('export '.length).trim()
: line;
const separatorIndex = normalizedLine.indexOf('=');
if (separatorIndex <= 0) {
continue;
}
const key = normalizedLine.slice(0, separatorIndex).trim();
if (!key) {
continue;
}
let value = normalizedLine.slice(separatorIndex + 1).trim();
const quoted = (value.startsWith('"') && value.endsWith('"')) || (value.startsWith('\'') && value.endsWith('\''));
if (quoted) {
value = value.slice(1, -1);
} else {
value = value.replace(/\s+#.*$/, '').trim();
}
parsed[key] = value;
}
return parsed;
}
/**
* Loads user-level auth env in Gemini's "first file found" order.
*/
private async loadUserLevelAuthEnv(): Promise<Record<string, string>> {
const geminiCliHome = this.getGeminiCliHome();
const envCandidates = [
path.join(geminiCliHome, '.gemini', '.env'),
path.join(geminiCliHome, '.env'),
];
for (const envPath of envCandidates) {
try {
const content = await readFile(envPath, 'utf8');
return this.parseEnvFile(content);
} catch {
// Continue to the next fallback.
}
}
return {};
}
/**
* Reads Gemini's selected auth type from settings.json when available.
*/
private async readSelectedAuthType(): Promise<GeminiAuthType> {
try {
const settingsPath = path.join(this.getGeminiCliHome(), '.gemini', 'settings.json');
const content = await readFile(settingsPath, 'utf8');
const settings = readObjectRecord(JSON.parse(content));
const security = readObjectRecord(settings?.security);
const auth = readObjectRecord(security?.auth);
const selectedType = readOptionalString(auth?.selectedType);
if (!selectedType) {
return null;
}
return selectedType as GeminiAuthType;
} catch {
return null;
}
}
/**
* Checks Gemini credentials from API key env vars or local OAuth credential files.
*/
@@ -165,46 +66,8 @@ export class GeminiProviderAuth implements IProviderAuth {
return { authenticated: true, email: 'API Key Auth', method: 'api_key' };
}
const userEnv = await this.loadUserLevelAuthEnv();
if (readOptionalString(userEnv.GEMINI_API_KEY)) {
return { authenticated: true, email: 'API Key Auth', method: 'api_key' };
}
const selectedType = await this.readSelectedAuthType();
if (selectedType === 'vertex-ai') {
const hasGoogleApiKey = Boolean(
process.env.GOOGLE_API_KEY?.trim()
|| readOptionalString(userEnv.GOOGLE_API_KEY)
);
const hasProject = Boolean(
process.env.GOOGLE_CLOUD_PROJECT?.trim()
|| process.env.GOOGLE_CLOUD_PROJECT_ID?.trim()
|| readOptionalString(userEnv.GOOGLE_CLOUD_PROJECT)
|| readOptionalString(userEnv.GOOGLE_CLOUD_PROJECT_ID)
);
const hasLocation = Boolean(
process.env.GOOGLE_CLOUD_LOCATION?.trim()
|| readOptionalString(userEnv.GOOGLE_CLOUD_LOCATION)
);
const hasServiceAccount = Boolean(
process.env.GOOGLE_APPLICATION_CREDENTIALS?.trim()
|| readOptionalString(userEnv.GOOGLE_APPLICATION_CREDENTIALS)
);
if (hasGoogleApiKey || hasServiceAccount || (hasProject && hasLocation)) {
return { authenticated: true, email: 'Vertex AI Auth', method: 'vertex_ai' };
}
return {
authenticated: false,
email: null,
method: 'vertex_ai',
error: 'Gemini is set to Vertex AI, but required env vars are missing',
};
}
try {
const credsPath = path.join(this.getGeminiCliHome(), '.gemini', 'oauth_creds.json');
const credsPath = path.join(os.homedir(), '.gemini', 'oauth_creds.json');
const content = await readFile(credsPath, 'utf8');
const creds = readObjectRecord(JSON.parse(content)) ?? {};
const accessToken = readOptionalString(creds.access_token);
@@ -243,25 +106,6 @@ export class GeminiProviderAuth implements IProviderAuth {
method: 'credentials_file',
};
} catch {
if (selectedType === 'gemini-api-key') {
return {
authenticated: false,
email: null,
method: 'api_key',
error: 'Gemini is set to "Use Gemini API key", but GEMINI_API_KEY is unavailable',
};
}
if (selectedType === 'oauth-personal') {
return {
authenticated: false,
email: null,
method: 'credentials_file',
error: 'Gemini is set to Google sign-in, but no cached OAuth credentials were found',
};
}
// If no explicit auth type was selected, surface the generic "not configured" error.
return {
authenticated: false,
email: null,
@@ -296,7 +140,7 @@ export class GeminiProviderAuth implements IProviderAuth {
*/
private async getActiveAccountEmail(): Promise<string | null> {
try {
const accPath = path.join(this.getGeminiCliHome(), '.gemini', 'google_accounts.json');
const accPath = path.join(os.homedir(), '.gemini', 'google_accounts.json');
const accContent = await readFile(accPath, 'utf8');
const accounts = readObjectRecord(JSON.parse(accContent));
return readOptionalString(accounts?.active) ?? null;

View File

@@ -39,37 +39,33 @@ export class GeminiSessionSynchronizer implements IProviderSessionSynchronizer {
async synchronize(since?: Date): Promise<number> {
const projectHashLookup = this.buildProjectHashLookup();
// const legacySessionFiles = await findFilesRecursivelyCreatedAfter(
// path.join(this.geminiHome, 'sessions'),
// '.json',
// since ?? null
// );
// Gemini creates overlapping artifacts across `sessions/` and `tmp/`.
// We currently index only `tmp/*/chats/*.jsonl` because those files are the
// live transcript source and avoid duplicate session rows from mirrored files.
// const legacyTempFiles = await findFilesRecursivelyCreatedAfter(
// path.join(this.geminiHome, 'tmp'),
// '.json',
// since ?? null
// );
// const jsonlSessionFiles = await findFilesRecursivelyCreatedAfter(
// path.join(this.geminiHome, 'sessions'),
// '.jsonl',
// since ?? null
// );
const legacySessionFiles = await findFilesRecursivelyCreatedAfter(
path.join(this.geminiHome, 'sessions'),
'.json',
since ?? null
);
const legacyTempFiles = await findFilesRecursivelyCreatedAfter(
path.join(this.geminiHome, 'tmp'),
'.json',
since ?? null
);
const jsonlSessionFiles = await findFilesRecursivelyCreatedAfter(
path.join(this.geminiHome, 'sessions'),
'.jsonl',
since ?? null
);
const jsonlTempFiles = await findFilesRecursivelyCreatedAfter(
path.join(this.geminiHome, 'tmp'),
'.jsonl',
since ?? null
);
// Current strategy: index only temp chat JSONL artifacts.
// Process legacy JSON first, then JSONL. If both exist for a session id,
// the JSONL artifact becomes the canonical jsonl_path via upsert.
const files = [
// ...legacySessionFiles,
// Intentionally disabled to avoid duplicate indexing from mirrored
// `sessions/*.json` and `sessions/*.jsonl` artifacts.
// ...legacyTempFiles,
// ...jsonlSessionFiles,
...legacySessionFiles,
...legacyTempFiles,
...jsonlSessionFiles,
...jsonlTempFiles,
];

View File

@@ -528,16 +528,10 @@ export class GeminiSessionsProvider implements IProviderSessions {
const messages = pageLimit === null
? normalized.slice(start)
: normalized.slice(start, start + pageLimit);
let total = 0;
for (const msg of normalized) {
if (msg.kind !== 'tool_result') {
total += 1;
}
}
return {
messages,
total,
total: normalized.length,
hasMore: pageLimit === null ? false : start + pageLimit < normalized.length,
offset: start,
limit: pageLimit,

View File

@@ -311,33 +311,12 @@ router.post(
);
// ----------------- Session routes -----------------
router.get(
'/sessions/archived',
asyncHandler(async (_req: Request, res: Response) => {
const sessions = sessionsService.listArchivedSessions();
res.json(createApiSuccessResponse({ sessions }));
}),
);
router.delete(
'/sessions/:sessionId',
asyncHandler(async (req: Request, res: Response) => {
const sessionId = parseSessionId(req.params.sessionId);
const force = parseOptionalBooleanQuery(req.query.force, 'force') ?? false;
const deletedFromDisk = parseOptionalBooleanQuery(req.query.deletedFromDisk, 'deletedFromDisk') ?? force;
const result = await sessionsService.deleteOrArchiveSessionById(sessionId, {
force,
deletedFromDisk,
});
res.json(createApiSuccessResponse(result));
}),
);
router.post(
'/sessions/:sessionId/restore',
asyncHandler(async (req: Request, res: Response) => {
const sessionId = parseSessionId(req.params.sessionId);
const result = sessionsService.restoreSessionById(sessionId);
const deletedFromDisk = parseOptionalBooleanQuery(req.query.deletedFromDisk, 'deletedFromDisk') ?? false;
const result = await sessionsService.deleteSessionById(sessionId, deletedFromDisk);
res.json(createApiSuccessResponse(result));
}),
);

View File

@@ -89,8 +89,13 @@ const RIPGREP_CHUNK_CONCURRENCY = 6;
const UNKNOWN_PROJECT_KEY = '__unknown_project__';
const INTERNAL_CONTENT_PREFIXES = [
'<command-name>',
'<command-message>',
'<command-args>',
'<local-command-stdout>',
'<system-reminder>',
'Caveat:',
'This session is being continued from a previous',
'Invalid API key',
'[Request interrupted',
] as const;
@@ -297,135 +302,6 @@ function extractClaudeText(content: unknown): string {
.join(' ');
}
function extractTaggedContent(content: string, tagName: string): string | null {
const escapedTagName = tagName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const match = new RegExp(`<${escapedTagName}>([\\s\\S]*?)<\\/${escapedTagName}>`).exec(content);
return match ? match[1] : null;
}
type ClaudeLocalCommandPayload = {
commandName: string;
commandMessage: string;
commandArgs: string;
};
function parseClaudeLocalCommandPayload(content: string): ClaudeLocalCommandPayload | null {
const commandName = extractTaggedContent(content, 'command-name');
const commandMessage = extractTaggedContent(content, 'command-message');
const commandArgs = extractTaggedContent(content, 'command-args');
if (commandName === null && commandMessage === null && commandArgs === null) {
return null;
}
return {
commandName: commandName ?? '',
commandMessage: commandMessage ?? '',
commandArgs: commandArgs ?? '',
};
}
function buildClaudeLocalCommandDisplayText(payload: ClaudeLocalCommandPayload): string {
const commandName = payload.commandName.trim();
const commandMessage = payload.commandMessage.trim();
const commandArgs = payload.commandArgs.trim();
const baseCommand = commandName || commandMessage;
if (!baseCommand) {
return '';
}
return commandArgs ? `${baseCommand} ${commandArgs}` : baseCommand;
}
function stripAnsiFormatting(text: string): string {
return text.replace(/\u001B\[[0-9;?]*[ -/]*[@-~]/g, '');
}
type ClaudeSearchableMessage = {
text: string;
role: 'user' | 'assistant';
};
/**
* Claude mixes visible chat, compact summaries, and local command wrappers into
* the same transcript stream. Search should operate on the user-visible meaning
* of those rows rather than the raw wrapper syntax.
*/
function extractClaudeSearchableMessage(entry: AnyRecord): ClaudeSearchableMessage | null {
if (!entry.message?.content || entry.isApiErrorMessage) {
return null;
}
const rawRole = entry.message.role;
if (rawRole !== 'user' && rawRole !== 'assistant') {
return null;
}
if (typeof entry.message.content === 'string') {
const content = String(entry.message.content);
if (entry.isCompactSummary === true && content.trim()) {
return {
text: content,
role: 'assistant',
};
}
const localCommand = parseClaudeLocalCommandPayload(content);
if (localCommand) {
const displayText = buildClaudeLocalCommandDisplayText(localCommand);
return displayText
? {
text: displayText,
role: 'user',
}
: null;
}
const localCommandStdout = extractTaggedContent(content, 'local-command-stdout');
if (localCommandStdout !== null) {
const stdoutText = stripAnsiFormatting(localCommandStdout).trim();
return stdoutText
? {
text: stdoutText,
role: 'assistant',
}
: null;
}
if (!content || isInternalContent(content)) {
return null;
}
return {
text: content,
role: rawRole,
};
}
const text = extractClaudeText(entry.message.content);
if (!text) {
return null;
}
if (entry.isCompactSummary === true) {
return {
text,
role: 'assistant',
};
}
if (isInternalContent(text)) {
return null;
}
return {
text,
role: rawRole,
};
}
function extractCodexText(content: unknown): string {
if (typeof content === 'string') {
return content;
@@ -472,7 +348,6 @@ function extractGeminiText(content: unknown): string {
function normalizeSearchableSessions(rows: SessionRepositoryRow[]): SearchableSessionRow[] {
const normalizedRows: SearchableSessionRow[] = [];
const projectArchiveStateByPath = new Map<string, boolean>();
for (const row of rows) {
const provider = row.provider as SearchableProvider;
@@ -490,27 +365,6 @@ function normalizeSearchableSessions(rows: SessionRepositoryRow[]): SearchableSe
continue;
}
/**
* Active session rows can still belong to an archived project because
* project archiving intentionally preserves the underlying session data.
* Global conversation search should follow the visible workspace model,
* which means excluding any session whose owning project is archived.
*
* Cache the archive lookup per normalized project path so one search pass
* does not re-query the same project row for every session in that folder.
*/
const normalizedProjectPath = typeof row.project_path === 'string' ? row.project_path.trim() : '';
if (normalizedProjectPath) {
if (!projectArchiveStateByPath.has(normalizedProjectPath)) {
const projectRow = projectsDb.getProjectPath(normalizedProjectPath);
projectArchiveStateByPath.set(normalizedProjectPath, Boolean(projectRow?.isArchived));
}
if (projectArchiveStateByPath.get(normalizedProjectPath) === true) {
continue;
}
}
normalizedRows.push({
...row,
provider,
@@ -879,21 +733,18 @@ async function parseClaudeSessionMatches(
}
}
const searchableMessage = extractClaudeSearchableMessage(entry);
if (!searchableMessage) {
if (!entry.message?.content || entry.isApiErrorMessage) {
continue;
}
const { text, role } = searchableMessage;
const role = entry.message.role;
if (role !== 'user' && role !== 'assistant') {
continue;
}
/**
* Claude compact summaries are the most faithful session-summary source
* after a `/compact` because they describe the post-compaction state that
* the resumed session actually continues from. Prefer them over generic
* fallback user text when present.
*/
if (entry.isCompactSummary === true) {
state.resolvedSummary = text;
const text = extractClaudeText(entry.message.content);
if (!text || isInternalContent(text)) {
continue;
}
if (role === 'user') {

View File

@@ -18,18 +18,16 @@ const PROVIDER_WATCH_PATHS: Array<{ provider: LLMProvider; rootPath: string }> =
},
{
provider: 'cursor',
rootPath: path.join(os.homedir(), '.cursor', 'projects'),
rootPath: path.join(os.homedir(), '.cursor', 'chats'),
},
{
provider: 'codex',
rootPath: path.join(os.homedir(), '.codex', 'sessions'),
},
// {
// provider: 'gemini',
// rootPath: path.join(os.homedir(), '.gemini', 'sessions'),
// },
// Keep `sessions/` watcher disabled: Gemini also mirrors artifacts there,
// which causes duplicate synchronization events.
{
provider: 'gemini',
rootPath: path.join(os.homedir(), '.gemini', 'sessions'),
},
{
provider: 'gemini',
rootPath: path.join(os.homedir(), '.gemini', 'tmp'),

View File

@@ -1,7 +1,6 @@
import fsp from 'node:fs/promises';
import path from 'node:path';
import { projectsDb, sessionsDb } from '@/modules/database/index.js';
import { sessionsDb } from '@/modules/database/index.js';
import { providerRegistry } from '@/modules/providers/provider.registry.js';
import type {
FetchHistoryOptions,
@@ -11,19 +10,6 @@ import type {
} from '@/shared/types.js';
import { AppError } from '@/shared/utils.js';
type ArchivedSessionListItem = {
sessionId: string;
provider: LLMProvider;
projectId: string | null;
projectPath: string | null;
projectDisplayName: string;
sessionTitle: string;
createdAt: string | null;
updatedAt: string | null;
lastActivity: string | null;
isProjectArchived: boolean;
};
/**
* Removes one file if it exists.
*/
@@ -40,28 +26,6 @@ async function removeFileIfExists(filePath: string): Promise<boolean> {
}
}
/**
* Archive rows need a stable project label even when the owning project is not
* part of the active sidebar payload. This lightweight resolver keeps the
* archive API self-contained while still matching the project's stored display
* name when one exists.
*/
function resolveProjectDisplayName(
projectPath: string | null,
customProjectName: string | null | undefined,
): string {
const trimmedCustomName = typeof customProjectName === 'string' ? customProjectName.trim() : '';
if (trimmedCustomName.length > 0) {
return trimmedCustomName;
}
if (!projectPath) {
return 'Unknown Project';
}
return path.basename(projectPath) || projectPath;
}
/**
* Application service for provider-backed session message operations.
*
@@ -115,53 +79,15 @@ export const sessionsService = {
},
/**
* Returns archived sessions with enough project metadata for the sidebar to
* group, filter, open, and restore them without a per-row follow-up query.
*/
listArchivedSessions(): ArchivedSessionListItem[] {
const archivedSessions = sessionsDb.getArchivedSessions();
const projectCache = new Map<string, ReturnType<typeof projectsDb.getProjectPath>>();
return archivedSessions.map((session) => {
const projectPath = session.project_path?.trim() ? session.project_path : null;
let project = null;
if (projectPath) {
if (!projectCache.has(projectPath)) {
projectCache.set(projectPath, projectsDb.getProjectPath(projectPath));
}
project = projectCache.get(projectPath) ?? null;
}
return {
sessionId: session.session_id,
provider: session.provider as LLMProvider,
projectId: project?.project_id ?? null,
projectPath,
projectDisplayName: resolveProjectDisplayName(projectPath, project?.custom_project_name),
sessionTitle: session.custom_name?.trim() || session.session_id,
createdAt: session.created_at ?? null,
updatedAt: session.updated_at ?? null,
lastActivity: session.updated_at ?? session.created_at ?? null,
isProjectArchived: Boolean(project?.isArchived),
};
});
},
/**
* Archives or permanently deletes one persisted session row by id.
* Deletes one persisted session row by id.
*
* Soft-delete mirrors the project behavior by toggling `isArchived` so the
* row disappears from active lists but remains restorable. Force-delete
* optionally removes the transcript file before deleting the database row.
* When `deletedFromDisk` is true and a session `jsonl_path` exists, the path
* is deleted from disk before the DB row is removed.
*/
async deleteOrArchiveSessionById(
async deleteSessionById(
sessionId: string,
options: {
force?: boolean;
deletedFromDisk?: boolean;
} = {},
): Promise<{ sessionId: string; action: 'archived' | 'deleted'; deletedFromDisk: boolean }> {
deletedFromDisk = false,
): Promise<{ sessionId: string; deletedFromDisk: boolean }> {
const session = sessionsDb.getSessionById(sessionId);
if (!session) {
throw new AppError(`Session "${sessionId}" was not found.`, {
@@ -170,17 +96,8 @@ export const sessionsService = {
});
}
if (!options.force) {
sessionsDb.updateSessionIsArchived(sessionId, true);
return {
sessionId,
action: 'archived',
deletedFromDisk: false,
};
}
let removedFromDisk = false;
if (options.deletedFromDisk && session.jsonl_path) {
if (deletedFromDisk && session.jsonl_path) {
removedFromDisk = await removeFileIfExists(session.jsonl_path);
}
@@ -192,27 +109,7 @@ export const sessionsService = {
});
}
return {
sessionId,
action: 'deleted',
deletedFromDisk: removedFromDisk,
};
},
/**
* Restores one archived session back into the active sidebar lists.
*/
restoreSessionById(sessionId: string): { sessionId: string; isArchived: false } {
const session = sessionsDb.getSessionById(sessionId);
if (!session) {
throw new AppError(`Session "${sessionId}" was not found.`, {
code: 'SESSION_NOT_FOUND',
statusCode: 404,
});
}
sessionsDb.updateSessionIsArchived(sessionId, false);
return { sessionId, isArchived: false };
return { sessionId, deletedFromDisk: removedFromDisk };
},
/**

View File

@@ -143,7 +143,7 @@ function transformCodexEvent(event) {
case 'thread.started':
return {
type: 'thread_started',
threadId: event.thread_id || event.id
threadId: event.id
};
case 'error':
@@ -207,8 +207,7 @@ export async function queryCodex(command, options = {}, ws) {
let codex;
let thread;
let capturedSessionId = sessionId;
let sessionCreatedSent = false;
let currentSessionId = sessionId;
let terminalFailure = null;
const abortController = new AbortController();
@@ -232,23 +231,20 @@ export async function queryCodex(command, options = {}, ws) {
thread = codex.startThread(threadOptions);
}
const registerSession = (id) => {
if (!id) {
return;
}
activeCodexSessions.set(id, {
thread,
codex,
status: 'running',
abortController,
startedAt: new Date().toISOString()
});
};
// Get the thread ID
currentSessionId = thread.id || sessionId || `codex-${Date.now()}`;
// Existing sessions can be tracked immediately; new sessions are tracked after thread.started.
if (capturedSessionId) {
registerSession(capturedSessionId);
}
// Track the session
activeCodexSessions.set(currentSessionId, {
thread,
codex,
status: 'running',
abortController,
startedAt: new Date().toISOString()
});
// Send session created event
sendMessage(ws, createNormalizedMessage({ kind: 'session_created', newSessionId: currentSessionId, sessionId: currentSessionId, provider: 'codex' }));
// Execute with streaming
const streamedTurn = await thread.runStreamed(command, {
@@ -256,34 +252,11 @@ export async function queryCodex(command, options = {}, ws) {
});
for await (const event of streamedTurn.events) {
// Capture thread/session id lazily from the stream (Codex emits this asynchronously).
if (event.type === 'thread.started') {
const discoveredSessionId = event.thread_id || event.id || null;
if (discoveredSessionId && !capturedSessionId) {
capturedSessionId = discoveredSessionId;
registerSession(capturedSessionId);
if (ws.setSessionId && typeof ws.setSessionId === 'function') {
ws.setSessionId(capturedSessionId);
}
if (!sessionId && !sessionCreatedSent) {
sessionCreatedSent = true;
sendMessage(ws, createNormalizedMessage({ kind: 'session_created', newSessionId: capturedSessionId, sessionId: capturedSessionId, provider: 'codex' }));
}
}
}
// Check if session was aborted
if (abortController.signal.aborted) {
const session = activeCodexSessions.get(currentSessionId);
if (!session || session.status === 'aborted') {
break;
}
if (capturedSessionId) {
const session = activeCodexSessions.get(capturedSessionId);
if (session?.status === 'aborted') {
break;
}
}
if (event.type === 'item.started' || event.type === 'item.updated') {
continue;
@@ -292,7 +265,7 @@ export async function queryCodex(command, options = {}, ws) {
const transformed = transformCodexEvent(event);
// Normalize the transformed event into NormalizedMessage(s) via adapter
const normalizedMsgs = sessionsService.normalizeMessage('codex', transformed, capturedSessionId || sessionId || null);
const normalizedMsgs = sessionsService.normalizeMessage('codex', transformed, currentSessionId);
for (const msg of normalizedMsgs) {
sendMessage(ws, msg);
}
@@ -302,7 +275,7 @@ export async function queryCodex(command, options = {}, ws) {
notifyRunFailed({
userId: ws?.userId || null,
provider: 'codex',
sessionId: capturedSessionId || sessionId || null,
sessionId: currentSessionId,
sessionName: sessionSummary,
error: terminalFailure
});
@@ -311,29 +284,24 @@ export async function queryCodex(command, options = {}, ws) {
// Extract and send token usage if available (normalized to match Claude format)
if (event.type === 'turn.completed' && event.usage) {
const totalTokens = (event.usage.input_tokens || 0) + (event.usage.output_tokens || 0);
sendMessage(ws, createNormalizedMessage({ kind: 'status', text: 'token_budget', tokenBudget: { used: totalTokens, total: 200000 }, sessionId: capturedSessionId || sessionId || null, provider: 'codex' }));
sendMessage(ws, createNormalizedMessage({ kind: 'status', text: 'token_budget', tokenBudget: { used: totalTokens, total: 200000 }, sessionId: currentSessionId, provider: 'codex' }));
}
}
// Send completion event
if (!terminalFailure) {
sendMessage(ws, createNormalizedMessage({
kind: 'complete',
actualSessionId: capturedSessionId || thread.id || sessionId || null,
sessionId: capturedSessionId || sessionId || null,
provider: 'codex'
}));
sendMessage(ws, createNormalizedMessage({ kind: 'complete', actualSessionId: thread.id, sessionId: currentSessionId, provider: 'codex' }));
notifyRunStopped({
userId: ws?.userId || null,
provider: 'codex',
sessionId: capturedSessionId || sessionId || null,
sessionId: currentSessionId,
sessionName: sessionSummary,
stopReason: 'completed'
});
}
} catch (error) {
const session = capturedSessionId ? activeCodexSessions.get(capturedSessionId) : null;
const session = currentSessionId ? activeCodexSessions.get(currentSessionId) : null;
const wasAborted =
session?.status === 'aborted' ||
error?.name === 'AbortError' ||
@@ -348,12 +316,12 @@ export async function queryCodex(command, options = {}, ws) {
? 'Codex CLI is not configured. Please set up authentication first.'
: error.message;
sendMessage(ws, createNormalizedMessage({ kind: 'error', content: errorContent, sessionId: capturedSessionId || sessionId || null, provider: 'codex' }));
sendMessage(ws, createNormalizedMessage({ kind: 'error', content: errorContent, sessionId: currentSessionId, provider: 'codex' }));
if (!terminalFailure) {
notifyRunFailed({
userId: ws?.userId || null,
provider: 'codex',
sessionId: capturedSessionId || sessionId || null,
sessionId: currentSessionId,
sessionName: sessionSummary,
error
});
@@ -362,8 +330,8 @@ export async function queryCodex(command, options = {}, ws) {
} finally {
// Update session status
if (capturedSessionId) {
const session = activeCodexSessions.get(capturedSessionId);
if (currentSessionId) {
const session = activeCodexSessions.get(currentSessionId);
if (session) {
session.status = session.status === 'aborted' ? 'aborted' : 'completed';
}

View File

@@ -320,7 +320,7 @@ Custom commands can be created in:
packageName,
uptime: uptimeFormatted,
uptimeSeconds: Math.floor(uptime),
model: context?.model || CLAUDE_MODELS.DEFAULT,
model: context?.model || 'claude-sonnet-4.5',
provider: context?.provider || 'claude',
nodeVersion: process.version,
platform: process.platform

View File

@@ -1,61 +0,0 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {
resolveClaudeCodeExecutablePath,
type ResolveClaudeCodeExecutablePathDependencies,
} from '@/shared/claude-cli-path.js';
test('resolveClaudeCodeExecutablePath resolves the npm Claude wrapper to its native exe on Windows', () => {
const wrapperDir = 'C:\\nvm4w\\nodejs';
const nativePath = `${wrapperDir}\\node_modules\\@anthropic-ai\\claude-code\\bin\\claude.exe`;
const execFileSync =
(() => `${wrapperDir}\\claude\r\n${wrapperDir}\\claude.cmd\r\n`) as unknown as ResolveClaudeCodeExecutablePathDependencies['execFileSync'];
const readFileSync = (() => '') as unknown as ResolveClaudeCodeExecutablePathDependencies['readFileSync'];
const resolved = resolveClaudeCodeExecutablePath('claude', {
platform: 'win32',
execFileSync,
existsSync: (candidate) => candidate === nativePath,
readFileSync,
});
assert.equal(resolved, nativePath);
});
test('resolveClaudeCodeExecutablePath keeps an explicit JavaScript launcher path unchanged', () => {
const scriptPath = 'C:\\tools\\claude.js';
const resolved = resolveClaudeCodeExecutablePath(scriptPath, {
platform: 'win32',
});
assert.equal(resolved, scriptPath);
});
test('resolveClaudeCodeExecutablePath can parse a wrapper file path containing letters r and n before claude.exe', () => {
const wrapperPath = 'C:\\tools\\claude';
const nativePath = 'C:\\tools\\custom\\bin\\node_modules\\@anthropic-ai\\claude-code\\bin\\claude.exe';
const readFileSync = (() => `exec "$basedir/custom/bin/node_modules/@anthropic-ai/claude-code/bin/claude.exe" "$@"`) as unknown as ResolveClaudeCodeExecutablePathDependencies['readFileSync'];
const resolved = resolveClaudeCodeExecutablePath(wrapperPath, {
platform: 'win32',
existsSync: (candidate) => candidate === nativePath,
readFileSync,
});
assert.equal(resolved, nativePath);
});
test('resolveClaudeCodeExecutablePath falls back to the configured command when PATH lookup fails', () => {
const execFileSync = (() => {
throw new Error('not found');
}) as unknown as ResolveClaudeCodeExecutablePathDependencies['execFileSync'];
const resolved = resolveClaudeCodeExecutablePath('claude', {
platform: 'win32',
execFileSync,
});
assert.equal(resolved, 'claude');
});

View File

@@ -1,139 +0,0 @@
import { execFileSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
const DEFAULT_CLAUDE_COMMAND = 'claude';
const CLAUDE_SCRIPT_EXTENSIONS = new Set(['.cjs', '.js', '.jsx', '.mjs', '.ts', '.tsx']);
const CLAUDE_WRAPPER_SEGMENTS = ['node_modules', '@anthropic-ai', 'claude-code', 'bin', 'claude.exe'] as const;
export type ResolveClaudeCodeExecutablePathDependencies = {
execFileSync?: typeof execFileSync;
existsSync?: typeof fs.existsSync;
platform?: NodeJS.Platform;
readFileSync?: typeof fs.readFileSync;
};
function getPathApi(platform: NodeJS.Platform) {
return platform === 'win32' ? path.win32 : path;
}
function stripWrappingQuotes(value: string): string {
const trimmed = value.trim();
if (
(trimmed.startsWith('"') && trimmed.endsWith('"')) ||
(trimmed.startsWith("'") && trimmed.endsWith("'"))
) {
return trimmed.slice(1, -1);
}
return trimmed;
}
function isPathLike(value: string): boolean {
return value.includes('/') || value.includes('\\');
}
function resolveClaudeWrapperBinary(
wrapperPath: string,
deps: Required<ResolveClaudeCodeExecutablePathDependencies>,
): string | null {
const pathApi = getPathApi(deps.platform);
const directCandidate = pathApi.resolve(pathApi.dirname(wrapperPath), ...CLAUDE_WRAPPER_SEGMENTS);
if (deps.existsSync(directCandidate)) {
return directCandidate;
}
let content: string;
try {
content = deps.readFileSync(wrapperPath, 'utf8');
} catch {
return null;
}
const matches = content.matchAll(/["']([^"'\\\r\n]*claude\.exe)["']/gi);
for (const match of matches) {
const rawTarget = match[1]
.replace(/^\$basedir[\\/]/i, '')
.replace(/^%dp0%[\\/]/i, '')
.replace(/^%~dp0[\\/]/i, '');
const normalizedTarget = rawTarget.replace(/[\\/]/g, pathApi.sep);
const candidate = pathApi.isAbsolute(normalizedTarget)
? normalizedTarget
: pathApi.resolve(pathApi.dirname(wrapperPath), normalizedTarget);
if (deps.existsSync(candidate)) {
return candidate;
}
}
return null;
}
function resolveWindowsClaudeExecutablePath(
configuredPath: string,
deps: Required<ResolveClaudeCodeExecutablePathDependencies>,
): string {
const pathApi = getPathApi(deps.platform);
const extension = pathApi.extname(configuredPath).toLowerCase();
const explicitPath = isPathLike(configuredPath) || pathApi.isAbsolute(configuredPath);
if (CLAUDE_SCRIPT_EXTENSIONS.has(extension)) {
return configuredPath;
}
if (explicitPath && extension === '.exe') {
return configuredPath;
}
if (explicitPath) {
return resolveClaudeWrapperBinary(configuredPath, deps) ?? configuredPath;
}
try {
const stdout = deps.execFileSync('where.exe', [configuredPath], {
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'ignore'],
windowsHide: true,
});
const candidates = stdout
.split(/\r?\n/)
.map((entry) => entry.trim())
.filter(Boolean);
for (const candidate of candidates) {
if (pathApi.extname(candidate).toLowerCase() === '.exe') {
return candidate;
}
}
for (const candidate of candidates) {
const resolved = resolveClaudeWrapperBinary(candidate, deps);
if (resolved) {
return resolved;
}
}
} catch {
return configuredPath;
}
return configuredPath;
}
export function resolveClaudeCodeExecutablePath(
configuredPath: string | undefined = process.env.CLAUDE_CLI_PATH,
dependencies: ResolveClaudeCodeExecutablePathDependencies = {},
): string {
const deps: Required<ResolveClaudeCodeExecutablePathDependencies> = {
execFileSync: dependencies.execFileSync ?? execFileSync,
existsSync: dependencies.existsSync ?? fs.existsSync,
platform: dependencies.platform ?? process.platform,
readFileSync: dependencies.readFileSync ?? fs.readFileSync,
};
const normalizedPath = stripWrappingQuotes(configuredPath || DEFAULT_CLAUDE_COMMAND);
if (deps.platform !== 'win32') {
return normalizedPath;
}
return resolveWindowsClaudeExecutablePath(normalizedPath, deps);
}

View File

@@ -102,21 +102,6 @@ export type NormalizedMessage = {
kind: MessageKind;
role?: 'user' | 'assistant';
content?: string;
/**
* Optional display-oriented metadata used by providers that need to expose
* richer transcript artifacts without introducing a brand-new message kind.
*
* Current Claude usage:
* - local slash commands expose parsed command fields
* - compact summaries are flagged so the UI can treat them differently later
*/
displayText?: string;
commandName?: string;
commandMessage?: string;
commandArgs?: string;
isLocalCommand?: boolean;
isLocalCommandStdout?: boolean;
isCompactSummary?: boolean;
images?: unknown;
toolName?: string;
toolInput?: unknown;

View File

@@ -13,8 +13,8 @@
export const CLAUDE_MODELS = {
// Models in SDK format (what the actual SDK accepts)
OPTIONS: [
{ value: "opus", label: "Opus" },
{ value: "sonnet", label: "Sonnet" },
{ value: "opus", label: "Opus" },
{ value: "haiku", label: "Haiku" },
{ value: "claude-opus-4-6", label: "Opus 4.6" },
{ value: "opusplan", label: "Opus Plan" },
@@ -51,7 +51,7 @@ export const CURSOR_MODELS = {
{ value: "grok", label: "Grok" },
],
DEFAULT: "gpt-5.3-codex",
DEFAULT: "gpt-5-3-codex",
};
/**
@@ -59,7 +59,6 @@ export const CURSOR_MODELS = {
*/
export const CODEX_MODELS = {
OPTIONS: [
{ value: "gpt-5.5", label: "GPT-5.5" },
{ value: "gpt-5.4", label: "GPT-5.4" },
{ value: "gpt-5.4-mini", label: "GPT-5.4 mini" },
{ value: "gpt-5.3-codex", label: "GPT-5.3 Codex" },
@@ -84,7 +83,6 @@ export const GEMINI_MODELS = {
{ value: "gemini-2.5-flash", label: "Gemini 2.5 Flash" },
{ value: "gemini-2.5-pro", label: "Gemini 2.5 Pro" },
{ value: "gemini-2.0-flash-lite", label: "Gemini 2.0 Flash Lite" },
{ value: "gemini-2.5-flash-lite", label: "Gemini 2.5 Flash Lite" },
{ value: "gemini-2.0-flash", label: "Gemini 2.0 Flash" },
{ value: "gemini-2.0-pro-exp", label: "Gemini 2.0 Pro Experimental" },
{
@@ -95,13 +93,3 @@ export const GEMINI_MODELS = {
DEFAULT: "gemini-3.1-pro-preview",
};
/**
* Ordered provider registry. Display order in selection UIs.
*/
export const PROVIDERS = [
{ id: "claude", name: "Anthropic", models: CLAUDE_MODELS },
{ id: "codex", name: "OpenAI", models: CODEX_MODELS },
{ id: "gemini", name: "Google", models: GEMINI_MODELS },
{ id: "cursor", name: "Cursor", models: CURSOR_MODELS },
];

View File

@@ -1,25 +1,14 @@
import { useEffect, useRef } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import Sidebar from '../sidebar/view/Sidebar';
import MainContent from '../main-content/view/MainContent';
import CommandPalette from '../command-palette/CommandPalette';
import { useWebSocket } from '../../contexts/WebSocketContext';
import { PaletteOpsProvider, usePaletteOpsRegister } from '../../contexts/PaletteOpsContext';
import { useDeviceSettings } from '../../hooks/useDeviceSettings';
import { useSessionProtection } from '../../hooks/useSessionProtection';
import { useProjectsState } from '../../hooks/useProjectsState';
export default function AppContent() {
return (
<PaletteOpsProvider>
<AppContentInner />
</PaletteOpsProvider>
);
}
function AppContentInner() {
const navigate = useNavigate();
const { sessionId } = useParams<{ sessionId?: string }>();
const { t } = useTranslation('common');
@@ -34,6 +23,7 @@ function AppContentInner() {
markSessionAsInactive,
markSessionAsProcessing,
markSessionAsNotProcessing,
replaceTemporarySession,
} = useSessionProtection();
const {
@@ -43,7 +33,6 @@ function AppContentInner() {
sidebarOpen,
isLoadingProjects,
externalMessageUpdate,
newSessionTrigger,
setActiveTab,
setSidebarOpen,
setIsInputFocused,
@@ -51,7 +40,6 @@ function AppContentInner() {
openSettings,
refreshProjectsSilently,
sidebarSharedProps,
handleNewSession,
} = useProjectsState({
sessionId,
navigate,
@@ -60,10 +48,27 @@ function AppContentInner() {
activeSessions,
});
usePaletteOpsRegister({
openSettings,
refreshProjects: refreshProjectsSilently,
});
useEffect(() => {
// Expose a non-blocking refresh for chat/session flows.
// Full loading refreshes are still available through direct fetchProjects calls.
window.refreshProjects = refreshProjectsSilently;
return () => {
if (window.refreshProjects === refreshProjectsSilently) {
delete window.refreshProjects;
}
};
}, [refreshProjectsSilently]);
useEffect(() => {
window.openSettings = openSettings;
return () => {
if (window.openSettings === openSettings) {
delete window.openSettings;
}
};
}, [openSettings]);
useEffect(() => {
if (typeof navigator === 'undefined' || !('serviceWorker' in navigator)) {
@@ -190,21 +195,13 @@ function AppContentInner() {
onSessionProcessing={markSessionAsProcessing}
onSessionNotProcessing={markSessionAsNotProcessing}
processingSessions={processingSessions}
onNavigateToSession={(targetSessionId: string, options) =>
navigate(`/session/${targetSessionId}`, { replace: Boolean(options?.replace) })
}
onReplaceTemporarySession={replaceTemporarySession}
onNavigateToSession={(targetSessionId: string) => navigate(`/session/${targetSessionId}`)}
onShowSettings={() => setShowSettings(true)}
externalMessageUpdate={externalMessageUpdate}
newSessionTrigger={newSessionTrigger}
/>
</div>
<CommandPalette
selectedProject={selectedProject}
onStartNewChat={handleNewSession}
onOpenSettings={() => openSettings()}
onShowTab={setActiveTab}
/>
</div>
);
}

View File

@@ -10,7 +10,6 @@ import type {
TouchEvent,
} from 'react';
import { useDropzone } from 'react-dropzone';
import { authenticatedFetch } from '../../../utils/api';
import { thinkingModes } from '../constants/thinkingModes';
import { grantClaudeToolPermission } from '../utils/chatPermissions';
@@ -22,7 +21,6 @@ import type {
} from '../types/types';
import type { Project, ProjectSession, LLMProvider } from '../../../types/app';
import { escapeRegExp } from '../utils/chatFormatting';
import { useFileMentions } from './useFileMentions';
import { type SlashCommand, useSlashCommands } from './useSlashCommands';
@@ -82,6 +80,9 @@ const createFakeSubmitEvent = () => {
return { preventDefault: () => undefined } as unknown as FormEvent<HTMLFormElement>;
};
const isTemporarySessionId = (sessionId: string | null | undefined) =>
Boolean(sessionId && sessionId.startsWith('new-session-'));
const getNotificationSessionSummary = (
selectedSession: ProjectSession | null,
fallbackInput: string,
@@ -532,6 +533,7 @@ export function useChatComposerState({
const effectiveSessionId =
currentSessionId || selectedSession?.id || sessionStorage.getItem('cursorSessionId');
const sessionToActivate = effectiveSessionId || `new-session-${Date.now()}`;
const userMessage: ChatMessage = {
type: 'user',
@@ -557,12 +559,10 @@ export function useChatComposerState({
// Reset stale pending IDs from previous interrupted runs before creating a new one.
sessionStorage.removeItem('pendingSessionId');
}
// For new sessions we intentionally keep this as `null` until the backend
// emits `session_created` with the canonical provider session id.
pendingViewSessionRef.current = { sessionId: null, startedAt: Date.now() };
}
if (effectiveSessionId) {
onSessionActive?.(effectiveSessionId);
onSessionActive?.(sessionToActivate);
if (effectiveSessionId && !isTemporarySessionId(effectiveSessionId)) {
onSessionProcessing?.(effectiveSessionId);
}
@@ -868,7 +868,7 @@ export function useChatComposerState({
];
const targetSessionId =
candidateSessionIds.find((sessionId) => Boolean(sessionId)) || null;
candidateSessionIds.find((sessionId) => Boolean(sessionId) && !isTemporarySessionId(sessionId)) || null;
if (!targetSessionId) {
console.warn('Abort requested but no concrete session ID is available yet.');

View File

@@ -11,9 +11,8 @@ import { decodeHtmlEntities, unescapeWithMathProtection, formatUsageLimitText }
* Convert NormalizedMessage[] from the session store into ChatMessage[]
* that the existing UI components expect.
*
* Truly internal/system content is already filtered server-side. Some Claude
* transcript artifacts such as local slash commands and compact summaries are
* intentionally preserved and annotated so they can render like normal chat.
* Internal/system content (e.g. <system-reminder>, <command-name>) is already
* filtered server-side by the Claude provider module.
*/
export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMessage[] {
const converted: ChatMessage[] = [];
@@ -27,16 +26,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
}
for (const msg of messages) {
const sharedMetadata = {
displayText: msg.displayText,
commandName: msg.commandName,
commandMessage: msg.commandMessage,
commandArgs: msg.commandArgs,
isLocalCommand: msg.isLocalCommand,
isLocalCommandStdout: msg.isLocalCommandStdout,
isCompactSummary: msg.isCompactSummary,
};
switch (msg.kind) {
case 'text': {
const content = msg.content || '';
@@ -53,14 +42,12 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
timestamp: msg.timestamp,
isTaskNotification: true,
taskStatus: taskNotifMatch[1]?.trim() || 'completed',
...sharedMetadata,
});
} else {
converted.push({
type: 'user',
content: unescapeWithMathProtection(decodeHtmlEntities(content)),
timestamp: msg.timestamp,
...sharedMetadata,
});
}
} else {
@@ -71,7 +58,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
type: 'assistant',
content: text,
timestamp: msg.timestamp,
...sharedMetadata,
});
}
break;
@@ -120,7 +106,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
isComplete: Boolean(toolResult),
}
: undefined,
...sharedMetadata,
});
break;
}
@@ -132,7 +117,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
content: unescapeWithMathProtection(msg.content),
timestamp: msg.timestamp,
isThinking: true,
...sharedMetadata,
});
}
break;
@@ -142,7 +126,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
type: 'error',
content: msg.content || 'Unknown error',
timestamp: msg.timestamp,
...sharedMetadata,
});
break;
@@ -152,7 +135,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
content: msg.content || '',
timestamp: msg.timestamp,
isInteractivePrompt: true,
...sharedMetadata,
});
break;
@@ -163,7 +145,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
timestamp: msg.timestamp,
isTaskNotification: true,
taskStatus: msg.status || 'completed',
...sharedMetadata,
});
break;
@@ -174,7 +155,6 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes
content: msg.content,
timestamp: msg.timestamp,
isStreaming: true,
...sharedMetadata,
});
}
break;

View File

@@ -4,16 +4,6 @@ import { CLAUDE_MODELS, CODEX_MODELS, CURSOR_MODELS, GEMINI_MODELS } from '../..
import type { PendingPermissionRequest, PermissionMode } from '../types/types';
import type { ProjectSession, LLMProvider } from '../../../types/app';
const getPermissionModesForProvider = (provider: LLMProvider): PermissionMode[] => {
if (provider === 'codex') {
return ['default', 'acceptEdits', 'bypassPermissions'];
}
if (provider === 'claude') {
return ['default', 'auto', 'acceptEdits', 'bypassPermissions', 'plan'];
}
return ['default', 'acceptEdits', 'bypassPermissions', 'plan'];
};
interface UseChatProviderStateArgs {
selectedSession: ProjectSession | null;
}
@@ -44,10 +34,9 @@ export function useChatProviderState({ selectedSession }: UseChatProviderStateAr
return;
}
const savedMode = localStorage.getItem(`permissionMode-${selectedSession.id}`) as PermissionMode | null;
const validModes = getPermissionModesForProvider(provider);
setPermissionMode(savedMode && validModes.includes(savedMode) ? savedMode : 'default');
}, [selectedSession?.id, provider]);
const savedMode = localStorage.getItem(`permissionMode-${selectedSession.id}`);
setPermissionMode((savedMode as PermissionMode) || 'default');
}, [selectedSession?.id]);
useEffect(() => {
if (!selectedSession?.__provider || selectedSession.__provider === provider) {
@@ -95,7 +84,10 @@ export function useChatProviderState({ selectedSession }: UseChatProviderStateAr
}, [provider]);
const cyclePermissionMode = useCallback(() => {
const modes = getPermissionModesForProvider(provider);
const modes: PermissionMode[] =
provider === 'codex'
? ['default', 'acceptEdits', 'bypassPermissions']
: ['default', 'acceptEdits', 'bypassPermissions', 'plan'];
const currentIndex = modes.indexOf(permissionMode);
const nextIndex = (currentIndex + 1) % modes.length;

View File

@@ -1,9 +1,7 @@
import { useEffect, useRef } from 'react';
import type { Dispatch, MutableRefObject, SetStateAction } from 'react';
import { usePaletteOps } from '../../../contexts/PaletteOpsContext';
import type { PendingPermissionRequest, SessionNavigationOptions } from '../types/types';
import type { ProjectSession, LLMProvider } from '../../../types/app';
import type { PendingPermissionRequest } from '../types/types';
import type { Project, ProjectSession, LLMProvider } from '../../../types/app';
import type { SessionStore, NormalizedMessage } from '../../../stores/useSessionStore';
type PendingViewSession = {
@@ -51,6 +49,7 @@ type LatestChatMessage = {
interface UseChatRealtimeHandlersArgs {
latestMessage: LatestChatMessage | null;
provider: LLMProvider;
selectedProject: Project | null;
selectedSession: ProjectSession | null;
currentSessionId: string | null;
setCurrentSessionId: (sessionId: string | null) => void;
@@ -60,12 +59,14 @@ interface UseChatRealtimeHandlersArgs {
setTokenBudget: (budget: Record<string, unknown> | null) => void;
setPendingPermissionRequests: Dispatch<SetStateAction<PendingPermissionRequest[]>>;
pendingViewSessionRef: MutableRefObject<PendingViewSession | null>;
streamBufferRef: MutableRefObject<string>;
streamTimerRef: MutableRefObject<number | null>;
accumulatedStreamRef: MutableRefObject<string>;
onSessionInactive?: (sessionId?: string | null) => void;
onSessionProcessing?: (sessionId?: string | null) => void;
onSessionNotProcessing?: (sessionId?: string | null) => void;
onNavigateToSession?: (sessionId: string, options?: SessionNavigationOptions) => void;
onReplaceTemporarySession?: (sessionId?: string | null) => void;
onNavigateToSession?: (sessionId: string) => void;
onWebSocketReconnect?: () => void;
sessionStore: SessionStore;
}
@@ -77,6 +78,7 @@ interface UseChatRealtimeHandlersArgs {
export function useChatRealtimeHandlers({
latestMessage,
provider,
selectedProject,
selectedSession,
currentSessionId,
setCurrentSessionId,
@@ -86,16 +88,17 @@ export function useChatRealtimeHandlers({
setTokenBudget,
setPendingPermissionRequests,
pendingViewSessionRef,
streamBufferRef,
streamTimerRef,
accumulatedStreamRef,
onSessionInactive,
onSessionProcessing,
onSessionNotProcessing,
onReplaceTemporarySession,
onNavigateToSession,
onWebSocketReconnect,
sessionStore,
}: UseChatRealtimeHandlersArgs) {
const paletteOps = usePaletteOps();
const lastProcessedMessageRef = useRef<LatestChatMessage | null>(null);
useEffect(() => {
@@ -181,6 +184,7 @@ export function useChatRealtimeHandlers({
if (msg.kind === 'stream_delta') {
const text = msg.content || '';
if (!text) return;
streamBufferRef.current += text;
accumulatedStreamRef.current += text;
if (!streamTimerRef.current) {
streamTimerRef.current = window.setTimeout(() => {
@@ -209,18 +213,12 @@ export function useChatRealtimeHandlers({
sessionStore.finalizeStreaming(sid);
}
accumulatedStreamRef.current = '';
streamBufferRef.current = '';
return;
}
// --- All other messages: route to store ---
const shouldPersist =
msg.kind !== 'session_created'
&& msg.kind !== 'complete'
&& msg.kind !== 'status'
&& msg.kind !== 'permission_request'
&& msg.kind !== 'permission_cancelled';
if (sid && shouldPersist) {
if (sid) {
sessionStore.appendRealtime(sid, msg as NormalizedMessage);
}
@@ -230,16 +228,13 @@ export function useChatRealtimeHandlers({
const newSessionId = msg.newSessionId;
if (!newSessionId) break;
// We no longer synthesize client-side placeholder IDs. Until the provider
// announces `session_created`, the active id is expected to be null.
if (!currentSessionId) {
console.log('Session created with ID:', newSessionId);
console.log('Existing session ID:', currentSessionId);
if (!currentSessionId || currentSessionId.startsWith('new-session-')) {
sessionStorage.setItem('pendingSessionId', newSessionId);
if (pendingViewSessionRef.current && !pendingViewSessionRef.current.sessionId) {
pendingViewSessionRef.current.sessionId = newSessionId;
}
setCurrentSessionId(newSessionId);
onReplaceTemporarySession?.(newSessionId);
setPendingPermissionRequests((prev) =>
prev.map((r) => (r.sessionId ? r : { ...r, sessionId: newSessionId })),
);
@@ -259,6 +254,7 @@ export function useChatRealtimeHandlers({
sessionStore.finalizeStreaming(sid);
}
accumulatedStreamRef.current = '';
streamBufferRef.current = '';
setIsLoading(false);
setCanAbortSession(false);
@@ -275,56 +271,18 @@ export function useChatRealtimeHandlers({
break;
}
const actualSessionId =
typeof msg.actualSessionId === 'string' && msg.actualSessionId.trim().length > 0
? msg.actualSessionId
: null;
const pendingSessionId = sessionStorage.getItem('pendingSessionId');
const completedSuccessfully = msg.exitCode === undefined || msg.exitCode === 0;
const isVisibleSession =
Boolean(
sid
&& (
sid === activeViewSessionId
|| sid === pendingSessionId
|| pendingViewSessionRef.current?.sessionId === sid
),
);
if (actualSessionId && sid && actualSessionId !== sid) {
sessionStore.replaceSessionId(sid, actualSessionId);
if (isVisibleSession) {
setCurrentSessionId(actualSessionId);
if (pendingViewSessionRef.current) {
const pendingSession = pendingViewSessionRef.current.sessionId;
if (!pendingSession || pendingSession === sid) {
pendingViewSessionRef.current.sessionId = actualSessionId;
}
}
}
if (completedSuccessfully && pendingSessionId === sid) {
sessionStorage.removeItem('pendingSessionId');
}
if (isVisibleSession) {
onNavigateToSession?.(actualSessionId, { replace: true });
setTimeout(() => { void paletteOps.refreshProjects(); }, 500);
}
break;
}
// Clear pending session
if (pendingSessionId && !currentSessionId && completedSuccessfully) {
const resolvedSessionId = actualSessionId || pendingSessionId;
setCurrentSessionId(resolvedSessionId);
if (actualSessionId) {
onNavigateToSession?.(resolvedSessionId, { replace: true });
const pendingSessionId = sessionStorage.getItem('pendingSessionId');
if (pendingSessionId && !currentSessionId && msg.exitCode === 0) {
const actualId = msg.actualSessionId || pendingSessionId;
setCurrentSessionId(actualId);
if (msg.actualSessionId) {
onNavigateToSession?.(actualId);
}
sessionStorage.removeItem('pendingSessionId');
setTimeout(() => { void paletteOps.refreshProjects(); }, 500);
if (window.refreshProjects) {
setTimeout(() => window.refreshProjects?.(), 500);
}
}
break;
}
@@ -387,6 +345,7 @@ export function useChatRealtimeHandlers({
}, [
latestMessage,
provider,
selectedProject,
selectedSession,
currentSessionId,
setCurrentSessionId,
@@ -396,14 +355,15 @@ export function useChatRealtimeHandlers({
setTokenBudget,
setPendingPermissionRequests,
pendingViewSessionRef,
streamBufferRef,
streamTimerRef,
accumulatedStreamRef,
onSessionInactive,
onSessionProcessing,
onSessionNotProcessing,
onReplaceTemporarySession,
onNavigateToSession,
onWebSocketReconnect,
sessionStore,
paletteOps,
]);
}

View File

@@ -1,13 +1,11 @@
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
import type { MutableRefObject } from 'react';
import { authenticatedFetch } from '../../../utils/api';
import type { Project, ProjectSession, LLMProvider } from '../../../types/app';
import type { SessionStore, NormalizedMessage } from '../../../stores/useSessionStore';
import type { ChatMessage, Provider } from '../types/types';
import type { Project, ProjectSession, LLMProvider } from '../../../types/app';
import { createCachedDiffCalculator, type DiffCalculator } from '../utils/messageTransforms';
import { normalizedToChatMessages } from './useChatMessages';
import type { SessionStore, NormalizedMessage } from '../../../stores/useSessionStore';
const MESSAGES_PER_PAGE = 20;
const INITIAL_VISIBLE_MESSAGES = 100;
@@ -24,7 +22,6 @@ interface UseChatSessionStateArgs {
sendMessage: (message: unknown) => void;
autoScrollToBottom?: boolean;
externalMessageUpdate?: number;
newSessionTrigger?: number;
processingSessions?: Set<string>;
resetStreamingState: () => void;
pendingViewSessionRef: MutableRefObject<PendingViewSession | null>;
@@ -98,7 +95,6 @@ export function useChatSessionState({
sendMessage,
autoScrollToBottom,
externalMessageUpdate,
newSessionTrigger,
processingSessions,
resetStreamingState,
pendingViewSessionRef,
@@ -135,86 +131,15 @@ export function useChatSessionState({
const loadAllFinishedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const loadAllOverlayTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const lastLoadedSessionKeyRef = useRef<string | null>(null);
/**
* Tracks the last processed value from `useProjectsState.newSessionTrigger`.
*
* The trigger itself is intentionally increment-only and routed via:
* useProjectsState -> AppContent -> MainContent -> ChatInterface -> this hook.
* We compare values to ensure each explicit New Session click runs exactly one
* reset pass in this local chat state domain.
*/
const previousNewSessionTriggerRef = useRef(newSessionTrigger ?? 0);
const createDiff = useMemo<DiffCalculator>(() => createCachedDiffCalculator(), []);
useEffect(() => {
const trigger = newSessionTrigger ?? 0;
if (trigger === previousNewSessionTriggerRef.current) {
return;
}
previousNewSessionTriggerRef.current = trigger;
/**
* Consumer-side reset for explicit New Session intent.
*
* Why this is essential:
* - Chat keeps local state that is not fully derived from `selectedSession`:
* `currentSessionId`, `pendingUserMessage`, streaming/status flags, message
* pagination/scroll bookkeeping, and pending session IDs in sessionStorage.
* - If the user clicks New Session while already on the same route with no
* selected session, parent state updates can be idempotent and this local
* state would otherwise persist, making the click appear to "do nothing".
*
* What this reset guarantees:
* - A deterministic clean draft state on every New Session click.
* - No dependence on route/tab/session-object identity changes.
* - No coupling to unrelated external update signals.
*/
resetStreamingState();
pendingViewSessionRef.current = null;
setClaudeStatus(null);
setCanAbortSession(false);
setIsLoading(false);
setCurrentSessionId(null);
setPendingUserMessage(null);
sessionStorage.removeItem('pendingSessionId');
sessionStorage.removeItem('cursorSessionId');
messagesOffsetRef.current = 0;
setHasMoreMessages(false);
setTotalMessages(0);
setTokenBudget(null);
setVisibleMessageCount(INITIAL_VISIBLE_MESSAGES);
setAllMessagesLoaded(false);
allMessagesLoadedRef.current = false;
setIsLoadingAllMessages(false);
setLoadAllJustFinished(false);
setShowLoadAllOverlay(false);
setViewHiddenCount(0);
setSearchTarget(null);
searchScrollActiveRef.current = false;
topLoadLockRef.current = false;
pendingScrollRestoreRef.current = null;
pendingInitialScrollRef.current = true;
lastLoadedSessionKeyRef.current = null;
if (loadAllOverlayTimerRef.current) {
clearTimeout(loadAllOverlayTimerRef.current);
loadAllOverlayTimerRef.current = null;
}
if (loadAllFinishedTimerRef.current) {
clearTimeout(loadAllFinishedTimerRef.current);
loadAllFinishedTimerRef.current = null;
}
}, [newSessionTrigger, pendingViewSessionRef, resetStreamingState]);
/* ---------------------------------------------------------------- */
/* Derive chatMessages from the store */
/* ---------------------------------------------------------------- */
const activeSessionId = selectedSession?.id || currentSessionId || null;
const [pendingUserMessage, setPendingUserMessage] = useState<ChatMessage | null>(null);
const flushedPendingUserMessageRef = useRef<ChatMessage | null>(null);
// Tell the store which session we're viewing so it only re-renders for this one
const prevActiveForStoreRef = useRef<string | null>(null);
@@ -223,29 +148,17 @@ export function useChatSessionState({
sessionStore.setActiveSession(activeSessionId);
}
useEffect(() => {
if (!pendingUserMessage) {
flushedPendingUserMessageRef.current = null;
return;
}
if (!activeSessionId) {
return;
}
if (flushedPendingUserMessageRef.current === pendingUserMessage) {
return;
}
// When a real session ID arrives and we have a pending user message, flush it to the store
const prevActiveSessionRef = useRef<string | null>(null);
if (activeSessionId && activeSessionId !== prevActiveSessionRef.current && pendingUserMessage) {
const prov = (localStorage.getItem('selected-provider') as LLMProvider) || 'claude';
const normalized = chatMessageToNormalized(pendingUserMessage, activeSessionId, prov);
if (normalized) {
sessionStore.appendRealtime(activeSessionId, normalized);
}
flushedPendingUserMessageRef.current = pendingUserMessage;
setPendingUserMessage(null);
}, [activeSessionId, pendingUserMessage, sessionStore]);
}
prevActiveSessionRef.current = activeSessionId;
const storeMessages = activeSessionId ? sessionStore.getMessages(activeSessionId) : [];
@@ -319,6 +232,7 @@ export function useChatSessionState({
if (!hasMoreMessages || !selectedSession || !selectedProject) return false;
const sessionProvider = selectedSession.__provider || 'claude';
if (sessionProvider === 'cursor') return false;
isLoadingMoreRef.current = true;
const previousScrollHeight = container.scrollHeight;
@@ -551,6 +465,7 @@ export function useChatSessionState({
const scrollToTarget = async () => {
if (!allMessagesLoadedRef.current && selectedSession && selectedProject) {
const sessionProvider = selectedSession.__provider || 'claude';
if (sessionProvider !== 'cursor') {
try {
// Load all messages into the store for search navigation
const slot = await sessionStore.fetchFromServer(selectedSession.id, {
@@ -572,6 +487,7 @@ export function useChatSessionState({
} catch {
// Fall through and scroll in current messages
}
}
}
setVisibleMessageCount(Infinity);
@@ -626,7 +542,7 @@ export function useChatSessionState({
// Token usage fetch for Claude
useEffect(() => {
if (!selectedProject || !selectedSession?.id) {
if (!selectedProject || !selectedSession?.id || selectedSession.id.startsWith('new-session-')) {
setTokenBudget(null);
return;
}
@@ -719,6 +635,15 @@ export function useChatSessionState({
if (!selectedSession || !selectedProject) return;
if (isLoadingAllMessages) return;
const sessionProvider = selectedSession.__provider || 'claude';
if (sessionProvider === 'cursor') {
setVisibleMessageCount(Infinity);
setAllMessagesLoaded(true);
allMessagesLoadedRef.current = true;
setLoadAllJustFinished(true);
if (loadAllFinishedTimerRef.current) clearTimeout(loadAllFinishedTimerRef.current);
loadAllFinishedTimerRef.current = setTimeout(() => { setLoadAllJustFinished(false); setShowLoadAllOverlay(false); }, 1000);
return;
}
const requestSessionId = selectedSession.id;
allMessagesLoadedRef.current = true;

View File

@@ -2,7 +2,7 @@ import type { Project, ProjectSession, LLMProvider } from '../../../types/app';
export type Provider = LLMProvider;
export type PermissionMode = 'default' | 'acceptEdits' | 'auto' | 'bypassPermissions' | 'plan';
export type PermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan';
export interface ChatImage {
data: string;
@@ -28,7 +28,6 @@ export interface SubagentChildTool {
export interface ChatMessage {
type: string;
content?: string;
displayText?: string;
timestamp: string | number | Date;
images?: ChatImage[];
reasoning?: string;
@@ -41,12 +40,6 @@ export interface ChatMessage {
toolResult?: ToolResult | null;
toolId?: string;
toolCallId?: string;
commandName?: string;
commandMessage?: string;
commandArgs?: string;
isLocalCommand?: boolean;
isLocalCommandStdout?: boolean;
isCompactSummary?: boolean;
isSubagentContainer?: boolean;
subagentState?: {
childTools: SubagentChildTool[];
@@ -98,10 +91,6 @@ export interface Question {
multiSelect?: boolean;
}
export type SessionNavigationOptions = {
replace?: boolean;
};
export interface ChatInterfaceProps {
selectedProject: Project | null;
selectedSession: ProjectSession | null;
@@ -115,7 +104,8 @@ export interface ChatInterfaceProps {
onSessionProcessing?: (sessionId?: string | null) => void;
onSessionNotProcessing?: (sessionId?: string | null) => void;
processingSessions?: Set<string>;
onNavigateToSession?: (targetSessionId: string, options?: SessionNavigationOptions) => void;
onReplaceTemporarySession?: (sessionId?: string | null) => void;
onNavigateToSession?: (targetSessionId: string) => void;
onShowSettings?: () => void;
autoExpandTools?: boolean;
showRawParameters?: boolean;
@@ -123,7 +113,6 @@ export interface ChatInterfaceProps {
autoScrollToBottom?: boolean;
sendByCtrlEnter?: boolean;
externalMessageUpdate?: number;
newSessionTrigger?: number;
onTaskClick?: (...args: unknown[]) => void;
onShowAllTasks?: (() => void) | null;
}

View File

@@ -34,6 +34,7 @@ function ChatInterface({
onSessionProcessing,
onSessionNotProcessing,
processingSessions,
onReplaceTemporarySession,
onNavigateToSession,
onShowSettings,
autoExpandTools,
@@ -42,13 +43,13 @@ function ChatInterface({
autoScrollToBottom,
sendByCtrlEnter,
externalMessageUpdate,
newSessionTrigger,
onShowAllTasks,
}: ChatInterfaceProps) {
const { tasksEnabled, isTaskMasterInstalled } = useTasksSettings();
const { t } = useTranslation('chat');
const sessionStore = useSessionStore();
const streamBufferRef = useRef('');
const streamTimerRef = useRef<number | null>(null);
const accumulatedStreamRef = useRef('');
const pendingViewSessionRef = useRef<PendingViewSession | null>(null);
@@ -58,6 +59,7 @@ function ChatInterface({
clearTimeout(streamTimerRef.current);
streamTimerRef.current = null;
}
streamBufferRef.current = '';
accumulatedStreamRef.current = '';
}, []);
@@ -121,7 +123,6 @@ function ChatInterface({
sendMessage,
autoScrollToBottom,
externalMessageUpdate,
newSessionTrigger,
processingSessions,
resetStreamingState,
pendingViewSessionRef,
@@ -222,6 +223,7 @@ function ChatInterface({
useChatRealtimeHandlers({
latestMessage,
provider,
selectedProject,
selectedSession,
currentSessionId,
setCurrentSessionId,
@@ -231,11 +233,13 @@ function ChatInterface({
setTokenBudget,
setPendingPermissionRequests,
pendingViewSessionRef,
streamBufferRef,
streamTimerRef,
accumulatedStreamRef,
onSessionInactive,
onSessionProcessing,
onSessionNotProcessing,
onReplaceTemporarySession,
onNavigateToSession,
onWebSocketReconnect: handleWebSocketReconnect,
sessionStore,

View File

@@ -325,11 +325,9 @@ export default function ChatComposer({
? 'border-border/60 bg-muted/50 text-muted-foreground hover:bg-muted'
: permissionMode === 'acceptEdits'
? 'border-green-300/60 bg-green-50 text-green-700 hover:bg-green-100 dark:border-green-600/40 dark:bg-green-900/15 dark:text-green-300 dark:hover:bg-green-900/25'
: permissionMode === 'auto'
? 'border-blue-300/60 bg-blue-50 text-blue-700 hover:bg-blue-100 dark:border-blue-600/40 dark:bg-blue-900/15 dark:text-blue-300 dark:hover:bg-blue-900/25'
: permissionMode === 'bypassPermissions'
? 'border-orange-300/60 bg-orange-50 text-orange-700 hover:bg-orange-100 dark:border-orange-600/40 dark:bg-orange-900/15 dark:text-orange-300 dark:hover:bg-orange-900/25'
: 'border-primary/20 bg-primary/5 text-primary hover:bg-primary/10'
: permissionMode === 'bypassPermissions'
? 'border-orange-300/60 bg-orange-50 text-orange-700 hover:bg-orange-100 dark:border-orange-600/40 dark:bg-orange-900/15 dark:text-orange-300 dark:hover:bg-orange-900/25'
: 'border-primary/20 bg-primary/5 text-primary hover:bg-primary/10'
}`}
title={t('input.clickToChangeMode')}
>
@@ -340,17 +338,14 @@ export default function ChatComposer({
? 'bg-muted-foreground'
: permissionMode === 'acceptEdits'
? 'bg-green-500'
: permissionMode === 'auto'
? 'bg-blue-500'
: permissionMode === 'bypassPermissions'
? 'bg-orange-500'
: 'bg-primary'
: permissionMode === 'bypassPermissions'
? 'bg-orange-500'
: 'bg-primary'
}`}
/>
<span className="hidden whitespace-nowrap sm:inline">
{permissionMode === 'default' && t('codex.modes.default')}
{permissionMode === 'acceptEdits' && t('codex.modes.acceptEdits')}
{permissionMode === 'auto' && t('codex.modes.auto')}
{permissionMode === 'bypassPermissions' && t('codex.modes.bypassPermissions')}
{permissionMode === 'plan' && t('codex.modes.plan')}
</span>

View File

@@ -213,6 +213,13 @@ export default function ChatMessagesPane({
</div>
)}
{/* Performance warning when all messages are loaded */}
{allMessagesLoaded && (
<div className="border-b border-amber-200 bg-amber-50 py-1.5 text-center text-xs text-amber-600 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-400">
{t('session.messages.perfWarning')}
</div>
)}
{/* Legacy message count indicator (for non-paginated view) */}
{!hasMoreMessages && chatMessages.length > visibleMessageCount && (
<div className="border-b border-gray-200 py-2 text-center text-sm text-gray-500 dark:border-gray-700 dark:text-gray-400">

View File

@@ -1,6 +1,6 @@
import React, { useCallback, useEffect, useMemo, useState } from "react";
import { Check, ChevronDown } from "lucide-react";
import { Trans, useTranslation } from "react-i18next";
import { useTranslation } from "react-i18next";
import { useServerPlatform } from "../../../../hooks/useServerPlatform";
import SessionProviderLogo from "../../../llm-logo-provider/SessionProviderLogo";
@@ -9,7 +9,6 @@ import {
CURSOR_MODELS,
CODEX_MODELS,
GEMINI_MODELS,
PROVIDERS,
} from "../../../../../shared/modelConstants";
import type { ProjectSession, LLMProvider } from "../../../../types/app";
import { NextTaskBanner } from "../../../task-master";
@@ -27,9 +26,6 @@ import {
Card,
} from "../../../../shared/view/ui";
const MOD_KEY =
typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform) ? "⌘" : "Ctrl";
type ProviderSelectionEmptyStateProps = {
selectedSession: ProjectSession | null;
currentSessionId: string | null;
@@ -56,11 +52,12 @@ type ProviderGroup = {
models: { value: string; label: string }[];
};
const PROVIDER_GROUPS: ProviderGroup[] = PROVIDERS.map((p) => ({
id: p.id as LLMProvider,
name: p.name,
models: p.models.OPTIONS,
}));
const PROVIDER_GROUPS: ProviderGroup[] = [
{ id: "claude", name: "Anthropic", models: CLAUDE_MODELS.OPTIONS },
{ id: "cursor", name: "Cursor", models: CURSOR_MODELS.OPTIONS },
{ id: "codex", name: "OpenAI", models: CODEX_MODELS.OPTIONS },
{ id: "gemini", name: "Google", models: GEMINI_MODELS.OPTIONS },
];
function getModelConfig(p: LLMProvider) {
if (p === "claude") return CLAUDE_MODELS;
@@ -234,14 +231,9 @@ export default function ProviderSelectionEmptyState({
defaultValue: "No models found.",
})}
</CommandEmpty>
{visibleProviderGroups.map((group, idx) => (
{visibleProviderGroups.map((group) => (
<CommandGroup
key={group.id}
className={
idx > 0
? "border-t border-border/40 [&_[cmdk-group-heading]]:mt-1 [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wider"
: "[&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wider"
}
heading={
<span className="flex items-center gap-1.5">
<SessionProviderLogo provider={group.id} className="h-3.5 w-3.5 shrink-0" />
@@ -256,7 +248,6 @@ export default function ProviderSelectionEmptyState({
key={`${group.id}-${model.value}`}
value={`${group.name} ${model.label}`}
onSelect={() => handleModelSelect(group.id, model.value)}
className="ml-4 border-l border-border/40 pl-4"
>
<span className="flex-1 truncate">{model.label}</span>
{isSelected && (
@@ -291,18 +282,6 @@ export default function ProviderSelectionEmptyState({
}
</p>
<p className="mt-3 flex items-center justify-center gap-1.5 text-center text-xs text-muted-foreground/60">
<Trans
i18nKey="providerSelection.pressToSearch"
values={{ shortcut: MOD_KEY === "⌘" ? "⌘K" : "Ctrl+K" }}
components={{
kbd: (
<kbd className="inline-flex items-center gap-0.5 rounded border border-border/60 bg-muted/40 px-1.5 py-0.5 font-mono text-[10px]" />
),
}}
/>
</p>
{provider && tasksEnabled && isTaskMasterInstalled && (
<div className="mt-5">
<NextTaskBanner

View File

@@ -3,7 +3,6 @@ import { unifiedMergeView } from '@codemirror/merge';
import type { Extension } from '@codemirror/state';
import { useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { usePaletteOps } from '../../../contexts/PaletteOpsContext';
import { useCodeEditorDocument } from '../hooks/useCodeEditorDocument';
import { useCodeEditorSettings } from '../hooks/useCodeEditorSettings';
import { useEditorKeyboardShortcuts } from '../hooks/useEditorKeyboardShortcuts';
@@ -37,7 +36,6 @@ export default function CodeEditor({
onPopOut = null,
}: CodeEditorProps) {
const { t } = useTranslation('codeEditor');
const paletteOps = usePaletteOps();
const [isFullscreen, setIsFullscreen] = useState(false);
const [showDiff, setShowDiff] = useState(Boolean(file.diffInfo));
const [markdownPreview, setMarkdownPreview] = useState(false);
@@ -201,7 +199,7 @@ export default function CodeEditor({
saving={saving}
saveSuccess={saveSuccess}
onToggleMarkdownPreview={() => setMarkdownPreview((previous) => !previous)}
onOpenSettings={() => paletteOps.openSettings('appearance')}
onOpenSettings={() => window.openSettings?.('appearance')}
onDownload={handleDownload}
onSave={handleSave}
onToggleFullscreen={() => setIsFullscreen((previous) => !previous)}

View File

@@ -1,373 +0,0 @@
import * as React from 'react';
import { useNavigate } from 'react-router-dom';
import {
ArrowDownToLine,
ArrowUpFromLine,
ChevronRight,
FileText,
GitCommit,
GitMerge,
MessageSquare,
MessageSquarePlus,
RefreshCw,
Settings,
SunMoon,
X,
} from 'lucide-react';
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
Dialog,
DialogContent,
DialogTitle,
} from '../../shared/view/ui';
import { useTheme } from '../../contexts/ThemeContext';
import { usePaletteOps } from '../../contexts/PaletteOpsContext';
import { SETTINGS_MAIN_TABS } from '../settings/constants/constants';
import type { AppTab, Project } from '../../types/app';
import { useSessionsSource } from './sources/useSessionsSource';
import { useFilesSource } from './sources/useFilesSource';
import { useCommitsSource } from './sources/useCommitsSource';
import { useSessionMessageSearch } from './sources/useSessionMessageSearch';
import { useBranchesSource } from './sources/useBranchesSource';
import { useGitActions } from './sources/useGitActions';
type Page = 'actions' | 'files' | 'sessions' | 'commits' | 'branches';
const PAGE_LABELS: Record<Page, string> = {
actions: 'Actions',
files: 'Files',
sessions: 'Sessions',
commits: 'Commits',
branches: 'Branches',
};
type CommandPaletteProps = {
selectedProject: Project | null;
onStartNewChat: (project: Project) => void;
onOpenSettings: (tab?: string) => void;
onShowTab?: (tab: AppTab) => void;
};
const NAV_TABS: Array<{ id: AppTab; label: string; keywords: string }> = [
{ id: 'chat', label: 'Go to Chat', keywords: 'chat messages conversation' },
{ id: 'files', label: 'Go to Files', keywords: 'files file tree explorer' },
{ id: 'shell', label: 'Go to Shell', keywords: 'shell terminal console' },
{ id: 'git', label: 'Go to Git', keywords: 'git diff branches' },
{ id: 'tasks', label: 'Go to Tasks', keywords: 'tasks taskmaster' },
];
export default function CommandPalette({
selectedProject,
onStartNewChat,
onOpenSettings,
onShowTab,
}: CommandPaletteProps) {
const [open, setOpen] = React.useState(false);
const [search, setSearch] = React.useState('');
const [pages, setPages] = React.useState<Page[]>([]);
const { toggleDarkMode } = useTheme();
const navigate = useNavigate();
const ops = usePaletteOps();
const page = pages.at(-1);
React.useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
const isCmdK = (e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey && e.key.toLowerCase() === 'k';
if (!isCmdK) return;
e.preventDefault();
setOpen((prev) => !prev);
};
document.addEventListener('keydown', handleKeyDown);
return () => document.removeEventListener('keydown', handleKeyDown);
}, []);
React.useEffect(() => {
if (!open) {
setSearch('');
setPages([]);
}
}, [open]);
const projectId = selectedProject?.projectId;
const showActions = !page || page === 'actions';
const showSessions = !page || page === 'sessions';
const showFiles = !page || page === 'files';
const showCommits = !page || page === 'commits';
const showBranches = !page || page === 'branches' || page === 'actions';
const sessions = useSessionsSource(projectId, open && showSessions);
const messageMatches = useSessionMessageSearch(projectId, search, open && showSessions);
const files = useFilesSource(projectId, open && showFiles);
const commits = useCommitsSource(projectId, open && showCommits);
const branches = useBranchesSource(projectId, open && showBranches);
const git = useGitActions(projectId);
const sessionRows = React.useMemo(() => {
if (!showSessions) return [];
type Row = { id: string; label: string; provider?: string; snippet?: string };
const byId = new Map<string, Row>();
for (const s of sessions) {
byId.set(s.id, { id: s.id, label: s.label, provider: s.provider });
}
for (const m of messageMatches) {
const existing = byId.get(m.sessionId);
if (existing) {
existing.snippet = m.snippet;
} else {
byId.set(m.sessionId, {
id: m.sessionId,
label: m.label,
provider: m.provider,
snippet: m.snippet,
});
}
}
return Array.from(byId.values());
}, [sessions, messageMatches, showSessions]);
const run = React.useCallback((fn: () => void) => {
setOpen(false);
fn();
}, []);
const pushPage = React.useCallback((next: Page) => {
setSearch('');
setPages((prev) => [...prev, next]);
}, []);
const popPage = React.useCallback(() => {
setSearch('');
setPages((prev) => prev.slice(0, -1));
}, []);
const handleKeyDown = React.useCallback((e: React.KeyboardEvent) => {
if (e.key === 'Backspace' && !search && pages.length > 0) {
e.preventDefault();
popPage();
}
}, [search, pages.length, popPage]);
const startNewChatDisabled = !selectedProject;
const browseLimit = 5;
const filesShown = page === 'files' ? files : files.slice(0, browseLimit);
const commitsShown = page === 'commits' ? commits : commits.slice(0, browseLimit);
const sessionsShown = page === 'sessions' ? sessionRows : sessionRows.slice(0, browseLimit);
const branchesShown = page === 'branches' ? branches : branches.slice(0, browseLimit);
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent className="max-w-xl overflow-hidden p-0">
<DialogTitle>Command palette</DialogTitle>
<Command label="Command palette" onKeyDown={handleKeyDown}>
{page && (
<div className="flex items-center gap-2 border-b px-3 py-2">
<span className="inline-flex items-center gap-1 rounded-md bg-accent px-2 py-0.5 text-xs font-medium text-accent-foreground">
{PAGE_LABELS[page]}
<button
type="button"
onClick={popPage}
aria-label="Back to all"
className="ml-0.5 rounded-sm opacity-70 hover:opacity-100"
>
<X className="h-3 w-3" />
</button>
</span>
<span className="text-xs text-muted-foreground">Backspace to go back</span>
</div>
)}
<CommandInput
placeholder={page ? `Search ${PAGE_LABELS[page].toLowerCase()}` : 'Type to search anything…'}
value={search}
onValueChange={setSearch}
/>
<CommandList>
<CommandEmpty>No results.</CommandEmpty>
{showActions && (
<CommandGroup heading="Actions">
<CommandItem
value="Start new chat"
disabled={startNewChatDisabled}
onSelect={() => {
if (!selectedProject) return;
run(() => onStartNewChat(selectedProject));
}}
>
<MessageSquarePlus className="h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<span className="flex-1">Start new chat</span>
{startNewChatDisabled && (
<span className="text-xs text-muted-foreground">Select a project first</span>
)}
</CommandItem>
<CommandItem value="Open settings" onSelect={() => run(() => onOpenSettings())}>
<Settings className="h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<span className="flex-1">Open settings</span>
</CommandItem>
<CommandItem value="Toggle theme dark light mode" onSelect={() => run(toggleDarkMode)}>
<SunMoon className="h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<span className="flex-1">Toggle theme</span>
</CommandItem>
</CommandGroup>
)}
{showActions && (
<CommandGroup heading="Navigate">
{NAV_TABS.map((tab) => (
<CommandItem
key={tab.id as string}
value={`${tab.label} ${tab.keywords}`}
onSelect={() => run(() => onShowTab?.(tab.id))}
>
<span className="flex-1">{tab.label}</span>
</CommandItem>
))}
</CommandGroup>
)}
{showActions && projectId && (
<CommandGroup heading="Git">
<CommandItem
value="Git Fetch remote"
onSelect={() => run(() => { void git.fetch(); onShowTab?.('git'); })}
>
<RefreshCw className="h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<span className="flex-1">Git: Fetch</span>
</CommandItem>
<CommandItem
value="Git Pull merge upstream"
onSelect={() => run(() => { void git.pull(); onShowTab?.('git'); })}
>
<ArrowDownToLine className="h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<span className="flex-1">Git: Pull</span>
</CommandItem>
<CommandItem
value="Git Push origin remote"
onSelect={() => run(() => { void git.push(); onShowTab?.('git'); })}
>
<ArrowUpFromLine className="h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<span className="flex-1">Git: Push</span>
</CommandItem>
</CommandGroup>
)}
{showActions && (
<CommandGroup heading="Settings">
{SETTINGS_MAIN_TABS.map(({ id, label, keywords, icon: Icon }) => (
<CommandItem
key={id}
value={`Settings ${label} ${keywords}`}
onSelect={() => run(() => onOpenSettings(id))}
>
<Icon className="h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<span className="flex-1">Settings: {label}</span>
</CommandItem>
))}
</CommandGroup>
)}
{showSessions && projectId && sessionsShown.length > 0 && (
<CommandGroup heading="Sessions">
{sessionsShown.map((s) => (
<CommandItem
key={s.id}
value={`${s.label} ${s.snippet ?? ''} ${s.id}`.trim()}
onSelect={() => run(() => navigate(`/session/${s.id}`))}
>
<MessageSquare className="h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<div className="flex min-w-0 flex-1 flex-col">
<span className="truncate">{s.label}</span>
{s.snippet && (
<span className="truncate text-xs text-muted-foreground">{s.snippet}</span>
)}
</div>
{s.provider && (
<span className="text-xs text-muted-foreground">{s.provider}</span>
)}
</CommandItem>
))}
{!page && sessionRows.length > browseLimit && (
<BrowseAllItem label={`Browse all sessions (${sessionRows.length})`} onSelect={() => pushPage('sessions')} />
)}
</CommandGroup>
)}
{showFiles && projectId && filesShown.length > 0 && (
<CommandGroup heading="Files">
{filesShown.map((f) => (
<CommandItem
key={f.path}
value={f.path}
onSelect={() => run(() => ops.openFile(f.path))}
>
<FileText className="h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<span className="flex-1 truncate">{f.name}</span>
<span className="truncate text-xs text-muted-foreground">{f.path}</span>
</CommandItem>
))}
{!page && files.length > browseLimit && (
<BrowseAllItem label={`Browse all files (${files.length})`} onSelect={() => pushPage('files')} />
)}
</CommandGroup>
)}
{showCommits && projectId && commitsShown.length > 0 && (
<CommandGroup heading="Commits">
{commitsShown.map((c) => (
<CommandItem
key={c.hash}
value={`${c.message} ${c.author} ${c.shortHash}`}
onSelect={() => run(() => onShowTab?.('git'))}
>
<GitCommit className="h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<span className="font-mono text-xs text-muted-foreground">{c.shortHash}</span>
<span className="flex-1 truncate">{c.message}</span>
<span className="truncate text-xs text-muted-foreground">{c.author}</span>
</CommandItem>
))}
{!page && commits.length > browseLimit && (
<BrowseAllItem label={`Browse all commits (${commits.length})`} onSelect={() => pushPage('commits')} />
)}
</CommandGroup>
)}
{showBranches && projectId && branchesShown.length > 0 && (
<CommandGroup heading="Branches">
{branchesShown.map((b) => (
<CommandItem
key={`branch-${b.name}`}
value={b.name}
onSelect={() => run(() => { void git.checkout(b.name); onShowTab?.('git'); })}
>
<GitMerge className="h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<span className="flex-1 truncate">Switch to: {b.name}</span>
</CommandItem>
))}
{!page && branches.length > browseLimit && (
<BrowseAllItem label={`Browse all branches (${branches.length})`} onSelect={() => pushPage('branches')} />
)}
</CommandGroup>
)}
</CommandList>
</Command>
</DialogContent>
</Dialog>
);
}
function BrowseAllItem({ label, onSelect }: { label: string; onSelect: () => void }) {
return (
<CommandItem value={label} onSelect={onSelect}>
<ChevronRight className="h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<span className="flex-1 text-muted-foreground">{label}</span>
</CommandItem>
);
}

View File

@@ -1,37 +0,0 @@
import { useEffect, useState, type DependencyList } from 'react';
export function useApiSource<T, R = unknown>(opts: {
enabled: boolean;
deps: DependencyList;
fetcher: (signal: AbortSignal) => Promise<Response>;
parse: (raw: R) => T[];
}): T[] {
const [items, setItems] = useState<T[]>([]);
const { enabled, deps, fetcher, parse } = opts;
useEffect(() => {
if (!enabled) {
setItems([]);
return;
}
const controller = new AbortController();
fetcher(controller.signal)
.then((r) => r.json() as Promise<R>)
.then((data) => {
if (controller.signal.aborted) return;
setItems(parse(data));
})
.catch((err: unknown) => {
if (controller.signal.aborted) return;
if (err instanceof DOMException && err.name === 'AbortError') return;
setItems([]);
});
return () => controller.abort();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [enabled, ...deps]);
return items;
}

View File

@@ -1,21 +0,0 @@
import { authenticatedFetch } from '../../../utils/api';
import { useApiSource } from './useApiSource';
export type BranchResult = { name: string };
interface BranchesResponse {
localBranches?: string[];
}
export function useBranchesSource(projectId: string | undefined, enabled: boolean) {
return useApiSource<BranchResult, BranchesResponse>({
enabled: enabled && !!projectId,
deps: [projectId],
fetcher: (signal) => {
const params = new URLSearchParams({ project: projectId! });
return authenticatedFetch(`/api/git/branches?${params.toString()}`, { signal });
},
parse: (data) => (data.localBranches ?? []).map((name) => ({ name })),
});
}

View File

@@ -1,35 +0,0 @@
import { authenticatedFetch } from '../../../utils/api';
import { useApiSource } from './useApiSource';
export type CommitResult = {
hash: string;
shortHash: string;
message: string;
author: string;
};
interface CommitsResponse {
commits?: Array<{ hash: string; message: string; author: string }>;
error?: string;
}
export function useCommitsSource(projectId: string | undefined, enabled: boolean) {
return useApiSource<CommitResult, CommitsResponse>({
enabled: enabled && !!projectId,
deps: [projectId],
fetcher: (signal) => {
const params = new URLSearchParams({ project: projectId!, limit: '50' });
return authenticatedFetch(`/api/git/commits?${params.toString()}`, { signal });
},
parse: (data) => {
if (!data.commits) return [];
return data.commits.map<CommitResult>((c) => ({
hash: c.hash,
shortHash: c.hash.slice(0, 7),
message: c.message,
author: c.author,
}));
},
});
}

View File

@@ -1,42 +0,0 @@
import { api } from '../../../utils/api';
import { useApiSource } from './useApiSource';
export type FileResult = {
path: string;
name: string;
};
interface FileNode {
type: 'file' | 'directory';
name: string;
path: string;
children?: FileNode[];
}
const MAX_FILES = 500;
function flatten(nodes: FileNode[], out: FileResult[]): void {
for (const node of nodes) {
if (out.length >= MAX_FILES) return;
if (node.type === 'file') {
out.push({ path: node.path, name: node.name });
} else if (node.children && node.children.length > 0) {
flatten(node.children, out);
}
}
}
export function useFilesSource(projectId: string | undefined, enabled: boolean) {
return useApiSource<FileResult, unknown>({
enabled: enabled && !!projectId,
deps: [projectId],
fetcher: (signal) => api.getFiles(projectId!, { signal }),
parse: (data) => {
const tree: FileNode[] = Array.isArray(data) ? (data as FileNode[]) : [];
const flat: FileResult[] = [];
flatten(tree, flat);
return flat;
},
});
}

View File

@@ -1,38 +0,0 @@
import { useCallback } from 'react';
import { authenticatedFetch } from '../../../utils/api';
async function postGit(path: string, body: Record<string, unknown>) {
const res = await authenticatedFetch(path, {
method: 'POST',
body: JSON.stringify(body),
});
return res.json();
}
export function useGitActions(projectId: string | undefined) {
const fetch = useCallback(() => {
if (!projectId) return Promise.resolve();
return postGit('/api/git/fetch', { project: projectId });
}, [projectId]);
const pull = useCallback(() => {
if (!projectId) return Promise.resolve();
return postGit('/api/git/pull', { project: projectId });
}, [projectId]);
const push = useCallback(() => {
if (!projectId) return Promise.resolve();
return postGit('/api/git/push', { project: projectId });
}, [projectId]);
const checkout = useCallback(
(branch: string) => {
if (!projectId) return Promise.resolve();
return postGit('/api/git/checkout', { project: projectId, branch });
},
[projectId],
);
return { fetch, pull, push, checkout };
}

View File

@@ -1,101 +0,0 @@
import { useEffect, useRef, useState } from 'react';
import { api } from '../../../utils/api';
import type { LLMProvider } from '../../../types/app';
export type SessionMessageMatch = {
sessionId: string;
label: string;
snippet: string;
provider: LLMProvider;
};
type ProjectResult = {
projectId: string | null;
projectName: string;
sessions: Array<{
sessionId: string;
provider: LLMProvider;
sessionSummary: string;
matches: Array<{ snippet: string }>;
}>;
};
const MIN_QUERY = 2;
const DEBOUNCE_MS = 250;
export function useSessionMessageSearch(
projectId: string | undefined,
query: string,
enabled: boolean,
) {
const [items, setItems] = useState<SessionMessageMatch[]>([]);
const seqRef = useRef(0);
const esRef = useRef<EventSource | null>(null);
useEffect(() => {
const trimmed = query.trim();
if (!enabled || !projectId || trimmed.length < MIN_QUERY) {
setItems([]);
esRef.current?.close();
esRef.current = null;
return;
}
esRef.current?.close();
esRef.current = null;
seqRef.current++;
const handle = setTimeout(() => {
const seq = ++seqRef.current;
const url = api.searchConversationsUrl(trimmed);
const es = new EventSource(url);
esRef.current = es;
const accumulated: SessionMessageMatch[] = [];
es.addEventListener('result', (evt) => {
if (seq !== seqRef.current) {
es.close();
return;
}
try {
const data = JSON.parse((evt as MessageEvent).data) as { projectResult: ProjectResult };
const pr = data.projectResult;
if (pr.projectId !== projectId) return;
for (const s of pr.sessions) {
accumulated.push({
sessionId: s.sessionId,
label: s.sessionSummary || s.sessionId,
snippet: s.matches[0]?.snippet ?? '',
provider: s.provider,
});
}
setItems([...accumulated]);
} catch {
// ignore malformed
}
});
const finish = () => {
if (seq !== seqRef.current) return;
es.close();
esRef.current = null;
};
es.addEventListener('done', finish);
es.addEventListener('error', finish);
}, DEBOUNCE_MS);
return () => {
clearTimeout(handle);
};
}, [projectId, query, enabled]);
useEffect(() => {
return () => {
esRef.current?.close();
esRef.current = null;
};
}, []);
return items;
}

View File

@@ -1,44 +0,0 @@
import { authenticatedFetch } from '../../../utils/api';
import type { LLMProvider, ProjectSession } from '../../../types/app';
import { useApiSource } from './useApiSource';
export type SessionResult = {
id: string;
label: string;
provider?: LLMProvider;
};
interface SessionsResponse {
sessions?: ProjectSession[];
cursorSessions?: ProjectSession[];
codexSessions?: ProjectSession[];
geminiSessions?: ProjectSession[];
}
export function useSessionsSource(projectId: string | undefined, enabled: boolean) {
return useApiSource<SessionResult, SessionsResponse>({
enabled: enabled && !!projectId,
deps: [projectId],
fetcher: (signal) => {
const params = new URLSearchParams({ limit: '50', offset: '0' });
return authenticatedFetch(
`/api/projects/${encodeURIComponent(projectId!)}/sessions?${params.toString()}`,
{ signal },
);
},
parse: (data) => {
const all: ProjectSession[] = [
...(data.sessions ?? []),
...(data.cursorSessions ?? []),
...(data.codexSessions ?? []),
...(data.geminiSessions ?? []),
];
return all.map<SessionResult>((s) => ({
id: s.id,
label: (s.title || s.summary || s.name || s.id) as string,
provider: s.__provider,
}));
},
});
}

View File

@@ -1,7 +1,5 @@
import type { Dispatch, SetStateAction } from 'react';
import type { AppTab, Project, ProjectSession } from '../../../types/app';
import type { SessionNavigationOptions } from '../../chat/types/types';
export type SessionLifecycleHandler = (sessionId?: string | null) => void;
@@ -51,10 +49,10 @@ export type MainContentProps = {
onSessionProcessing: SessionLifecycleHandler;
onSessionNotProcessing: SessionLifecycleHandler;
processingSessions: Set<string>;
onNavigateToSession: (targetSessionId: string, options?: SessionNavigationOptions) => void;
onReplaceTemporarySession: SessionLifecycleHandler;
onNavigateToSession: (targetSessionId: string) => void;
onShowSettings: () => void;
externalMessageUpdate: number;
newSessionTrigger: number;
};
export type MainContentHeaderProps = {

View File

@@ -1,5 +1,4 @@
import React, { useEffect } from 'react';
import ChatInterface from '../../chat/view/ChatInterface';
import FileTree from '../../file-tree/view/FileTree';
import StandaloneShell from '../../standalone-shell/view/StandaloneShell';
@@ -7,14 +6,12 @@ import GitPanel from '../../git-panel/view/GitPanel';
import PluginTabContent from '../../plugins/view/PluginTabContent';
import type { MainContentProps } from '../types/types';
import { useTaskMaster } from '../../../contexts/TaskMasterContext';
import { usePaletteOpsRegister } from '../../../contexts/PaletteOpsContext';
import { useTasksSettings } from '../../../contexts/TasksSettingsContext';
import { useUiPreferences } from '../../../hooks/useUiPreferences';
import { useEditorSidebar } from '../../code-editor/hooks/useEditorSidebar';
import EditorSidebar from '../../code-editor/view/EditorSidebar';
import type { Project } from '../../../types/app';
import { TaskMasterPanel } from '../../task-master';
import MainContentHeader from './subcomponents/MainContentHeader';
import MainContentStateView from './subcomponents/MainContentStateView';
import ErrorBoundary from './ErrorBoundary';
@@ -47,10 +44,10 @@ function MainContent({
onSessionProcessing,
onSessionNotProcessing,
processingSessions,
onReplaceTemporarySession,
onNavigateToSession,
onShowSettings,
externalMessageUpdate,
newSessionTrigger,
}: MainContentProps) {
const { preferences } = useUiPreferences();
const { autoExpandTools, showRawParameters, showThinking, autoScrollToBottom, sendByCtrlEnter } = preferences;
@@ -92,13 +89,6 @@ function MainContent({
}
}, [shouldShowTasksTab, activeTab, setActiveTab]);
usePaletteOpsRegister({
openFile: (filePath: string) => {
setActiveTab('files');
handleFileOpen(filePath);
},
});
if (isLoading) {
return <MainContentStateView mode="loading" isMobile={isMobile} onMenuClick={onMenuClick} />;
}
@@ -136,6 +126,7 @@ function MainContent({
onSessionProcessing={onSessionProcessing}
onSessionNotProcessing={onSessionNotProcessing}
processingSessions={processingSessions}
onReplaceTemporarySession={onReplaceTemporarySession}
onNavigateToSession={onNavigateToSession}
onShowSettings={onShowSettings}
autoExpandTools={autoExpandTools}
@@ -144,7 +135,6 @@ function MainContent({
autoScrollToBottom={autoScrollToBottom}
sendByCtrlEnter={sendByCtrlEnter}
externalMessageUpdate={externalMessageUpdate}
newSessionTrigger={newSessionTrigger}
onShowAllTasks={tasksEnabled ? () => setActiveTab('tasks') : null}
/>
</ErrorBoundary>

View File

@@ -1,15 +1,3 @@
import type { ComponentType } from 'react';
import {
Bell,
Bot,
GitBranch,
Info,
KeyRound,
ListChecks,
Palette,
Plug,
} from 'lucide-react';
import type {
AgentCategory,
AgentProvider,
@@ -19,22 +7,13 @@ import type {
SettingsMainTab,
} from '../types/types';
export type SettingsMainTabMeta = {
id: SettingsMainTab;
label: string;
keywords: string;
icon: ComponentType<{ className?: string }>;
};
export const SETTINGS_MAIN_TABS: SettingsMainTabMeta[] = [
{ id: 'agents', label: 'Agents', keywords: 'agents subagents claude code', icon: Bot },
{ id: 'appearance', label: 'Appearance', keywords: 'appearance theme dark light language', icon: Palette },
{ id: 'git', label: 'Git', keywords: 'git github commits', icon: GitBranch },
{ id: 'api', label: 'API Tokens', keywords: 'api tokens auth keys', icon: KeyRound },
{ id: 'tasks', label: 'Tasks', keywords: 'tasks taskmaster', icon: ListChecks },
{ id: 'notifications', label: 'Notifications', keywords: 'notifications alerts push', icon: Bell },
{ id: 'plugins', label: 'Plugins', keywords: 'plugins extensions integrations', icon: Plug },
{ id: 'about', label: 'About', keywords: 'about version info', icon: Info },
export const SETTINGS_MAIN_TABS: SettingsMainTab[] = [
'agents',
'appearance',
'git',
'api',
'tasks',
'notifications',
];
export const AGENT_PROVIDERS: AgentProvider[] = ['claude', 'cursor', 'codex', 'gemini'];
@@ -55,3 +34,4 @@ export const DEFAULT_CURSOR_PERMISSIONS: CursorPermissionsState = {
disallowedCommands: [],
skipPermissions: false,
};

View File

@@ -2,14 +2,10 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import type { TFunction } from 'i18next';
import { api } from '../../../utils/api';
import { usePaletteOps } from '../../../contexts/PaletteOpsContext';
import type { Project, ProjectSession, LLMProvider } from '../../../types/app';
import type {
ArchivedProjectListItem,
ArchivedSessionListItem,
DeleteProjectConfirmation,
ProjectSortOrder,
SidebarSearchMode,
SessionDeleteConfirmation,
SessionWithProvider,
} from '../types/types';
@@ -63,20 +59,6 @@ export type SearchProgress = {
totalProjects: number;
};
type ArchivedSessionsApiPayload = {
success?: boolean;
data?: {
sessions?: ArchivedSessionListItem[];
};
};
type ArchivedProjectsApiPayload = {
success?: boolean;
data?: {
projects?: ArchivedProjectListItem[];
};
};
type UseSidebarControllerArgs = {
projects: Project[];
selectedProject: Project | null;
@@ -113,7 +95,6 @@ export function useSidebarController({
setSidebarVisible,
sidebarVisible,
}: UseSidebarControllerArgs) {
const paletteOps = usePaletteOps();
const [expandedProjects, setExpandedProjects] = useState<Set<string>>(new Set());
const [editingProject, setEditingProject] = useState<string | null>(null);
const [showNewProject, setShowNewProject] = useState(false);
@@ -129,13 +110,10 @@ export function useSidebarController({
const [deleteConfirmation, setDeleteConfirmation] = useState<DeleteProjectConfirmation | null>(null);
const [sessionDeleteConfirmation, setSessionDeleteConfirmation] = useState<SessionDeleteConfirmation | null>(null);
const [showVersionModal, setShowVersionModal] = useState(false);
const [searchMode, setSearchMode] = useState<SidebarSearchMode>('projects');
const [searchMode, setSearchMode] = useState<'projects' | 'conversations'>('projects');
const [conversationResults, setConversationResults] = useState<ConversationSearchResults | null>(null);
const [isSearching, setIsSearching] = useState(false);
const [searchProgress, setSearchProgress] = useState<SearchProgress | null>(null);
const [archivedProjects, setArchivedProjects] = useState<ArchivedProjectListItem[]>([]);
const [archivedSessions, setArchivedSessions] = useState<ArchivedSessionListItem[]>([]);
const [isArchivedSessionsLoading, setIsArchivedSessionsLoading] = useState(false);
const [debouncedSearchQuery, setDebouncedSearchQuery] = useState('');
const [optimisticStarByProjectId, setOptimisticStarByProjectId] = useState<Map<string, boolean>>(new Map());
const [loadingMoreProjects, setLoadingMoreProjects] = useState<Set<string>>(new Set());
@@ -221,40 +199,6 @@ export function useSidebarController({
onRefreshRef.current = onRefresh;
}, [onRefresh]);
const fetchArchivedSessions = useCallback(async () => {
setIsArchivedSessionsLoading(true);
try {
const [archivedProjectsResponse, archivedSessionsResponse] = await Promise.all([
api.archivedProjects(),
api.getArchivedSessions(),
]);
if (!archivedProjectsResponse.ok) {
throw new Error(`Failed to load archived projects: ${archivedProjectsResponse.status}`);
}
if (!archivedSessionsResponse.ok) {
throw new Error(`Failed to load archived sessions: ${archivedSessionsResponse.status}`);
}
const archivedProjectsPayload = (await archivedProjectsResponse.json()) as ArchivedProjectsApiPayload;
const archivedSessionsPayload = (await archivedSessionsResponse.json()) as ArchivedSessionsApiPayload;
const nextProjects = Array.isArray(archivedProjectsPayload.data?.projects) ? archivedProjectsPayload.data.projects : [];
const archivedProjectIds = new Set(nextProjects.map((project) => project.projectId));
const nextStandaloneSessions = Array.isArray(archivedSessionsPayload.data?.sessions)
? archivedSessionsPayload.data.sessions.filter((session) => !session.projectId || !archivedProjectIds.has(session.projectId))
: [];
setArchivedProjects(nextProjects);
setArchivedSessions(nextStandaloneSessions);
} catch (error) {
console.error('[Sidebar] Failed to load archived sessions:', error);
} finally {
setIsArchivedSessionsLoading(false);
}
}, []);
useEffect(() => {
if (migrationStartedRef.current) {
return;
@@ -281,20 +225,6 @@ export function useSidebarController({
void migrateLegacyStars();
}, [onRefresh]);
useEffect(() => {
void fetchArchivedSessions();
}, [fetchArchivedSessions]);
useEffect(() => {
if (searchMode !== 'archived') {
return;
}
// Refresh archive contents when the archived tab opens so restore actions
// and background synchronizer updates are reflected without a full reload.
void fetchArchivedSessions();
}, [fetchArchivedSessions, searchMode]);
useEffect(() => {
setOptimisticStarByProjectId((previous) => {
if (previous.size === 0) {
@@ -587,56 +517,6 @@ export function useSidebarController({
[debouncedSearchQuery, sortedProjects],
);
const filteredArchivedSessions = useMemo(() => {
const normalizedSearch = debouncedSearchQuery.trim().toLowerCase();
if (!normalizedSearch) {
return archivedSessions;
}
return archivedSessions.filter((session) => {
const searchableFields = [
session.sessionTitle,
session.projectDisplayName,
session.projectPath ?? '',
session.provider,
];
return searchableFields.some((value) => value.toLowerCase().includes(normalizedSearch));
});
}, [archivedSessions, debouncedSearchQuery]);
const filteredArchivedProjects = useMemo(() => {
const normalizedSearch = debouncedSearchQuery.trim().toLowerCase();
if (!normalizedSearch) {
return archivedProjects;
}
return archivedProjects.filter((project) => {
const projectMatches = [
project.displayName,
project.fullPath || '',
].some((value) => value.toLowerCase().includes(normalizedSearch));
if (projectMatches) {
return true;
}
return getAllSessions(project).some((session) => {
const sessionSummary =
typeof session.summary === 'string' && session.summary.trim().length > 0
? session.summary
: typeof session.name === 'string'
? session.name
: '';
return [
sessionSummary,
session.__provider,
].some((value) => value.toLowerCase().includes(normalizedSearch));
});
});
}, [archivedProjects, debouncedSearchQuery]);
const startEditing = useCallback((project: Project) => {
// `editingProject` is keyed by projectId so it stays stable across
// display-name mutations that happen while the input is open.
@@ -656,7 +536,11 @@ export function useSidebarController({
try {
const response = await api.renameProject(projectId, editingName);
if (response.ok) {
await paletteOps.refreshProjects();
if (window.refreshProjects) {
await window.refreshProjects();
} else {
window.location.reload();
}
} else {
console.error('Failed to rename project');
}
@@ -667,33 +551,24 @@ export function useSidebarController({
setEditingName('');
}
},
[editingName, paletteOps],
[editingName],
);
const showDeleteSessionConfirmation = useCallback(
// Kept with project/provider arguments for component wiring compatibility;
// deletion now uses only `sessionId` via /api/providers/sessions/:sessionId.
(
projectId: string | null,
projectId: string,
sessionId: string,
sessionTitle: string,
provider: SessionDeleteConfirmation['provider'] = 'claude',
options: {
isArchived?: boolean;
} = {},
) => {
setSessionDeleteConfirmation({
projectId,
sessionId,
sessionTitle,
provider,
isArchived: Boolean(options.isArchived),
});
setSessionDeleteConfirmation({ projectId, sessionId, sessionTitle, provider });
},
[],
);
const confirmDeleteSession = useCallback(async (hardDelete = false) => {
const confirmDeleteSession = useCallback(async () => {
if (!sessionDeleteConfirmation) {
return;
}
@@ -702,11 +577,10 @@ export function useSidebarController({
setSessionDeleteConfirmation(null);
try {
const response = await api.deleteSession(sessionId, hardDelete);
const response = await api.deleteSession(sessionId);
if (response.ok) {
onSessionDelete?.(sessionId);
await fetchArchivedSessions();
} else {
const errorText = await response.text();
console.error('[Sidebar] Failed to delete session:', {
@@ -719,7 +593,7 @@ export function useSidebarController({
console.error('[Sidebar] Error deleting session:', error);
alert(t('messages.deleteSessionError'));
}
}, [fetchArchivedSessions, onSessionDelete, sessionDeleteConfirmation, t]);
}, [onSessionDelete, sessionDeleteConfirmation, t]);
const requestProjectDelete = useCallback(
(project: Project) => {
@@ -775,88 +649,14 @@ export function useSidebarController({
[onProjectSelect, setCurrentProject],
);
const openArchivedSession = useCallback((session: ArchivedSessionListItem) => {
const activeProject = session.projectId
? projects.find((candidate) => candidate.projectId === session.projectId)
: null;
const archivedProject = session.projectId
? archivedProjects.find((candidate) => candidate.projectId === session.projectId)
: null;
const matchingProject = activeProject ?? archivedProject ?? null;
const sessionPayload: ProjectSession = {
id: session.sessionId,
summary: session.sessionTitle,
__provider: session.provider,
__projectId: matchingProject?.projectId ?? session.projectId ?? undefined,
};
// Archived sessions still need a selected project context. Active projects
// come from the normal sidebar list, while archived-project sessions resolve
// through the archive payload loaded by this controller.
if (matchingProject) {
handleProjectSelect(matchingProject);
}
onSessionSelect(sessionPayload);
}, [archivedProjects, handleProjectSelect, onSessionSelect, projects]);
const restoreArchivedProject = useCallback(async (projectId: string) => {
try {
const response = await api.restoreProject(projectId);
if (!response.ok) {
const errorText = await response.text();
console.error('[Sidebar] Failed to restore project:', {
status: response.status,
error: errorText,
});
alert(t('messages.restoreProjectFailed', 'Failed to restore project. Please try again.'));
return;
}
await Promise.all([
Promise.resolve(onRefresh()),
fetchArchivedSessions(),
]);
} catch (error) {
console.error('[Sidebar] Error restoring project:', error);
alert(t('messages.restoreProjectError', 'Error restoring project. Please try again.'));
}
}, [fetchArchivedSessions, onRefresh, t]);
const restoreArchivedSession = useCallback(async (sessionId: string) => {
try {
const response = await api.restoreSession(sessionId);
if (!response.ok) {
const errorText = await response.text();
console.error('[Sidebar] Failed to restore session:', {
status: response.status,
error: errorText,
});
alert(t('messages.restoreSessionFailed', 'Failed to restore session. Please try again.'));
return;
}
await Promise.all([
Promise.resolve(onRefresh()),
fetchArchivedSessions(),
]);
} catch (error) {
console.error('[Sidebar] Error restoring session:', error);
alert(t('messages.restoreSessionError', 'Error restoring session. Please try again.'));
}
}, [fetchArchivedSessions, onRefresh, t]);
const refreshProjects = useCallback(async () => {
setIsRefreshing(true);
try {
await Promise.all([
Promise.resolve(onRefresh()),
fetchArchivedSessions(),
]);
await onRefresh();
} finally {
setIsRefreshing(false);
}
}, [fetchArchivedSessions, onRefresh]);
}, [onRefresh]);
const updateSessionSummary = useCallback(
// `_projectId` and `_provider` are preserved for compatibility with
@@ -914,10 +714,6 @@ export function useSidebarController({
sessionDeleteConfirmation,
showVersionModal,
filteredProjects,
archivedProjects: filteredArchivedProjects,
archivedSessions: filteredArchivedSessions,
archivedSessionsCount: archivedProjects.length + archivedSessions.length,
isArchivedSessionsLoading,
toggleProject,
handleSessionClick,
toggleStarProject,
@@ -932,9 +728,6 @@ export function useSidebarController({
requestProjectDelete,
confirmDeleteProject,
handleProjectSelect,
openArchivedSession,
restoreArchivedProject,
restoreArchivedSession,
refreshProjects,
updateSessionSummary,
collapseSidebar,

View File

@@ -1,26 +1,11 @@
import type { LoadingProgress, Project, ProjectSession, LLMProvider } from '../../../types/app';
export type ProjectSortOrder = 'name' | 'date';
export type SidebarSearchMode = 'projects' | 'conversations' | 'archived';
export type ArchivedProjectListItem = Project & { isArchived: true };
export type SessionWithProvider = ProjectSession & {
__provider: LLMProvider;
};
export type ArchivedSessionListItem = {
sessionId: string;
provider: LLMProvider;
projectId: string | null;
projectPath: string | null;
projectDisplayName: string;
sessionTitle: string;
createdAt: string | null;
updatedAt: string | null;
lastActivity: string | null;
isProjectArchived: boolean;
};
export type DeleteProjectConfirmation = {
project: Project;
sessionCount: number;
@@ -29,11 +14,10 @@ export type DeleteProjectConfirmation = {
// Delete confirmation payload used by sidebar UX. `projectId`/`provider` are
// kept for wiring compatibility, while API deletion now keys only by sessionId.
export type SessionDeleteConfirmation = {
projectId: string | null;
projectId: string;
sessionId: string;
sessionTitle: string;
provider: LLMProvider;
isArchived: boolean;
};
export type SidebarProps = {

View File

@@ -1,5 +1,4 @@
import type { TFunction } from 'i18next';
import type { Project } from '../../../types/app';
import type { ProjectSortOrder, SettingsProject, SessionViewModel, SessionWithProvider } from '../types/types';
@@ -53,24 +52,44 @@ export const clearLegacyStarredProjectIds = () => {
}
};
const getCreatedTimestamp = (session: SessionWithProvider): string => {
return String(session.createdAt || session.created_at || '');
};
const getUpdatedTimestamp = (session: SessionWithProvider): string => {
return String(session.lastActivity || '');
};
export const getSessionDate = (session: SessionWithProvider): Date => {
return new Date(getUpdatedTimestamp(session) || getCreatedTimestamp(session) || 0);
if (session.__provider === 'cursor') {
return new Date(session.createdAt || 0);
}
if (session.__provider === 'codex') {
return new Date(session.createdAt || session.lastActivity || 0);
}
return new Date(session.lastActivity || session.createdAt || 0);
};
export const getSessionName = (session: SessionWithProvider, t: TFunction): string => {
return session.summary || session.name || t('projects.newSession');
if (session.__provider === 'cursor') {
return session.summary || session.name || t('projects.untitledSession');
}
if (session.__provider === 'codex') {
return session.summary || session.name || t('projects.codexSession');
}
if (session.__provider === 'gemini') {
return session.summary || session.name || t('projects.newSession');
}
return session.summary || t('projects.newSession');
};
export const getSessionTime = (session: SessionWithProvider): string => {
return getUpdatedTimestamp(session) || getCreatedTimestamp(session);
if (session.__provider === 'cursor') {
return String(session.createdAt || '');
}
if (session.__provider === 'codex') {
return String(session.createdAt || session.lastActivity || '');
}
return String(session.lastActivity || session.createdAt || '');
};
export const createSessionViewModel = (

View File

@@ -6,7 +6,6 @@ import { useVersionCheck } from '../../../hooks/useVersionCheck';
import { useUiPreferences } from '../../../hooks/useUiPreferences';
import { useSidebarController } from '../hooks/useSidebarController';
import { useTaskMaster } from '../../../contexts/TaskMasterContext';
import { usePaletteOps } from '../../../contexts/PaletteOpsContext';
import { useTasksSettings } from '../../../contexts/TasksSettingsContext';
import type { Project, LLMProvider } from '../../../types/app';
import type { MCPServerStatus, SidebarProps } from '../types/types';
@@ -50,7 +49,6 @@ function Sidebar({
const { sidebarVisible } = preferences;
const { setCurrentProject, mcpServerStatus } = useTaskMaster() as TaskMasterSidebarContext;
const { tasksEnabled } = useTasksSettings();
const paletteOps = usePaletteOps();
const {
isSidebarCollapsed,
@@ -75,10 +73,6 @@ function Sidebar({
sessionDeleteConfirmation,
showVersionModal,
filteredProjects,
archivedProjects,
archivedSessions,
archivedSessionsCount,
isArchivedSessionsLoading,
toggleProject,
handleSessionClick,
toggleStarProject,
@@ -94,9 +88,6 @@ function Sidebar({
requestProjectDelete,
confirmDeleteProject,
handleProjectSelect,
openArchivedSession,
restoreArchivedProject,
restoreArchivedSession,
refreshProjects,
updateSessionSummary,
collapseSidebar: handleCollapseSidebar,
@@ -137,7 +128,12 @@ function Sidebar({
}, [isPWA]);
const handleProjectCreated = () => {
void paletteOps.refreshProjects();
if (window.refreshProjects) {
void window.refreshProjects();
return;
}
window.location.reload();
};
const projectListProps: SidebarProjectListProps = {
@@ -191,8 +187,8 @@ function Sidebar({
return (
<>
<SidebarModals
projects={projects}
<SidebarModals
projects={projects}
showSettings={showSettings}
settingsInitialTab={settingsInitialTab}
onCloseSettings={onCloseSettings}
@@ -224,38 +220,22 @@ function Sidebar({
/>
) : (
<>
<SidebarContent
<SidebarContent
isPWA={isPWA}
isMobile={isMobile}
isLoading={isLoading}
projects={projects}
archivedProjects={archivedProjects}
archivedSessions={archivedSessions}
archivedSessionsCount={archivedSessionsCount}
isArchivedSessionsLoading={isArchivedSessionsLoading}
searchFilter={searchFilter}
onSearchFilterChange={setSearchFilter}
onClearSearchFilter={() => setSearchFilter('')}
searchMode={searchMode}
onSearchModeChange={(mode) => {
onSearchModeChange={(mode: 'projects' | 'conversations') => {
setSearchMode(mode);
if (mode === 'projects') clearConversationResults();
}}
conversationResults={conversationResults}
isSearching={isSearching}
searchProgress={searchProgress}
onRestoreArchivedProject={restoreArchivedProject}
onArchivedSessionClick={openArchivedSession}
onRestoreArchivedSession={restoreArchivedSession}
onDeleteArchivedSession={(session) => {
showDeleteSessionConfirmation(
session.projectId,
session.sessionId,
session.sessionTitle,
session.provider,
{ isArchived: true },
);
}}
onConversationResultClick={(projectId: string | null, sessionId: string, provider: string, messageTimestamp?: string | null, messageSnippet?: string | null) => {
// `projectId` (DB key) is the canonical identifier post-migration.
// The server emits null when it can't resolve a project row for

View File

@@ -1,16 +1,15 @@
import { type ReactNode } from 'react';
import { Archive, Folder, MessageSquare, RotateCcw, Search, Trash2 } from 'lucide-react';
import { Folder, MessageSquare, Search } from 'lucide-react';
import type { TFunction } from 'i18next';
import { ScrollArea } from '../../../../shared/view/ui';
import type { Project } from '../../../../types/app';
import type { ReleaseInfo } from '../../../../types/sharedTypes';
import type { ConversationSearchResults, SearchProgress } from '../../hooks/useSidebarController';
import type { ArchivedProjectListItem, ArchivedSessionListItem, SidebarSearchMode } from '../../types/types';
import SessionProviderLogo from '../../../llm-logo-provider/SessionProviderLogo';
import SidebarFooter from './SidebarFooter';
import SidebarHeader from './SidebarHeader';
import SidebarProjectList, { type SidebarProjectListProps } from './SidebarProjectList';
import { getAllSessions } from '../../utils/utils';
type SearchMode = 'projects' | 'conversations';
function HighlightedSnippet({ snippet, highlights }: { snippet: string; highlights: { start: number; end: number }[] }) {
const parts: ReactNode[] = [];
@@ -36,100 +35,19 @@ function HighlightedSnippet({ snippet, highlights }: { snippet: string; highligh
);
}
type ArchivedSessionGroup = {
key: string;
projectId: string | null;
projectDisplayName: string;
projectPath: string | null;
isProjectArchived: boolean;
sessions: ArchivedSessionListItem[];
latestActivity: string | null;
};
/**
* Groups archived sessions by project metadata so the archive view preserves
* the same mental model as the active sidebar: projects first, then sessions.
*/
function groupArchivedSessionsByProject(sessions: ArchivedSessionListItem[]): ArchivedSessionGroup[] {
const groups = new Map<string, ArchivedSessionGroup>();
for (const session of sessions) {
const key = session.projectId ?? session.projectPath ?? `session:${session.sessionId}`;
const existingGroup = groups.get(key);
if (existingGroup) {
existingGroup.sessions.push(session);
if (!existingGroup.latestActivity || (session.lastActivity && session.lastActivity > existingGroup.latestActivity)) {
existingGroup.latestActivity = session.lastActivity;
}
continue;
}
groups.set(key, {
key,
projectId: session.projectId,
projectDisplayName: session.projectDisplayName,
projectPath: session.projectPath,
isProjectArchived: session.isProjectArchived,
sessions: [session],
latestActivity: session.lastActivity,
});
}
return [...groups.values()].sort((groupA, groupB) => {
const a = groupA.latestActivity ?? '';
const b = groupB.latestActivity ?? '';
return b.localeCompare(a);
});
}
function formatCompactArchivedAge(dateString: string | null): string {
if (!dateString) {
return '';
}
const date = new Date(dateString);
if (Number.isNaN(date.getTime())) {
return '';
}
const diffInMinutes = Math.floor(Math.max(0, Date.now() - date.getTime()) / (1000 * 60));
if (diffInMinutes < 1) {
return '<1m';
}
if (diffInMinutes < 60) {
return `${diffInMinutes}m`;
}
const diffInHours = Math.floor(diffInMinutes / 60);
if (diffInHours < 24) {
return `${diffInHours}hr`;
}
return `${Math.floor(diffInHours / 24)}d`;
}
type SidebarContentProps = {
isPWA: boolean;
isMobile: boolean;
isLoading: boolean;
projects: Project[];
archivedProjects: ArchivedProjectListItem[];
archivedSessions: ArchivedSessionListItem[];
archivedSessionsCount: number;
isArchivedSessionsLoading: boolean;
searchFilter: string;
onSearchFilterChange: (value: string) => void;
onClearSearchFilter: () => void;
searchMode: SidebarSearchMode;
onSearchModeChange: (mode: SidebarSearchMode) => void;
searchMode: SearchMode;
onSearchModeChange: (mode: SearchMode) => void;
conversationResults: ConversationSearchResults | null;
isSearching: boolean;
searchProgress: SearchProgress | null;
onRestoreArchivedProject: (projectId: string) => void;
onArchivedSessionClick: (session: ArchivedSessionListItem) => void;
onRestoreArchivedSession: (sessionId: string) => void;
onDeleteArchivedSession: (session: ArchivedSessionListItem) => void;
// Conversation result clicks pass back the DB projectId (or null when the
// server couldn't resolve it). Consumers must handle the null case.
onConversationResultClick: (projectId: string | null, sessionId: string, provider: string, messageTimestamp?: string | null, messageSnippet?: string | null) => void;
@@ -152,10 +70,6 @@ export default function SidebarContent({
isMobile,
isLoading,
projects,
archivedProjects,
archivedSessions,
archivedSessionsCount,
isArchivedSessionsLoading,
searchFilter,
onSearchFilterChange,
onClearSearchFilter,
@@ -164,10 +78,6 @@ export default function SidebarContent({
conversationResults,
isSearching,
searchProgress,
onRestoreArchivedProject,
onArchivedSessionClick,
onRestoreArchivedSession,
onDeleteArchivedSession,
onConversationResultClick,
onRefresh,
isRefreshing,
@@ -184,7 +94,6 @@ export default function SidebarContent({
}: SidebarContentProps) {
const showConversationSearch = searchMode === 'conversations' && searchFilter.trim().length >= 2;
const hasPartialResults = conversationResults && conversationResults.results.length > 0;
const groupedArchivedSessions = groupArchivedSessionsByProject(archivedSessions);
return (
<div
@@ -196,8 +105,6 @@ export default function SidebarContent({
isMobile={isMobile}
isLoading={isLoading}
projectsCount={projects.length}
archivedSessionsCount={archivedSessionsCount}
isArchivedSessionsLoading={isArchivedSessionsLoading}
searchFilter={searchFilter}
onSearchFilterChange={onSearchFilterChange}
onClearSearchFilter={onClearSearchFilter}
@@ -307,207 +214,6 @@ export default function SidebarContent({
))}
</div>
) : null
) : searchMode === 'archived' ? (
isArchivedSessionsLoading ? (
<div className="px-4 py-12 text-center md:py-8">
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-lg bg-muted md:mb-3">
<div className="h-6 w-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent" />
</div>
<h3 className="mb-2 text-base font-medium text-foreground md:mb-1">
{t('archived.loadingTitle', 'Loading archive...')}
</h3>
<p className="text-sm text-muted-foreground">
{t('archived.loadingDescription', 'Fetching hidden workspaces and sessions you can restore later.')}
</p>
</div>
) : archivedProjects.length === 0 && groupedArchivedSessions.length === 0 ? (
<div className="px-4 py-12 text-center md:py-8">
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-lg bg-muted md:mb-3">
<Archive className="h-6 w-6 text-muted-foreground" />
</div>
<h3 className="mb-2 text-base font-medium text-foreground md:mb-1">
{archivedSessionsCount > 0
? t('archived.noMatchingSessions', 'No matching archived items')
: t('archived.emptyTitle', 'No archived items')}
</h3>
<p className="text-sm text-muted-foreground">
{archivedSessionsCount > 0
? t('archived.tryDifferentSearch', 'Try a different search term.')
: t('archived.emptyDescription', 'Archived workspaces and sessions will appear here when you hide them from the active list.')}
</p>
</div>
) : (
<div className="space-y-3 px-2">
<div className="flex items-center justify-between px-1">
<p className="text-xs text-muted-foreground">
{`${archivedSessionsCount} ${t(
archivedSessionsCount === 1 ? 'archived.sessionCountOne' : 'archived.sessionCountOther',
archivedSessionsCount === 1 ? 'archived item' : 'archived items',
)}`}
</p>
</div>
{archivedProjects.map((project) => {
const projectSessions = getAllSessions(project);
return (
<div key={project.projectId} className="overflow-hidden rounded-xl border border-border/70 bg-card/60 shadow-sm">
<div className="flex items-start justify-between gap-3 border-b border-border/60 px-3 py-2.5">
<div className="min-w-0">
<div className="flex items-center gap-2">
<Folder className="h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" />
<span className="truncate text-sm font-medium text-foreground">
{project.displayName}
</span>
<span className="inline-flex items-center justify-center rounded-full bg-muted px-1 py-px text-[7px] font-medium uppercase leading-none tracking-[0.02em] text-center text-muted-foreground">
{t('archived.projectArchived', 'Project archived')}
</span>
</div>
<p className="mt-1 truncate text-xs text-muted-foreground/70" title={project.fullPath}>
{project.fullPath}
</p>
</div>
<button
className="flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-lg bg-emerald-50 text-emerald-700 transition-colors hover:bg-emerald-100 dark:bg-emerald-900/20 dark:text-emerald-300 dark:hover:bg-emerald-900/30"
onClick={() => onRestoreArchivedProject(project.projectId)}
title={t('archived.restoreProject', 'Restore workspace')}
>
<RotateCcw className="h-3.5 w-3.5" />
</button>
</div>
{projectSessions.length > 0 && (
<div className="divide-y divide-border/50">
{projectSessions.map((session) => (
<button
key={String(session.id)}
className="flex w-full items-center gap-2 px-3 py-2.5 text-left transition-colors hover:bg-accent/40"
onClick={() => onArchivedSessionClick({
sessionId: String(session.id),
provider: session.__provider,
projectId: project.projectId,
projectPath: project.fullPath,
projectDisplayName: project.displayName,
sessionTitle:
(typeof session.summary === 'string' && session.summary.trim().length > 0
? session.summary
: typeof session.name === 'string' && session.name.trim().length > 0
? session.name
: String(session.id)),
createdAt: typeof session.created_at === 'string' ? session.created_at : null,
updatedAt: typeof session.updated_at === 'string' ? session.updated_at : null,
lastActivity:
typeof session.lastActivity === 'string'
? session.lastActivity
: typeof session.updated_at === 'string'
? session.updated_at
: typeof session.created_at === 'string'
? session.created_at
: null,
isProjectArchived: true,
})}
>
<SessionProviderLogo provider={session.__provider} className="h-3.5 w-3.5 flex-shrink-0" />
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2">
<span className="truncate text-xs font-medium text-foreground">
{(typeof session.summary === 'string' && session.summary.trim().length > 0
? session.summary
: typeof session.name === 'string' && session.name.trim().length > 0
? session.name
: String(session.id))}
</span>
<span className="ml-auto flex-shrink-0 text-[11px] text-muted-foreground">
{formatCompactArchivedAge(
typeof session.lastActivity === 'string'
? session.lastActivity
: typeof session.updated_at === 'string'
? session.updated_at
: typeof session.created_at === 'string'
? session.created_at
: null,
)}
</span>
</div>
<p className="mt-0.5 text-[11px] uppercase tracking-wide text-muted-foreground/70">
{session.__provider}
</p>
</div>
</button>
))}
</div>
)}
</div>
);
})}
{groupedArchivedSessions.map((group) => (
<div key={group.key} className="overflow-hidden rounded-xl border border-border/70 bg-card/60 shadow-sm">
<div className="flex items-start justify-between gap-3 border-b border-border/60 px-3 py-2.5">
<div className="min-w-0">
<div className="flex items-center gap-2">
<Folder className="h-3.5 w-3.5 flex-shrink-0 text-muted-foreground" />
<span className="truncate text-sm font-medium text-foreground">
{group.projectDisplayName}
</span>
{group.isProjectArchived && (
<span className="inline-flex items-center justify-center rounded-full bg-muted px-1 py-px text-[7px] font-medium uppercase leading-none tracking-[0.02em] text-center text-muted-foreground">
{t('archived.projectArchived', 'Project archived')}
</span>
)}
</div>
{group.projectPath && (
<p className="mt-1 truncate text-xs text-muted-foreground/70" title={group.projectPath}>
{group.projectPath}
</p>
)}
</div>
<span className="flex-shrink-0 text-[11px] text-muted-foreground">
{group.sessions.length}
</span>
</div>
<div className="divide-y divide-border/50">
{group.sessions.map((session) => (
<div key={session.sessionId} className="flex items-center gap-2 px-3 py-2.5">
<button
className="flex min-w-0 flex-1 items-center gap-2 text-left transition-colors hover:text-foreground"
onClick={() => onArchivedSessionClick(session)}
>
<SessionProviderLogo provider={session.provider} className="h-3.5 w-3.5 flex-shrink-0" />
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2">
<span className="truncate text-xs font-medium text-foreground">
{session.sessionTitle}
</span>
{session.lastActivity && (
<span className="ml-auto flex-shrink-0 text-[11px] text-muted-foreground">
{formatCompactArchivedAge(session.lastActivity)}
</span>
)}
</div>
<p className="mt-0.5 text-[11px] uppercase tracking-wide text-muted-foreground/70">
{session.provider}
</p>
</div>
</button>
<button
className="flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-lg bg-emerald-50 text-emerald-700 transition-colors hover:bg-emerald-100 dark:bg-emerald-900/20 dark:text-emerald-300 dark:hover:bg-emerald-900/30"
onClick={() => onRestoreArchivedSession(session.sessionId)}
title={t('archived.restore', 'Restore session')}
>
<RotateCcw className="h-3.5 w-3.5" />
</button>
<button
className="flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-lg bg-red-50 text-red-700 transition-colors hover:bg-red-100 dark:bg-red-900/20 dark:text-red-300 dark:hover:bg-red-900/30"
onClick={() => onDeleteArchivedSession(session)}
title={t('archived.deletePermanently', 'Delete permanently')}
>
<Trash2 className="h-3.5 w-3.5" />
</button>
</div>
))}
</div>
</div>
))}
</div>
)
) : (
<SidebarProjectList {...projectListProps} />
)}

View File

@@ -1,26 +1,22 @@
import { Archive, Folder, FolderPlus, MessageSquare, Plus, RefreshCw, Search, X, PanelLeftClose } from 'lucide-react';
import { Folder, FolderPlus, MessageSquare, Plus, RefreshCw, Search, X, PanelLeftClose } from 'lucide-react';
import type { TFunction } from 'i18next';
import { Button, Input, Tooltip } from '../../../../shared/view/ui';
import { Button, Input } from '../../../../shared/view/ui';
import { IS_PLATFORM } from '../../../../constants/config';
import { cn } from '../../../../lib/utils';
import type { SidebarSearchMode } from '../../types/types';
import GitHubStarBadge from './GitHubStarBadge';
const MOD_KEY =
typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌘' : 'Ctrl';
type SearchMode = 'projects' | 'conversations';
type SidebarHeaderProps = {
isPWA: boolean;
isMobile: boolean;
isLoading: boolean;
projectsCount: number;
archivedSessionsCount: number;
isArchivedSessionsLoading: boolean;
searchFilter: string;
onSearchFilterChange: (value: string) => void;
onClearSearchFilter: () => void;
searchMode: SidebarSearchMode;
onSearchModeChange: (mode: SidebarSearchMode) => void;
searchMode: SearchMode;
onSearchModeChange: (mode: SearchMode) => void;
onRefresh: () => void;
isRefreshing: boolean;
onCreateProject: () => void;
@@ -33,8 +29,6 @@ export default function SidebarHeader({
isMobile,
isLoading,
projectsCount,
archivedSessionsCount,
isArchivedSessionsLoading,
searchFilter,
onSearchFilterChange,
onClearSearchFilter,
@@ -46,13 +40,6 @@ export default function SidebarHeader({
onCollapseSidebar,
t,
}: SidebarHeaderProps) {
const showSearchTools = (projectsCount > 0 || archivedSessionsCount > 0 || isArchivedSessionsLoading) && !isLoading;
const searchPlaceholder = searchMode === 'conversations'
? t('search.conversationsPlaceholder')
: searchMode === 'archived'
? t('search.archivedPlaceholder', 'Search archived sessions...')
: t('projects.searchPlaceholder');
const LogoBlock = () => (
<div className="flex min-w-0 items-center gap-2.5">
<div className="flex h-7 w-7 flex-shrink-0 items-center justify-center rounded-lg bg-primary/90 shadow-sm">
@@ -123,7 +110,7 @@ export default function SidebarHeader({
<GitHubStarBadge />
{/* Search bar */}
{showSearchTools && (
{projectsCount > 0 && !isLoading && (
<div className="mt-2.5 space-y-2">
{/* Search mode toggle */}
<div className="flex rounded-lg bg-muted/50 p-0.5">
@@ -153,33 +140,17 @@ export default function SidebarHeader({
<MessageSquare className="h-3 w-3" />
{t('search.modeConversations')}
</button>
<Tooltip content={t('search.archiveOnlyTooltip', 'Archive only')} position="top">
<button
onClick={() => onSearchModeChange('archived')}
aria-pressed={searchMode === 'archived'}
aria-label={t('search.archiveOnlyTooltip', 'Archive only')}
title={t('search.archiveOnlyTooltip', 'Archive only')}
className={cn(
"flex items-center justify-center rounded-md px-2.5 py-1.5 text-xs font-medium transition-all",
searchMode === 'archived'
? "bg-background shadow-sm text-foreground"
: "text-muted-foreground hover:text-foreground"
)}
>
<Archive className="h-3 w-3" />
</button>
</Tooltip>
</div>
<div className="relative">
<Search className="pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground/50" />
<Input
type="text"
placeholder={searchPlaceholder}
placeholder={searchMode === 'conversations' ? t('search.conversationsPlaceholder') : t('projects.searchPlaceholder')}
value={searchFilter}
onChange={(event) => onSearchFilterChange(event.target.value)}
className="nav-search-input h-9 rounded-xl border-0 pl-9 pr-14 text-sm transition-all duration-200 placeholder:text-muted-foreground/40 focus-visible:ring-0 focus-visible:ring-offset-0"
className="nav-search-input h-9 rounded-xl border-0 pl-9 pr-8 text-sm transition-all duration-200 placeholder:text-muted-foreground/40 focus-visible:ring-0 focus-visible:ring-offset-0"
/>
{searchFilter ? (
{searchFilter && (
<button
onClick={onClearSearchFilter}
aria-label={t('tooltips.clearSearch')}
@@ -187,15 +158,6 @@ export default function SidebarHeader({
>
<X className="h-3 w-3 text-muted-foreground" />
</button>
) : (
<kbd
aria-hidden
title={t('tooltips.openCommandPalette')}
className="pointer-events-none absolute right-2.5 top-1/2 hidden -translate-y-1/2 items-center gap-0.5 rounded border border-border/60 bg-muted/40 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground md:inline-flex"
>
{MOD_KEY}
<span>K</span>
</kbd>
)}
</div>
</div>
@@ -241,7 +203,7 @@ export default function SidebarHeader({
</div>
{/* Mobile search */}
{showSearchTools && (
{projectsCount > 0 && !isLoading && (
<div className="mt-2.5 space-y-2">
<div className="flex rounded-lg bg-muted/50 p-0.5">
<button
@@ -270,28 +232,12 @@ export default function SidebarHeader({
<MessageSquare className="h-3 w-3" />
{t('search.modeConversations')}
</button>
<Tooltip content={t('search.archiveOnlyTooltip', 'Archive only')} position="top">
<button
onClick={() => onSearchModeChange('archived')}
aria-pressed={searchMode === 'archived'}
aria-label={t('search.archiveOnlyTooltip', 'Archive only')}
title={t('search.archiveOnlyTooltip', 'Archive only')}
className={cn(
"flex items-center justify-center rounded-md px-2.5 py-1.5 text-xs font-medium transition-all",
searchMode === 'archived'
? "bg-background shadow-sm text-foreground"
: "text-muted-foreground hover:text-foreground"
)}
>
<Archive className="h-3 w-3" />
</button>
</Tooltip>
</div>
<div className="relative">
<Search className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/50" />
<Input
type="text"
placeholder={searchPlaceholder}
placeholder={searchMode === 'conversations' ? t('search.conversationsPlaceholder') : t('projects.searchPlaceholder')}
value={searchFilter}
onChange={(event) => onSearchFilterChange(event.target.value)}
className="nav-search-input h-10 rounded-xl border-0 pl-10 pr-9 text-sm transition-all duration-200 placeholder:text-muted-foreground/40 focus-visible:ring-0 focus-visible:ring-offset-0"

View File

@@ -25,7 +25,7 @@ type SidebarModalsProps = {
onConfirmDeleteProject: (deleteData?: boolean) => void;
sessionDeleteConfirmation: SessionDeleteConfirmation | null;
onCancelDeleteSession: () => void;
onConfirmDeleteSession: (hardDelete?: boolean) => void;
onConfirmDeleteSession: () => void;
showVersionModal: boolean;
onCloseVersionModal: () => void;
releaseInfo: ReleaseInfo | null;
@@ -133,7 +133,7 @@ export default function SidebarModals({
onClick={() => onConfirmDeleteProject(false)}
>
<EyeOff className="mr-2 h-4 w-4" />
{t('deleteConfirmation.archiveProject', 'Archive project')}
{t('deleteConfirmation.removeFromSidebar')}
</Button>
<Button
variant="destructive"
@@ -173,34 +173,22 @@ export default function SidebarModals({
?
</p>
<p className="mt-3 text-xs text-muted-foreground">
{sessionDeleteConfirmation.isArchived
? t('deleteConfirmation.archivedSessionNotice', 'This session is already archived. You can keep it hidden or delete it permanently.')
: t('deleteConfirmation.archiveSessionNotice', 'Archive keeps the session out of the active list while preserving its history.')}
{t('deleteConfirmation.cannotUndo')}
</p>
</div>
</div>
</div>
<div className="flex flex-col gap-2 border-t border-border bg-muted/30 p-4">
{!sessionDeleteConfirmation.isArchived && (
<Button
variant="outline"
className="w-full justify-start"
onClick={() => onConfirmDeleteSession(false)}
>
<EyeOff className="mr-2 h-4 w-4" />
{t('deleteConfirmation.archiveSession', 'Archive session')}
</Button>
)}
<div className="flex gap-3 border-t border-border bg-muted/30 p-4">
<Button variant="outline" className="flex-1" onClick={onCancelDeleteSession}>
{t('actions.cancel')}
</Button>
<Button
variant="destructive"
className="w-full justify-start bg-red-600 text-white hover:bg-red-700"
onClick={() => onConfirmDeleteSession(true)}
className="flex-1 bg-red-600 text-white hover:bg-red-700"
onClick={onConfirmDeleteSession}
>
<Trash2 className="mr-2 h-4 w-4" />
{t('deleteConfirmation.deleteSessionPermanently', 'Delete permanently')}
</Button>
<Button variant="ghost" className="w-full" onClick={onCancelDeleteSession}>
{t('actions.cancel')}
{t('actions.delete')}
</Button>
</div>
</div>

View File

@@ -239,7 +239,7 @@ export default function SidebarSessionItem({
event.stopPropagation();
requestDeleteSession();
}}
title={t('tooltips.deleteSessionOptions', 'Archive or permanently delete this session')}
title={t('tooltips.deleteSession')}
>
<Trash2 className="h-3 w-3 text-red-600 dark:text-red-400" />
</button>

View File

@@ -1,53 +0,0 @@
import { createContext, useContext, useEffect, useMemo, useRef } from 'react';
import type { MutableRefObject, ReactNode } from 'react';
export type PaletteOps = {
openFile: (path: string) => void;
openSettings: (tab?: string) => void;
refreshProjects: () => Promise<void> | void;
};
type Registry = MutableRefObject<Partial<PaletteOps>>;
const PaletteOpsContext = createContext<Registry | null>(null);
const defaultOps: PaletteOps = {
openFile: () => undefined,
openSettings: () => undefined,
refreshProjects: () => undefined,
};
export function PaletteOpsProvider({ children }: { children: ReactNode }) {
const ref = useRef<Partial<PaletteOps>>({});
return <PaletteOpsContext.Provider value={ref}>{children}</PaletteOpsContext.Provider>;
}
export function usePaletteOps(): PaletteOps {
const ref = useContext(PaletteOpsContext);
return useMemo<PaletteOps>(
() => ({
openFile: (path) => (ref?.current.openFile ?? defaultOps.openFile)(path),
openSettings: (tab) => (ref?.current.openSettings ?? defaultOps.openSettings)(tab),
refreshProjects: () => (ref?.current.refreshProjects ?? defaultOps.refreshProjects)(),
}),
[ref],
);
}
export function usePaletteOpsRegister(partial: Partial<PaletteOps>) {
const ref = useContext(PaletteOpsContext);
const { openFile, openSettings, refreshProjects } = partial;
useEffect(() => {
if (!ref) return undefined;
const prev = { ...ref.current };
if (openFile) ref.current.openFile = openFile;
if (openSettings) ref.current.openSettings = openSettings;
if (refreshProjects) ref.current.refreshProjects = refreshProjects;
return () => {
if (openFile && ref.current.openFile === openFile) ref.current.openFile = prev.openFile;
if (openSettings && ref.current.openSettings === openSettings) ref.current.openSettings = prev.openSettings;
if (refreshProjects && ref.current.refreshProjects === refreshProjects) ref.current.refreshProjects = prev.refreshProjects;
};
}, [ref, openFile, openSettings, refreshProjects]);
}

View File

@@ -5,7 +5,6 @@ import { api } from '../utils/api';
import type {
AppSocketMessage,
AppTab,
LLMProvider,
LoadingProgress,
Project,
ProjectSession,
@@ -262,27 +261,6 @@ export function useProjectsState({
const [showSettings, setShowSettings] = useState(false);
const [settingsInitialTab, setSettingsInitialTab] = useState('agents');
const [externalMessageUpdate, setExternalMessageUpdate] = useState(0);
/**
* `newSessionTrigger` is an explicit, monotonic intent signal for user-driven
* New Session actions.
*
* It exists because `handleNewSession` can be invoked while the app is already in
* the same visible state (`selectedSession === null`, `activeTab === 'chat'`,
* route already `/`). In that case, React/router updates are idempotent and no
* downstream reset logic runs.
*
* Usage across the codebase:
* 1) Produced here in `handleNewSession` via increment (always changes).
* 2) Returned from this hook and threaded through:
* useProjectsState -> AppContent -> MainContent -> ChatInterface.
* 3) Consumed in `useChatSessionState` as an effect dependency to forcibly clear
* chat-local state (`currentSessionId`, pending draft message, streaming flags,
* pending session storage keys, pagination/scroll artifacts).
*
* Keeping this signal dedicated avoids coupling resets to unrelated counters/events
* (for example websocket/project refresh updates) that could cause accidental resets.
*/
const [newSessionTrigger, setNewSessionTrigger] = useState(0);
const loadingProgressTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const lastHandledMessageRef = useRef<AppSocketMessage | null>(null);
@@ -435,7 +413,9 @@ export function useProjectsState({
}
}
const hasActiveSession = Boolean(selectedSession && activeSessions.has(selectedSession.id));
const hasActiveSession =
(selectedSession && activeSessions.has(selectedSession.id)) ||
(activeSessions.size > 0 && Array.from(activeSessions).some((id) => id.startsWith('new-session-')));
const updatedProjectsWithTaskMaster = mergeTaskMasterCache(projectsMessage.projects, projects);
const updatedProjects = mergeExpandedSessionPages(projects, updatedProjectsWithTaskMaster);
@@ -556,42 +536,7 @@ export function useProjectsState({
return;
}
}
// Session id is in the URL but not yet present on any project payload (common
// right after `session_created` + navigate, before the next projects refresh).
// Without a `selectedSession`, chat state clears `currentSessionId` and the
// UI stops reading the session store even though messages stream under this id.
if (selectedSession?.id === sessionId) {
return;
}
if (!selectedProject) {
return;
}
let providerFromStorage: string | null = null;
try {
providerFromStorage = localStorage.getItem('selected-provider');
} catch {
providerFromStorage = null;
}
const normalizedProvider: LLMProvider =
providerFromStorage === 'cursor'
? 'cursor'
: providerFromStorage === 'codex'
? 'codex'
: providerFromStorage === 'gemini'
? 'gemini'
: 'claude';
setSelectedSession({
id: sessionId,
__provider: normalizedProvider,
__projectId: selectedProject.projectId,
summary: '',
});
}, [sessionId, projects, selectedProject, selectedSession?.id, selectedSession?.__provider]);
}, [sessionId, projects, selectedProject?.projectId, selectedSession?.id, selectedSession?.__provider]);
const handleProjectSelect = useCallback(
(project: Project) => {
@@ -642,7 +587,6 @@ export function useProjectsState({
setSelectedProject(project);
setSelectedSession(null);
setActiveTab('chat');
setNewSessionTrigger((previous) => previous + 1);
navigate('/');
if (isMobile) {
@@ -862,7 +806,6 @@ export function useProjectsState({
showSettings,
settingsInitialTab,
externalMessageUpdate,
newSessionTrigger,
setActiveTab,
setSidebarOpen,
setIsInputFocused,

View File

@@ -44,6 +44,23 @@ export function useSessionProtection() {
});
}, []);
const replaceTemporarySession = useCallback((realSessionId?: string | null) => {
if (!realSessionId) {
return;
}
setActiveSessions((prev) => {
const next = new Set<string>();
for (const sessionId of prev) {
if (!sessionId.startsWith('new-session-')) {
next.add(sessionId);
}
}
next.add(realSessionId);
return next;
});
}, []);
return {
activeSessions,
processingSessions,
@@ -51,5 +68,6 @@ export function useSessionProtection() {
markSessionAsInactive,
markSessionAsProcessing,
markSessionAsNotProcessing,
replaceTemporarySession,
};
}

View File

@@ -89,14 +89,12 @@
"permissionMode": "Berechtigungsmodus",
"modes": {
"default": "Standardmodus",
"auto": "Auto Mode",
"acceptEdits": "Bearbeitungen akzeptieren",
"bypassPermissions": "Berechtigungen umgehen",
"plan": "Planungsmodus"
},
"descriptions": {
"default": "Nur vertrauenswürdige Befehle (ls, cat, grep, git status usw.) werden automatisch ausgeführt. Andere Befehle werden übersprungen. Kann in den Arbeitsbereich schreiben.",
"auto": "A model classifier decides per tool call whether to approve or deny. Hands-off, but safer than Bypass — denials still happen.",
"acceptEdits": "Alle Befehle werden automatisch innerhalb des Arbeitsbereichs ausgeführt. Vollautomatischer Modus mit isolierter Ausführung.",
"bypassPermissions": "Vollständiger Systemzugriff ohne Einschränkungen. Alle Befehle werden automatisch mit vollem Festplatten- und Netzwerkzugriff ausgeführt. Mit Vorsicht verwenden.",
"plan": "Planungsmodus keine Befehle werden ausgeführt"
@@ -190,8 +188,7 @@
"codex": "Bereit, Codex mit {{model}} zu verwenden. Gib unten deine Nachricht ein.",
"gemini": "Bereit, Gemini mit {{model}} zu verwenden. Gib unten deine Nachricht ein.",
"default": "Wähl oben einen Anbieter, um zu beginnen"
},
"pressToSearch": "Drücke <kbd>{{shortcut}}</kbd>, um Sitzungen, Dateien und Commits zu durchsuchen"
}
},
"session": {
"continue": {

View File

@@ -47,8 +47,7 @@
"deleteSession": "Diese Sitzung dauerhaft löschen",
"save": "Speichern",
"cancel": "Abbrechen",
"clearSearch": "Suche leeren",
"openCommandPalette": "Befehlspalette öffnen"
"clearSearch": "Suche leeren"
},
"navigation": {
"chat": "Chat",

View File

@@ -89,14 +89,12 @@
"permissionMode": "Permission Mode",
"modes": {
"default": "Default Mode",
"auto": "Auto Mode",
"acceptEdits": "Accept Edits",
"bypassPermissions": "Bypass Permissions",
"plan": "Plan Mode"
},
"descriptions": {
"default": "Only trusted commands (ls, cat, grep, git status, etc.) run automatically. Other commands are skipped. Can write to workspace.",
"auto": "A model classifier decides per tool call whether to approve or deny. Hands-off, but safer than Bypass — denials still happen.",
"acceptEdits": "All commands run automatically within the workspace. Full auto mode with sandboxed execution.",
"bypassPermissions": "Full system access with no restrictions. All commands run automatically with full disk and network access. Use with caution.",
"plan": "Planning mode - no commands are executed"
@@ -190,8 +188,7 @@
"codex": "Ready to use Codex with {{model}}. Start typing your message below.",
"gemini": "Ready to use Gemini with {{model}}. Start typing your message below.",
"default": "Select a provider above to begin"
},
"pressToSearch": "Press <kbd>{{shortcut}}</kbd> to search sessions, files, and commits"
}
},
"session": {
"continue": {

View File

@@ -47,8 +47,7 @@
"deleteSession": "Delete this session permanently",
"save": "Save",
"cancel": "Cancel",
"clearSearch": "Clear search",
"openCommandPalette": "Open command palette"
"clearSearch": "Clear search"
},
"navigation": {
"chat": "Chat",

View File

@@ -89,14 +89,12 @@
"permissionMode": "Modalità permessi",
"modes": {
"default": "Modalità predefinita",
"auto": "Auto Mode",
"acceptEdits": "Accetta modifiche",
"bypassPermissions": "Ignora permessi",
"plan": "Modalità piano"
},
"descriptions": {
"default": "Solo i comandi attendibili (ls, cat, grep, git status, ecc.) vengono eseguiti automaticamente. Gli altri comandi vengono saltati. Può scrivere nell'area di lavoro.",
"auto": "A model classifier decides per tool call whether to approve or deny. Hands-off, but safer than Bypass — denials still happen.",
"acceptEdits": "Tutti i comandi vengono eseguiti automaticamente nell'area di lavoro. Modalità completamente automatica con esecuzione sandboxed.",
"bypassPermissions": "Accesso completo al sistema senza restrizioni. Tutti i comandi vengono eseguiti automaticamente con accesso completo a disco e rete. Usa con cautela.",
"plan": "Modalità pianificazione - nessun comando viene eseguito"
@@ -190,8 +188,7 @@
"codex": "Pronto a usare Codex con {{model}}. Inizia a digitare il tuo messaggio qui sotto.",
"gemini": "Pronto a usare Gemini con {{model}}. Inizia a digitare il tuo messaggio qui sotto.",
"default": "Seleziona un provider sopra per iniziare"
},
"pressToSearch": "Premi <kbd>{{shortcut}}</kbd> per cercare sessioni, file e commit"
}
},
"session": {
"continue": {

View File

@@ -47,8 +47,7 @@
"deleteSession": "Elimina questa sessione permanentemente",
"save": "Salva",
"cancel": "Annulla",
"clearSearch": "Cancella ricerca",
"openCommandPalette": "Apri tavolozza comandi"
"clearSearch": "Cancella ricerca"
},
"navigation": {
"chat": "Chat",

View File

@@ -88,14 +88,12 @@
"permissionMode": "権限モード",
"modes": {
"default": "デフォルトモード",
"auto": "Auto Mode",
"acceptEdits": "編集を許可",
"bypassPermissions": "権限をバイパス",
"plan": "プランモード"
},
"descriptions": {
"default": "信頼されたコマンドls、cat、grep、git statusなどのみ自動実行。その他のコマンドはスキップ。ワークスペースへの書き込みは可能。",
"auto": "A model classifier decides per tool call whether to approve or deny. Hands-off, but safer than Bypass — denials still happen.",
"acceptEdits": "ワークスペース内ですべてのコマンドを自動実行。サンドボックス環境での完全自動モード。",
"bypassPermissions": "制限なしの完全なシステムアクセス。すべてのコマンドがディスクとネットワークへの完全なアクセスで自動実行されます。注意して使用してください。",
"plan": "プランニングモード - コマンドは実行されません"
@@ -167,8 +165,7 @@
"cursor": "{{model}}でCursorを使用する準備ができました。下にメッセージを入力してください。",
"codex": "{{model}}でCodexを使用する準備ができました。下にメッセージを入力してください。",
"default": "上からプロバイダーを選択して開始してください"
},
"pressToSearch": "<kbd>{{shortcut}}</kbd> を押してセッション、ファイル、コミットを検索"
}
},
"session": {
"continue": {

View File

@@ -46,8 +46,7 @@
"editSessionName": "セッション名を手動で編集",
"deleteSession": "このセッションを完全に削除",
"save": "保存",
"cancel": "キャンセル",
"openCommandPalette": "コマンドパレットを開く"
"cancel": "キャンセル"
},
"navigation": {
"chat": "チャット",

View File

@@ -89,14 +89,12 @@
"permissionMode": "권한 모드",
"modes": {
"default": "기본 모드",
"auto": "Auto Mode",
"acceptEdits": "편집 허용",
"bypassPermissions": "권한 우회",
"plan": "Plan 모드"
},
"descriptions": {
"default": "신뢰할 수 있는 명령어(ls, cat, grep, git status 등)만 자동 실행됩니다. 다른 명령어는 건너뜁니다. 워크스페이스에 쓰기 가능.",
"auto": "A model classifier decides per tool call whether to approve or deny. Hands-off, but safer than Bypass — denials still happen.",
"acceptEdits": "워크스페이스 내에서 모든 명령어가 자동 실행됩니다. 샌드박스 내 완전 자동 모드.",
"bypassPermissions": "제한 없는 전체 시스템 접근. 모든 명령어가 전체 디스크 및 네트워크 접근 권한으로 자동 실행됩니다. 주의해서 사용하세요.",
"plan": "계획 모드 - 명령어가 실행되지 않습니다"
@@ -172,8 +170,7 @@
"codex": "{{model}} 모델로 Codex를 사용할 준비가 되었습니다. 아래에 메시지를 입력하세요.",
"gemini": "{{model}} 모델로 Gemini를 사용할 준비가 되었습니다. 아래에 메시지를 입력하세요.",
"default": "시작하려면 위에서 제공자를 선택하세요"
},
"pressToSearch": "<kbd>{{shortcut}}</kbd>를 눌러 세션, 파일 및 커밋을 검색하세요"
}
},
"session": {
"continue": {

View File

@@ -46,8 +46,7 @@
"editSessionName": "세션 이름 직접 편집",
"deleteSession": "이 세션 영구 삭제",
"save": "저장",
"cancel": "취소",
"openCommandPalette": "명령 팔레트 열기"
"cancel": "취소"
},
"navigation": {
"chat": "채팅",

View File

@@ -89,14 +89,12 @@
"permissionMode": "Режим разрешений",
"modes": {
"default": "Режим по умолчанию",
"auto": "Auto Mode",
"acceptEdits": "Принимать правки",
"bypassPermissions": "Обход разрешений",
"plan": "Режим планирования"
},
"descriptions": {
"default": "Только доверенные команды (ls, cat, grep, git status и т.д.) выполняются автоматически. Другие команды пропускаются. Может записывать в рабочее пространство.",
"auto": "A model classifier decides per tool call whether to approve or deny. Hands-off, but safer than Bypass — denials still happen.",
"acceptEdits": "Все команды выполняются автоматически в рабочем пространстве. Полный автоматический режим с изолированным выполнением.",
"bypassPermissions": "Полный системный доступ без ограничений. Все команды выполняются автоматически с полным доступом к диску и сети. Используйте с осторожностью.",
"plan": "Режим планирования - команды не выполняются"
@@ -190,8 +188,7 @@
"codex": "Готов использовать Codex с {{model}}. Начните вводить сообщение ниже.",
"gemini": "Готов использовать Gemini с {{model}}. Начните вводить сообщение ниже.",
"default": "Выберите провайдера выше для начала"
},
"pressToSearch": "Нажмите <kbd>{{shortcut}}</kbd>, чтобы искать сессии, файлы и коммиты"
}
},
"session": {
"continue": {

View File

@@ -47,8 +47,7 @@
"deleteSession": "Удалить этот сеанс навсегда",
"save": "Сохранить",
"cancel": "Отмена",
"clearSearch": "Очистить поиск",
"openCommandPalette": "Открыть палитру команд"
"clearSearch": "Очистить поиск"
},
"navigation": {
"chat": "Чат",

View File

@@ -89,14 +89,12 @@
"permissionMode": "İzin Modu",
"modes": {
"default": "Varsayılan Mod",
"auto": "Auto Mode",
"acceptEdits": "Düzenlemeleri Kabul Et",
"bypassPermissions": "İzinleri Atla",
"plan": "Plan Modu"
},
"descriptions": {
"default": "Sadece güvenilir komutlar (ls, cat, grep, git status, vb.) otomatik çalışır. Diğer komutlar atlanır. Çalışma alanına yazabilir.",
"auto": "A model classifier decides per tool call whether to approve or deny. Hands-off, but safer than Bypass — denials still happen.",
"acceptEdits": "Tüm komutlar çalışma alanı içinde otomatik çalışır. Sandbox'lu çalıştırma ile tam otomatik mod.",
"bypassPermissions": "Kısıtlama olmadan tam sistem erişimi. Tüm komutlar tam disk ve ağ erişimiyle otomatik çalışır. Dikkatli kullan.",
"plan": "Planlama modu — hiçbir komut çalıştırılmaz"
@@ -190,8 +188,7 @@
"codex": "Codex'i {{model}} ile kullanmaya hazır. Mesajını aşağıya yazmaya başla.",
"gemini": "Gemini'yi {{model}} ile kullanmaya hazır. Mesajını aşağıya yazmaya başla.",
"default": "Başlamak için yukarıdan bir sağlayıcı seç"
},
"pressToSearch": "Oturumlarda, dosyalarda ve commit'lerde arama yapmak için <kbd>{{shortcut}}</kbd> tuşlarına bas"
}
},
"session": {
"continue": {

View File

@@ -47,8 +47,7 @@
"deleteSession": "Bu oturumu kalıcı olarak sil",
"save": "Kaydet",
"cancel": "İptal",
"clearSearch": "Aramayı temizle",
"openCommandPalette": "Komut paletini aç"
"clearSearch": "Aramayı temizle"
},
"navigation": {
"chat": "Sohbet",

View File

@@ -89,14 +89,12 @@
"permissionMode": "权限模式",
"modes": {
"default": "默认模式",
"auto": "Auto Mode",
"acceptEdits": "编辑模式",
"bypassPermissions": "无限制模式",
"plan": "计划模式"
},
"descriptions": {
"default": "只有受信任的命令ls、cat、grep、git status 等)自动运行。其他命令将被跳过。可以写入工作区。",
"auto": "A model classifier decides per tool call whether to approve or deny. Hands-off, but safer than Bypass — denials still happen.",
"acceptEdits": "工作区内的所有命令自动运行。完全自动模式,具有沙盒执行功能。",
"bypassPermissions": "完全的系统访问,无限制。所有命令自动运行,具有完整的磁盘和网络访问权限。请谨慎使用。",
"plan": "计划模式 - 不执行任何命令"
@@ -172,8 +170,7 @@
"codex": "准备好使用带有 {{model}} 的 Codex。请在下方开始输入您的消息。",
"gemini": "准备好使用带有 {{model}} 的 Gemini。请在下方开始输入您的消息。",
"default": "请在上方选择一个提供者以开始"
},
"pressToSearch": "按 <kbd>{{shortcut}}</kbd> 搜索会话、文件和提交"
}
},
"session": {
"continue": {

View File

@@ -47,8 +47,7 @@
"deleteSession": "永久删除此会话",
"save": "保存",
"cancel": "取消",
"clearSearch": "清除搜索",
"openCommandPalette": "打开命令面板"
"clearSearch": "清除搜索"
},
"navigation": {
"chat": "聊天",

View File

@@ -1,107 +1,320 @@
import * as React from 'react';
import { Command as CommandPrimitive } from 'cmdk';
import { Search } from 'lucide-react';
import { cn } from '../../../lib/utils';
const Command = React.forwardRef<
React.ElementRef<typeof CommandPrimitive>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive>
>(({ className, ...props }, ref) => (
<CommandPrimitive
ref={ref}
className={cn('flex flex-col', className)}
{...props}
/>
));
Command.displayName = CommandPrimitive.displayName;
/*
* Lightweight command palette — inspired by cmdk but no external deps.
*
* Architecture:
* - Command owns the search string and a flat list of registered item values.
* - Items register via context on mount and deregister on unmount.
* - Filtering, active index, and keyboard nav happen centrally in Command.
* - Items read their "is visible" / "is active" state from context.
*/
const CommandInput = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Input>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>
>(({ className, ...props }, ref) => (
<div className="flex items-center border-b px-3">
<Search className="mr-2 h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<CommandPrimitive.Input
interface ItemEntry {
id: string;
value: string; // searchable text (lowercase)
onSelect: () => void;
element: HTMLElement | null;
}
interface CommandContextValue {
search: string;
setSearch: (value: string) => void;
/** Set of visible item IDs after filtering (derived state, not a ref). */
visibleIds: Set<string>;
activeId: string | null;
setActiveId: (id: string | null) => void;
register: (entry: ItemEntry) => void;
unregister: (id: string) => void;
updateEntry: (id: string, patch: Partial<Pick<ItemEntry, 'value' | 'onSelect' | 'element'>>) => void;
}
const CommandContext = React.createContext<CommandContextValue | null>(null);
function useCommand() {
const ctx = React.useContext(CommandContext);
if (!ctx) throw new Error('Command components must be used within <Command>');
return ctx;
}
/* ─── Command (root) ─────────────────────────────────────────────── */
type CommandProps = React.HTMLAttributes<HTMLDivElement>;
const Command = React.forwardRef<HTMLDivElement, CommandProps>(
({ className, children, ...props }, ref) => {
const [search, setSearch] = React.useState('');
const entriesRef = React.useRef<Map<string, ItemEntry>>(new Map());
// Bump this counter whenever the entry set changes so derived state recalculates
const [revision, setRevision] = React.useState(0);
const register = React.useCallback((entry: ItemEntry) => {
entriesRef.current.set(entry.id, entry);
setRevision(r => r + 1);
}, []);
const unregister = React.useCallback((id: string) => {
entriesRef.current.delete(id);
setRevision(r => r + 1);
}, []);
const updateEntry = React.useCallback((id: string, patch: Partial<Pick<ItemEntry, 'value' | 'onSelect' | 'element'>>) => {
const existing = entriesRef.current.get(id);
if (existing) {
Object.assign(existing, patch);
}
}, []);
// Derive visible IDs from search + entries
const visibleIds = React.useMemo(() => {
const lowerSearch = search.toLowerCase();
const ids = new Set<string>();
for (const [id, entry] of entriesRef.current) {
if (!lowerSearch || entry.value.includes(lowerSearch)) {
ids.add(id);
}
}
return ids;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [search, revision]);
// Ordered list of visible entries (preserves DOM order via insertion order)
const visibleEntries = React.useMemo(() => {
const result: ItemEntry[] = [];
for (const [, entry] of entriesRef.current) {
if (visibleIds.has(entry.id)) result.push(entry);
}
return result;
}, [visibleIds]);
// Active item tracking
const [activeId, setActiveId] = React.useState<string | null>(null);
// Reset active to first visible item when search or visible set changes
React.useEffect(() => {
setActiveId(visibleEntries.length > 0 ? visibleEntries[0].id : null);
}, [visibleEntries]);
const handleKeyDown = React.useCallback((e: React.KeyboardEvent) => {
if (e.key === 'ArrowDown' || e.key === 'ArrowUp' || e.key === 'Enter') {
e.preventDefault();
} else {
return;
}
const entries = visibleEntries;
if (entries.length === 0) return;
if (e.key === 'Enter') {
const active = entries.find(entry => entry.id === activeId);
active?.onSelect();
return;
}
const currentIndex = entries.findIndex(entry => entry.id === activeId);
let nextIndex: number;
if (e.key === 'ArrowDown') {
nextIndex = currentIndex < entries.length - 1 ? currentIndex + 1 : 0;
} else {
nextIndex = currentIndex > 0 ? currentIndex - 1 : entries.length - 1;
}
const nextId = entries[nextIndex].id;
setActiveId(nextId);
// Scroll the active item into view
const nextEntry = entries[nextIndex];
nextEntry.element?.scrollIntoView({ block: 'nearest' });
}, [visibleEntries, activeId]);
const value = React.useMemo<CommandContextValue>(
() => ({ search, setSearch, visibleIds, activeId, setActiveId, register, unregister, updateEntry }),
[search, visibleIds, activeId, register, unregister, updateEntry]
);
return (
<CommandContext.Provider value={value}>
<div
ref={ref}
role="combobox"
aria-expanded="true"
aria-haspopup="listbox"
className={cn('flex flex-col', className)}
onKeyDown={handleKeyDown}
{...props}
>
{children}
</div>
</CommandContext.Provider>
);
}
);
Command.displayName = 'Command';
/* ─── CommandInput ───────────────────────────────────────────────── */
type CommandInputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'value' | 'type'>;
const CommandInput = React.forwardRef<HTMLInputElement, CommandInputProps>(
({ className, placeholder = 'Search...', ...props }, ref) => {
const { search, setSearch } = useCommand();
return (
<div className="flex items-center border-b px-3" role="presentation">
<Search className="mr-2 h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
<input
ref={ref}
type="text"
role="searchbox"
aria-autocomplete="list"
autoComplete="off"
autoCorrect="off"
spellCheck={false}
value={search}
onChange={(e) => setSearch(e.target.value)}
placeholder={placeholder}
className={cn(
'flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none',
'placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50',
className
)}
{...props}
/>
</div>
);
}
);
CommandInput.displayName = 'CommandInput';
/* ─── CommandList ────────────────────────────────────────────────── */
const CommandList = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
'flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none',
'placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
role="listbox"
className={cn('max-h-[300px] overflow-y-auto overflow-x-hidden', className)}
{...props}
/>
</div>
));
CommandInput.displayName = CommandPrimitive.Input.displayName;
)
);
CommandList.displayName = 'CommandList';
const CommandList = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.List>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>
>(({ className, ...props }, ref) => (
<CommandPrimitive.List
ref={ref}
className={cn('max-h-[300px] overflow-y-auto overflow-x-hidden', className)}
{...props}
/>
));
CommandList.displayName = CommandPrimitive.List.displayName;
/* ─── CommandEmpty ───────────────────────────────────────────────── */
const CommandEmpty = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Empty>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
>((props, ref) => (
<CommandPrimitive.Empty
ref={ref}
className="py-6 text-center text-sm text-muted-foreground"
{...props}
/>
));
CommandEmpty.displayName = CommandPrimitive.Empty.displayName;
const CommandEmpty = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => {
const { search, visibleIds } = useCommand();
const CommandGroup = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Group>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>
>(({ className, ...props }, ref) => (
<CommandPrimitive.Group
ref={ref}
className={cn(
'overflow-hidden p-1 text-foreground',
'[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground',
className,
)}
{...props}
/>
));
CommandGroup.displayName = CommandPrimitive.Group.displayName;
// Only show when there's a search term and zero matches
if (!search || visibleIds.size > 0) return null;
const CommandItem = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
>(({ className, ...props }, ref) => (
<CommandPrimitive.Item
ref={ref}
className={cn(
'relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none',
'data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground',
'data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50',
className,
)}
{...props}
/>
));
CommandItem.displayName = CommandPrimitive.Item.displayName;
return (
<div ref={ref} className={cn('py-6 text-center text-sm text-muted-foreground', className)} {...props} />
);
}
);
CommandEmpty.displayName = 'CommandEmpty';
const CommandSeparator = React.forwardRef<
React.ElementRef<typeof CommandPrimitive.Separator>,
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>
>(({ className, ...props }, ref) => (
<CommandPrimitive.Separator
ref={ref}
className={cn('-mx-1 h-px bg-border', className)}
{...props}
/>
));
CommandSeparator.displayName = CommandPrimitive.Separator.displayName;
/* ─── CommandGroup ───────────────────────────────────────────────── */
interface CommandGroupProps extends React.HTMLAttributes<HTMLDivElement> {
heading?: React.ReactNode;
}
const CommandGroup = React.forwardRef<HTMLDivElement, CommandGroupProps>(
({ className, heading, children, ...props }, ref) => (
<div ref={ref} className={cn('overflow-hidden p-1', className)} role="group" aria-label={typeof heading === 'string' ? heading : undefined} {...props}>
{heading && (
<div className="px-2 py-1.5 text-xs font-medium text-muted-foreground" role="presentation">
{heading}
</div>
)}
{children}
</div>
)
);
CommandGroup.displayName = 'CommandGroup';
/* ─── CommandItem ────────────────────────────────────────────────── */
interface CommandItemProps extends React.HTMLAttributes<HTMLDivElement> {
value?: string;
onSelect?: () => void;
disabled?: boolean;
}
const CommandItem = React.forwardRef<HTMLDivElement, CommandItemProps>(
({ className, value, onSelect, disabled, children, ...props }, ref) => {
const { visibleIds, activeId, setActiveId, register, unregister, updateEntry } = useCommand();
const stableId = React.useId();
const elementRef = React.useRef<HTMLElement | null>(null);
const searchableText = value || (typeof children === 'string' ? children : '');
// Register on mount, unregister on unmount
React.useEffect(() => {
register({
id: stableId,
value: searchableText.toLowerCase(),
onSelect: onSelect || (() => {}),
element: elementRef.current,
});
return () => unregister(stableId);
// Only re-register when the identity changes, not onSelect
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [stableId, searchableText, register, unregister]);
// Keep onSelect up-to-date without re-registering
React.useEffect(() => {
updateEntry(stableId, { onSelect: onSelect || (() => {}) });
}, [stableId, onSelect, updateEntry]);
// Keep element ref up-to-date
const setRef = React.useCallback((node: HTMLDivElement | null) => {
elementRef.current = node;
updateEntry(stableId, { element: node });
if (typeof ref === 'function') ref(node);
else if (ref) ref.current = node;
}, [stableId, updateEntry, ref]);
// Hidden by filter
if (!visibleIds.has(stableId)) return null;
const isActive = activeId === stableId;
return (
<div
ref={setRef}
role="option"
aria-selected={isActive}
aria-disabled={disabled || undefined}
data-active={isActive || undefined}
className={cn(
'relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none',
isActive && 'bg-accent text-accent-foreground',
disabled && 'pointer-events-none opacity-50',
className
)}
onPointerMove={() => { if (!disabled && activeId !== stableId) setActiveId(stableId); }}
onClick={() => !disabled && onSelect?.()}
{...props}
>
{children}
</div>
);
}
);
CommandItem.displayName = 'CommandItem';
/* ─── CommandSeparator ───────────────────────────────────────────── */
const CommandSeparator = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div ref={ref} className={cn('-mx-1 h-px bg-border', className)} {...props} />
)
);
CommandSeparator.displayName = 'CommandSeparator';
export { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandSeparator };

View File

@@ -40,20 +40,6 @@ export interface NormalizedMessage {
// kind-specific fields (flat for simplicity)
role?: 'user' | 'assistant';
content?: string;
/**
* Mirrors optional transcript metadata from the server.
*
* These fields are currently used by Claude history normalization so local
* slash commands, local stdout, and compact summaries do not disappear when
* the session store hydrates from REST history.
*/
displayText?: string;
commandName?: string;
commandMessage?: string;
commandArgs?: string;
isLocalCommand?: boolean;
isLocalCommandStdout?: boolean;
isCompactSummary?: boolean;
images?: string[];
toolName?: string;
toolInput?: unknown;
@@ -118,126 +104,17 @@ function createEmptySlot(): SessionSlot {
}
/**
* Compute merged messages: server + realtime, deduped by id and adjacent
* assistant echo (same trimmed text), so finalized stream rows do not stack
* on top of the persisted copy before realtime is cleared.
* Compute merged messages: server + realtime, deduped by id.
* Server messages take priority (they're the persisted source of truth).
* Realtime messages that aren't yet in server stay (in-flight streaming).
*/
function userTextFingerprint(m: NormalizedMessage): string | null {
if (m.kind !== 'text' || m.role !== 'user') return null;
const t = (m.content || '').trim();
return t.length > 0 ? t : null;
}
/**
* After `finalizeStreaming`, the client holds a synthetic assistant `text` row
* while the sessions API soon returns the same reply with a different id.
* Those sit back-to-back in merged order and look like duplicate bubbles until
* `refreshFromServer` clears realtime. Collapse same-text assistant rows and
* stream_placeholder → text when content matches.
*/
function dedupeAdjacentAssistantEchoes(merged: NormalizedMessage[]): NormalizedMessage[] {
const out: NormalizedMessage[] = [];
for (const m of merged) {
const prev = out[out.length - 1];
if (prev) {
if (prev.kind === 'stream_delta' && m.kind === 'text' && m.role === 'assistant') {
const ps = (prev.content || '').trim();
const ms = (m.content || '').trim();
if (ps.length > 0 && ps === ms) {
out[out.length - 1] = m;
continue;
}
}
if (
prev.kind === 'text'
&& m.kind === 'text'
&& prev.role === 'assistant'
&& m.role === 'assistant'
) {
const ms = (m.content || '').trim();
if (ms.length > 0 && ms === (prev.content || '').trim()) {
continue;
}
}
}
out.push(m);
}
return out;
}
function computeMerged(server: NormalizedMessage[], realtime: NormalizedMessage[]): NormalizedMessage[] {
if (realtime.length === 0) return server;
if (server.length === 0) return dedupeAdjacentAssistantEchoes(realtime);
if (server.length === 0) return realtime;
const serverIds = new Set(server.map(m => m.id));
const serverUserTexts = new Set(
server.map(userTextFingerprint).filter((t): t is string => t !== null),
);
const extra = realtime.filter((m) => {
if (serverIds.has(m.id)) return false;
// Optimistic user rows use `local_*` ids; once the same text exists on the
// server-backed copy, drop the realtime echo to avoid duplicate bubbles.
if (m.id.startsWith('local_')) {
const fp = userTextFingerprint(m);
if (fp && serverUserTexts.has(fp)) return false;
}
return true;
});
const extra = realtime.filter(m => !serverIds.has(m.id));
if (extra.length === 0) return server;
return dedupeAdjacentAssistantEchoes([...server, ...extra]);
}
function compareMessagesByTimestamp(left: NormalizedMessage, right: NormalizedMessage): number {
const leftTime = Date.parse(left.timestamp);
const rightTime = Date.parse(right.timestamp);
if (Number.isNaN(leftTime) || Number.isNaN(rightTime) || leftTime === rightTime) {
return 0;
}
return leftTime - rightTime;
}
function rewriteMessageSessionId(
msg: NormalizedMessage,
fromSessionId: string,
toSessionId: string,
): NormalizedMessage {
const streamingSourceId = `__streaming_${fromSessionId}`;
const nextId = msg.id === streamingSourceId ? `__streaming_${toSessionId}` : msg.id;
if (msg.sessionId === toSessionId && nextId === msg.id) {
return msg;
}
return {
...msg,
id: nextId,
sessionId: toSessionId,
};
}
function mergeMessagesById(
existing: NormalizedMessage[],
incoming: NormalizedMessage[],
): NormalizedMessage[] {
if (existing.length === 0) return incoming;
if (incoming.length === 0) return existing;
const merged = [...existing, ...incoming];
const deduped: NormalizedMessage[] = [];
const seen = new Set<string>();
for (const msg of merged) {
if (seen.has(msg.id)) {
continue;
}
seen.add(msg.id);
deduped.push(msg);
}
deduped.sort(compareMessagesByTimestamp);
return deduped;
return [...server, ...extra];
}
/**
@@ -264,59 +141,28 @@ const MAX_REALTIME_MESSAGES = 500;
export function useSessionStore() {
const storeRef = useRef(new Map<string, SessionSlot>());
const sessionAliasesRef = useRef(new Map<string, string>());
const activeSessionIdRef = useRef<string | null>(null);
// Bump to force re-render — only when the active session's data changes
const [, setTick] = useState(0);
const notify = useCallback((sessionId: string) => {
const aliases = sessionAliasesRef.current;
let resolvedSessionId = sessionId;
const visited = new Set<string>();
while (aliases.has(resolvedSessionId) && !visited.has(resolvedSessionId)) {
visited.add(resolvedSessionId);
resolvedSessionId = aliases.get(resolvedSessionId)!;
}
if (resolvedSessionId === activeSessionIdRef.current) {
if (sessionId === activeSessionIdRef.current) {
setTick(n => n + 1);
}
}, []);
const resolveSessionId = useCallback((sessionId: string | null | undefined): string | null => {
if (!sessionId) {
return null;
}
const aliases = sessionAliasesRef.current;
let resolvedSessionId = sessionId;
const visited = new Set<string>();
while (aliases.has(resolvedSessionId) && !visited.has(resolvedSessionId)) {
visited.add(resolvedSessionId);
resolvedSessionId = aliases.get(resolvedSessionId)!;
}
return resolvedSessionId;
const setActiveSession = useCallback((sessionId: string | null) => {
activeSessionIdRef.current = sessionId;
}, []);
const setActiveSession = useCallback((sessionId: string | null) => {
activeSessionIdRef.current = resolveSessionId(sessionId);
}, [resolveSessionId]);
const getSlot = useCallback((sessionId: string): SessionSlot => {
const resolvedSessionId = resolveSessionId(sessionId) ?? sessionId;
const store = storeRef.current;
if (!store.has(resolvedSessionId)) {
store.set(resolvedSessionId, createEmptySlot());
if (!store.has(sessionId)) {
store.set(sessionId, createEmptySlot());
}
return store.get(resolvedSessionId)!;
}, [resolveSessionId]);
return store.get(sessionId)!;
}, []);
const has = useCallback((sessionId: string) => {
const resolvedSessionId = resolveSessionId(sessionId) ?? sessionId;
return storeRef.current.has(resolvedSessionId);
}, [resolveSessionId]);
const has = useCallback((sessionId: string) => storeRef.current.has(sessionId), []);
/**
* Fetch messages from the provider sessions endpoint and populate serverMessages.
@@ -333,10 +179,9 @@ export function useSessionStore() {
offset?: number;
} = {},
) => {
const resolvedSessionId = resolveSessionId(sessionId) ?? sessionId;
const slot = getSlot(resolvedSessionId);
const slot = getSlot(sessionId);
slot.status = 'loading';
notify(resolvedSessionId);
notify(sessionId);
try {
const params = new URLSearchParams();
@@ -346,7 +191,7 @@ export function useSessionStore() {
}
const qs = params.toString();
const url = `/api/providers/sessions/${encodeURIComponent(resolvedSessionId)}/messages${qs ? `?${qs}` : ''}`;
const url = `/api/providers/sessions/${encodeURIComponent(sessionId)}/messages${qs ? `?${qs}` : ''}`;
const response = await authenticatedFetch(url);
if (!response.ok) {
@@ -367,15 +212,15 @@ export function useSessionStore() {
slot.tokenUsage = data.tokenUsage;
}
notify(resolvedSessionId);
notify(sessionId);
return slot;
} catch (error) {
console.error(`[SessionStore] fetch failed for ${resolvedSessionId}:`, error);
console.error(`[SessionStore] fetch failed for ${sessionId}:`, error);
slot.status = 'error';
notify(resolvedSessionId);
notify(sessionId);
return slot;
}
}, [getSlot, notify, resolveSessionId]);
}, [getSlot, notify]);
/**
* Load older (paginated) messages and prepend to serverMessages.
@@ -389,8 +234,7 @@ export function useSessionStore() {
limit?: number;
} = {},
) => {
const resolvedSessionId = resolveSessionId(sessionId) ?? sessionId;
const slot = getSlot(resolvedSessionId);
const slot = getSlot(sessionId);
if (!slot.hasMore) return slot;
const params = new URLSearchParams();
@@ -399,7 +243,7 @@ export function useSessionStore() {
params.append('offset', String(slot.offset));
const qs = params.toString();
const url = `/api/providers/sessions/${encodeURIComponent(resolvedSessionId)}/messages${qs ? `?${qs}` : ''}`;
const url = `/api/providers/sessions/${encodeURIComponent(sessionId)}/messages${qs ? `?${qs}` : ''}`;
try {
const response = await authenticatedFetch(url);
@@ -412,54 +256,43 @@ export function useSessionStore() {
slot.hasMore = Boolean(data.hasMore);
slot.offset = slot.offset + olderMessages.length;
recomputeMergedIfNeeded(slot);
notify(resolvedSessionId);
notify(sessionId);
return slot;
} catch (error) {
console.error(`[SessionStore] fetchMore failed for ${resolvedSessionId}:`, error);
console.error(`[SessionStore] fetchMore failed for ${sessionId}:`, error);
return slot;
}
}, [getSlot, notify, resolveSessionId]);
}, [getSlot, notify]);
/**
* Append a realtime (WebSocket) message to the correct session slot.
* This works regardless of which session is actively viewed.
*/
const appendRealtime = useCallback((sessionId: string, msg: NormalizedMessage) => {
const resolvedSessionId = resolveSessionId(sessionId) ?? sessionId;
const slot = getSlot(resolvedSessionId);
const normalizedMessage =
msg.sessionId === resolvedSessionId
? msg
: { ...msg, sessionId: resolvedSessionId };
let updated = [...slot.realtimeMessages, normalizedMessage];
const slot = getSlot(sessionId);
let updated = [...slot.realtimeMessages, msg];
if (updated.length > MAX_REALTIME_MESSAGES) {
updated = updated.slice(-MAX_REALTIME_MESSAGES);
}
slot.realtimeMessages = updated;
recomputeMergedIfNeeded(slot);
notify(resolvedSessionId);
}, [getSlot, notify, resolveSessionId]);
notify(sessionId);
}, [getSlot, notify]);
/**
* Append multiple realtime messages at once (batch).
*/
const appendRealtimeBatch = useCallback((sessionId: string, msgs: NormalizedMessage[]) => {
if (msgs.length === 0) return;
const resolvedSessionId = resolveSessionId(sessionId) ?? sessionId;
const slot = getSlot(resolvedSessionId);
const normalizedMessages = msgs.map((msg) =>
msg.sessionId === resolvedSessionId
? msg
: { ...msg, sessionId: resolvedSessionId },
);
let updated = [...slot.realtimeMessages, ...normalizedMessages];
const slot = getSlot(sessionId);
let updated = [...slot.realtimeMessages, ...msgs];
if (updated.length > MAX_REALTIME_MESSAGES) {
updated = updated.slice(-MAX_REALTIME_MESSAGES);
}
slot.realtimeMessages = updated;
recomputeMergedIfNeeded(slot);
notify(resolvedSessionId);
}, [getSlot, notify, resolveSessionId]);
notify(sessionId);
}, [getSlot, notify]);
/**
* Re-fetch serverMessages from the provider sessions endpoint.
@@ -472,13 +305,12 @@ export function useSessionStore() {
projectPath?: string;
} = {},
) => {
const resolvedSessionId = resolveSessionId(sessionId) ?? sessionId;
const slot = getSlot(resolvedSessionId);
const slot = getSlot(sessionId);
try {
const params = new URLSearchParams();
const qs = params.toString();
const url = `/api/providers/sessions/${encodeURIComponent(resolvedSessionId)}/messages${qs ? `?${qs}` : ''}`;
const url = `/api/providers/sessions/${encodeURIComponent(sessionId)}/messages${qs ? `?${qs}` : ''}`;
const response = await authenticatedFetch(url);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
@@ -491,43 +323,40 @@ export function useSessionStore() {
// drop realtime messages that the server has caught up with to prevent unbounded growth.
slot.realtimeMessages = [];
recomputeMergedIfNeeded(slot);
notify(resolvedSessionId);
notify(sessionId);
} catch (error) {
console.error(`[SessionStore] refresh failed for ${resolvedSessionId}:`, error);
console.error(`[SessionStore] refresh failed for ${sessionId}:`, error);
}
}, [getSlot, notify, resolveSessionId]);
}, [getSlot, notify]);
/**
* Update session status.
*/
const setStatus = useCallback((sessionId: string, status: SessionStatus) => {
const resolvedSessionId = resolveSessionId(sessionId) ?? sessionId;
const slot = getSlot(resolvedSessionId);
const slot = getSlot(sessionId);
slot.status = status;
notify(resolvedSessionId);
}, [getSlot, notify, resolveSessionId]);
notify(sessionId);
}, [getSlot, notify]);
/**
* Check if a session's data is stale (>30s old).
*/
const isStale = useCallback((sessionId: string) => {
const resolvedSessionId = resolveSessionId(sessionId) ?? sessionId;
const slot = storeRef.current.get(resolvedSessionId);
const slot = storeRef.current.get(sessionId);
if (!slot) return true;
return Date.now() - slot.fetchedAt > STALE_THRESHOLD_MS;
}, [resolveSessionId]);
}, []);
/**
* Update or create a streaming message (accumulated text so far).
* Uses a well-known ID so subsequent calls replace the same message.
*/
const updateStreaming = useCallback((sessionId: string, accumulatedText: string, msgProvider: LLMProvider) => {
const resolvedSessionId = resolveSessionId(sessionId) ?? sessionId;
const slot = getSlot(resolvedSessionId);
const streamId = `__streaming_${resolvedSessionId}`;
const slot = getSlot(sessionId);
const streamId = `__streaming_${sessionId}`;
const msg: NormalizedMessage = {
id: streamId,
sessionId: resolvedSessionId,
sessionId,
timestamp: new Date().toISOString(),
provider: msgProvider,
kind: 'stream_delta',
@@ -541,18 +370,17 @@ export function useSessionStore() {
slot.realtimeMessages = [...slot.realtimeMessages, msg];
}
recomputeMergedIfNeeded(slot);
notify(resolvedSessionId);
}, [getSlot, notify, resolveSessionId]);
notify(sessionId);
}, [getSlot, notify]);
/**
* Finalize streaming: convert the streaming message to a regular text message.
* The well-known streaming ID is replaced with a unique text message ID.
*/
const finalizeStreaming = useCallback((sessionId: string) => {
const resolvedSessionId = resolveSessionId(sessionId) ?? sessionId;
const slot = storeRef.current.get(resolvedSessionId);
const slot = storeRef.current.get(sessionId);
if (!slot) return;
const streamId = `__streaming_${resolvedSessionId}`;
const streamId = `__streaming_${sessionId}`;
const idx = slot.realtimeMessages.findIndex(m => m.id === streamId);
if (idx >= 0) {
const stream = slot.realtimeMessages[idx];
@@ -564,104 +392,35 @@ export function useSessionStore() {
role: 'assistant',
};
recomputeMergedIfNeeded(slot);
notify(resolvedSessionId);
notify(sessionId);
}
}, [notify, resolveSessionId]);
}, [notify]);
/**
* Clear realtime messages for a session (e.g., after stream completes and server fetch catches up).
*/
const clearRealtime = useCallback((sessionId: string) => {
const resolvedSessionId = resolveSessionId(sessionId) ?? sessionId;
const slot = storeRef.current.get(resolvedSessionId);
const slot = storeRef.current.get(sessionId);
if (slot) {
slot.realtimeMessages = [];
recomputeMergedIfNeeded(slot);
notify(resolvedSessionId);
notify(sessionId);
}
}, [notify, resolveSessionId]);
}, [notify]);
/**
* Get merged messages for a session (for rendering).
*/
const getMessages = useCallback((sessionId: string): NormalizedMessage[] => {
const resolvedSessionId = resolveSessionId(sessionId) ?? sessionId;
return storeRef.current.get(resolvedSessionId)?.merged ?? [];
}, [resolveSessionId]);
return storeRef.current.get(sessionId)?.merged ?? [];
}, []);
/**
* Get session slot (for status, pagination info, etc.).
*/
const getSessionSlot = useCallback((sessionId: string): SessionSlot | undefined => {
const resolvedSessionId = resolveSessionId(sessionId) ?? sessionId;
return storeRef.current.get(resolvedSessionId);
}, [resolveSessionId]);
const replaceSessionId = useCallback((fromSessionId: string, toSessionId: string) => {
const resolvedFromSessionId = resolveSessionId(fromSessionId) ?? fromSessionId;
const resolvedToSessionId = resolveSessionId(toSessionId) ?? toSessionId;
if (resolvedFromSessionId === resolvedToSessionId) {
sessionAliasesRef.current.set(fromSessionId, resolvedToSessionId);
return;
}
const store = storeRef.current;
const sourceSlot = store.get(resolvedFromSessionId);
const targetSlot = store.get(resolvedToSessionId) ?? createEmptySlot();
if (sourceSlot) {
const migratedServerMessages = sourceSlot.serverMessages.map((msg) =>
rewriteMessageSessionId(msg, resolvedFromSessionId, resolvedToSessionId),
);
const migratedRealtimeMessages = sourceSlot.realtimeMessages.map((msg) =>
rewriteMessageSessionId(msg, resolvedFromSessionId, resolvedToSessionId),
);
targetSlot.serverMessages = mergeMessagesById(targetSlot.serverMessages, migratedServerMessages);
targetSlot.realtimeMessages = mergeMessagesById(targetSlot.realtimeMessages, migratedRealtimeMessages);
if (targetSlot.realtimeMessages.length > MAX_REALTIME_MESSAGES) {
targetSlot.realtimeMessages = targetSlot.realtimeMessages.slice(-MAX_REALTIME_MESSAGES);
}
targetSlot.status =
sourceSlot.status === 'error'
? 'error'
: sourceSlot.status === 'streaming' || targetSlot.status === 'streaming'
? 'streaming'
: sourceSlot.status === 'loading' || targetSlot.status === 'loading'
? 'loading'
: targetSlot.status;
targetSlot.fetchedAt = Math.max(targetSlot.fetchedAt, sourceSlot.fetchedAt, Date.now());
targetSlot.total = Math.max(
targetSlot.total,
sourceSlot.total,
targetSlot.serverMessages.length,
targetSlot.realtimeMessages.length,
);
targetSlot.hasMore = targetSlot.hasMore || sourceSlot.hasMore;
targetSlot.offset = Math.max(targetSlot.offset, sourceSlot.offset);
targetSlot.tokenUsage = targetSlot.tokenUsage ?? sourceSlot.tokenUsage;
recomputeMergedIfNeeded(targetSlot);
store.set(resolvedToSessionId, targetSlot);
store.delete(resolvedFromSessionId);
}
sessionAliasesRef.current.set(resolvedFromSessionId, resolvedToSessionId);
sessionAliasesRef.current.set(fromSessionId, resolvedToSessionId);
for (const [aliasSessionId, targetSessionId] of sessionAliasesRef.current.entries()) {
if (targetSessionId === resolvedFromSessionId) {
sessionAliasesRef.current.set(aliasSessionId, resolvedToSessionId);
}
}
if (activeSessionIdRef.current === resolvedFromSessionId) {
activeSessionIdRef.current = resolvedToSessionId;
}
notify(resolvedToSessionId);
}, [notify, resolveSessionId]);
return storeRef.current.get(sessionId);
}, []);
return useMemo(() => ({
getSlot,
@@ -679,12 +438,11 @@ export function useSessionStore() {
clearRealtime,
getMessages,
getSessionSlot,
replaceSessionId,
}), [
getSlot, has, fetchFromServer, fetchMore,
appendRealtime, appendRealtimeBatch, refreshFromServer,
setActiveSession, setStatus, isStale, updateStreaming, finalizeStreaming,
clearRealtime, getMessages, getSessionSlot, replaceSessionId,
clearRealtime, getMessages, getSessionSlot,
]);
}

View File

@@ -3,6 +3,8 @@ export {};
declare global {
interface Window {
__ROUTER_BASENAME__?: string;
refreshProjects?: () => void | Promise<void>;
openSettings?: (tab?: string) => void;
}
interface EventSourceEventMap {

View File

@@ -54,7 +54,6 @@ export const api = {
// After the projectName → projectId migration the path/query identifier is
// the DB-assigned `projectId`; parameter names reflect that for clarity.
projects: () => authenticatedFetch('/api/projects'),
archivedProjects: () => authenticatedFetch('/api/projects/archived'),
projectSessions: (projectId, { limit = 20, offset = 0 } = {}) => {
const params = new URLSearchParams();
params.set('limit', String(limit));
@@ -79,28 +78,9 @@ export const api = {
method: 'PUT',
body: JSON.stringify({ displayName }),
}),
restoreProject: (projectId) =>
authenticatedFetch(`/api/projects/${encodeURIComponent(projectId)}/restore`, {
method: 'POST',
}),
// Session deletion now mirrors project deletion:
// - default: archive only (`isArchived = 1`)
// - hardDelete: remove the row and, by default, its persisted transcript file
deleteSession: (sessionId, hardDelete = false) => {
const params = new URLSearchParams();
if (hardDelete) {
params.set('force', 'true');
}
const qs = params.toString();
return authenticatedFetch(`/api/providers/sessions/${sessionId}${qs ? `?${qs}` : ''}`, {
deleteSession: (sessionId) =>
authenticatedFetch(`/api/providers/sessions/${sessionId}`, {
method: 'DELETE',
});
},
getArchivedSessions: () =>
authenticatedFetch('/api/providers/sessions/archived'),
restoreSession: (sessionId) =>
authenticatedFetch(`/api/providers/sessions/${sessionId}/restore`, {
method: 'POST',
}),
renameSession: (sessionId, summary) =>
authenticatedFetch(`/api/providers/sessions/${sessionId}`, {