diff --git a/.claude/skills/ponytail-audit/LICENSE b/.claude/skills/ponytail-audit/LICENSE new file mode 100644 index 0000000000..715d483338 --- /dev/null +++ b/.claude/skills/ponytail-audit/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 DietrichGebert + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/.claude/skills/ponytail-audit/SKILL.md b/.claude/skills/ponytail-audit/SKILL.md new file mode 100644 index 0000000000..ff9a954807 --- /dev/null +++ b/.claude/skills/ponytail-audit/SKILL.md @@ -0,0 +1,103 @@ +--- +name: ponytail-audit +description: > + Quality audit of a whole repo: bugs, security holes, what breaks under real + load, risky code without tests, slow paths, and what to delete, merge or + split. Ranked, each finding explained in plain English. One-shot report, + changes nothing. Use for "audit this codebase", "review the whole repo", + "find bloat", "what can I delete", /ponytail-audit. +--- + +Audit the whole repo like the senior developer who just inherited it and +will be paged when it breaks. Order of importance: correct, safe, holds under +load, tested, fast, lean. Lean still matters: every extra line must be read, +tested and fixed later. This is a report the user asked for, so give it in full. + +## 1. Map first + +- Audit what the user names: a folder, a package, or the whole repo. + Nothing named: the whole repo. +- Read the README, the deploy and build config, the dependency list, the + entry points (main, routes, handlers, jobs, CLI commands) and the tests. +- Find the expected load: one person running a script, or many users and + processes at once. Judge scale against that, and say which load you assumed. +- Trace the main flows end to end: where data comes in, what is stored, + what goes out. Read those paths fully: input from users, money, auth, + data writes, background jobs, anything shared between processes. +- Big repo: go deep where a mistake costs the most, not file by file. Say + which parts you did not read. + +## 2. Look for + +1. **Bug:** wrong result, crash, missed edge case (empty, zero, last item, + rounding, time zones), callers that disagree with what a function returns, + the same rule applied differently in two places. +2. **Risk:** security holes (injection, weak randomness, secrets in code, + missing checks on input from users), data loss (errors swallowed, writes + in the wrong order, no transaction). +3. **Scale:** fine for one user, wrong for many: check-then-write races, the + same work done by every process, memory or lists that only grow, a query + per item, O(n^2) on big input, per-process state that must be shared. +4. **Missing test:** risky logic (a branch, a parser, money, security, data + writes) with no test that fails when it breaks. One good test, not coverage. +5. **Speed:** big slowdowns are problems. Small wins (work repeated in a hot + loop) are suggestions; some software counts every millisecond. +6. **Lean:** code that should not exist or should be smaller. + - delete: dead code, unused options, flags and config, speculative features + - reuse: two helpers doing the same thing (keep one, name the path) + - stdlib / native: the standard library or platform already does it; + a dependency doing what a few lines or the platform can do + - yagni: interface with one implementation, factory with one product, + wrapper that only passes calls through + - merge: near-copies that must change together + - split: one function or class doing several unrelated jobs, so it is + hard to read or test. Split by job, never by line count, and never into + helpers that exist only to make a function shorter. + +## 3. Check before you report + +- Every finding needs a concrete case: "this input or situation leads to this + wrong result". No case, no finding. +- Before calling code unused, grep the whole tree for it, including tests, + fixtures, config, and string or dynamic references. +- A shortcut marked with a `shortcut:` (or older `ponytail:`) comment that names its limit is a + decision, not a finding, unless the expected load already crosses it. +- Propose the smallest fix that works. Prefer fixes that delete code. Never + add layers, frameworks or config the problem does not need. +- No style taste, no "consider", no vague worries. + +## 4. Output + +Very simple English: short sentences, everyday words. Explain a technical +term the first time you use it. The reader may never have seen this code. + +Start with `What this repo does:` in two or three sentences, and the load +you assumed. + +Then the findings in three groups, most important first, skip empty groups: +- **Must fix:** bug, security, data loss, breaks at the expected load. +- **Should fix:** risky code without a test, real slowness, duplication, a + function that mixes jobs, code that should not exist. +- **Nice to have:** small speed-ups, shorter forms. + +Number findings across all groups, so the user can say "fix 2 and 5". At +most 20 findings; if you left smaller ones out, say how many. +Every finding has all four parts, each one or two short sentences: + +2. **Orders land on the wrong day** (`billing/close_day.py:L40-52`) + - **What this is:** At midnight this job closes the day and bills all orders of that day. + - **Problem:** It takes "today" from the server clock, which runs in UTC. An order placed + at 00:30 in Berlin is billed on the day before. + - **Fix:** Compute the day once in the shop's time zone: + `datetime.now(ZoneInfo("Europe/Berlin")).date()`. One line, nothing else changes. + - **If we skip it:** Late orders show the wrong date, and accounting fixes them by hand. + +End with: +- `Verdict:` one line: healthy, or what to fix first. +- `Lean: - lines, - dependencies possible.` when lean findings exist. +- `Not checked:` the parts you did not read or could not run. + +Nothing found: `What this repo does:`, then `Healthy. Nothing to fix.` and +one line on what you checked. + +One-shot report, changes no code. diff --git a/.claude/skills/ponytail-debt/LICENSE b/.claude/skills/ponytail-debt/LICENSE new file mode 100644 index 0000000000..715d483338 --- /dev/null +++ b/.claude/skills/ponytail-debt/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 DietrichGebert + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/.claude/skills/ponytail-debt/SKILL.md b/.claude/skills/ponytail-debt/SKILL.md new file mode 100644 index 0000000000..3124f520a6 --- /dev/null +++ b/.claude/skills/ponytail-debt/SKILL.md @@ -0,0 +1,44 @@ +--- +name: ponytail-debt +description: > + List every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, + changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the + shortcuts", /ponytail-debt. +--- + +Every deliberate ponytail shortcut is marked with a `shortcut:` comment naming +its ceiling and upgrade path (older code may say `ponytail:`). This collects them into one ledger so a deferral +can't quietly become permanent. + +## Scan + +Grep the repo for comment markers, skipping `.git` and everything the +`.gitignore` files ignore (dependencies, build output, caches, in any stack): + +`git grep --no-index --exclude-standard -nE '(#|//|/[*]) ?(shortcut|ponytail):'` (add other comment prefixes if your stack uses them) + +If the user names their own marker word (`/ponytail-debt TODO`), grep for that word instead. + +Each hit is one ledger row. The comment prefix keeps prose that merely mentions +the convention out of the ledger. Skip hits that are not a deferral, like a note +about a keyboard shortcut. + +## Output + +One row per marker, grouped by file: + +`:, . ceiling: . upgrade: .` + +The convention is `shortcut: , `, so pull the ceiling +and the trigger straight from the comment. Want an owner per row too? add +`git blame -L,`. + +Flag the rot risk: any marker comment that names no upgrade path or +trigger gets a `no-trigger` tag, those are the ones that silently rot. + +End with ` markers, with no trigger.` Nothing found: `No shortcut debt. Clean ledger.` + +## Boundaries + +Reads and reports only, changes nothing. To persist it, ask and it writes the +ledger to a file (e.g. `PONYTAIL-DEBT.md`). One-shot. diff --git a/.claude/skills/ponytail-gain/LICENSE b/.claude/skills/ponytail-gain/LICENSE new file mode 100644 index 0000000000..715d483338 --- /dev/null +++ b/.claude/skills/ponytail-gain/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 DietrichGebert + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/.claude/skills/ponytail-gain/SKILL.md b/.claude/skills/ponytail-gain/SKILL.md new file mode 100644 index 0000000000..6b86249d32 --- /dev/null +++ b/.claude/skills/ponytail-gain/SKILL.md @@ -0,0 +1,52 @@ +--- +name: ponytail-gain +description: > + Show ponytail's measured savings (code, cost, speed) from the benchmark. + One-shot display. Use for /ponytail-gain, "what does ponytail save", + "ponytail impact". +--- + +# Ponytail Gain + +Display this scoreboard when invoked. One-shot: do NOT change mode, write flag +files, or persist anything. + +The figures are the published agentic benchmark of Ponytail 5: headless Claude +Code (Opus 5.5, default effort) on 39 tasks (feature tickets in a real FastAPI + +React repo, bug fixes, security and privacy cases, small apps), 5 runs each, +against the same agent without the skill. 18 of the tasks have hidden checks +for correctness and safety. Each figure is the geometric mean of the per-task +medians. They are measured, not computed from the current repo. +Source: [upstream benchmark report](https://github.com/DietrichGebert/ponytail/blob/ebd8654c2c627f721eb8f9c0d1bd4090a29f9e10/benchmarks/results/2026-10-07-agentic.md). + +## Scoreboard + +Render plain ASCII bars. The bar length shows ponytail as a share of the +no-skill baseline; the label carries the exact figure: + +``` + ponytail gain benchmark · 39 tasks × 5 runs · Opus 5.5 + + no-skill ████████████████████ 100% + Lines of code █████████··········· 47% ▼ 53% + Output tokens ███████████········· 55% ▼ 45% + Cost ███████████████····· 74% ▼ 26% + Time ████████████········ 59% ▼ 41% + Hidden checks passed 97% (no-skill 96%) + Tests where the logic needs one 98% (no-skill 68%) + + This repo: /ponytail-debt (shortcuts you deferred) + /ponytail-audit (what's still cuttable) +``` + +## Honesty boundary + +These are benchmark averages, not this repo. NEVER print a per-repo savings +number ("you saved X lines/tokens here"): the unbuilt version was never +written, so there is no real baseline to subtract from in a live repo. The +only real per-repo figures come from `/ponytail-debt` (a counted ledger), and +this card points there instead of inventing one. + +## Boundaries + +One-shot display. Edits nothing, changes no mode. diff --git a/.claude/skills/ponytail-help/LICENSE b/.claude/skills/ponytail-help/LICENSE new file mode 100644 index 0000000000..715d483338 --- /dev/null +++ b/.claude/skills/ponytail-help/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 DietrichGebert + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/.claude/skills/ponytail-help/SKILL.md b/.claude/skills/ponytail-help/SKILL.md new file mode 100644 index 0000000000..ded6802b80 --- /dev/null +++ b/.claude/skills/ponytail-help/SKILL.md @@ -0,0 +1,87 @@ +--- +name: ponytail-help +description: > + Quick reference for ponytail levels, skills and commands. One-shot display. + Use for /ponytail-help, "ponytail help", "how do I use ponytail". +--- + +# Ponytail Help + +Display this reference card when invoked. One-shot, do NOT change mode, +write flag files, or persist anything. + +## BiSheng project installation + +For BiSheng, show the skill list and project instructions first. Codex uses +`$ponytail`, `$ponytail-review`, `$ponytail-audit`, `$ponytail-debt`, +`$ponytail-gain`, and `$ponytail-help`. In Claude Code, use the corresponding +slash commands. State the desired level in the request, for example +`$ponytail lite`. The project ships standalone skill files. Automatic +activation, persisted modes, Band, and plugin updates in the upstream reference +below apply to plugin installations. Show those details only if requested. +See `docs/SDD-Guide.md` for when to use each skill in BiSheng. + +## Levels + +| Level | Trigger | What change | +|-------|---------|-------------| +| **Lite** | `/ponytail lite` | Build what was asked, name the smaller option in one line. | +| **Full** | `/ponytail` | The smallest complete change, a check where the logic needs one, and a reply that names what was skipped and any risk. Default. | +| **Ultra** | `/ponytail ultra` | Also questions the request and pushes back before building. | + +Level sticks until changed or session end. + +## Skills + +| Skill | Trigger | What it does | +|-------|---------|--------------| +| **ponytail** | `/ponytail` | Lazy mode itself: least new code, clear replies that name skipped work and risks. | +| **ponytail-review** | `/ponytail-review` | Quality review of a diff: bugs, security, load, missing tests, speed, what to cut. Each finding says what goes wrong and how to fix it. | +| **ponytail-audit** | `/ponytail-audit` | The same quality review for the whole repo, ranked. | +| **ponytail-debt** | `/ponytail-debt` | Harvest `shortcut:` comments into a tracked ledger. | +| **ponytail-gain** | `/ponytail-gain` | Measured-impact scoreboard: less code, less cost, more speed. | +| **ponytail-help** | `/ponytail-help` | This card. | + +In Codex CLI and the IDE extension, invoke skills with `$ponytail:ponytail`, +`$ponytail:ponytail-review`, or `$ponytail:ponytail-help`. Claude Code and OpenCode use the +slash-command forms above (OpenCode ships all six as slash commands). + +## Deactivate + +Say "stop ponytail" or "normal mode". Resume anytime with `/ponytail`. +`/ponytail off` also works. + +## Band (Claude Code) + +`/ponytail band` hides the band above the prompt, the same command brings it back. +`/ponytail band on` and `/ponytail band off` set it directly. The level stays. +`/ponytail band import` adds your past Claude Code sessions (cost, agent time, tokens) to the board. + +## Configure Default Mode + +Default mode = `full`, auto-active every session. Change it: + +**Environment variable** (highest priority): +```bash +export PONYTAIL_DEFAULT_MODE=ultra +``` + +**Config file** (`~/.config/ponytail/config.json`, Windows: `%APPDATA%\ponytail\config.json`): +```json +{ "defaultMode": "lite" } +``` + +Set `"off"` to disable auto-activation on session start, activate manually +with `/ponytail` when wanted. + +Resolution: env var > config file > `full`. + +## Update + +Enable auto-update once: open `/plugin`, go to Marketplaces, pick ponytail, Enable auto-update. Claude Code then pulls new versions at startup (run `/reload-plugins` when it prompts). Manual refresh: `/plugin marketplace update ponytail` then `/reload-plugins`. + +If `/plugin` is not recognized, your Claude Code is out of date. Update it (`npm install -g @anthropic-ai/claude-code@latest`, or `brew upgrade claude-code`) and restart. Other hosts use their own update flow. + +## More + +Full docs + examples: https://github.com/DietrichGebert/ponytail diff --git a/.claude/skills/ponytail-review/LICENSE b/.claude/skills/ponytail-review/LICENSE new file mode 100644 index 0000000000..715d483338 --- /dev/null +++ b/.claude/skills/ponytail-review/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 DietrichGebert + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/.claude/skills/ponytail-review/SKILL.md b/.claude/skills/ponytail-review/SKILL.md new file mode 100644 index 0000000000..a50e3ac6de --- /dev/null +++ b/.claude/skills/ponytail-review/SKILL.md @@ -0,0 +1,101 @@ +--- +name: ponytail-review +description: > + Quality review of a change: is the logic right, is it safe, does it hold + under real load, is risky code tested, is it fast enough, and is every line + needed. Reads the connected code, not only the diff. Each finding is + explained in plain English. Use for "review this", "code review", "review + the last commit", "review my PR", "is this over-engineered", /ponytail-review. +--- + +Review a change like the senior developer who will be paged when it breaks. +Order of importance: correct, safe, holds under load, tested, fast, lean. +Lean still matters: every extra line must be read, tested and fixed later. +This is a report the user asked for, so give it in full. + +## 1. Understand first + +- Review what the user names: uncommitted or staged changes, a branch, a PR + link, or files. Nothing named: the uncommitted changes, or the last commit + if there are none. +- Read the diff, then the code it touches: callers of every changed function, + the functions it calls, the tests, the README. +- Trace the real flow: where data comes in, what is stored, what goes out. +- A change can break code it does not touch. When a signature, return value + or behavior changes, grep every caller. +- Find the expected load in the repo (README, deploy config): one person + running a script, or many users and processes at once. Judge scale against + that, and say which load you assumed. + +## 2. Look for + +1. **Bug:** wrong result, crash, missed edge case (empty, zero, last item, + rounding, time zones), a caller broken by the change, a fix applied in one + caller while the shared function stays broken. +2. **Risk:** security holes (injection, weak randomness, secrets, missing + checks on input from users), data loss (errors swallowed, writes in the + wrong order, no transaction). +3. **Scale:** fine for one user, wrong for many: check-then-write races, the + same work done by every process, memory or lists that only grow, a query + per item, O(n^2) on big input, per-process state that must be shared. +4. **Missing test:** risky new logic (a branch, a parser, money, security, + data writes, a bug fix) with no test that fails when it breaks. One good + test, not coverage. +5. **Speed:** big slowdowns are problems. Small wins (work repeated in a hot + loop) are suggestions; some software counts every millisecond. +6. **Lean:** code that should not exist or should be smaller. + - delete: dead code, unused options, speculative features + - reuse: the repo already has this helper (name the path) + - stdlib / native: the standard library or platform already does it; a + new dependency for a few lines + - yagni: abstraction with one implementation, config nobody sets + - merge: near-copies that must change together + - split: one function doing several unrelated jobs, so it is hard to read + or test. Split by job, never by line count, and never into helpers that + exist only to make a function shorter. + +## 3. Check before you report + +- Every finding needs a concrete case: "this input or situation leads to this + wrong result". No case, no finding. +- Re-read the lines and confirm: the caller exists, the value can really be + empty, the code really is unused. +- A shortcut marked with a `shortcut:` (or older `ponytail:`) comment that names its limit is a + decision, not a finding, unless the expected load already crosses it. +- Propose the smallest fix that works. Prefer fixes that delete code. Never + add layers, frameworks or config the problem does not need. +- No style taste, no "consider", no vague worries. + +## 4. Output + +Very simple English: short sentences, everyday words. Explain a technical +term the first time you use it. The reader may never have seen this code. + +Start with `What this change does:` in two or three sentences. + +Then the findings in three groups, skip empty groups: +- **Must fix:** bug, security, data loss, breaks at the expected load. +- **Should fix:** risky code without a test, real slowness, duplication, a + function that mixes jobs, code that should not exist. +- **Nice to have:** small speed-ups, shorter forms. + +Number findings across all groups, so the user can say "fix 2 and 5". +Every finding has all four parts, each one or two short sentences: + +2. **Orders land on the wrong day** (`billing/close_day.py:L40-52`) + - **What this is:** At midnight this job closes the day and bills all orders of that day. + - **Problem:** It takes "today" from the server clock, which runs in UTC. An order placed + at 00:30 in Berlin is billed on the day before. + - **Fix:** Compute the day once in the shop's time zone: + `datetime.now(ZoneInfo("Europe/Berlin")).date()`. One line, nothing else changes. + - **If we skip it:** Late orders show the wrong date, and accounting fixes them by hand. + +End with: +- `Verdict: Ship.` or `Verdict: fix 1 and 3 first.` +- `Lean: - lines possible.` when lean findings exist. +- `Not checked:` one line, if something mattered and you could not check it. + +Nothing found: `What this change does:`, then `Looks good. Ship.` and one line +on what you checked. + +Lists findings, changes no code. diff --git a/.claude/skills/ponytail/LICENSE b/.claude/skills/ponytail/LICENSE new file mode 100644 index 0000000000..715d483338 --- /dev/null +++ b/.claude/skills/ponytail/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 DietrichGebert + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/.claude/skills/ponytail/SKILL.md b/.claude/skills/ponytail/SKILL.md new file mode 100644 index 0000000000..d64edd3226 --- /dev/null +++ b/.claude/skills/ponytail/SKILL.md @@ -0,0 +1,52 @@ +--- +name: ponytail +description: > + Lazy senior dev mode: the smallest change that fully solves the task, and a + reply a busy human understands in one read. Use on any coding task (writing, + fixing, refactoring, reviewing, choosing dependencies) and when the user says + "ponytail", "be lazy", "simplest solution", "yagni", or complains about + over-engineering or bloat. Levels: lite, full (default), ultra. +argument-hint: "[lite|full|ultra|off]" +license: MIT +--- + +# Ponytail + +You are a lazy senior developer. The best code is the code never written. You solve the whole problem with the least new code. End your reply with one or two lines: what you skipped or did not check, and any risk the user must know. + +Active for the whole session until the user says "stop ponytail" or "normal mode". Switch level: `/ponytail lite|full|ultra`. + +## Before you write + +Read the task and the code it touches. List every place your change must reach: callers, tests, fixtures, config, exports. Check what your change could break for users: data it would destroy or expose, callers that stop working. That is scope. Extra features are not. + +## The smallest complete change + +Take the first option that fully works: + +1. Does it need to exist? Skip features, options and flexibility nobody asked for, and name them in one line. A vague request ("build me X") gets the smallest version that does the core job. +2. Already in this codebase (a helper, component, service, pattern)? Use it the way the surrounding code does. +3. Standard library or a platform feature? Use it, unless the project has its own. A house component beats a native widget. +4. An installed dependency? Use it. Never add a dependency for a few lines. +5. Can it be one line a reader gets at a glance? One line. +6. Otherwise: the minimum code that works. + +- Be lazy about the solution, never about the change itself: finish every part the task needs, including the callers, tests and fixtures your change breaks. +- No abstraction, wrapper, type conversion, option, config, boilerplate or "for later" code nobody asked for. Keep values in the form the platform already gives you. Deletion beats addition. Keep the structure the codebase already has: its layers, interfaces and conventions. +- The shortest working diff wins, once you know everything it must touch. A one-liner that needs decoding is not short. +- Comment only the why the code cannot show, in one line. +- Bug fix: before you edit, grep every caller of the function you touch, then fix the root cause once in the shared code. +- Code you move or merge keeps its error handling and validation. +- Between options of equal size, take the one that is correct on edge cases. +- Lazy code without its check is unfinished: new non-trivial logic (a branch, a loop, a parser, money or security, or a whole new script or app) leaves one small test or an assert-based self-check. Trivial changes need none. +- A shortcut with a known limit gets a code comment in this form: `shortcut: , `. + +Never cut: validation at trust boundaries, error handling that prevents data loss, security, accessibility, the calibration real hardware needs, anything the user asked for. + +## Levels + +| Level | Behavior | +|-------|----------| +| **lite** | Build what was asked. Name the smaller option in one line and let the user pick. | +| **full** | The rules above. Default. | +| **ultra** | Also question the request: before building, push back on any part the need does not justify. | diff --git a/.claude/skills/sdd-code-review/SKILL.md b/.claude/skills/sdd-code-review/SKILL.md index 40619a979c..2214196855 100644 --- a/.claude/skills/sdd-code-review/SKILL.md +++ b/.claude/skills/sdd-code-review/SKILL.md @@ -29,7 +29,7 @@ L2 特性级多维度代码审查。Feature 全部任务完成后执行(SDD 1. 执行 `git diff ...HEAD --stat` 获取变更文件列表 2. 执行 `git diff ...HEAD` 获取完整 diff -3. 对照 Feature 的 `spec.md`、`design.md` 和 `tasks.md` +3. 对照所选 SDD 流程要求的 Feature 文档。无需新建文档的热修,按改动涉及的现有契约或设计约束审查 4. 按 7 维度逐一审查 5. 输出审查报告 @@ -50,15 +50,15 @@ L2 特性级多维度代码审查。Feature 全部任务完成后执行(SDD ### 维度 2:权限与认证 -> 以 `docs/constitution.md` C4 为准;本表只列审查时要看的点。 +> 权限规则以[架构宪章](../../../docs/constitution.md) C4 为准。审查时沿调用链核对以下事项。 | 检查项 | 说明 | |--------|------| | 认证注入 | 需要认证的端点是否使用 `UserPayload = Depends(UserPayload.get_login_user)` | -| 资源动作鉴权 | 资源操作是否走 `permission.application` 的 `require_business_action` / `check_business_action`(F048 统一运行时),而不是直接查 `role_access`、OpenFGA 或旧的 relation/`permission_id` 模板(RULE-8) | -| 判定顺序 | 不自行重写 super_admin → 租户不匹配拒绝 → 租户管理员 → Catalog/动作闸 → OpenFGA 的短路顺序;RBAC 菜单权限不能当资源动作的兜底放行 | -| 资源生命周期 | 资源创建、移动、复制、删除与授权变更是否走权限模块的投影台账,而不是业务代码自己写 tuple(RULE-9) | -| tenant_id 隔离 | 跨租户访问被阻止;批量 `update()` / `delete()` 和原生 SQL 是否手写了 tenant 条件(自动过滤只拦 SELECT) | +| 资源动作鉴权 | 核对各业务入口怎样调用 C4 规定的权限入口,是否存在绕过路径(RULE-8) | +| 判定顺序 | 按 C4 核对拒绝条件和短路顺序,抽查拒绝后能否被其他权限分支放行 | +| 资源生命周期 | 核对资源创建、移动、复制、删除和授权变更是否走 C4 规定的投影台账(RULE-9) | +| 租户隔离 | 按 [C3](../../../docs/constitution.md#c3-multi-tenant-data-isolation) 核查 ORM 查询、批量写入和原生 SQL;确认整条链路使用已验证的目标租户,较宽的查询范围不会扩大写入范围 | | 普通用户验证 | 权限相关的测试或手动验证是否用了非管理员账号(super_admin 会短路) | | WebSocket 认证 | WS 端点是否使用 `UserPayload.get_login_user_from_ws` | @@ -101,9 +101,8 @@ L2 特性级多维度代码审查。Feature 全部任务完成后执行(SDD |--------|------| | DDD 分层 | 新代码在正确的层级(domain/services vs api/endpoints) | | 命名一致 | DAO/Service/错误码命名遵循项目约定 | -| 代码重复 | 无复制粘贴式重复逻辑(应提取到 Service 或工具函数) | -| 未使用代码 | 无 dead code、注释掉的代码块、空函数 | -| 格式化 | Python 代码通过 ruff check(hook 自动处理) | +| 实现范围 | 按 [Ponytail](../ponytail/SKILL.md) 核对本次变更是否复用了合适的现有实现,是否新增可省的封装或无用代码 | +| 格式化 | 核对本次 Python 改动的 Ruff 检查结果,命令见[后端规范](../../../src/backend/AGENTS.md) | ### 维度 7:文档同步(design.md 现状快照) @@ -111,7 +110,7 @@ L2 特性级多维度代码审查。Feature 全部任务完成后执行(SDD | 检查项 | 说明 | 严重度 | |--------|------|--------| -| design.md 存在 | feature 目录下有 `design.md`(按 `features/_templates/design.md` 起的稿) | HIGH(缺失直接 NEEDS_FIX) | +| design.md 存在 | 所选流程要求设计文档时,feature 目录有按 `features/_templates/design.md` 编写的 `design.md` | HIGH(应有而缺失时 NEEDS_FIX) | | 决策同步 | diff 中新增/替换的关键技术决策(数据格式、配对/匹配策略、同步 vs 异步、二进制依赖等)在 §3 方案对比有记录,且给出"何时该重新考虑" | HIGH | | 数据流/契约同步 | diff 触及 API 路径 / 请求响应字段 / 内部 Service 入参出参 / 数据库新表新字段 / 关键文件职责变化 → §4.1 数据流、§4.2 字段约定、§4.3 模块职责对应章节已更新 | HIGH | | 已知坑同步 | 修了一个"代码里看不出的"反直觉 bug(典型:上游字段格式不符合直觉、运行时值与文档不符、必须的兜底逻辑)→ §5 已知坑 表新增一行(带"如果不知道会怎样"+"在哪处理") | HIGH | diff --git a/.claude/skills/sdd-review/SKILL.md b/.claude/skills/sdd-review/SKILL.md index 7c55026d6e..631773a37c 100644 --- a/.claude/skills/sdd-review/SKILL.md +++ b/.claude/skills/sdd-review/SKILL.md @@ -1,7 +1,7 @@ --- name: sdd-review description: 对 BiSheng 项目的 SDD 文档执行审查。 - - spec:写完 spec.md 后调用,同时检查 PRD gap 和架构合规性,生成报告供用户参考 + - spec:写完 spec.md 后调用,检查需求覆盖、验收标准和功能边界 - design:写完 design.md 后调用,检查"接手测试"四要素(现状/决策/坑/契约),生成报告供用户参考 - tasks:写完 tasks.md 后自动调用,检查 AC 追溯、任务拆解质量和技术债预防 用法:/sdd-review ,doc_type 为 spec / design / tasks。 @@ -32,22 +32,22 @@ description: 对 BiSheng 项目的 SDD 文档执行审查。 若参数缺失或无效,向用户报告错误后停止。 +三个模式均从特性所属版本目录读取版本契约(`/../release-contract.md`)。如果缺失,报告缺失路径,标明相关检查未完成。 + --- ### spec 模式(辅助审查,不自动推进) -spec.md 合并了需求规范和技术设计,因此 spec 审查同时覆盖需求覆盖和架构合规检查。 +`spec.md` 只定义要做什么、如何验收和范围边界。技术方案和架构合规留到 design 模式。 -**第二步(spec):执行合并审查** +**第二步(spec):审查需求** 读取文件: - `/spec.md`(已写的规格文档) - spec.md 中"关联 PRD"字段指向的文件(若未标注,读取 `docs/PRD/` 下与特性名最相关的文件) -- `features/v2.5.0/release-contract.md`(不变量约束,确认 spec 未越界) -- `docs/architecture/02-backend-modules.md`(后端模块架构) -- `docs/architecture/10-permission-rbac.md`(权限体系) +- 当前版本的 `release-contract.md`(领域归属和可观测的业务不变量) -按 `references/spec-checklist.md` 中的检查清单执行 14 项检查。 +按 `references/spec-checklist.md` 审查。 **第三步(spec):展示报告,等待用户确认** @@ -55,7 +55,7 @@ spec.md 合并了需求规范和技术设计,因此 spec 审查同时覆盖需 - 无 gap / 无问题:告知"审查通过,可继续确认" - 有 gap / 有问题:展示每个问题(MISSING / FORMAT / CONFLICT / ISSUE),供用户决定是否修改 -**等待用户确认**(唯一手动暂停点)。用户确认后,将 `/tasks.md` 状态表中 spec.md 行更新为 `✅ 已评审`。 +**等待用户确认**。确认后,将 `tasks.md` 状态表中 spec.md 行记为 `✅ 已评审`。如果尚未创建 `tasks.md`,在任务拆解阶段补录这次确认。 --- @@ -70,7 +70,7 @@ design.md 是"现状快照 + 关键决策"文档,决定新 agent 接手时能 - `/spec.md`(校验 design 没偏离需求) - `/tasks.md`(若存在;校验偏差记录已回写) - `features/_templates/design.md`(模板结构基线) -- `features/v{X.Y.Z}/release-contract.md`(关键约束、不变量) +- 当前版本的 `release-contract.md`(关键约束、不变量) 按 `references/design-checklist.md` 中的检查清单执行 24 项检查。 @@ -80,7 +80,7 @@ design.md 是"现状快照 + 关键决策"文档,决定新 agent 接手时能 - 无问题:告知"审查通过,可继续确认" - 有问题:展示每个问题(ISSUE 含 SEVERITY 和 LOC),供用户决定是否修改 -**等待用户确认**(唯一手动暂停点)。用户确认后,将 `/tasks.md` 状态表中 design.md 行更新为 `✅ 已评审`(若状态表尚无该行,提示用户补一行 `| design.md | 🔲 草稿 | ... |`)。 +**等待用户确认**。确认后,将 `tasks.md` 状态表中 design.md 行记为 `✅ 已评审`。如果尚未创建 `tasks.md`,在任务拆解阶段补录这次确认。 --- @@ -90,8 +90,9 @@ design.md 是"现状快照 + 关键决策"文档,决定新 agent 接手时能 读取文件: - `/tasks.md` -- `/spec.md`(验收标准 + 技术方案) -- `features/v2.5.0/release-contract.md`(领域归属 + 不变量) +- `/spec.md`(验收标准) +- `/design.md`(已确认的技术方案,所选流程要求时) +- 当前版本的 `release-contract.md`(领域归属和不变量) 按 `references/tasks-checklist.md` 中的检查清单执行 21 项检查。 diff --git a/.claude/skills/sdd-review/references/design-checklist.md b/.claude/skills/sdd-review/references/design-checklist.md index d20d32e6e4..03672d98dc 100644 --- a/.claude/skills/sdd-review/references/design-checklist.md +++ b/.claude/skills/sdd-review/references/design-checklist.md @@ -5,8 +5,8 @@ - {feature_dir}/spec.md(What 和 AC,校验 design 没有偏离需求) - {feature_dir}/tasks.md(若已存在;校验流水账与 design 现状一致) - features/_templates/design.md(模板结构基线) -- features/v{X.Y.Z}/release-contract.md(确认关键约束、不变量、依赖契约对齐) -- docs/constitution.md(架构铁律 C1–C7,用于 Constitution Check) +- {feature_dir}/../release-contract.md(确认当前版本的关键约束、不变量、依赖契约对齐) +- docs/constitution.md(当前架构铁律,用于 Constitution Check) **核心评判标准 — 接手测试**: > 想象一个新 agent 一个月后接手这个 feature 做扩展。他**只能读 design.md**, @@ -23,8 +23,8 @@ **§2 关键约束 + Constitution Check**: 3. 是否只写**本功能特有**的约束(性能 / 容量 / 部署形态 / 上游数据格式依赖)? -4. 全局架构铁律(双 DB / 多租户 / 权限 / 分层 / 错误码)是否**只引用 `docs/constitution.md` C1–C7、未重抄**(而非凭空写或抄一遍)? - - **Constitution Check(门禁)**:design 的方案是否违反 constitution 任一条 C1–C7?违反 → SEVERITY high(BLOCKER)。 +4. 全局架构铁律是否只引用 `docs/constitution.md` 中的相关条款? + - **Constitution Check(门禁)**:design 的方案是否违反当前架构宪章的任一适用条款?违反 → SEVERITY high(BLOCKER)。 **§3 方案对比与选定(最高价值章节)**: 5. 是否至少记录 1-3 条**关键设计决策**?(feature 完全无决策极少见) diff --git a/.claude/skills/sdd-review/references/spec-checklist.md b/.claude/skills/sdd-review/references/spec-checklist.md index 1169e6d34d..2f33e25d79 100644 --- a/.claude/skills/sdd-review/references/spec-checklist.md +++ b/.claude/skills/sdd-review/references/spec-checklist.md @@ -5,8 +5,7 @@ 请自行读取以下文件: - {feature_dir}/spec.md(已写的规格文档) - {prd_path}(从 spec.md「关联 PRD」字段获取;未标注则读 docs/PRD/ 下与特性名最相关的文件) -- features/v{X.Y.Z}/release-contract.md(不变量约束 + 领域归属,确认 spec 未越界) -- docs/constitution.md(架构铁律 C1–C7) +- {feature_dir}/../release-contract.md(当前版本的领域归属和业务不变量) **需求覆盖**: 1. PRD 的功能点 / 用户场景,spec 是否都有对应 AC? @@ -21,7 +20,7 @@ **边界与合规**: 8. 是否越界进入 release-contract 表 1 中归属其他 Feature 的领域? -9. 是否与 release-contract 的 INV 不变量、或 constitution C1–C7 冲突? +9. 需求描述的行为是否与当前版本契约的业务不变量(INV)冲突? 10. **spec 是否误写了 How**(架构决策 / API 契约 / 数据模型 / 分层 / 响应格式 / 文件清单 / 性能指标)?这些应在 design.md —— spec 里出现即为 gap(违反纯 What 模型)。 返回格式(必须严格遵守): @@ -29,7 +28,7 @@ 有 gap / 问题时,每个问题单独一行: - MISSING: | SEVERITY: high/medium/low | PRD_REF: - ISSUE: | SEVERITY: high/medium/low | AC: -- CONFLICT: <与 INV / constitution 冲突> | SEVERITY: high | REF: +- CONFLICT: <与当前版本的业务不变量冲突> | SEVERITY: high | REF: 无 gap 且无问题时,只返回一行:LGTM diff --git a/.claude/skills/sdd-review/references/tasks-checklist.md b/.claude/skills/sdd-review/references/tasks-checklist.md index 9bd6315703..8ec5681d65 100644 --- a/.claude/skills/sdd-review/references/tasks-checklist.md +++ b/.claude/skills/sdd-review/references/tasks-checklist.md @@ -1,14 +1,14 @@ 你是 BiSheng 项目的任务计划评审员。请审查 {feature_dir}/tasks.md。 请自行读取以下文件: -- {feature_dir}/spec.md(验收标准 + 技术方案) -- features/v2.5.0/release-contract.md(领域归属 + 不变量) +- {feature_dir}/spec.md(验收标准) +- {feature_dir}/design.md(已确认的技术方案,所选流程要求时) +- {feature_dir}/../release-contract.md(当前版本的领域归属和不变量) 任务规范要求: - Test-First:后端测试任务必须先于其配对的实现任务 - 每个测试任务必须有"覆盖 AC: AC-NN, AC-NN"标注 - 基础设施任务(ORM 模型、错误码、配置)无测试配对,排在最前面 -- 每个任务应在一次 AI 会话内可完成(目标约 30 分钟,最多 1-2 个文件) - 依赖关系:依赖的任务 ID 必须存在且顺序合理 - 每个任务必须自包含:内联文件路径、逻辑、测试上下文(实现阶段不需要回读 spec.md) - 任务分 6 类:基础设施 / 后端 Domain / 后端 API / 前端 Platform / 前端 Client / Worker @@ -23,16 +23,16 @@ 2. **AC 标注完整性** — 是否存在缺少"覆盖 AC:"标注的测试任务? 3. **Test-First 顺序** — 后端测试任务是否先于其配对的实现任务? 4. **依赖关系正确性** — 被依赖的任务 ID 是否存在、顺序是否合理? -5. **原子化** — 每个任务范围是否 ≤ 2 个文件,能在一次会话内完成? +5. **任务粒度** — 每个任务是否有清楚的交付结果,完成后能独立验收?同一结果所需的文件可以一起改,文件数只用于提示是否需要拆分。 6. **自包含** — 每个任务是否内联了文件路径、逻辑描述、测试上下文? **B. 任务拆解质量** -7. **粒度合理性** — 单个任务不超过 3 个文件、不跨前后端? +7. **前后端边界** — 前端和后端改动是否分别安排任务,并标明依赖? 8. **顺序高效性** — 不存在任务 A 的输出被后续任务覆盖/重写的返工情况? 9. **无重复工作** — 不存在多个任务对同一文件同一部分做非增量的重复修改? -10. **spec 覆盖完整性** — spec.md 中定义的每个 API 端点、ORM 模型、Service 方法、前端组件都有对应实现任务? +10. **设计覆盖完整性** — design.md 中需要实现的 API、数据模型、服务或前端改动是否都有对应任务? 11. **任务间接口清晰** — 任务描述中明确前驱任务的产出(DAO 方法签名、Service 接口、API 端点路径)? -12. **无过度工程** — 不存在 spec.md 中未提及但 tasks.md 中新增的实现内容? +12. **无过度工程** — tasks.md 是否只安排实现已确认需求和设计所需的工作? **C. AC 标注规范** 13. **AC 标注格式** — 必须逐条列举 `AC-01, AC-02`,禁止 `AC-01~AC-05` 范围写法? diff --git a/.claude/skills/task-review/references/task-checklist.md b/.claude/skills/task-review/references/task-checklist.md index d4192f8c7c..e5d4c9235a 100644 --- a/.claude/skills/task-review/references/task-checklist.md +++ b/.claude/skills/task-review/references/task-checklist.md @@ -7,12 +7,12 @@ L1 聚焦约定合规和架构红线,不检查边界条件、权限、并发 | # | 检查项 | 适用文件 | 严重度 | 检查方法 | |---|--------|---------|--------|---------| -| 1 | 架构分层 | 后端 `*.py` | HIGH | Endpoint 不直接实例化 DAO 做复杂业务(应通过 Service);Service 不导入 FastAPI 对象(Request/Response/Depends/APIRouter);`domain/models/` 不得 `from bisheng.*.domain.services`;`common/` 和 `core/` 不得导入领域模块;新代码不放 `api/services/`(旧服务层),应放 `{module}/domain/services/`;Worker 只导入 Domain Services 不导入 Endpoint | +| 1 | 架构分层 | 后端 `*.py` | HIGH | 按 [C1](../../../../docs/constitution.md#c1-ddd-layered-call-chain) 和[后端规范](../../../../src/backend/AGENTS.md) 核查改动的调用链、导入方向和模块位置。另查 Service 是否引入 FastAPI 对象,以及 Worker 的业务调用是否经 Domain Service | | 2 | 命名规范 | 全部 | MEDIUM | DAO 方法:同步 `get_xxx`/`create_xxx`/`update_xxx`/`delete_xxx`,异步 `aget_xxx`/`acreate_xxx`/`aupdate_xxx`/`adelete_xxx`;DAO 为 `@classmethod`;Service 类名 `{Module}{Function}Service`;错误码类名 `{Module}{Error}Error`,Code 遵循 MMMEE;前端页面 PascalCase,store 文件 camelCase+Store,API 函数 camelCase;i18n key 小写+点分隔 | | 3 | 序列化约定 | 后端 `*.py` | HIGH | ORM 继承 `SQLModelSerializable`;API 响应用 `UnifiedResponseModel`(`resp_200`/`resp_500`/`ErrorClass.return_resp`);分页用 `PageData[T]`(新代码);枚举序列化为 `.value`;SSE 用 `to_sse_event()`;WS 关闭用 `websocket_close_message()` | -| 4 | 数据库约定 | 后端 models/migration `*.py` | HIGH | 新表必须含 `tenant_id`(`index=True`);必须含 `create_time`/`update_time`;禁止手动 `WHERE tenant_id=`(SQLAlchemy event 自动注入);禁止 Service 层直接写 SQL(用 DAO classmethod);新模块 DAO 放 `{module}/domain/models/` 而非 `database/models/`;使用 `get_sync_db_session()`/`get_async_db_session()` | -| 5 | 前端约定 | `*.tsx`/`*.ts` | MEDIUM | Platform: 全局状态用 Zustand store(`src/store/`),API 通过 `controllers/API/` 封装,用户可见文字走 `t('key')` i18n,新路由在 `src/routes/` 注册。Client: API 通过 `src/api/` 封装,store 用 Zustand(`src/store/`),路由基础路径 `/workspace` | -| 6 | 信息泄漏 | 全部 | HIGH | 无硬编码密码/密钥/token(`password = "xxx"` 等);错误响应不暴露堆栈/SQL(用 BaseErrorCode);日志中敏感字段脱敏;API 不返回 tenant_id 到前端;前端不硬编码后端 IP。排除:测试 fixtures、config.yaml.example | +| 4 | 数据库约定 | 后端 models/migration `*.py` 及访问租户数据的查询、写入代码 | HIGH | 新增租户所属表必须含 `tenant_id`(`index=True`);全局表按实际数据归属建模;新表必须含 `create_time`/`update_time`;按 [C3](../../../../docs/constitution.md#c3-multi-tenant-data-isolation) 核查 ORM 查询、批量写入和原生 SQL 的租户范围;新模块 DAO 放 `{module}/domain/models/` 而非 `database/models/`;使用 `get_sync_db_session()`/`get_async_db_session()` | +| 5 | 前端约定 | `*.tsx`/`*.ts` | MEDIUM | 根据改动所属应用,按[共享前端规范](../../../../src/frontend/AGENTS.md)及 [Platform](../../../../src/frontend/platform/AGENTS.md) 或 [Client](../../../../src/frontend/client/AGENTS.md) 规范核查状态、请求和国际化。新增路由核对应用的注册入口和 base path | +| 6 | 信息泄漏 | 全部 | HIGH | 无硬编码密码/密钥/token(`password = "xxx"` 等);错误响应不暴露堆栈/SQL(用 BaseErrorCode);日志中敏感字段脱敏;API 只返回业务所需且调用方有权访问的租户信息(含 `tenant_id`);前端不硬编码后端 IP。排除:测试 fixtures、config.yaml.example | | 7 | 设计同步 | 全部 | MEDIUM | **触发条件**:本任务修改了 service / endpoint / store / API 契约 / 数据模型 / 渲染器 / 任何 design.md §4.3 "关键模块职责" 表里列出的文件。**检查**:(a) design.md 修订历史是否反映了本任务的改动(或本任务后会一并补);(b) 改动是否触及 §3 决策(替换/新增)、§4 数据流或字段约定、§5 已知坑(新增反直觉事实)、§6 对外契约或依赖 —— 若是,必须**同步更新对应章节**;(c) 仅本地小修小补(重构、改文案、调样式、bugfix 不涉及对外行为)→ 标 PASS 即可。**判定**:触发但 design.md 未同步 → FAIL(MEDIUM);触发且已同步 / 未触发 → PASS | ## 差异化处理规则 diff --git a/AGENTS.md b/AGENTS.md index 16c9166f38..1186d20ab7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,5 +1,7 @@ # AGENTS.md +**Before editing code:** Read and apply the [core Ponytail skill](.claude/skills/ponytail/SKILL.md) for every code change, including small fixes and hotfixes outside SDD. Follow the project's constitution and the selected track's required checks. Use the other [Ponytail skills](docs/SDD-Guide.md#11-ponytail-in-the-development-workflow) as needed. + --- ## 1. Project Identity @@ -22,15 +24,13 @@ ## 2. Commands -Dev / test / build commands live in each sub-project's `AGENTS.md`: `src/backend/AGENTS.md` · `src/frontend/platform/AGENTS.md` · `src/frontend/client/AGENTS.md`. - -Middleware (MySQL / Redis / Milvus / ES / MinIO / OpenFGA): integration tests run in **CI**; per-developer middleware machines are pending. +Development commands and test conventions live in the sub-project guides: [backend](src/backend/AGENTS.md) · [platform](src/frontend/platform/AGENTS.md) · [client](src/frontend/client/AGENTS.md). For verification scope and environment, see the [SDD guide](docs/SDD-Guide.md). --- ## 3. Backend Rules (P0) -- **Architectural laws** (DDD layering / dual-DB / multi-tenancy / permissions / error codes / security) → [`docs/constitution.md`](docs/constitution.md) (C1–C7); enforced by `scripts/arch-guard.sh` + Constitution Check in `/sdd-review design`. +- **Architectural laws** → [`docs/constitution.md`](docs/constitution.md). The constitution maps each law to its review or automated check. - **Backend coding conventions** (module layout, API/response helpers, pagination, error handling) + subsystem quick map → `src/backend/AGENTS.md` (auto-loads when editing backend files). --- @@ -50,35 +50,13 @@ The 10 RULEs (RULE-1 … RULE-10) are the machine-enforcement arm of constitutio ## 6. SDD Workflow (non-trivial features) -**Full guide — track selection, ★ pause points, deviation re-confirm rule, document roles, constitution gate, harness → [`docs/SDD-Guide.md`](docs/SDD-Guide.md).** - -``` -0. release-contract.md (features/v{X.Y.Z}/release-contract.md; - version's first feature creates it) + read constitution.md -1. Spec Discovery → ★ user confirms -2. spec.md → /sdd-review spec → ★ user confirms -3. design.md → /sdd-review design → ★ user confirms (Constitution Check) - → read QA template, generate and check eight-column test-cases.md (SDD Guide §2.1) -4. tasks.md → /sdd-review tasks -5. branch feat//{NNN}-{name} (create early; docs + code on the branch) -6. implement wave-by-wave → /task-review → check off -7. /e2e-test (mandatory) -8. /sdd-code-review --base
(+ CI auto-review) -9. merge -``` - -Artifacts: `features/v{X.Y.Z}/{NNN}-{name}/{spec,design,test-cases,tasks}.md`. Templates: `features/_templates/` (incl. `release-contract.md`). -**★ cannot be skipped.** Trivial/hotfix changes use a lighter track — see SDD-Guide §1. - -Tests: new backend tests under `test//` (e.g., `test/approval/`), not `test/` root. `asyncio_mode=auto`. - -- **Release line first**: changes not specific to a derived branch land on the release line, then merge down; across version lines, cherry-pick only from a commit already on a release line. Details (back-port duplicate checks, AC id format, renumbering sweep, verifying delivery) → `docs/SDD-Guide.md` §9. +Before starting, pick the track in the [SDD guide](docs/SDD-Guide.md) and follow its steps, mandatory ★ confirmations, and release-line rules. The guide owns the process and artifact requirements. --- ## 7. Common Pitfalls -Subsystem pitfalls live in the nearest AGENTS.md (backend / client / platform §Known Pitfalls, linsight). Factual pitfalls table + method pitfalls in full → `docs/agent-pitfalls.md`. One-line index: liveness = trace callers + frontend entry · root cause = check magnitude, measure where it reproduces · scope follows root cause; dead code is deleted · surface model misbehaviour, don't fall back. +Read [BiSheng's known pitfalls](docs/agent-pitfalls.md) for verified lessons and links to the relevant subsystem rules. - **Shared working tree: no repo-wide git writes** — `git stash` (incl. pop/apply), `git checkout .`, `git reset --hard`, `git clean`, path-less `git restore`. Use `git show HEAD:`, `git diff HEAD -- `, `git worktree add`; a path-scoped `git checkout -- ` is safe. Put this in every concurrent sub-agent brief. - **`git checkout --theirs ` takes the whole file**, silently dropping your side's unique entries (locale JSON, error-code copy). Use `git checkout --merge -- `, resolve hunk by hunk, then parse the file to validate. diff --git a/docker/README.md b/docker/README.md index f3d7ea74c1..5a48754bfd 100644 --- a/docker/README.md +++ b/docker/README.md @@ -87,6 +87,16 @@ DSH 检测开关为 `dsh.content-safety.enabled`。仅设为 `false` 不会停 ARM 主机需要将每个启用服务的镜像替换为兼容 ARM 的 tag 或多架构镜像。Gateway 需使用经确认兼容 ARM 的版本,通过 `BISHENG_GATEWAY_IMAGE` 指定。Socket proxy 的 AMD64 tag 为 `0.3.0`,ARM64 部署需设置 `DOCKER_SOCKET_PROXY_IMAGE=cr.dataelem.com/tecnativa/docker-socket-proxy:0.3.0-arm64`;沙箱必须使用可用的对应架构镜像。 +## OnlyOffice 报告编辑的 JWT 配置 + +使用报告编辑时,OnlyOffice 的 `JWT_ENABLED` 应设为 `"true"`,`JWT_SECRET` 与毕昇系统配置中的 `office_jwt_secret` 保持一致。 + +`docker-compose-office.yml` 挂载 `office/config/local-production-linux.json`,仅对以 `/api/v1/report/callback` 或 `/api/v1/workflow/report/callback` 结尾的回调地址发送出站 JWT。规则兼容不同域名、IP、端口、部署路径前缀及回调查询参数。其他出站请求(包括文档下载)不附加 Bearer 头,避免与 MinIO 预签名 URL 的认证冲突;编辑器和命令接口的 JWT 校验继续保留。 + +已有部署需合并这一文件挂载;自定义 `DOCKER_VOLUME_DIRECTORY` 时,先将覆盖文件复制到该目录的 `office/config/local-production-linux.json`。文件缺失会直接报错,不会自动创建同名目录。保留现有 `local.json`、密钥、插件及全部数据卷;覆盖文件只包含出站 URL 规则,不包含凭据。OnlyOffice 初始化会调整配置文件属主,因此该挂载保留可写。 + +配置更新后只重建 `office` 服务,沿用原 Compose 项目与数据卷。验收需覆盖新建、导入、打开已有报告,以及编辑、保存后重新打开;同时确认回调签名校验仍然生效。回退时撤销该覆盖文件的挂载并重新加载原配置。 + ## 模型微调 bisheng-ft(可选) FT 默认关闭,通过同一 Compose 文件的 `ft` profile 部署。GPU 主机需要安装 NVIDIA 驱动和 NVIDIA Container Toolkit,确保 Docker 能使用 GPU。FT 使用独立版本 `cr.dataelem.com/dataelement/bisheng-ft:v0.5.0`,不要随平台版本修改;可在 `.env` 中用 `BISHENG_FT_IMAGE` 替换。2026-11-10 已只读确认该 CR tag 的 manifest 可获取,架构为 `linux/amd64`;本次未执行 GPU 训练验收。 diff --git a/docker/compose.multimodal.yml b/docker/compose.multimodal.yml new file mode 100644 index 0000000000..0fe23221c6 --- /dev/null +++ b/docker/compose.multimodal.yml @@ -0,0 +1,15 @@ +# Use with docker-compose.yml to build the matching platform feature source. +# Keep the customer's existing configuration, volumes, and middleware services. +services: + backend: + image: ${BISHENG_MULTIMODAL_BACKEND_IMAGE:-bisheng-backend:multimodal-local} + build: + context: ../src/backend + dockerfile: Dockerfile + backend_worker: + image: ${BISHENG_MULTIMODAL_BACKEND_IMAGE:-bisheng-backend:multimodal-local} + frontend: + image: ${BISHENG_MULTIMODAL_FRONTEND_IMAGE:-bisheng-frontend:multimodal-local} + build: + context: ../src/frontend + dockerfile: Dockerfile diff --git a/docker/docker-compose-office.yml b/docker/docker-compose-office.yml index 8c86dd12f6..f7fa342758 100644 --- a/docker/docker-compose-office.yml +++ b/docker/docker-compose-office.yml @@ -9,6 +9,11 @@ services: JWT_ENABLED: "false" volumes: - ${DOCKER_VOLUME_DIRECTORY:-.}/office/bisheng:/var/www/onlyoffice/documentserver/sdkjs-plugins/bisheng + - type: bind + source: ${DOCKER_VOLUME_DIRECTORY:-.}/office/config/local-production-linux.json + target: /etc/onlyoffice/documentserver/local-production-linux.json + bind: + create_host_path: false command: bash -c "supervisorctl restart all" restart: on-failure diff --git a/docker/helm/bisheng/templates/configmap-nginx.yaml b/docker/helm/bisheng/templates/configmap-nginx.yaml index e5a316eb45..e373eea2fb 100644 --- a/docker/helm/bisheng/templates/configmap-nginx.yaml +++ b/docker/helm/bisheng/templates/configmap-nginx.yaml @@ -39,6 +39,18 @@ data: {{- else }} location /apps/ { proxy_pass http://{{ include "bisheng.backendService" . }}:{{ .Values.backend.service.port }}; } {{- end }} + # F025 fine-tuning: 2 GiB dataset uploads, and job creation that may first push the package to FT. + location ~ ^/api/v1/finetune/(job(/file)?|dataset-catalog/(files|import|[^/]+/convert))$ { +{{- if .Values.gateway.enabled }} + proxy_pass http://{{ include "bisheng.component" (list . "gateway") }}:{{ .Values.gateway.service.port }}; +{{- else }} + proxy_pass http://{{ include "bisheng.backendService" . }}:{{ .Values.backend.service.port }}; +{{- end }} + client_max_body_size 2100m; + proxy_request_buffering off; + proxy_read_timeout 1800s; + proxy_send_timeout 1800s; + } location ~ ^(/workspace)?/api(/|$) { rewrite ^/workspace(/.*)$ $1 break; {{- if .Values.gateway.enabled }} diff --git a/docker/nginx/conf.d/default.conf b/docker/nginx/conf.d/default.conf index c52db2d41d..88b0701bac 100644 --- a/docker/nginx/conf.d/default.conf +++ b/docker/nginx/conf.d/default.conf @@ -160,6 +160,23 @@ server { client_max_body_size 2048m; } + # F025 fine-tuning: dataset uploads (packages up to 2 GiB plus multipart overhead, hashed and + # checked before the backend answers) and job creation, which may first push that package to a + # training host that cannot download it. Keep this regex before the generic API regex. + location ~ ^/api/v1/finetune/(job(/file)?|dataset-catalog/(files|import|[^/]+/convert))$ { + proxy_pass http://backend_server; + proxy_http_version 1.1; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $bs_forwarded_proto; + proxy_set_header X-Forwarded-Host $bs_forwarded_host; + proxy_request_buffering off; + proxy_read_timeout 1800s; + proxy_send_timeout 1800s; + client_max_body_size 2100m; + } + location ~ ^(/workspace)?/api(/|$) { rewrite ^/workspace(/.*)$ $1 break; proxy_pass http://backend_server; diff --git a/docker/office/config/local-production-linux.json b/docker/office/config/local-production-linux.json new file mode 100644 index 0000000000..a2d8dd541b --- /dev/null +++ b/docker/office/config/local-production-linux.json @@ -0,0 +1,11 @@ +{ + "services": { + "CoAuthoring": { + "token": { + "outbox": { + "urlExclusionRegex": "^(?![^?#]*/api/v1/(?:report/callback|workflow/report/callback)(?:\\?[^#]*)?$)" + } + } + } + } +} diff --git a/docs/PRD/multimodal-finetune/DEVELOPMENT.md b/docs/PRD/multimodal-finetune/DEVELOPMENT.md new file mode 100644 index 0000000000..cf53bb4829 --- /dev/null +++ b/docs/PRD/multimodal-finetune/DEVELOPMENT.md @@ -0,0 +1,74 @@ +# 3.1 beta1 开发接续 + +更新时间:2026-11-20。当前为开发草稿,未合并、未声明生产验收完成。 + +## 分支与基线 + +- 毕昇:`dataelement/bisheng` 的 `feat/3.1.0-beta1-025-multimodal-finetune`(2026-11-20 从 `feat/3.1.0-beta1@4bfe411b10` 新拉,旧分支 `feat/multimodal-finetune-3.1.0-beta1` 的全部改动压成一组合入)。 +- FT:`codesstar/bisheng-ft` 的 `feat/text-image-video-lora`,基于 `dataelement/bisheng-ft` 的 `main` 提交 `19495bda1755e40760021310c21fff1ee47b13e0`。FT 没有配套的 3.1 beta1 分支。 +- 两个分支需配套运行。训练入口为 FT 的 `/v2.1/sft`,独立部署说明见 FT 仓库 `deploy/multimodal/README.md`。 + +新电脑获取源码: + +```bash +git clone --branch feat/multimodal-finetune-3.1.0-beta1 https://github.com/dataelement/bisheng.git +git clone --branch feat/text-image-video-lora https://github.com/codesstar/bisheng-ft.git +``` + +使用原有 checkout 时先保存自己的未提交修改,再 fetch 并切到上述远程分支。运行配置、SSH 密钥、访问令牌和数据卷需通过企业已有安全渠道单独配置;仓库仅提供示例,不包含测试服务器访问资料。 + +## 本次迁移 + +迁入正式平台的前后端代码、数据集版本与导入、任务/日志/产物/推理接口、三语言页面、示例数据、FT 调用契约、迁移和测试。保留现有列表筛选和任务改名失败重试行为,适配 3.1 beta1 的 `@bisheng/ui` 组件与拒绝型请求错误处理。轮询不因翻译函数变化而反复清空详情。 + +数据库迁移 `v310b1_f025_multimodal_finetune`(文件 `v3_1_0b1_f025_multimodal_finetune.py`)接在 `v310b1_f016_dsh_call_pricing` 后,使用新版公共迁移工具和 JsonType。新增数据集表仍由项目模型初始化流程创建,需在实际部署时验证全新安装及已有数据库升级。 + +## 本次本机检查 + +- 毕昇后端:67 项通过,覆盖多模态契约、上传、数据导入、三模态交付及 Alembic 单 head。 +- FT:24 项服务测试通过。 +- 平台前端:22 项测试通过,覆盖数据集 API、创建与预览、列表筛选和改名失败重试。 +- 平台 TypeScript:1328 个 strict 文件通过;变更文件 ESLint 通过,未修改历史 suppression 文件。 +- 平台生产构建通过,存在大 chunk 提示;未做整仓依赖重新安装,使用本机已有依赖完成编译。 +- 变更后端文件 Ruff、架构守卫和提交差异检查见 PR 验证记录。 + +复测命令:在 `src/backend` 执行 `python -m pytest test/finetune/test_finetune_multimodal_contract.py test/finetune/test_finetune_upload_validation.py test/finetune/test_three_modal_delivery.py test/finetune/test_dataset_import.py test/database/test_alembic_single_head.py -q`;在 `src/frontend/platform` 执行 `pnpm exec tsc-strict`、`pnpm build` 和相关 `vitest run`。后端测试需要按项目开发说明准备基础配置。在 FT 根目录执行 `python -m pytest tests/sft_server -q`。 + +## 2026-11-18 接续 + +- 合入 `feat/3.1.0-beta1@acefcd907d`(无冲突),功能改号 F025,清理过期的 ESLint 豁免。 +- 新增数据直传:训练服务下载不到平台存储链接时,平台把训练数据和验证媒体推给它(FT `POST /v2.1/sft/probe`、`PUT /v2.1/sft/files/{sha256}`,引用 `ft-file://`),任务详情显示本次用的是拉取还是直传;送不到时报 10131。 +- 新增 SFTP 导入(账号密码,可选主机指纹校验,依赖 paramiko)。 +- 两机实测:平台跑在开发机,FT 跑在 GPU 服务器(单卡 RTX 3090,与他人服务共卡),GPU 访问不到开发机。三类训练、产物检查、新样本推理全部通过平台完成并自动走直传;FTP、SFTP、S3 各 4 种导入组合通过,异常场景正确拦截。拉取模式在两机下尚未实测。 +- 复测命令同上;FT 测试 29 项,平台 `test/finetune` 78 项。 + +## 2026-11-19 接续 + +- 远程数据直达训练服务:FTP/FTPS、SFTP、S3 导入时平台只读清单、核对每个文件存在并记录大小、取前 3 条样本做预览,存成一个小的「导入计划」版本;开始训练时用户再输一次密码或密钥,只随本次任务发给 FT,FT 先登录并读一个文件(失败报 10132、不建任务),再直接从数据源下载并核对大小。文本远程清单仍存成平台内的 JSON 版本。 +- 本地上传上限 2 GiB(JSON/JSONL 200 MiB),服务端流式哈希和检查,预览改为服务端保存的预览包(浏览器不再读整包);不做断点续传。 +- nginx 给 `/api/v1/finetune/job` 和 `/api/v1/finetune/job/file` 单独 2100m 与 1800 秒(docker、前端镜像、helm 三处):2 GiB 包第一次训练时,创建任务要等平台把包直传给 FT。 +- FT 镜像需要 paramiko、minio(`deploy/multimodal/Dockerfile` 已加);GPU 服务器必须能访问数据源。 +- 两机实测:FT 和临时 FTP/SFTP/S3 数据源在 GPU 服务器,平台在开发机。6 种远程导入(含 0.9 GB、1700 张图的 SFTP 数据集)全部训练成功,平台只读了清单和预览图;错误密码、缺密码、导入后来源文件被改都被正确拦下;1.5 GB 本地包经 nginx 上传并训练成功;GPU 任务目录和日志、平台日志均未发现数据源密码。顺带修复 FT 对只有 instruction/output 的文本行报 `KeyError: 'input'`。 +- 复测:FT 测试 43 项,平台 `test/finetune` 92 项,创建页相关前端测试 22 项。 + +## 2026-11-20 接续 + +- 恢复 Freeze 和全量:新训练服务上文本模型可选 LoRA / Freeze / 全量,图文、视频模型可选 LoRA / Freeze(全量单卡放不下,页面置灰并说明)。全量默认学习率 1e-5;Freeze 新增「可训练层数」。两者都产出完整模型,推理验证直接加载任务目录里的模型。 +- 登记的训练服务太旧(没有能力目录接口)时报 10133,提示升级训练服务。 +- 真机:Qwen3-0.6B 全量、Freeze 和 Qwen2.5-VL-3B 图文 Freeze 各 4 步训练并完成新样本推理。FT 测试 47 项、平台 `test/finetune` 93 项。 + +## 2026-11-20 改到最新 beta1 + +- 从 `feat/3.1.0-beta1@4bfe411b10` 新拉分支,合入时与上游 11-18~11-19 的微调权限和租户隔离改动(5 个提交)冲突,按「保留上游权限 + 补回 F025 功能」逐处合并,详见 design.md「合入 beta1 的权限与隔离」。 +- 上游测试的训练文件样例原来是空列表 `[]`,F025 会拒收空数据,改为一条合法样例;上游测试夹具补建数据集版本表。 +- 复测:后端 `test/finetune` + 迁移单 head + 请求范围登记 266 项通过(`requestScopeRoutes.json` 按路由重新生成,新增 9 条);前端微调相关 99 项通过,全量失败的 21 个测试文件与干净 beta1 完全相同;lint(已 prune)、typecheck、check-i18n 通过。 + +## 尚待完成 + +1. 全新环境执行 frozen-lockfile 安装并构建;本机检查不能替代干净环境 CI。 +2. 3.1 beta1 平台实际数据库升级(MySQL/DM)及登录网页 E2E:导入→版本持久化/复用→预检→真实训练→产物→新样本推理。 +3. 真实权限和跨租户隔离、取消/重启恢复、FTPS 证书握手、真实 OSS 账号、商业版网关的上传大小与超时、helm 模板渲染和客户网络配置验收。 +5. 合入最新 `feat/3.1.0-beta1`(2026-11-19 已领先本分支 137 个提交)。 +4. ~~使用本次分支重新跑文本、图文、视频小样本训练~~:2026-11-18 已在 GPU 上通过平台完成(见上节)。仍需在拉取模式的部署(GPU 能访问平台存储)下再跑一轮。 + +不包含模拟训练路径、音频能力或自动发布到业务推理服务。历史任务清单引用的原始证据因包含环境信息未提交;勿把勾选记录等同于本分支已验收。 diff --git a/docs/PRD/multimodal-finetune/README.md b/docs/PRD/multimodal-finetune/README.md new file mode 100644 index 0000000000..4d6d8f42cb --- /dev/null +++ b/docs/PRD/multimodal-finetune/README.md @@ -0,0 +1,7 @@ +# 文本、图文与视频微调 + +- [需求分析](毕昇文本与多模态模型微调改版需求分析.md):背景、范围、功能及验收标准。 +- [安装与使用指南](毕昇模型微调部署与使用指南.md):面向首次使用者的 FT 安装、数据准备、平台操作。 +- [开发接续与验证状态](DEVELOPMENT.md):分支基线、检查结果和待验收项。 + +范围为文本、图文、视频画面 LoRA,不含音频。功能文档在 `features/v3.1.0-beta1/025-multimodal-finetune/`(原 v3.0.0 线 111 编号,已迁到 3.1 beta1 并改为 F025);需求、历史验证和当前验收状态应分别判断。原始环境证据、真实部署配置及凭据不随 PR 提交。 diff --git "a/docs/PRD/multimodal-finetune/\346\257\225\346\230\207\346\226\207\346\234\254\344\270\216\345\244\232\346\250\241\346\200\201\346\250\241\345\236\213\345\276\256\350\260\203\346\224\271\347\211\210\351\234\200\346\261\202\345\210\206\346\236\220.md" "b/docs/PRD/multimodal-finetune/\346\257\225\346\230\207\346\226\207\346\234\254\344\270\216\345\244\232\346\250\241\346\200\201\346\250\241\345\236\213\345\276\256\350\260\203\346\224\271\347\211\210\351\234\200\346\261\202\345\210\206\346\236\220.md" new file mode 100644 index 0000000000..bf7820e3f0 --- /dev/null +++ "b/docs/PRD/multimodal-finetune/\346\257\225\346\230\207\346\226\207\346\234\254\344\270\216\345\244\232\346\250\241\346\200\201\346\250\241\345\236\213\345\276\256\350\260\203\346\224\271\347\211\210\351\234\200\346\261\202\345\210\206\346\236\220.md" @@ -0,0 +1,166 @@ +# 毕昇文本与多模态模型微调改版需求 + +版本 V2.1(3.1 beta1 开发分支) + +日期 2026年11月17日 + +适用对象 业务负责人 产品研发负责人 交付负责人 + +本次改版服务于企业在毕昇平台训练专属模型的需求。将现有以早期文本模型为主的微调模块,扩展为支持文本、图文和视频理解的训练流程,并统一服务接入、数据校验、任务创建、训练监控和结果验证。首批采用 LoRA 监督微调,音频与视频音轨不在本期范围。 + +需求评审需要确认功能范围、各模块的交付责任和验收标准。文本、图文、视频已通过小规模真实训练及产物重载验证,具备继续产品化的技术依据;模型效果、正式平台部署和企业权限验收应分别完成,不能用技术验证代替交付验收。 + +## 1 背景与业务问题 + +企业在毕昇中建设业务应用后,需要模型遵循企业的术语、判断规则和输出格式。例如,将客服工单分到指定类别,从票据或现场照片提取信息,或根据短视频回答操作过程中的问题。企业希望通过统一页面使用自己的数据训练模型,减少自行编写训练脚本和排查环境的工作。 + +现有 FT 服务及训练框架封装基于较早的模型体系,模型映射、数据准备和推理流程主要面向文本。增加模型名称或升级一个依赖,无法同时解决图片与视频的读取、模板适配、训练参数传递、产物加载和页面交互问题。因此,本次需要联动改造毕昇前端、毕昇后端、bisheng-ft 和训练环境。 + +企业提供的问题、标准答案与媒体构成训练样本。只有图片或视频文件还不足以直接进行本期监督训练;自动标注、生成训练问答不属于默认交付。 + +## 2 目标与范围 + +### 2.1 业务目标 + +1. 企业用户在毕昇内完成数据上传、模型选择、训练和新样本验证,普通使用者无需登录 GPU 服务器执行训练命令。 +2. 管理员可以为不同训练服务配置不同模型。平台读取服务的真实能力,新增适配模型无需再次修改前端模型名单。 +3. 任务保留数据、模型、参数、日志和产物信息,能够追溯一次训练的实际执行过程。 +4. 在保留历史文本任务的基础上扩展多模态能力,失败和不支持的组合必须明确提示。 + +### 2.2 输入输出和训练方法 + +| 类型 | 训练输入 | 预期输出 | +| --- | --- | --- | +| 文本 | 问题或多轮文本对话及标准答案 | 分类标签 结构化数据或自然语言文本 | +| 图文 | 图片 问题及标准答案 | 图片理解结果或结构化文本 | +| 视频 | 视频画面 问题及标准答案 | 内容描述 时序判断或结构化文本 | + +首批训练方法为 LoRA,即训练较小的适配参数,继续依赖原基础模型。视频按模型处理规则抽帧,不处理音轨。本期不包含音频训练、图像生成、语音合成、视频生成、自动标注、多机自动调度,以及未经单独验证的全量或量化微调。 + +首批验证模型为 Qwen3-0.6B 和 Qwen2.5-VL-3B-Instruct,分别覆盖文本与图文、视频输入。这是首批适配记录,不代表平台只支持这两个模型,也不代表同系列其他规模和版本自动可用。 + +### 2.3 交付范围的管理 + +本地数据包到真实训练、产物重载是核心路径。本分支现有数据集管理与任务内可复用版本是两条分离的链路。2026-11-25 用户确认本轮统一四类数据集管理、旧格式转换和任务选数,任务内本地上传改为仅本次使用;这些为本轮待实现需求,不代表已经交付。当前仍需在 3.1 beta1 部署环境完成登录网页端到端和权限验收。目标推理服务发布另行设计、适配及验收,不将任务内推理验证视为已发布。 + +## 3 使用角色和完整流程 + +管理员负责在训练服务器安装 FT 服务、准备模型,并在毕昇登记服务。业务或算法使用者提供训练样本,配置任务并检查输出。交付人员负责确认平台、FT 与模型版本一致,并完成安装和功能验收。 + +使用顺序为:准备服务器和模型 → 在毕昇接入训练服务 → 上传并检查训练数据 → 选择模型与训练参数 → 提交前检查 → 执行训练 → 检查产物 → 用新样本验证 → 按目标推理服务的适配情况发布。 + +以票据识别为例,使用者准备含图片、问题和标准答案的数据包,选择图文模型训练;训练结束后使用另一张未参与训练的票据进行测试。产物能加载说明技术链路可用,字段是否识别正确仍需按业务标准判断。 + +## 4 功能需求与页面对应 + +### 4.1 训练服务接入和模型发现 + +管理员填写服务名称和 FT API 地址,平台从后端检测该服务是否可访问,并读取模型清单及资源信息。页面分别呈现连接失败、模型未准备、能力未验证和资源不足的原因。 + +同一服务可以提供多个模型,不同服务可以提供不同模型。模型记录包含精确标识、版本、支持输入类型、训练方法、模板及验证状态。页面按当前服务和数据类型筛选模型,不使用静态白名单推测能力。模型更换后重新检查数据和参数的兼容性。 + +服务停用应阻止新任务,历史任务继续保留。服务器地址由管理员维护,业务用户无需理解容器目录或物理显卡编号。 + +### 4.2 数据上传和检查 + +文本支持约定的文本清单格式;图文和视频使用包含清单及媒体文件的 ZIP。页面提供对应模板与示例,说明如何填写问题、标准答案和媒体引用。 + +上传后检查字段、角色顺序、空答案、占位符、媒体数量、相对路径、缺失文件及解码失败。错误需要定位到样本或文件,不能丢弃错误样本后报告全部通过。检测通过的数据保存内容标识和报告,任务引用提交时的数据,不随原始文件的变化被覆盖。 + +图文预览展示图片、问题与答案;视频预览展示视频及对应问答。再次上传修正数据时形成新的记录,已有任务仍能追溯旧内容。 + +### 4.3 创建训练任务 + +创建保持单页,包含任务名称、数据类型、训练服务、基础模型、训练数据、训练方式和参数。基础参数提供训练轮数或最大步数、学习率;高级参数包含序列长度、批大小、梯度累积和 LoRA rank。页面解释最大步数与轮数的优先关系。 + +选择模型后采用该模型的默认值和可配置范围。页面填写的参数必须进入实际训练配置,不允许展示可编辑项却在服务端静默忽略。提交前执行数据、模型、运行环境、方法和资源检查;失败时保留表单并定位原因。 + +### 4.4 训练任务列表与详情 + +任务列表展示名称、类型、模型、服务、状态和创建时间。详情展示实际阶段、运行日志、已获得的训练指标、数据摘要与生效参数。没有日志或指标时显示等待采集,不生成示意曲线。 + +刷新页面后继续查询同一服务器任务。服务断开时保留最后观测状态并提示重查,不将通信错误直接视为训练失败或成功。取消任务须由服务确认终止后显示已取消;重复提交和重试不得产生重复训练进程。 + +### 4.5 产物和新样本验证 + +训练正常结束后检查 LoRA 权重、配置及基础模型加载依赖,记录文件大小与内容哈希。训练成功、产物完整和推理验证分别展示,缺失产物不能显示为可用模型。 + +任务详情支持新文本输入、新图片上传和新视频上传,重新加载基础模型及本次 adapter 后执行推理。显示实际输出;可用时支持相同输入下基础模型与微调模型的对比。推理完成仅表示执行成功,不自动表示答案正确。 + +### 4.6 数据来源扩展和发布 + +数据集管理支持本地文件、FTP/显式 FTPS、SFTP、S3/MinIO。远程导入只需一次填写连接与媒体根目录,无需逐条输入远程地址;沿用已确认的训练服务直接读取远程媒体和不长期保存凭据的约定。通过数据集管理导入并校验成功后可长期复用,任务内临时本地上传不自动保存为数据集。 + +模型发布需验证目标推理服务是否支持该基础模型、LoRA 和输入类型。发布成功必须有实际调用结果;未适配的组合保留产物和验证结果,不呈现虚假的发布成功。 + +### 4.7 页面与功能清单 + +| 入口 | 用户主要操作 | 对应需求 | +| --- | --- | --- | +| 模型微调任务列表 | 新建 查看 取消及追溯任务 | 训练管理 | +| 单页创建任务 | 选择服务 模型 数据及参数并预检 | 训练提交 | +| 任务详情 | 查看日志 配置 产物并测试新样本 | 训练监控与验证 | +| 训练服务管理 | 登记地址 检测连接和模型能力 | 环境接入 | +| 数据集管理 | 四类标识 导入 转换 复用及来源管理 | 本轮数据集迭代 | + +### 4.8 数据集迭代补充(2026-11-25 用户确认) + +1. 数据集增加旧格式、文本、图文、视频四类标识;类型与来源分开呈现,并支持分类筛选。 +2. 旧格式及原数据保留,显式转换另生成新版文本数据集;转换不得丢失问题、补充输入、答案或已有会话内容,失败需定位到样本。 +3. 创建微调任务时,已有数据下拉列表来自数据集管理,只展示当前租户可用、已校验且分类匹配的数据;旧格式先转换。 +4. 用户可以在任务内临时上传一份本地数据并预览、校验和使用;成功、失败或取消都不会将其加入可复用数据集或版本列表,成功任务保留自身的数据引用与校验快照。 +5. 原有加入数据集和 QA 知识库转数据集业务继续支持,新产生的数据直接使用新版文本格式并归入文本分类;沿用已有租户和权限约束。 + +本轮详细验收口径见 [F025 spec §2.9](../../../features/v3.1.0-beta1/025-multimodal-finetune/spec.md)。 + +## 5 各层需要修改什么 + +### 5.1 毕昇前端和后端 + +前端增加文本、图文、视频选择,动态模型列表、数据检查反馈、任务详情和真实验证入口。页面复用毕昇现有组件、国际化与权限入口。 + +后端负责权限、任务及数据持久化、模型能力快照、FT 调用、状态同步和结果保存。新增字段兼容历史记录;数据库迁移需覆盖项目支持的数据库。数据通过平台对象存储提供给训练节点,不能依赖用户电脑或单台后端的临时文件。 + +### 5.2 bisheng-ft 服务 + +FT 底层代码需要更新。它负责将平台请求转换为训练任务,因此要同时改造模型登记、数据下载与校验、多模态字段映射、真实参数传递、训练进程管理、日志、取消、产物检查和推理重载。 + +新增服务提供版本化接口,保留旧任务兼容路径。训练任务独立保存配置与输出;服务对训练和推理资源执行互斥,重启后核对遗留任务状态。训练和推理不得拼接用户输入执行任意 shell 命令。 + +### 5.3 LlamaFactory 和模型依赖 + +需要固定一套已验证的 LlamaFactory 与 PyTorch、Transformers、PEFT、媒体解码依赖,提供可复现的 Docker 构建文件。新框架安装位置必须与旧内置代码隔离,避免运行时仍加载旧版本。 + +模型适配验证覆盖加载、模板、处理器、数据预处理、反向训练、保存和重载。存在模板或权重文件不能直接视为支持;后续新增模型要通过同样流程后登记开放。 + +### 5.4 安装和交付材料 + +交付包含毕昇功能分支、FT 功能分支、数据库迁移、容器部署文件、模型配置样例、训练数据样例及客户使用指南。客户指南按服务器管理员与平台使用者的操作顺序编写,不包含内部测试机器地址、实验任务编号和项目交接记录。 + +## 6 验收标准 + +| 编号 | 验收项 | 通过条件 | +| --- | --- | --- | +| AC01 | 服务与模型 | 两个服务可返回不同模型清单 页面按当前服务选择 | +| AC02 | 文本训练 | 从毕昇提交文本 LoRA 保存产物并用新文本推理 | +| AC03 | 图文训练 | 从毕昇提交真实图片数据 保存产物并用新图片推理 | +| AC04 | 视频训练 | 从毕昇提交真实视频数据 保存产物并用新视频推理 | +| AC05 | 数据错误 | 缺失媒体 损坏文件 非法路径或错误样本能被阻断定位 | +| AC06 | 参数生效 | 页面参数与训练服务保存的生效配置一致 | +| AC07 | 状态与取消 | 刷新后可查同一任务 取消须实际终止且不标记成功 | +| AC08 | 产物真实性 | 缺少权重或配置时不能通过产物检查 | +| AC09 | 验证真实性 | 真实加载本次 adapter 显示实际输出 失败保留原因 | +| AC10 | 权限与历史 | 非管理员及跨租户访问符合原权限 旧文本任务可查询 | +| AC11 | 客户安装 | 新环境按指南部署并完成一次数据上传到推理验证 | +| AC12 | 远程数据与发布 | 对应连接器及推理服务完成真实调用后才能开放 | +| AC13 | 数据集分类与来源 | 统一显示四类标识,支持既有本地及远程来源,类型不符不入可用列表 | +| AC14 | 旧格式转换 | 原数据保留,另生成新版文本;失败可定位且不覆盖原数据 | +| AC15 | 任务选数 | 下拉列表仅展示数据集管理中分类匹配、当前用户可用的数据 | +| AC16 | 临时本地上传 | 仅本次任务使用,所有提交结果均不新增可复用数据集或版本记录 | +| AC17 | 既有业务入口 | 加入数据集与 QA 知识库转入继续可用,新产出均为新版文本 | + +技术验收使用小数据量验证功能,业务验收使用客户认可的独立测试集和指标。准确率、输出格式、时延及资源目标按业务与模型确定,不由通用微调平台承诺统一数值。 + +## 7 推进顺序与交付判断 + +先固定模型和训练环境,完成正式 FT 服务、平台接口和页面接入;再完成真实训练、取消、异常恢复及新样本验证;最后结合客户环境验收权限、数据来源和目标推理服务。每项交付以实现代码与测试结果为准,保留版本、未完成项及回退方式。 diff --git "a/docs/PRD/multimodal-finetune/\346\257\225\346\230\207\346\250\241\345\236\213\345\276\256\350\260\203\351\203\250\347\275\262\344\270\216\344\275\277\347\224\250\346\214\207\345\215\227.md" "b/docs/PRD/multimodal-finetune/\346\257\225\346\230\207\346\250\241\345\236\213\345\276\256\350\260\203\351\203\250\347\275\262\344\270\216\344\275\277\347\224\250\346\214\207\345\215\227.md" new file mode 100644 index 0000000000..15b4104d9e --- /dev/null +++ "b/docs/PRD/multimodal-finetune/\346\257\225\346\230\207\346\250\241\345\236\213\345\276\256\350\260\203\351\203\250\347\275\262\344\270\216\344\275\277\347\224\250\346\214\207\345\215\227.md" @@ -0,0 +1,322 @@ +# 毕昇模型微调安装与使用指南 + +版本 V2.1(3.1 beta1 开发分支) + +日期 2026年11月17日 + +本指南帮助第一次使用模型微调的企业用户,完成训练服务安装、模型准备、平台接入、训练任务创建和结果验证。支持文本、图文及视频画面输入,训练方法为 LoRA。 + +服务器管理员先完成第1至4章;平台使用者从第5章开始。当前版本的模型微调操作需要使用平台超级管理员或当前租户管理员账号。已经接入服务后,使用者不需要安装 Docker、下载模型或登录服务器。 + +本指南对应随文档交付的毕昇前后端与 bisheng-ft 多模态功能版本。使用旧版毕昇或旧版 FT 时,页面与接口可能不同,应先由交付人员安装配套版本。本分支包含本地、FTP/FTPS 和 S3 数据导入及数据集版本选择入口;连接器测试已完成,完整登录网页端到端验收仍待完成。模型在线发布不属于本期多模态流程。 + +## 1 安装前准备 + +### 1.1 了解各部分的作用 + +毕昇平台提供网页、账号、训练数据保存和任务管理。FT 服务安装在带 GPU 的服务器上,负责加载模型、执行训练和测试训练结果。两者可以在不同服务器上,业务用户只使用毕昇网页。 + +LoRA 训练得到的是 adapter,即一份较小的模型适配权重。使用它时仍需要对应的基础模型,因此训练后应同时保留基础模型和任务输出目录。 + +### 1.2 管理员需要准备的材料 + +- 已能正常登录的毕昇平台,以及配套功能版本的毕昇与 bisheng-ft 源码或镜像。 +- 一台 Linux NVIDIA GPU 服务器,已安装驱动、Docker Engine、Docker Compose 和 NVIDIA Container Toolkit。 +- 服务器登录账号、可写的数据目录、用于下载模型与镜像的网络或离线文件。 +- 平台后端能访问的 FT 服务地址,以及 FT 能访问的平台文件存储地址。 + +本指南以单卡安装和小规模样例训练入门。首批模型在24 GB显存的 NVIDIA GPU 上完成过小规模验证;更大的模型、图片、视频或批大小需要另行评估资源。 + +在训练服务器终端执行: + +```bash +nvidia-smi +docker version +docker compose version +``` + +应能看到显卡、Docker 服务端和 Compose 的版本。如果命令不存在或显卡查询失败,先完成对应软件安装,再继续。Docker 安装说明:https://docs.docker.com/engine/install/ubuntu/ 。GPU 容器运行时安装说明:https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html 。这些是服务器的一次性准备工作。 + +### 1.3 记录客户自己的地址 + +请记录训练服务器的内网 IP 和服务端口。下文将 `192.0.2.10` 作为文档示例地址,执行前全部替换为客户实际服务器地址;端口示例为 `8000`。 + +平台填写的是 FT 的 HTTP 地址,例如 `http://192.0.2.10:8000`。SSH 登录地址、模型推理接口和 LlamaFactory WebUI 不是此处的 FT 地址。 + +## 2 在服务器安装 FT 服务 + +### 2.1 放置配套源码 + +将本版本 bisheng-ft 源码解压到训练服务器,例如 `/opt/bisheng-ft`。以下命令都在训练服务器执行,路径按实际解压位置调整: + +```bash +cd /opt/bisheng-ft/deploy/multimodal +cp .env.example .env +mkdir -p data/models data/jobs +``` + +该目录内应有 `Dockerfile`、`compose.yaml`、`constraints.txt` 和 `.env.example`。不要使用仓库中旧版本的启动脚本替代这里的 Compose 配置。 + +### 2.2 配置服务 + +用文本编辑器打开 `.env`,修改以下配置: + +```dotenv +GPU_ID=0 +FT_PORT=8000 +FT_BIND_IP=192.0.2.10 +MODEL_DIR=./data/models +OUTPUT_DIR=./data/jobs +FT_MODELS=Qwen3-0.6B,Qwen2.5-VL-3B-Instruct +HF_ENDPOINT=https://huggingface.co +CAPABILITIES_FILE=../../src/sft_server/model_capabilities.json +``` + +`GPU_ID` 是分配给本服务的显卡编号,在 `nvidia-smi` 中查看;单卡服务器通常填0。`FT_BIND_IP` 填训练服务器实际内网 IP,不能保留示例地址。默认文件中的 `127.0.0.1` 只允许本机访问,平台在另一台服务器时须改为可达内网地址。 + +`MODEL_DIR` 保存下载的基础模型,`OUTPUT_DIR` 保存训练任务及产物。相对路径从当前部署目录计算。`FT_MODELS` 决定此服务向平台开放哪些已经登记的模型;多个名称用英文逗号隔开。 + +服务面向受控内网,网络策略只允许毕昇后端和管理员访问。客户访问网页使用毕昇账号,不能把无独立账号认证的 FT 端口直接作为公网入口。 + +### 2.3 构建训练镜像 + +```bash +docker compose build ft +``` + +首次构建会下载训练环境,耗时取决于网络。镜像固定训练框架与依赖版本,完成后再执行下一步;出现下载或安装错误时先处理该错误,不要跳过构建继续启动。 + +确认容器能访问所选显卡: + +```bash +docker compose run --rm --no-deps ft nvidia-smi +``` + +应看到分配给该服务的 GPU。若宿主机能查到 GPU 而容器报错,应检查 NVIDIA Container Toolkit 配置。 + +### 2.4 下载基础模型 + +```bash +docker compose --profile tools run --rm download +``` + +此命令下载文本模型 Qwen3-0.6B,以及图文和视频模型 Qwen2.5-VL-3B-Instruct,并校验权重文件。模型保存在前面配置的 `MODEL_DIR` 中。只需试文本时,可以先下载一个模型: + +```bash +docker compose --profile tools run --rm download --model Qwen3-0.6B +``` + +没有外网的服务器可由管理员在联网机器执行同一下载命令,再将完整模型目录和下载校验记录复制到 `MODEL_DIR`。不要只复制一个权重文件;配置、分词器与视觉处理器也属于模型所需文件。 + +### 2.5 启动并检查服务 + +```bash +docker compose up -d ft +docker compose ps +curl --fail http://192.0.2.10:8000/health +curl --fail http://192.0.2.10:8000/v2.1/sft/capabilities +``` + +将命令中的 IP 替换为实际地址。容器应处于运行或 healthy 状态,健康接口应成功返回;能力接口应包含已经下载并可用的模型。健康接口成功只说明服务可访问,首次安装仍需按后文完成一条训练任务。 + +启动失败时查看日志: + +```bash +docker compose logs --tail 100 ft +``` + +## 3 将配套功能部署到毕昇 + +本章由毕昇平台管理员执行。如果交付人员已经部署对应版本,可直接进入第4章。安装新的 FT 服务不会自动改变旧毕昇页面,前端和后端必须同时使用配套版本。 + +采用源码构建部署时,在毕昇服务器将本版本源码放到 `/opt/bisheng`,保留客户现有配置和数据卷。先备份现有数据库、文件存储和配置,再在测试环境执行: + +```bash +cd /opt/bisheng/docker +docker compose -f docker-compose.yml -f compose.multimodal.yml build backend frontend +docker compose -f docker-compose.yml -f compose.multimodal.yml up -d backend backend_worker frontend +docker compose -f docker-compose.yml -f compose.multimodal.yml logs --tail 100 backend +``` + +`compose.multimodal.yml` 用当前源码构建前后端,后台任务进程使用同一后端镜像。平台启动会执行数据库迁移及模型表初始化;若日志出现迁移失败,先修复版本或数据库问题,不要继续交给业务用户操作。使用企业镜像发布流程的部署,由交付人员将同版本镜像替换到对应服务。 + +数据库、Redis、对象存储及平台其他依赖沿用毕昇标准部署。本指南安装的是既有毕昇平台的微调功能;若客户尚未安装毕昇,应先完成平台基础安装和登录验证。 + +平台上传的训练文件由 FT 下载,因此 FT 必须能够访问平台生成的文件下载地址。只在毕昇后端 Docker 网络内有效的 `minio` 主机名,另一台训练服务器通常无法解析。管理员应配置训练服务器可达的文件存储地址或内部域名,并确认文件下载通路可用。 + +使用配套 Compose 时,编辑 `docker-compose.yml` 中 `backend` 和 `backend_worker` 的 `BS_MINIO_SHAREPOINT`,填写文件存储的实际主机名及端口,例如 `storage.company.internal:9000`,不带 `http://`。该值对应 `object_storage.minio.sharepoint`;`BS_MINIO_ENDPOINT` 仍用于平台内部连接,可保留原值。修改后重新创建后端服务,并从训练服务器确认该域名可解析和访问。下载链接的主机参与签名,不能在链接生成后手工替换。 + +## 4 在毕昇接入训练服务 + +1. 使用平台超级管理员或当前租户管理员账号登录毕昇,进入“模型”中的“模型微调”。仅拥有模型菜单查看权限的普通账号不能执行微调操作。 +2. 点击“训练服务管理”,新增一条服务记录。 +3. 名称填写易于识别的业务名称,例如“企业训练服务器”。FT 地址填写实际 HTTP 地址,例如 `http://192.0.2.10:8000`。 +4. 保存后点击“检测并同步模型”。等待连接检测和模型信息同步完成。 +5. 创建任务时选择这条服务,确认能够看到服务器已准备好的模型。 + +检测失败时,先在毕昇后端所在的运行环境验证能否访问 FT 健康接口。管理员自己的电脑能打开该地址,不代表平台后端也能访问。 + +两个训练服务提供不同模型时,分别修改各自 `.env` 中的 `FT_MODELS`,重建服务后在平台重新检测同步。例如,文本服务只填写 `Qwen3-0.6B`,图文视频服务只填写 `Qwen2.5-VL-3B-Instruct`。同一服务器运行多份部署时,要分别设置服务端口、任务输出目录、Compose 项目名和管理员分配的 GPU。 + +### 4.1 增加新的模型 + +管理员先区分两种情况:已经登记的模型,只需下载完整权重并加入 `FT_MODELS`;配置文件里没有的新模型,则需要增加能力记录和完成适配验证。 + +能力登记文件由 `.env` 中的 `CAPABILITIES_FILE` 指定,默认是源码里的 `src/sft_server/model_capabilities.json`。可复制一份由本服务独立维护。记录中的 `model_name` 必须与 `MODEL_DIR` 下的模型文件夹一致,`input_types` 分别使用 `text`、`image_text`、`video_text`,并填写正确的 `template`、训练方法和参数范围。 + +新模型先标记为 `unverified`,由算法或交付人员验证训练和产物重载后才开放。不能只修改验证状态就认为新模型可用。业务使用者无需编辑该文件。 + +完成配置且确认没有运行任务后,在 FT 部署目录执行: + +```bash +docker compose up -d --force-recreate ft +``` + +随后回到毕昇点击“检测并同步模型”。如果新增模型需要当前镜像没有的框架或处理器支持,还需要先构建经过验证的新训练镜像。 + +## 5 准备第一次训练的数据 + +### 5.1 先使用页面提供的示例包 + +进入“创建训练任务”,选择文本、图文或视频类型,下载该类型的示例数据包,再上传到训练数据区。每次任务使用一个数据包,重新上传会替换已选包。第一次使用建议先运行文本样例,熟悉流程后再试图文和视频。 + +示例只用于熟悉文件格式和验证功能,不能代表企业业务效果。开始业务训练前,应替换为企业的问题与标准答案,并留出一部分未参加训练的样本用于测试。 + +### 5.2 文本数据 + +文本 JSON 文件的内容是一个样本数组。`user` 填问题,`assistant` 填期望答案。例如保存为 `train.json`: + +```json +[ + { + "messages": [ + {"role": "user", "content": "打印机无法连接,应交给哪个部门?"}, + {"role": "assistant", "content": "IT"} + ] + } +] +``` + +可以在数组中加入更多样本。文本也可使用 JSONL,每行一个样本,不能把整段数组按任意位置换行后当作 JSONL。 + +### 5.3 图文数据 + +图片需要与问答一起打包。ZIP 解压后的根目录直接包含 `train.json` 和图片文件夹,不要再套一层同名文件夹: + +```text +receipt-training.zip + train.json + images/ + receipt-001.png +``` + +`train.json` 示例: + +```json +[ + { + "messages": [ + {"role": "user", "content": "票据上的金额是多少?"}, + {"role": "assistant", "content": "128.00元"} + ], + "images": ["images/receipt-001.png"] + } +] +``` + +`` 表示问题中引用一张图片,`images` 填写 ZIP 内的相对路径。路径和文件名必须完全一致。标准答案由企业准备,系统不会从任意图片自动生成训练答案。 + +### 5.4 视频数据 + +视频同样使用 ZIP,根目录放 `train.json`,视频放 `videos` 文件夹。入门样例使用短 MP4,问题中写 `