Commit Graph

180 Commits

Author SHA1 Message Date
Pleasurecruise
a54bf43217 fix(code-cli): address review feedback
Signed-off-by: Pleasurecruise <3196812536@qq.com>
2026-07-06 15:51:58 +08:00
eeee0717
89be892e1e Merge upstream/main into refactor/code-cli
Signed-off-by: eeee0717 <chentao020717Work@outlook.com>
2026-07-04 21:53:10 +08:00
fullex
315c0baa72 build(eslint): add renderer dependency-direction boundary gate
Enforce the renderer type-bucket layering (renderer-architecture.md §5)
with import-x/no-restricted-paths, resolving @renderer/@shared/@logger
aliases via eslint-import-resolver-typescript.

Two env-gated rule instances over non-overlapping file scopes:
- block L (shared buckets: components/hooks/services/utils) guards the
  reverse layer edge and utils purity — gated by RENDERER_BOUNDARY_ERROR.
- block P (pages) guards page->window and sibling-page coupling — gated
  by RENDERER_PAGE_SIBLING_ERROR.

Both default to 'warn' so CI stays green while violations are burned
down, each independently promotable to 'error'. Add eslint-plugin-import-x
+ eslint-import-resolver-typescript and allow the native unrs-resolver
build in pnpm-workspace.
2026-07-04 00:56:11 -07:00
eeee0717
0af3b45a81 Merge remote-tracking branch 'upstream/main' into refactor/code-cli
Signed-off-by: eeee0717 <chentao020717Work@outlook.com>

# Conflicts:
#	src/main/ipc/handlers/index.ts
#	src/main/services/OpenClawService.ts
#	src/main/services/codeCli/CodeCliService.ts
#	src/preload/index.ts
#	src/renderer/i18n/label.ts
#	src/shared/IpcChannel.ts
#	src/shared/ipc/schemas/index.ts
2026-07-04 11:00:38 +08:00
fullex
e8de948d25 refactor(i18n): lazy-load renderer locale packs via explicit initI18n
Replace the module-level top-level-await i18next init with a memoized
initI18n() that loads locale packs on demand via i18next-resources-to-backend.
The 12 statically-bundled translation JSONs (~3.7 MB) no longer ship in every
window entry chunk; each language now builds as its own async chunk, loaded on
demand for the current language plus the en-US fallback.

- src/renderer/i18n/index.ts: per-language resourcesToBackend loaders,
  load:'currentOnly' and initImmediate:false; getLanguage/getLanguageCode/
  setDayjsLocale and the default export are unchanged.
- Six window entryPoints await initI18n() before render (migrationV2 keeps its
  own independent catalog and is untouched).
- tests/renderer.setup.ts seeds i18n once per test file, guarded by try/catch so
  files that mock @renderer/i18n or react-i18next (which make the import or init
  throw) fall back to their own mocks instead of failing.

Adds i18next-resources-to-backend@^1.2.1 as a devDependency.
2026-07-03 08:11:04 -07:00
LiuVaayne
9eb784fc2f feat(provider): add login-based providers — Claude Code, OpenAI Codex & Grok CLI (#16283)
Co-authored-by: 亢奋猫 <kangfenmao@qq.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Signed-off-by: Vaayne <liu.vaayne@gmail.com>
Signed-off-by: kangfenmao <kangfenmao@qq.com>
2026-07-03 21:03:21 +08:00
Asurada
f2673f70e3 fix(lint): use cross-env for Windows npm scripts (#16647)
Signed-off-by: ousugo <dkzyxh@gmail.com>
2026-07-03 20:53:54 +08:00
Pleasurecruise
9d22bce7cc Merge remote-tracking branch 'origin/main' into refactor/code-cli 2026-07-03 15:28:49 +08:00
Pleasurecruise
b387010a29 feat: add CLI config editor & remove Hermes support
Introduce a new renderer-side CLI config subsystem (src/renderer/pages/code/cliConfig/*) with draft editing, parsing, builders, injection, and clearing logic plus UI (CliConfigEditor, config panel integration). Move/refactor CLI page hooks/constants and tests to use the new module. Remove Hermes-specific code and config writers (hermesConfig + tests), drop Hermes from presets/i18n/CodeCli enums and paths. Add openclaw.sync_config IPC handler and adapt CodeCliService to delegate OpenClaw config sync to OpenClawService. Update preference/types to allow optional modelId and adjust related tests.
2026-07-03 15:04:22 +08:00
jd
145eea00c0 feat(artifact-preview): add inline Word and PowerPoint document previews (#16593)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Signed-off-by: jd <59188306+zhangjiadi225@users.noreply.github.com>
2026-07-03 13:18:46 +08:00
SuYao
bd87e9a6cb feat(provider-registry): generate catalog from src/creators + src/providers, add TokenHub (#16401)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: suyao <sy20010504@gmail.com>
2026-07-03 13:01:36 +08:00
fullex
9b9570116a refactor(db): replace libsql with better-sqlite3 + sqlite-vec (#16626) 2026-07-02 13:21:13 +08:00
Pleasurecruise
84840a21f4 Merge remote-tracking branch 'origin/main' into refactor/code-cli
Signed-off-by: Pleasurecruise <3196812536@qq.com>

# Conflicts:
#	src/shared/data/preference/preferenceSchemas.ts
2026-07-01 14:45:52 +08:00
robin
65c54e5ce5 chore(deps): bump @openrouter/ai-sdk-provider to ^2.10.0 (#16467)
Signed-off-by: Robinnnnn <12162433+Robinnnnn@users.noreply.github.com>
2026-06-29 16:51:14 +08:00
SuYao
af69f8cc43 fix(paintings): use motion react import (#16545)
Signed-off-by: suyao <sy20010504@gmail.com>
2026-06-29 13:19:09 +08:00
SuYao
611944599f refactor(deps): replace lodash with es-toolkit/compat and drop it (#16528)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: suyao <sy20010504@gmail.com>
2026-06-29 12:28:57 +08:00
fullex
a0bf51a1a0 refactor(renderer): migrate remaining TanStack Query usages to SWR
Drop @tanstack/react-query in favor of SWR (already the renderer's
data-fetching library via DataApi) and remove the dependency. Redesign
each fetch's semantics instead of mirroring the old behavior:

- Notes file content (useNotesQuery): event-driven via the chokidar
  watcher + save invalidation, re-reading on file switch. Drop the focus
  refetch (redundant with the watcher) and the contradictory 30s
  staleTime. Invalidate through the bound mutate; remove the dead
  refetchFileContent.
- Citation panel/tooltip: switch to useSWRImmutable and share an
  xOembedKey so the tooltip reuses the panel's cached oEmbed. Hide the
  preview snippet on fetch failure (fetchWebContent degrades to
  noContent) and drop the inert retry.
- Window roots (main/settings/subWindow): remove QueryClientProvider;
  SWR's global cache needs no provider.

Rewrite the citation tests on real SWR + mocked fetch utils and add
useNotesQuery tests.
2026-06-28 08:01:46 -07:00
Pleasurecruise
c2cea64a20 refactor(code-cli): split main process — persist provider configs to native CLI files, migrate OpenClaw IPC
Main-process half of the code-cli refactor (split from renderer changes).

- Persist provider configs to native CLI config files (claude-code/codex/opencode/hermes/openclaw) instead of launch env vars
- Multi-config per CLI tool (named configs in preference)
- Migrate OpenClaw command IPC to IpcApi (openclaw.*), drop legacy IpcChannel.OpenClaw_* handlers and install-progress broadcast
- Keep OpenClawService syncConfig/resolveSyncConfig logic + install dedup from #16105; only the IPC surface is migrated
- Add per-CLI config writers (claudeCodeConfig/codexConfig/openCodeConfig/hermesConfig/openclawConfig) with unit tests
- Remove v1 CodeCliTransforms migrator + tests
- Add smol-toml/json5/js-yaml deps

Part 1 of 2. Renderer changes land in the stacked follow-up PR.

Signed-off-by: Pleasurecruise <3196812536@qq.com>
2026-06-28 10:03:52 +08:00
SuYao
0665ce7270 fix(anthropic): strip unsupported JSON Schema keywords from tool schemas (#16480)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Signed-off-by: suyao <sy20010504@gmail.com>
2026-06-27 18:22:00 +08:00
fullex
32e8ef273c feat(window-manager): add declarative rememberBounds persistence
Migrate window-bounds persistence off the electron-window-state library into
a WindowManager built-in `rememberBounds` capability, backed by the main-process
persist cache (`window.bounds` key — its first real consumer).

- New `windowBoundsTracker` free-function module: validates the stored record
  (including displayBounds), restores onto the display the window was last on
  (clamping into its work area, never resetting to primary), and snapshots at
  teardown via getNormalBounds + isMaximized.
- Singleton-only gate (dev warning for non-singleton types). Runtime toggle
  `wm.setRememberBounds` (orthogonal to the registry flag; OFF drops only that
  type's slot) plus `wm.peekWindowBounds`.
- Persist at three teardown exits: native close (singletons), before
  window.destroy() in destroyWindow (programmatic destroys), and a new onStop
  so shutdown writes land before CacheService flushes its persist map.
- Wire Main + QuickAssistant. Main re-applies maximize consumer-side on its own
  show schedule (tray-on-launch defers to first show); remove electron-window-state
  and its orphaned keepers/constants/comments.

Fullscreen is not persisted and old *-state.json is not migrated (one-time
reset, loseable). Adds tracker/integration/persist tests, extends the main
CacheService mock with persist methods, and documents the capability plus a
breaking-change note.
2026-06-26 22:39:52 -07:00
亢奋猫
9ed91491c1 refactor(styling): remove styled-components usage (#16370)
Co-authored-by: gujiaming <52187003+AtomsH4@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: kangfenmao <kangfenmao@qq.com>
Signed-off-by: gujiaming <52187003+AtomsH4@users.noreply.github.com>
2026-06-26 18:40:12 +08:00
fullex
a507acfefb chore(deps): remove unused redux packages
The v1 Redux store was deleted, so @reduxjs/toolkit, react-redux, redux,
and redux-persist have no importers anywhere in the codebase. Drop them as
direct dependencies. redux/react-redux remain in the lockfile only as
transitive deps of @hello-pangea/dnd, which uses them internally.
2026-06-26 01:18:50 -07:00
亢奋猫
eb2622e9af refactor(ui): remove antd dependency (#16336)
Co-authored-by: gujiaming <52187003+AtomsH4@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: kangfenmao <kangfenmao@qq.com>
Signed-off-by: gujiaming <52187003+AtomsH4@users.noreply.github.com>
2026-06-26 15:49:22 +08:00
fullex
85db2c6128 chore(deps): upgrade electron-builder to 26.15.3 2026-06-25 00:57:30 -07:00
LiuVaayne
efecdd5007 refactor(binary-manager): unify CLI binary acquisition behind mise-backed BinaryManager (#15184)
### What this PR does

**Before this PR**, Cherry Studio managed external CLI binaries through
five uncoordinated mechanisms — each requiring its own download script,
IPC channel, and on-disk layout:

| Mechanism | Where it lived | How it worked |
|---|---|---|
| rtk extraction | `src/main/utils/rtk.ts` + `AgentBootstrapService` |
Copies bundled binary to `~/.cherrystudio/bin/` |
| OpenClaw installer | `resources/scripts/install-openclaw.js` |
Downloads from GitHub/mirror with custom extraction |
| CodeCliService | `src/main/services/CodeCliService.ts` | `bun install
-g` to `~/.cherrystudio/install/global/` |
| ripgrep | `node_modules/@anthropic-ai/claude-agent-sdk/vendor/` |
Vendored, hardcoded path in `FileStorage` |
| (old) MiseService | `src/main/services/MiseService.ts` | Bundled mise
+ `mise use -g` |

**After this PR**, a single `BinaryManager` lifecycle service owns all
third-party CLI binary acquisition. It wraps
[mise](https://mise.jdx.dev) as the only acquisition backend (no custom
`BinaryBackend` interface — mise's polyglot grammar already covers
`npm:`, `pipx:`, `github:`, registry entries). Tools install into an
isolated environment under `~/.cherrystudio/mise/` so user-level mise
installs are never touched. `uv`, `bun`, `rg`, and mise itself ship
bundled at build time for instant first-run availability; everything
else flows through mise on demand.

<img width=\"1304\" height=\"714\" alt=\"BinaryManager settings UI\"
src=\"https://github.com/user-attachments/assets/7a4b78ab-5aa2-4e97-9ab7-134b20a4d78d\"
/>
<img width=\"1165\" height=\"748\" alt=\"Three-state managed vs bundled
vs not-installed\"
src=\"https://github.com/user-attachments/assets/a0dcfb7d-8bc3-4acd-b563-0fc04d99e252\"
/>
<img width=\"523\" height=\"328\" alt=\"Custom tool dialog\"
src=\"https://github.com/user-attachments/assets/90c3ee95-7f2a-4daf-a334-f20de6ff5ca2\"
/>

Fixes #15183. Addresses #15370.

### Why we need it and why it was done in this way

Adding a new managed CLI tool should be a one-line preset entry — not 4+
files of bespoke download/extract/IPC code. mise is a mature polyglot
tool manager that already speaks the backends Cherry needs.

**Tradeoffs made:**
- **mise bundled at build time** (~15 MB per platform) rather than
downloaded at first run — faster first-run UX, no chicken-and-egg on a
fresh install.
- **Fully isolated mise environment** (\`HOME\`/\`XDG_*\`/\`MISE_*\` all
relocated under \`feature.binaries.data\`) — Cherry never reads or
writes the user's own \`~/.config/mise/\` or \`~/.local/share/mise/\`.
- **No custom \`BinaryBackend\` interface.** mise's grammar (\`npm:\`,
\`pipx:\`, \`github:\`, registry) is already polyglot; wrapping it would
be a shallow seam that re-implements what mise owns. Removing this
abstraction makes consumers simpler (deletion test passes).
- **Auth-token policy: opt-in only.** Ambient \`GITHUB_TOKEN\` /
\`GH_TOKEN\` are not forwarded into mise's process env. Users who hit
GitHub's unauthenticated 60 req/hr API limit can set
\`CHERRY_GITHUB_TOKEN\` to raise it to 5000 req/hr without consenting to
share their general shell token.
- **China mirror auto-detection.** \`isUserInChina()\` toggles
\`NPM_CONFIG_REGISTRY=registry.npmmirror.com\` +
\`PIP_INDEX_URL=pypi.tuna.tsinghua.edu.cn\` for every npm/pipx backend
transparently.

**Alternatives considered:**
- *Keep per-tool install scripts.* Doesn't scale — each new tool is 4+
files of duplicated logic.
- *Use mise from user's \`PATH\`.* Would depend on user having mise
installed and could conflict with their config.
- *Custom \`BinaryBackend\` abstraction.* Shallow wrapper over mise's
grammar; no second backend in sight; deletion test passes.

**Scope (what's in / what's out):**
- **In:** uv, bun, ripgrep, claude-code, openclaw, gh, opencode,
gemini-cli, lark, kimi-cli, qwen-code, iflow-cli, github-copilot-cli —
anything mise can install as a single relocatable binary.
- **Out:** \`OvmsManager\` (multi-file server provisioning, hardware
detection, generated config); Tesseract OCR data (not a binary; lives
with \`OvOcrService\`).

### Breaking changes

None at the user-facing layer. v2 data is throwaway per CLAUDE.md, so
the preference-key rename (\`feature.mise.*\` → \`feature.binaries.*\`)
intentionally ships without a migrator.

### Special notes for your reviewer

**Architecture & docs**
- \`docs/references/binary-manager/README.md\` — scope criterion,
persisted/contract surface, bundled-vs-mise state contract, China mirror
behavior, \`CHERRY_GITHUB_TOKEN\` opt-in, adding a new managed binary.
- \`CLAUDE.md\` adds a \`**MUST READ**\` link next to Lifecycle / Window
Manager / Data / Paths.
- The mise-shim-wins-over-\`cherry.bin\` precedence rule is documented
in the README's "State contract" section.

**Code orientation**
- \`src/main/services/BinaryManager.ts\` — the lifecycle service. Wraps
mise via \`runMise()\`; isolated env in \`buildIsolatedEnv()\`; bundled
extraction with atomic tmp+rename; per-tool try/catch so a single
failure can't abort init; \`isManagedBinaryReady()\` verifies the
resolved file is executable (not just that mise thinks it's installed).
- \`packages/shared/data/presets/binary-tools.ts\` —
\`PREDEFINED_BINARY_TOOLS\` registry; \`tool\` field is a mise spec.
-
\`src/renderer/src/pages/settings/McpSettings/EnvironmentDependencies.tsx\`
— three-state UI (\`managed\` / \`bundled\` / \`not-installed\`) backed
by \`Binary_GetState\` + \`Binary_ProbeBundled\`.
- \`scripts/download-binaries.js\` — build-time downloader for mise / uv
/ bun / rg (HTTPS + sha256-verified, archive-aware extraction).

**Migration**
- \`OpenClawService.install()\` is now two lines delegating to
\`BinaryManager\` — \`install-openclaw.js\` is gone.
- \`CodeCliService\` no longer uses \`bun install -g\`; the
\`BUN_INSTALL\` / \`~/.cherrystudio/install/global/\` path is removed.
- \`FileStorage.getRipgrepBinaryPath()\` now resolves via
\`getBinaryPath('rg')\`; the vendored SDK rg is no longer used.
- \`extractRtkBinaries\` + the \`AgentBootstrapService\` call are
deleted. \`rtkRewrite()\` degrades gracefully when rtk is absent;
\`rtkAvailable\` caches with a 60s TTL so install-via-mise takes effect
without restart.

**Multi-round review**
Two adversarial review rounds against this branch (Bug Hunter / Security
/ Architecture / Correctness) ran during development; both rounds'
High-severity findings are addressed in commits \`70afde6af\` and
\`1d864439d\`. R3 known follow-ups (architecture duplications in
\`CodeCliService\`'s switch statements, etc.) are tracked as Medium and
intentionally deferred.

### Checklist

- [x] PR: The PR description is expressive enough and will help future
contributors
- [x] Code: Write code that humans can understand and Keep it simple
- [x] Refactor: Leaves binary acquisition meaningfully cleaner than
before (five mechanisms → one)
- [x] Upgrade: v2 data is throwaway; no migrator needed and the absence
is intentional
- [x] Documentation: \`docs/references/binary-manager/README.md\` +
\`CLAUDE.md\` Architecture section
- [x] Self-review: Two multi-perspective review rounds against the
branch; all Highs addressed

### Release note

\`\`\`release-note
NONE
\`\`\`

---------

Signed-off-by: Vaayne <liu.vaayne@gmail.com>
Signed-off-by: Vaayne Liu <vaayne@macos.shared>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
2026-06-24 15:15:25 +08:00
SuYao
32a6666bb3 chore(chat-page): scaffold chat component tree (#14997)
Co-authored-by: jdzhang <625013594@qq.com>
Co-authored-by: gujiaming <52187003+AtomsH4@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: kangfenmao <kangfenmao@qq.com>
Co-authored-by: jd <59188306+zhangjiadi225@users.noreply.github.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Signed-off-by: gujiaming <52187003+AtomsH4@users.noreply.github.com>
Signed-off-by: suyao <sy20010504@gmail.com>
Signed-off-by: kangfenmao <kangfenmao@qq.com>
Signed-off-by: jdzhang <625013594@qq.com>
Signed-off-by: jd <59188306+zhangjiadi225@users.noreply.github.com>
2026-06-23 20:31:49 +08:00
SuYao
e19f7cbc06 feat(chat): carve the v2 chat shell/orchestration layer onto main (#16272)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: kangfenmao <kangfenmao@qq.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Signed-off-by: suyao <sy20010504@gmail.com>
Signed-off-by: kangfenmao <kangfenmao@qq.com>
2026-06-22 23:34:47 +08:00
Phantom
ba7174fe04 chore(i18n): add i18next-cli extraction and lint tooling (#16220)
Signed-off-by: icarus <eurfelux@gmail.com>
2026-06-21 21:12:14 +08:00
SuYao
1f41a5168a feat(chat): carve the v2 message renderer onto the foundation layer (#16229)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Signed-off-by: suyao <sy20010504@gmail.com>
2026-06-21 20:44:55 +08:00
fullex
1fc8664e34 chore(deps): upgrade electron 41.2.1 to 41.8.0
Bump Electron within the same Chromium 146 milestone. Picks up
backported security fixes (CVE-2026-6296..6363 and later batches),
a browser-process crash fix for webContents.reload()/render-process-gone,
and a macOS auto-update fix. No breaking changes; no app code changes.
Node.js updated to v24.16.0.
2026-06-21 02:37:16 -07:00
Phantom
9c9422a14e chore(pnpm): migrate to pnpm 11 (#16223)
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Signed-off-by: icarus <eurfelux@gmail.com>
2026-06-20 21:45:53 +08:00
SuYao
22ffb62f62 feat(richeditor): native @tiptap/markdown AST on Tiptap 3.26.1 (#16118)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Signed-off-by: suyao <sy20010504@gmail.com>
2026-06-17 18:38:54 +08:00
亢奋猫
2e3520678c feat(ui): add shared markdown, tree view, and portal primitives (#16020)
Co-authored-by: gujiaming <52187003+AtomsH4@users.noreply.github.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Signed-off-by: kangfenmao <kangfenmao@qq.com>
Signed-off-by: gujiaming <52187003+AtomsH4@users.noreply.github.com>
2026-06-17 13:26:53 +08:00
fullex
21a2a672f7 fix(deps): declare @vectorstores/env as a direct dependency to avoid duplicate module load
@vectorstores/readers subpaths are bundled into the main process and import @vectorstores/env as ESM, while the externalized @vectorstores/core requires the CJS copy at runtime. The two copies trip env's single-import guard ("vectorstores was already imported ..."). Declaring env directly externalizes it via the dependency-based external list and lets pnpm link it into top-level node_modules, so both paths resolve to one CJS instance.
2026-06-15 06:47:58 -07:00
槑囿脑袋
20035a83ff feat(knowledge): engine-portable per-base index store and retrieval cutover (#15973)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Signed-off-by: eeee0717 <chentao020717Work@outlook.com>
2026-06-15 19:43:10 +08:00
SuYao
fa27fa473a feat(ai-runtime): agent runtime warm sessions + Claude MCP tool runtime (#15939)
Co-authored-by: jdzhang <625013594@qq.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Co-authored-by: jd <59188306+zhangjiadi225@users.noreply.github.com>
Signed-off-by: suyao <sy20010504@gmail.com>
Signed-off-by: jdzhang <625013594@qq.com>
2026-06-15 18:59:58 +08:00
SallySilly
630f9bd1ee fix: migrate PaddleOCR handlers to use @paddleocr/api-sdk (#15929)
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Co-authored-by: 槑囿脑袋 <70054568+eeee0717@users.noreply.github.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Signed-off-by: SallySilly <alialiaaa0712@gmail.com>
2026-06-12 18:23:04 +08:00
槑囿脑袋
1382a8dd7c feat(knowledge): route embeddings and reranking through the AI service (#15796)
### What this PR does

Before this PR:

- Knowledge embeddings and reranking ran through the legacy
embedjs-based
knowledgeV1 stack with their own provider clients, independent of the
app's
  AI service.
- File-processing intake accepted several heterogeneous input shapes,
and
knowledge file items were tracked by FileEntry ids, coupling file
content to
  the file-manager entry/cache.

After this PR:

- Embeddings and reranking are routed through the unified `AiService`
(with
cherryin rerank support) and guarded by strict embedding-dimension
validation
  that rejects stale/mismatched vectors.
- File-processing intake is collapsed to a single path-based model;
knowledge
  file items are stored by base-relative path under the knowledge-base
directory, and v1 uploads are copied into the v2 base dir during
migration so
  migrated items stay reindexable/restorable.
- Legacy `knowledgeV1` is removed; the orchestration services were
renamed to
  `KnowledgeService` / `FileProcessingService`.
- Chat -> knowledge attach is temporarily disconnected (tracked TODO)
while the
  v2 file-manager bridge is rebuilt.

Fixes #N/A (no linked issue)

### Why we need it and why it was done in this way

Routing embeddings/rerank through `AiService` unifies provider handling
and
credentials and removes the parallel embedjs client stack and its v1
coupling.
Storing knowledge files by base-relative path (instead of FileEntry ids)
makes
each knowledge base self-contained and portable.

The following tradeoffs were made:

- A large, coordinated refactor plus a migration step that physically
copies v1
uploads into the v2 base dir, in exchange for removing the parallel
client
  stack and making bases self-contained.
- Base-relative path storage required a fail-fast/dedup strategy for
same-named
  files and a guard for blank legacy filenames.

The following alternatives were considered:

- Keeping the embedjs stack behind an adapter — rejected; perpetuates
the
  parallel client and v1 coupling.
- Keeping FileEntry-id storage — rejected; couples knowledge files to
the
  file-manager cache and blocks portability.

### Breaking changes

- `knowledgeV1` is removed. Legacy v1 knowledge data reaches v2 only
through the
  v2 migrators; there is no v1 fallback.
- The v2 knowledge HTTP API (API gateway) now returns v2-native
per-entry fields
(`embeddingModelId`, `createdAt` on base entries; `chunkId`,
`scoreKind`,
  `rank` on search results). The response envelope (`knowledge_bases`,
  `searched_bases`, `total`) is unchanged. See

`v2-refactor-temp/docs/breaking-changes/2026-06-05-knowledge-api-v2.md`.

### Special notes for your reviewer

- This branch went through several rounds of multi-agent code review.
The most
recent 6 commits address review findings: directory-import path
collisions,
migrated-file source copying + blank `relativePath` guard, addItems
rollback
error preservation, eager `document_to_markdown` output-target
validation, a
`CompletedKnowledgeBase` type guard, and breaking-changes doc
corrections.
- Chat -> knowledge attach is intentionally disconnected for now
(tracked in
  `v2-refactor-temp/docs/knowledge/knowledge-todo.md`).
- Local full `pnpm lint`/`pnpm test` was not run per the project's
review
  conventions; please rely on CI / `pnpm build:check`.

### Checklist

- [x] Branch: This PR targets the correct branch — `main` for active
development, `v1` for v1 maintenance fixes
- [x] PR: The PR description is expressive enough and will help future
contributors
- [x] Code: Write code that humans can understand and Keep it simple
- [x] Refactor: You have left the code cleaner than you found it (Boy
Scout Rule)
- [x] Upgrade: Impact of this change on upgrade flows was considered and
addressed if required
- [ ] Documentation: A user-guide update was considered and is present
(link) or not required.
- [x] Self-review: I have reviewed my own code before requesting review
from others

### Release note

```release-note
NONE
```

---------

Signed-off-by: eeee0717 <chentao020717Work@outlook.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-09 14:04:29 +08:00
SuYao
de580c2fb1 feat(api-gateway): port the universal API gateway onto v2 (ElysiaJS rewrite) (#15705)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Signed-off-by: suyao <sy20010504@gmail.com>
2026-06-07 18:04:26 +08:00
fullex
bc86fb6a2e refactor(storage-monitor): move disk-space monitoring to the main process
Replace the v1 renderer-driven disk polling with a main-process service:

- Remove checkAppStorageQuota (browser storage-quota >=95% warning); v2
  business data lives in main-process SQLite, so the browser-side quota no
  longer reflects where data is stored.
- Add StorageMonitorService (WhenReady, @DependsOn WindowManager): fs.statfs
  with capacity-adaptive polling (5-60 min by free space), pushing health
  transitions (ok<->low) to the main window only.
- Rename utils/dataLimit.ts to hooks/useStorageMonitorNotification.ts, a thin
  subscriber that drives the existing antd notification (UI migration deferred
  to the broader v2 refactor).
- Drop the App_GetDiskInfo IPC handler, the getDiskInfo preload API, and the
  check-disk-space dependency.
- Add a breaking-change entry for the removed storage-quota warning.
2026-06-05 20:33:45 -07:00
fullex
0734aea9e4 Revert "feat(excel-word-preview): add main-process Excel/Word preview services" (#15718) 2026-06-05 19:41:55 +08:00
SuYao
d7a6620e55 feat(excel-word-preview): add main-process Excel/Word preview services (#15694)
Co-authored-by: zhangjiadi225 <59188306+zhangjiadi225@users.noreply.github.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Co-authored-by: jdzhang <625013594@qq.com>
Signed-off-by: jdzhang <625013594@qq.com>
2026-06-05 19:28:20 +08:00
SuYao
488ea66b47 refactor(trace-window): remove the standalone trace BrowserWindow (#15698)
Signed-off-by: suyao <sy20010504@gmail.com>
2026-06-05 18:47:05 +08:00
fullex
355f703b5a fix(deps): override protobufjs to ^7.5.5 for CVE-2026-41242
protobufjs < 7.5.5 is vulnerable to arbitrary code execution via injected
protobuf definition type fields (GHSA-xq3m-2v4x-88gg, CVSS 9.4). It is only
pulled in transitively, by @google/genai, @larksuiteoapi/node-sdk and
@opentelemetry/otlp-transformer, which all declare ^7.x ranges.

Add a pnpm.overrides entry pinning protobufjs to ^7.5.5 (resolves to 7.6.2),
fixing all three entry points at once while staying within the 7.x major
those packages support. No source changes; package.json and pnpm-lock.yaml
only.
2026-06-04 19:26:11 -07:00
SuYao
5706307451 refactor(ai-service): consolidate AI runtime to main process (#14911)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Signed-off-by: suyao <sy20010504@gmail.com>
2026-06-05 00:06:51 +08:00
亢奋猫
26508591f8 refactor(paintings): migrate to v2 data layer and UI (#15154)
Co-authored-by: jidan745le <420511176@qq.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: SuYao <sy20010504@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
Signed-off-by: jidan745le <420511176@qq.com>
Signed-off-by: suyao <sy20010504@gmail.com>
2026-06-02 15:18:53 +08:00
fullex
fa5bbb7607 Merge branch 'main' of github.com:CherryHQ/cherry-studio into v2 2026-05-28 19:38:52 -07:00
SuYao
db8a1834c2 feat(file-manager): unified DirectoryTreeBuilder primitive for Notes (#15363)
### What this PR does

Before this PR:

- Directory loading is split between two pipelines:
`FileStorage.getDirectoryStructure` (Notes) and
`FileStorage.listDirectory` (everything else). Same workspace, two
scans, two watchers.
- `FileStorage.listDirectory` defaults `maxEntries: 20`, silently
truncating list-mode callers (workspace trees rendered `tests/__mocks__`
as a file because it sorted out of the first 20 results).
- Notes' manual chokidar plumbing (`startFileWatcher` / `onFileChange`)
lives on legacy `file-change` IPC and crashes with `EMFILE: too many
open files` on large repos because the watcher opens one FD per
directory in `node_modules`.

After this PR:

- One primitive — `DirectoryTreeBuilder`
(`src/main/file/tree/builder.ts`, RFC §12) — owns the in-memory tree and
the chokidar watcher. It is the only directory-walking code on the main
side.
- Builder dedupe lives behind `TreeRegistry` (lifecycle `WhenReady`):
identical `(rootPath, options)` requests share one builder, with a 500ms
grace window so a remount inside one React commit reuses the warm scan +
watcher instead of paying for a rescan.
- `.gitignore` parsing (via `ignore@7`) drives BOTH ripgrep's
`--ignore-file` AND chokidar's `ignored` predicate, so EMFILE on
`node_modules`-heavy workspaces is gone. `.git` is always excluded even
when `.gitignore` doesn't list it.
- `search.listDirectory` is the now-real Phase 2 entry point (was a
stub). `maxEntries` default raised to `Number.MAX_SAFE_INTEGER`;
truncation is a search-mode concern and callers that want a cap pass it
explicitly. The 20-entry default was the bug.
- Renderer-side `useDirectoryTree(rootPath, options)` hook applies
mutation pushes to a JSON-mirrored `TreeDirRoot`. The tree DTO and
`TreeNode` class live in `packages/shared/file/types/tree.ts` so main
and renderer share one shape (no parent cycles in JSON; WeakMap parent
ref recovered in `FromJSON`).
- Notes (`NotesPage`) migrated off `getDirectoryStructure` + manual
watcher onto `useDirectoryTree` + `useNote` join. The Redux
`starredPaths` / `expandedPaths` path stays untouched in this PR —
`useNote` already covers that surface via `noteTable`.

Fixes #

### Why we need it and why it was done in this way

The following tradeoffs were made:

- **Builder dedupe on main, not renderer.** A renderer-side cache would
still pay one IPC round-trip per remount because the expensive thing is
the FS scan + watcher install, which only the main side owns. Sharing on
the main means one ripgrep + one chokidar regardless of how many panes
mount the same root.
- **500ms grace window for builder teardown.** Long enough to cover
React's "deletions before insertions" effect ordering (sub-millisecond
in practice), short enough that closing a workspace doesn't keep watcher
FDs alive noticeably.
- **`Tree_*` IPC owned by `TreeRegistry.onInit`.** The lifetime of the
handlers must match the lifetime of the chokidar watchers they
reference. Putting them in `FileManager` would leak handlers across
re-init.
- **`TreeNode` class hierarchy (not plain DTOs)** lets `rename` mutate
`path` once at the subtree root and have `adjustChildrenPaths` cascade —
the alternative is rebuilding the subtree, which throws away every
consumer's identity-based caching.
- **Hard ESLint isolation:** `src/main/file/tree/**` does not import
`@main/data/**`. Tree is a runtime concern; persistence is an orthogonal
one (`noteTable` is a sparse state overlay on top of FS paths, not a
tree mirror). RFC §12.6.

The following alternatives were considered:

- Keep the renderer-side cache (rejected — covered above; main-side
dedupe is strictly stronger).
- Add an `excludeGlobs` array option (rejected — the right source of
truth is `.gitignore`, and users editing `.gitignore` get free updates).
- One DTO without classes (rejected — rename cascade is the load-bearing
case).

Links to places where the discussion took place: RFC §12
(`v2-refactor-temp/docs/file-manager/rfc-file-manager.md`)

### Breaking changes

- Removed legacy IPC channels: `File_GetDirectoryStructure`,
`File_StartWatcher`, `File_StopWatcher`, `File_PauseWatcher`,
`File_ResumeWatcher`. Only Notes used them; the migration is in this PR.
No renderer outside Notes touched them.
- `search.listDirectory` (renamed from `FileStorage.listDirectory`) now
defaults to unbounded `maxEntries`. Existing callers that relied on the
implicit 20-cap (none I could find) would need to pass `maxEntries: 20`
explicitly.

### Special notes for your reviewer

- `src/main/file/tree/__tests__/builder.test.ts` covers initial scan,
`.gitignore` honoring, chokidar fan-out, `dispose` cleanup, and JSON
round-trip (no parent cycles).
- `src/main/file/tree/__tests__/registry.test.ts` covers builder dedupe,
grace-window reuse, multi-consumer mutation fan-out, and
`webContents`-destroyed cascade cleanup.
- `src/main/utils/file/__tests__/search.test.ts` locks in the
`maxEntries` default fix and the `--hidden` flag wiring.
- ArtifactPane / chat-page integration of this primitive lives on
`feat/chat-page` and is not part of this PR (that branch has the Shell
forceMount + chat-page Tree IPC integration on top).

### Checklist

- [x] PR: The PR description is expressive enough and will help future
contributors
- [x] Code: Write code that humans can understand and Keep it simple
- [x] Refactor: You have left the code cleaner than you found it (Boy
Scout Rule)
- [ ] Upgrade: Impact of this change on upgrade flows was considered and
addressed if required
- [ ] Documentation: A user-guide update was considered and is present
(link) or not required.
- [x] Self-review: I have reviewed my own code before requesting review
from others

### Release note

```release-note
NONE
```

---------

Signed-off-by: suyao <sy20010504@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 23:33:48 +08:00
fullex
344c58eb8e feat(job): introduce JobManager + SchedulerService backbone (Phase 1)
cherry-studio v2 had 6+ ad-hoc queue/scheduler implementations (Knowledge,
FileProcessing, agent SchedulerService, TopicQueue, NotificationQueue,
protocol heartbeats) with no shared registry, inconsistent cancel and
progress semantics, and no cross-restart recovery outside agent_task.
This commit lands the unified replacement: JobManager owns Job lifecycle
and SchedulerService owns time-only scheduling, both reusable independently.

Phase 1 ships the backbone only: jobTable + jobScheduleTable, entity
services, 6-state machine with per-handler recovery (abandon/retry/
singleton), catch-up policy (skip-missed/after-startup), retry backoff,
GC, idempotencyKey dedup, useJob renderer hook, and 4 reference docs.
Four-layer lock model addresses libsql client-ts issue #288 (Layer 0
global dispatch mutex serializes all transactions).

croner@^10 is introduced for cron expressions (zero-dep, Electron-friendly).
Application.SHUTDOWN_TIMEOUT_MS is promoted to public for JobManager reuse.
cron-parser stays until Phase 2 agent task migration.

No business migrations in this commit — Knowledge/FileProcessing/agent
SchedulerService remain untouched and migrate in Phase 2-4 per
docs/references/job-and-scheduler/migration-checklist.md.

Follow-ups for Phase 1 completion: DataApi GET /jobs handler, dummy.echo
smoke test, integration tests, migration feasibility report.
2026-05-19 03:57:18 -07:00
Asurada
0b697210bd fix: support Grok 4.3 reasoning effort in xAI responses (#15137)
### What this PR does

Before this PR:

- Grok 4.3 did not fully support reasoning effort through the xAI
responses path.
- Cherry Studio did not expose the Grok 4.3 reasoning options
consistently in model configuration.
- The local @ai-sdk/xai patch could fail pnpm install after manual patch
edits.

After this PR:

- Grok 4.3 correctly maps `reasoning_effort` to xAI responses with
`none`, `low`, `medium`, and `high`.
- The renderer exposes Grok 4.3 as a supported reasoning model with the
correct option set.
- The local @ai-sdk/xai patch is regenerated and narrowed to the
responses path so pnpm install succeeds.

Fixes #

N/A

### Why we need it and why it was done in this way

The following tradeoffs were made:

- The change is scoped to the xAI responses path because Grok is already
routed to `xai-responses` in this repository.
- A local patch is still required because the latest stable
`@ai-sdk/xai` release does not yet support `none` for xAI responses
`reasoningEffort`.
- The patch was narrowed to responses-only to avoid widening behavior
for the base xAI chat path.

The following alternatives were considered:

- Upgrading directly to the latest stable `@ai-sdk/xai`, but the latest
stable release still does not support `none` for responses
`reasoningEffort`.
- Broadening the patch to cover xAI chat options as well, but that would
expand behavior beyond the required Grok 4.3 responses path.

Links to places where the discussion took place: None

### Breaking changes

None.

If this PR introduces breaking changes, please describe the changes and
the impact on users.

### Special notes for your reviewer

- Focused validation passed with `pnpm install`, `pnpm typecheck:web`,
and targeted Vitest suites for xAI/Grok reasoning and model config.
- Full `pnpm test` on Windows still has unrelated baseline failures
outside this change set.

### Checklist

This checklist is not enforcing, but it's a reminder of items that could
be relevant to every PR.
Approvers are expected to review this list.

- [x] PR: The PR description is expressive enough and will help future
contributors
- [x] Code: [Write code that humans can
understand](https://en.wikiquote.org/wiki/Martin_Fowler#code-for-humans)
and [Keep it simple](https://en.wikipedia.org/wiki/KISS_principle)
- [x] Refactor: You have [left the code cleaner than you found it (Boy
Scout
Rule)](https://learning.oreilly.com/library/view/97-things-every/9780596809515/ch08.html)
- [x] Upgrade: Impact of this change on upgrade flows was considered and
addressed if required
- [x] Documentation: A [user-guide update](https://docs.cherry-ai.com)
was considered and is present (link) or not required. Check this only
when the PR introduces or changes a user-facing feature or behavior.
- [x] Self-review: I have reviewed my own code (e.g., via
[`/gh-pr-review`](/.claude/skills/gh-pr-review/SKILL.md), `gh pr diff`,
or GitHub UI) before requesting review from others

### Release note

<!--  Write your release note:
1. Enter your extended release note in the below block. If the PR
requires additional action from users switching to the new release,
include the string "action required".
2. If no release note is required, just write "NONE".
3. Only include user-facing changes (new features, bug fixes visible to
users, UI changes, behavior changes). For CI, maintenance, internal
refactoring, build tooling, or other non-user-facing work, write "NONE".
-->

```release-note
Fixed Grok 4.3 reasoning effort support in xAI responses so Cherry Studio now correctly exposes and applies the `none`, `low`, `medium`, and `high` reasoning levels.
```

---------

Signed-off-by: ousugo <dkzydkzyxh@gmail.com>
Co-authored-by: ousugo <dkzydkzyxh@gmail.com>
Co-authored-by: SuYao <sy20010504@gmail.com>
2026-05-18 16:24:22 +08:00