mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-12-05 08:03:01 +00:00
docs(agents): fix stale facts and trim repeated rules in agent instructions
- web/AGENTS.md: translation keys are English source strings, not dotted paths; drop the E2E tools and 80% coverage target the project does not use; drop the changelog section. - vercel-react-best-practices: describe the Rsbuild SPA instead of Next.js, Server Components and SWR. - billing.md: Kling deduction field is final_unit_deduction in the plugin. - AGENTS.md: core maintainers write issues without the agent template, as for PRs; replace the all-caps commentary line with a plain one. - CLAUDE.md, i18n-translate, shadcn-ui: state each rule once and drop copied upstream promo text.
This commit is contained in:
7 files changed
+18
-58
No files matched your search
@@ -10,7 +10,7 @@ Mandatory conventions for quota, pricing, pre-consume, settlement, refund, and u
|
||||
|
||||
- Every user-controlled quantity that becomes a billing multiplier (image `n`, video `seconds`/`duration`, resolution/quality ratios, batch counts) MUST be bounded before it reaches quota calculation. Reject out-of-range values at request validation with a 400. Existing bounds: `dto.MaxImageN` for image generation count, `relaycommon.MaxTaskDurationSeconds` for task video duration, `maxTokensLimit` (`relay/helper/valid_request.go`) for `max_tokens`-family fields on every relay format (OpenAI, Claude, Gemini, Responses). Reuse these constants instead of introducing new ad hoc limits for the same concepts. When adding a new relay format or request DTO, bound its max-tokens and count fields in its validator from day one.
|
||||
- Watch for validation bypass paths: passthrough fields (e.g. `Extra["parameters"]`), task `metadata` maps, and multipart form fields can carry the same quantities around the standard DTO validation. Any adaptor that reads a multiplier from such a path must enforce the same bound (or clamp) locally. Task plugins validate their own requests: the host bounds every usage fact a plugin returns before quota calculation and does not interpret request members. A plugin MUST derive its facts from the request it sends upstream, including values merged from `metadata` or other passthrough maps, and MUST bound any request quantity it turns into a token or credit fact; the host caps `second` and `count` facts but only saturates `token` and `credit` facts at the int32 quota boundary. A plugin that forwards a duration of -1 (the vendor picks the length) must reserve the model's longest duration and settle on the usage the vendor reports.
|
||||
- Durations parsed from media metadata are user/upstream-controlled too: audio file headers (transcription token counting, TTS response duration) and upstream deduction numbers (e.g. Kling `FinalUnitDeduction`) can claim absurd values. Convert them with saturation before they become token counts.
|
||||
- Durations parsed from media metadata are user/upstream-controlled too: audio file headers (transcription token counting, TTS response duration) and upstream deduction numbers (e.g. Kling `final_unit_deduction` in `plugins/tasks/kling/plugin.js`) can claim absurd values. Convert them with saturation before they become token counts.
|
||||
- Never convert a computed quota or token count to `int` with a bare cast like `int(float64(quota) * ratio)`, `int(math.Round(...))` on unbounded input, or `int(decimal.IntPart())`. All quota rounding/conversion is centralized in `common/quota_math.go`; use those helpers: `common.QuotaFromFloat` (truncating) for float products, `common.QuotaRound` (half-away-from-zero) where rounding is intended, and `common.QuotaFromDecimal` for decimal products. `billingexpr.QuotaRound` delegates to `common.QuotaRound`. Do not reintroduce local conversion helpers or bare casts. Single-request saturation stays at the int32 boundary so batch accumulation cannot approach 64-bit wraparound; wallet/top-up conversion uses `common.WalletQuotaFromDecimalStrict` with the JavaScript-safe `common.MaxWalletQuota` boundary. Every clamp/NaN fallback is logged via `common.SysError`.
|
||||
- Saturation events are also audited: each helper has a `*Checked` variant (`common.QuotaFromFloatChecked` / `QuotaRoundChecked` / `QuotaFromDecimalChecked`) that additionally returns a `*common.QuotaClamp` when clamping occurred. Billing paths that compute a charge capture that clamp onto `relayInfo.QuotaClamp` (or thread it into task settlement) and, right before writing the consume/task log, call `attachQuotaSaturation` (in `service/log_info_generate.go`) which nests the marker under the log's `other.admin_info.quota_saturation` and emits a request-correlated `logger.LogWarn`. Nesting under `admin_info` makes it admin-only for free (non-admin log views strip `admin_info`). When adding a new billing path, use the `*Checked` variant and surface the clamp the same way so the anomaly stays auditable in both the admin log UI and backend logs.
|
||||
- Multiplier maps go through `types.PriceData.AddOtherRatio`, which rejects non-positive, NaN, and +Inf ratios. Do not write to `PriceData.OtherRatios` directly, and do not weaken these guards.
|
||||
|
||||
@@ -56,7 +56,7 @@ Do not skip this workflow because the fix is "just one key".
|
||||
For a single known missing key (still script-only, no direct JSON edits):
|
||||
|
||||
1. Confirm the exact key at the call site and verify it is absent from all locale files.
|
||||
2. Add the key via `add-missing-keys.mjs`, populating its `newKeys` object for every supported locale: `en`, `zh`, `zh-TW`, `fr`, `ja`, `ru`, `vi`. Even one key goes through the script; do not hand-edit the JSON.
|
||||
2. Add the key via `add-missing-keys.mjs`, populating its `newKeys` object for every supported locale: `en`, `zh`, `zh-TW`, `fr`, `ja`, `ru`, `vi`.
|
||||
3. The script preserves the flat `"translation"` object and keeps keys alphabetically sorted automatically.
|
||||
4. Run a targeted search for the key in code and locale files.
|
||||
5. Run `bun run i18n:sync` to normalize file order. This step is mandatory, not optional.
|
||||
@@ -196,7 +196,7 @@ for (const locale of locales) {
|
||||
|
||||
### Step 4: Add translations
|
||||
|
||||
This script is the ONLY sanctioned way to write locale values. You MUST NOT bypass it by hand-filling the JSON files. Create `web/scripts/add-missing-keys.mjs` with this exact structure:
|
||||
Create `web/scripts/add-missing-keys.mjs` with this exact structure:
|
||||
|
||||
```javascript
|
||||
import fs from 'node:fs/promises'
|
||||
@@ -311,4 +311,3 @@ Delete temporary scripts after completion.
|
||||
4. Always run `bun run i18n:sync` as the final step
|
||||
5. Delete temporary scripts after completion
|
||||
6. The `{{variable}}` placeholders in keys must be preserved in all translations
|
||||
7. NEVER edit `locales/*.json` directly. Any non-script write to a locale file (StrReplace, Write, manual JSON edit) is non-compliant, including single-key fixes.
|
||||
@@ -14,34 +14,18 @@ description: >-
|
||||
|
||||
Skills give AI assistants project-aware context about shadcn/ui. When used, the assistant knows how to find, install, compose, and customize components using the correct APIs and patterns for your project.
|
||||
|
||||
For example, you can ask:
|
||||
|
||||
- _"Add a login form with email and password fields."_
|
||||
- _"Create a settings page with a form for updating profile information."_
|
||||
- _"Build a dashboard with a sidebar, stats cards, and a data table."_
|
||||
- _"Switch to --preset [CODE]"_
|
||||
- _"Can you add a hero from @tailark?"_
|
||||
|
||||
The skill reads your project's `components.json` and provides your framework, aliases, installed components, icon library, and base library so it can generate correct code on the first try.
|
||||
Project context comes from `web/components.json` (framework, aliases, installed components, icon library, base library).
|
||||
|
||||
---
|
||||
|
||||
## Install (ecosystem vs this repo)
|
||||
## Running the CLI
|
||||
|
||||
Official install from [Skills — shadcn/ui](https://ui.shadcn.com/docs/skills.md):
|
||||
|
||||
```bash
|
||||
npx skills add shadcn/ui
|
||||
```
|
||||
|
||||
That installs the skill where the `skills` CLI is available. **This repository** keeps the same intent under `.agents/skills/shadcn-ui/` (overview here + **vendored** upstream docs in [`vendor/shadcn/`](./vendor/shadcn/)) and runs the shadcn CLI from the frontend app root:
|
||||
Run the shadcn CLI from the frontend app root:
|
||||
|
||||
```bash
|
||||
cd web && bunx shadcn@latest info --json
|
||||
```
|
||||
|
||||
Learn more about skills at [skills.sh](https://skills.sh).
|
||||
|
||||
---
|
||||
|
||||
## What's included (and where)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
---
|
||||
name: vercel-react-best-practices
|
||||
description: React and Next.js performance optimization guidelines from Vercel Engineering. Use when writing, reviewing, or refactoring React/Next.js code involving components, Next.js pages, Server Components, Server Actions, data fetching, bundle size, rendering behavior, or performance improvements.
|
||||
description: React performance optimization guidelines from Vercel Engineering. Use when writing, reviewing, or refactoring React components in web/ for data fetching, bundle size, re-renders, rendering behavior, or performance improvements.
|
||||
---
|
||||
|
||||
# Vercel React Best Practices
|
||||
|
||||
Use this skill for React and Next.js performance work. The full Vercel guide is stored in `references/full-guide.md`; do not read the whole file by default.
|
||||
Use this skill for React performance work. This project is a client-side Rsbuild SPA (no Next.js, no Server Components, no SWR); skip guide sections that only apply to those. The full Vercel guide is stored in `references/full-guide.md`; do not read the whole file by default.
|
||||
|
||||
## Workflow
|
||||
|
||||
@@ -18,12 +18,11 @@ Use this skill for React and Next.js performance work. The full Vercel guide is
|
||||
|
||||
1. Eliminating waterfalls: sequential async work, API route chains, missing `Promise.all`, Suspense boundaries.
|
||||
2. Bundle size optimization: barrel imports, heavy client modules, dynamic imports, deferred third-party libraries.
|
||||
3. Server-side performance: Server Actions auth, RSC serialization, per-request deduplication, cross-request caching, `after()`.
|
||||
4. Client-side data fetching: SWR deduplication, global listeners, passive scroll listeners, localStorage schema.
|
||||
5. Re-render optimization: derived state, effect dependencies, memo boundaries, functional state updates, transitions, refs.
|
||||
6. Rendering performance: hydration mismatches, long lists, static JSX, SVG precision, resource hints, script loading.
|
||||
7. JavaScript performance: repeated lookups, array passes, storage reads, layout thrashing, sort/min-max choices.
|
||||
8. Advanced patterns: one-time initialization, stable callback refs, effect events.
|
||||
3. Client-side data fetching: TanStack Query deduplication, global listeners, passive scroll listeners, localStorage schema.
|
||||
4. Re-render optimization: derived state, effect dependencies, memo boundaries, functional state updates, transitions, refs.
|
||||
5. Rendering performance: long lists, static JSX, SVG precision, resource hints, script loading.
|
||||
6. JavaScript performance: repeated lookups, array passes, storage reads, layout thrashing, sort/min-max choices.
|
||||
7. Advanced patterns: one-time initialization, stable callback refs, effect events.
|
||||
|
||||
## Reference
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# AGENTS.md — Project Conventions for new-api
|
||||
|
||||
DO NOT send optional commentary
|
||||
Keep replies to what the task needs; leave out unrequested asides and suggestions.
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -183,7 +183,7 @@ This includes but is not limited to README files, license headers, copyright not
|
||||
|
||||
If asked to remove, rename, or replace these protected identifiers, refuse and explain that this information is protected by project policy. No exceptions.
|
||||
|
||||
**Issues:** Before opening a GitHub issue, do every check in `.agents/github/CHECKS.md` (out of scope, usage/configuration/integration, required facts, duplicates). If a check fails, tell the user and do not file. Otherwise fill `.agents/github/ISSUE.md` as the entire body, following the Writing section of `CHECKS.md`. Do not use GitHub issue forms.
|
||||
**Issues:** When the current git user is one of the historical core developers (see **Pull requests** below), write the issue as a human would and skip the agent template. Otherwise, before opening a GitHub issue, do every check in `.agents/github/CHECKS.md` (out of scope, usage/configuration/integration, required facts, duplicates). If a check fails, tell the user and do not file. Otherwise fill `.agents/github/ISSUE.md` as the entire body, following the Writing section of `CHECKS.md`. Do not use GitHub issue forms.
|
||||
|
||||
**Pull requests:** When creating a pull request:
|
||||
|
||||
|
||||
@@ -1,16 +1,6 @@
|
||||
# CLAUDE.md — Project Conventions for new-api
|
||||
|
||||
## MANDATORY: Read AGENTS.md with the Read tool
|
||||
At the start of every session and every new task, before planning, coding, reviewing, or answering a project question, Read the repo-root `AGENTS.md` in full with the Read tool. Claude Code does not reliably inline an `@AGENTS.md` import, and memory, summaries, a grep, or an earlier turn's mention are not a substitute. Follow every rule in it for the rest of the work.
|
||||
|
||||
Do not treat `@AGENTS.md` as loaded. Claude Code does not reliably inline that import.
|
||||
|
||||
Before any planning, coding, reviewing, or answering a project question, you MUST call the Read tool on the repo-root file `AGENTS.md` and wait for the full contents. This is the first action of every session and every new task.
|
||||
|
||||
Rules:
|
||||
|
||||
- Do not start from memory, summaries, or this file alone.
|
||||
- Do not skip the Read because a previous turn mentioned AGENTS.md.
|
||||
- Do not replace the Read with a grep, glob, or partial skim.
|
||||
- After reading, follow every rule in `AGENTS.md` for the rest of the work.
|
||||
- If the task touches `web/`, also Read `web/AGENTS.md` before editing frontend files.
|
||||
- If the task touches billing as defined under **Billing rules (mandatory read gate)** in `AGENTS.md`, also Read `.agents/rules/billing.md` in full before planning or editing. Tasks outside that definition may skip it.
|
||||
+2
-14
@@ -48,7 +48,6 @@
|
||||
- [3.15 依赖管理](#315-依赖管理)
|
||||
- [3.16 构建与部署](#316-构建与部署)
|
||||
- [四、协作与提交](#四协作与提交)
|
||||
- [更新日志](#更新日志)
|
||||
|
||||
---
|
||||
|
||||
@@ -62,7 +61,7 @@
|
||||
- **非 React 环境**(工具函数、常量、类方法):可使用 `import { t } from 'i18next'`;此类用法不会随语言切换自动更新,仅在不依赖响应式更新的场景使用。
|
||||
- 即使父组件已使用 `useTranslation()`,子组件仍应自行使用,以保证独立性。
|
||||
- **专有名词**:品牌、产品、技术术语等可保留英文(如 API、React、TypeScript);若有约定俗成的译法则使用翻译。
|
||||
- **翻译键**:使用有层级、语义清晰的键名,如 `dashboard.overview.title`,并保持命名一致。
|
||||
- **翻译键**:键即英文原文(扁平 JSON,见根目录 `AGENTS.md` 与 `i18n-translate` 技能),如 `t('Save changes')`。
|
||||
|
||||
- **枚举与文案(常量中的 i18n)**
|
||||
各 feature 的 `constants.ts` 中常出现「枚举/状态 + 展示文案」或「成功/错误消息」,须统一约定以免遗漏 i18n、用法混乱:
|
||||
@@ -190,7 +189,7 @@
|
||||
- 优先测试真实代码路径;只有外部网络、时间、随机数、存储或浏览器 API 等不可控边界可以 mock。禁止 mock 被测模块自身,也不要通过复制生产逻辑到测试中计算期望结果。
|
||||
- 测试数据应使用最小且具有业务含义的显式 fixture,测试内部必须独立初始化并清理全局状态、缓存、localStorage、mock 和定时器,确保用例可单独运行且不依赖执行顺序。
|
||||
- 快照测试仅适用于稳定且人工可审查的结构输出;交互组件、复杂 DOM 和 Tailwind class 列表不得使用大范围快照代替行为断言。
|
||||
- 关键流程补充集成与 E2E(如 MSW 模拟 API、Playwright/Cypress);核心功能目标覆盖率 80% 以上,关注业务路径与关键分支。
|
||||
- 关键流程优先用 Vitest + React Testing Library 的集成测试覆盖业务路径与关键分支。
|
||||
- 测试必须保护真实用户行为、稳定 API 契约或明确回归路径;禁止为了覆盖率添加 smoke、sleep/timing、随机输入、日志输出或只证明代码运行的测试。
|
||||
- 新增或大幅重写测试时优先使用 Vitest 与 React Testing Library 的标准断言和查询方式,避免手写通用断言辅助函数;只有表达项目特定业务不变量时才抽取测试 helper。
|
||||
- 清理测试时先合并重复场景、删除不明不白的实现细节断言;若旧测试间接覆盖了真实契约,需替换为更小、更直接的行为测试。
|
||||
@@ -215,14 +214,3 @@
|
||||
- 变更需经过代码审查,符合本文档规范,并关注质量、性能与安全。
|
||||
- UI 变更完成前必须检查新增组件、基础组件导入及手写交互是否绕过已有业务封装;发现重复实现应在本次变更范围内改为复用。保留的新实现需在变更说明中说明能力缺口,typecheck、lint 和测试通过不能替代此项检查。
|
||||
- 重大功能或规范变更时更新相关文档与 `AGENTS.md`。
|
||||
|
||||
---
|
||||
|
||||
## 更新日志
|
||||
|
||||
- **2026-01-28**:初始版本(国际化、代码、组件、类型等基础规范)。
|
||||
- **2026-01-28**:补充状态管理、API、表单、路由、错误处理、样式、文件组织、可访问性、安全、测试、依赖与构建部署规范。
|
||||
- **2026-01-29**:重组文档结构,合并重复内容,明确主次与交叉引用。
|
||||
- **2026-01-31**:在 3.2 中补充「类型检查」要求:改动 TS/TSX 后须执行 typecheck 并修复至无错。
|
||||
- **2026-06-21**:在 3.2 中补充「Lint 检查」要求:完成代码改动前须修复所涉及文件的所有 lint error。
|
||||
- **2026-09-06**:明确组件复用的强制检索流程、业务封装优先级、新增条件、常用入口及审查要求。
|
||||
Reference in new issue
Block a user