Commit Graph

18 Commits

Author SHA1 Message Date
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
25fe3343fc docs(data): add canonical pagination guide and wire references
Pagination docs were scattered across api-types.md (types + cursor
semantics), data-api-in-renderer.md (hooks), data-api-in-main.md (offset
example + keyset note), api-design-guidelines.md (query params), and
data-ordering-guide.md (cache shapes + determinism), with no single
discoverable home for the offset-vs-cursor model.

Add docs/references/data/data-pagination-guide.md as the canonical hub
(mirrors data-ordering-guide.md): two modes, four-layer quickstart, wire
contract, server impl (offset + keyset cursor + multi-band caveat),
renderer consumption, FTS pagination, gotchas, and a see-also map. Other
docs keep their authoritative slice and link to the guide; the migrated
conceptual prose is removed from api-types.md to avoid duplication.

Also fix two pre-existing broken anchors found while verifying links
(database-patterns withWriteTx; ordering guide section number).
2026-06-22 06:41:27 -07:00
槑囿脑袋
954bd576bb refactor(knowledge): migrate runtime IPC to IpcApi (#16191)
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: eeee0717 <chentao020717Work@outlook.com>
2026-06-18 18:58:27 +08:00
fullex
57e072b143 refactor(data-api): unify sort param naming to sortBy + sortOrder
Resolve the spec conflict between api-design-guidelines.md (orderBy +
order) and api-types.md / SortParams (sortBy + sortOrder) by adopting
sortBy + sortOrder everywhere:

- api-design-guidelines.md: align the sorting convention with
  SortParams and cross-link api-types.md
- ListOptions: extend SortParams; rename the direction field
  orderBy -> sortOrder
- AgentService + tests: follow the ListOptions rename
- renderer types/agent.ts: drop the unused, drifted ListOptions copy
2026-06-12 00:34:33 -07:00
fullex
89dc40d467 docs(data-api): forbid non-data side effects on DataApi code paths
DataApi handlers and their services may perform only SQLite reads/writes via Drizzle; fs/network/process/external-service side effects are prohibited regardless of nesting depth or an accompanying DB write. Add a Hard Rule section to api-design-guidelines, scope-limit service domain workflows to DB I/O, and echo the boundary in the overview and README.
2026-06-06 09:02:06 -07:00
fullex
adfde89c20 refactor(data): prefix agent DataApi endpoints and types with agent
Unify the agent domain at the DataApi contract layer so the agent prefix is
consistent with the DB tables (agent_session, agent_workspace) and services.

- routes: /sessions, /workspaces, /channels -> /agent-sessions,
  /agent-workspaces, /agent-channels (kebab-case)
- rename schema/handler files sessions/workspaces -> agentSessions/agentWorkspaces
- types: SessionSchemas/WorkspaceSchemas -> AgentSessionSchemas/AgentWorkspaceSchemas,
  WorkspaceEntity -> AgentWorkspaceEntity, session DTOs/queries, SESSION_MESSAGES_* consts
- handler exports: sessionHandlers/workspaceHandlers -> agentSession/agentWorkspaceHandlers
- skills left unprefixed (shared library resource)
- docs: add "Resource <-> Table Naming" convention to api-design-guidelines.md

Internal IPC routes only; no external API or DB schema change.
2026-06-04 21:44:38 -07:00
fullex
c514dcc049 refactor(shared): move packages/shared to src/shared
packages/shared was never a real pnpm workspace package (no package.json); it was referenced only through the @shared TypeScript path alias. Relocate it under src/ via git mv (143 files, detected as pure renames).

Repoint the @shared alias and include globs to src/shared across electron.vite.config.ts, tsconfig.{json,node,web}.json and vitest.config.ts; update scripts/check-custom-exts.ts, scripts/update-languages.ts, the eslint.config.mjs generated-file globs, the data-classify generator output targets, .github/CODEOWNERS path rules, and CLAUDE.md/docs/source-comment references.

The @shared alias name is unchanged, so all 1403 @shared/* import sites resolve without modification. Verified with typecheck:node, typecheck:web and the full test suite (700 files, 9739 tests passing).
2026-05-28 21:02:49 -07:00
fullex
4c156c5eea refactor(job): collapse jobs DataApi to read-only and relocate main-only types
- Remove POST /jobs (enqueue) and DELETE /jobs/:id (cancel); Job DataApi
  is GET-only. Business services call JobManager.enqueue/.cancel in main;
  renderer-initiated triggering goes through a dedicated IPC channel.
- Move Trigger / RetryPolicy / CatchUpPolicy / JobScheduleSnapshot /
  Create+Update JobScheduleDto / JobScheduleNameAtomSchema /
  JOB_ERROR_CODES from packages/shared/data/api/schemas/jobs.ts into
  src/main/core/job/{scheduleTypes,errorCodes}.ts. These are
  main-process-only types that never cross IPC.
- shared/jobs.ts retains JobSnapshot, JobProgress, JobError,
  ListJobsQuerySchema, JobSchemas (GET-only) — the actual renderer
  surface useJob/useJobProgress consume via DataApi + cache.
- Update DataApi anti-patterns table and job-and-scheduler docs to
  reference IPC channels for renderer-initiated triggering.

shared/jobs.ts: 316 → 139 lines
handler/jobs.ts: 102 → 43 lines
2026-05-21 02:28:06 -07:00
fullex
de1d85d059 docs(data-api): clarify schema file organization rule
The rule that schema files in packages/shared/data/api/schemas/ are
organized by the entity's domain (not URL prefix) was followed in code
but never written down, so readers could reasonably misinfer "the URL
parent decides the file" from routes like /topics/:topicId/messages
living in messages.ts.

Add a Schema File Organization section to api-types.md, with a small
table comparing routes whose URL parent and returned entity disagree,
and a cross-reference note from api-design-guidelines.md so path-design
readers land on the right page.
2026-05-13 06:56:22 -07:00
fullex
69e9cb6184 docs(data-api): codify default values & nullability rules
Establish team standards for placing default values across the data stack (DB DEFAULT / Drizzle $defaultFn / Zod .default() / service ??) and judging column nullability.

Originating context: PR #14689 fixed a PATCH leakage bug rooted in defaults living in three places at once (DB, Zod Create schema, row mapper) for the assistant entity. The follow-up discussion recovered general principles that other entities (agent, message) also violate; this doc captures them as a reference for future schema/service work.

- New: best-practice-default-values-and-nullability.md — Five rules (R1-R5), decision matrices for nullability and default placement, standard layered design example, anti-patterns table, case studies (assistant, modelId, agent.accessiblePaths)
- api-design-guidelines.md: refine Rule C Update derivation guidance; add Rule E discouraging Zod .default() on entity / Create / Update schemas
- data-api-in-main.md: upgrade row-mapper ?? fallbacks from "needs hand-write" tolerance to anti-pattern; add Write-path defaults section codifying R4
- database-patterns.md: add Column Nullability and Defaults section; add R3 no-fabricated-fallbacks bullet to Row → Entity Mapping
- README.md: index entry under Reference Guides

No code changes. Implementation follow-up will land in separate PRs that apply these rules entity by entity.
2026-04-29 02:49:11 -07:00
fullex
f60ef2bfd6 docs(cache): rewrite to match current API and add design invariants
Align cache-overview.md and cache-usage.md with the template-key and
subscribe* APIs (sharedCasual was dropped in 3fbc52e05). Extract the
"adding keys" content into a new cache-schema-guide.md aligned with
preference and boot-config schema guides. Lift non-obvious invariants
(isEqual short-circuit, TTL-with-hooks warning, Persist has no delete,
Main-wins convergence, template placeholder rules) into a first-class
Design Invariants section in the overview.

Fix two code-contradicted claims:
- useCache does not accept a TTL options argument (hook signature is
  (key, initValue?)).
- Persist is renderer-authoritative; Main only relays IPC and does
  not store (CacheService.ts:477-479 is "Reserved, not implemented").

Update peripheral references in the same pass so cross-references stay
coherent: v2-renderer skill, CLAUDE.md, architecture-overview.md,
api-design-guidelines.md (Cache vs DataApi matcher contrast), and the
package READMEs.

Net change: +249 / -579.
2026-04-22 22:56:34 -07:00
fullex
01986a47b6 docs(data-api): codify Zod schema & DTO conventions
- Add "Zod Schema & DTO Conventions" section to api-design-guidelines.md
  covering the four rules applied across the prior refactor commits:
  A. type (not interface) for XxxSchemas route tables
  B. XxxSchema for Zod constants, XxxDto for TypeScript type names
  C. EntitySchema.pick({...}) whitelist derivation with field atoms
     and z.strictObject (guarded against overposting)
  D. handwritten Zod everywhere; no drizzle-zod; no pure TS interface
     DTOs (responses stay as interface — opposite direction of the
     IPC trust boundary)
- Include a decision rule for when to extract an XXX_MUTABLE_FIELDS
  constant: both Create/Update share the pick set AND fields >= 5
- Sync example code in api-types.md to the new conventions
- Flip the TopicSchemas example in data-api-in-main.md from interface
  to type
2026-04-22 05:15:33 -07:00
fullex
c9abc6e058 docs(data-ordering): add ordering guide and update cross-references 2026-04-21 03:21:05 -07:00
fullex
686bd15290 feat(data-api): support template paths, function refresh, and /* prefix matching
Extend the renderer data hooks to cover three mutation shapes that
previously had to drop to imperative dataApiService calls:

- Template paths (e.g. `/providers/:providerId`) with a runtime `params`
  option on useQuery / useMutation / useInfiniteQuery / usePaginatedQuery,
  so a single hook instance can operate on ids chosen at call time.
  ParamsForPath derives types directly from the schema's existing
  `params: {...}` declarations (no template-string parsing).
- Function-form `refresh: ({ args, result }) => ConcreteApiPaths[]` for
  invalidation keys that depend on trigger input or server response. Args
  are closure-captured at trigger entry to avoid races between concurrent
  calls.
- Explicit `/*` suffix for path-segment prefix matching on refresh and
  invalidate patterns, preserving the trailing slash so `/providers/*`
  doesn't match siblings like `/providers-archived`.

A single `resolveTemplate` function is the canonical path-replacement
point, so `useQuery('/providers/:id', { params: { id: 'abc' } })` and
`useQuery('/providers/abc')` produce byte-for-byte identical cache keys.

Dev-mode assertions flag invalid `/*` patterns (bare wildcard or missing
trailing slash) and warn on concurrent triggers against the same template
hook instance, which would share SWR mutation state.

Fully backward compatible: existing `refresh: ['/topics']` and
concrete-path hook calls compile and behave identically.
2026-04-20 09:02:57 -07:00
fullex
a2adc8fcce feat(data-api): support greedy path params for IDs containing slashes
Extend the DataApi router's `extractPathParams` to recognize `:name*` segments
as greedy captures that consume one or more path segments joined with `/`.
Greedy params may appear as the last segment or in the middle anchored by
trailing static / plain-param segments; at most one greedy is allowed per
pattern. No decoding is performed, consistent with the existing raw-string
policy.

This unblocks routing for composite identifiers whose values contain `/`
(e.g. OpenRouter-style `qwen/qwen3-vl`, Fireworks-style
`accounts/fireworks/models/deepseek-v3p2`) without resorting to URL encoding,
which the project does not use.

- Add 21 unit tests covering plain params, tail greedy, middle greedy,
  multi-greedy rejection, and edge cases.
- Document the feature under "Greedy Path Parameters" in the API design
  guidelines with tail/middle/mixed examples.
2026-04-17 07:29:27 -07:00
fullex
544a8373f8 refactor(data): translate SQLite constraint errors via withSqliteErrors
Introduce src/main/data/db/sqliteErrors.ts with three APIs:

- classifySqliteError(e): walks the .cause chain and classifies UNIQUE /
  FOREIGN KEY / CHECK / NOT NULL violations, including PRIMARYKEY and
  ROWID codes which SQLite reports as semantically UNIQUE.
- withSqliteErrors(op, handlers): runs op and routes recognized
  violations through a sparse handlers map. Constraint kinds without a
  handler and non-SQLite errors are rethrown unchanged by construction,
  so "forgot to rethrow" is not representable in client code.
- defaultHandlersFor(resource, identifier): complete default handler set
  for the common CRUD case. Spread to override specific kinds.

Migrate TranslateLanguageService.create and MiniAppService.create to the
new API. The MiniAppService migration also removes a select-then-insert
TOCTOU race: two concurrent create requests with the same appId now
produce one 201 and one 409 instead of one 201 and one 500.

Delete the now-unused errorUtils.ts. Document the module in
src/main/data/db/README.md and api-design-guidelines.md with a note that
withSqliteErrors handlers are a TOCTOU fallback, not a replacement for
application-level pre-validation.
2026-04-16 09:31:36 -07:00
fullex
209b8aa6c7 docs: remove Repository layer from data architecture, default to Service-only pattern
Services now handle both business logic and data access directly via Drizzle ORM.
Repository pattern is strongly discouraged unless absolutely necessary.

Signed-off-by: fullex <0xfullex@gmail.com>
2026-04-10 01:18:32 -07:00
亢奋猫
a83f98fd24 docs: consolidate bilingual docs, add link checker and architecture overview (#14138)
Co-authored-by: fullex <106392080+0xfullex@users.noreply.github.com>
2026-04-09 16:01:40 +08:00