docs: product-level README, AGENTS.md split into code/reading parts, add CLAUDE.md, move task briefs to docs/tasks

- README.md is now the product/repo front door (architecture, repo map,
  local dev, test tiers, delivery flow, doc map). Engine positioning,
  VedAstro/Codex setup and the oracle/benchmark command reference move
  verbatim to docs/engine/README.md, docs/engine/vedastro-gateway.md and
  docs/benchmark/README.md. Capability badges realigned with the registry
  (91/78/8/0); tests/test_readme_badges.py was red on staging.
- AGENTS.md: Part A (environment truth, delivery, worktrees, record
  placement, bug workflow, growth freeze, frontend red lines, privacy,
  pre-work check, test tiers) and Part B (reading-rigor constraints).
  GitHub issue-tracker/triage boilerplate removed: GitHub is a read-only
  mirror. All strings locked by tests/ are preserved.
- CLAUDE.md added: roles, three working modes, task-brief sections,
  acceptance criteria, session discipline; imports AGENTS.md.
- 50 tracked TASK-*/PROGRESS-* files and 3 never-committed briefs move to
  docs/tasks/ with an index; REPO_LAYOUT.md merged into README.

Docs-only change (no gated path touched).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0193vBv6w5MV2cifdTUu9H5P
This commit is contained in:
Jesse_Chen
2026-09-03 06:56:06 +00:00
co-authored by Claude Fable 5.1
parent af411f590a
commit 8db71aaf81
63 changed files with 1958 additions and 1196 deletions
+159 -140
View File
@@ -1,31 +1,156 @@
# Jyotish Skill Agent Constraints
# Jyotisha Agent Constraints
本文件是当前项目给协作代理、自动化助手与派生工作流的硬约束补充。它不替代 `SKILL.md`,而是把最容易被偷懒、省略、或在多窗口工作时遗失的高严谨规则单独钉死。
本文件对所有协作代理生效(Claude Code、Codex、Cursor 以及派生工作流)。它把最容易被省略、或在多窗口工作时遗失的规则钉死。`CLAUDE.md` 只补充 Claude 会话的分工,不重复这里的规则;`frontend/AGENTS.md` 是 Next.js 版本提示。
## 0. Production Maintenance Truth
全文分两部分:**Part A** 是所有代码与文档工作的约束;**Part B** 只在输出占星解读(解盘、推运、校正解释)时生效。
任何部署、线上故障、域名、登录或环境变量任务,先读取 `deploy/README.md`,不要重新猜测架构。
## 0. 先读什么
- Production domain: `https://jyotisha.chat`
- Primary source: `https://git.copse.top/root/Jyotisha.git`; GitHub upstream/mirror: `https://github.com/jesse-ux/Jyotisha.git`
- Migration target: Ubuntu VPS `118.194.235.34`; confirmed SSH port is a required deployment variable
- Target runtime: `/opt/jyotisha-production`, Compose project `jyotisha-production`
- Target secrets: `/opt/jyotisha-production/.env.production` and `.env.production.database`; never print, copy into chat, or commit
- Public edge: Caddy only; Next.js `3000` and Python API `5200` stay Docker-private
- Migration source: Spaceship DNS and Supabase project `vtvnfqmonbfuxmqkqdlc`; production target uses private PostgreSQL + Better Auth
- Capacity boundary: 2 vCPU / 4 GB RAM; use digest-pinned images, bounded DB pools, and no on-host application builds
- Cutover runbook: `docs/operations/production-server-migration-2026-08.md`; old VPS/Supabase remain rollback assets until final reconciliation
| 任务类型 | 开工前必读 |
| --- | --- |
| 任何任务 | 本文件 §1–§4;`git status -sb` 的第一行(确认分支) |
| 前端改动 | `frontend/AGENTS.md`、`frontend/DESIGN.md`、`frontend/docs/VOICE.md`、§7 |
| Bug / 报错 / 回归 | §5,并检索 `docs/BUG_HISTORY.md` |
| 部署、线上故障、域名、登录、环境变量 | `deploy/README.md`(不要重新猜架构) |
| 引擎、外部 oracle、镜像边界、远端同步、发布 | §9 与 `docs/research/pre_work_error_ledger.md` |
| 领域术语(会话、轮次、故障、评价) | `CONTEXT.md`;命名与术语表一致,见 `docs/agents/domain.md` |
| 输出占星解读 | Part B |
Deployment safety rules:
---
1. Run `git status --short --branch` before packaging; do not overwrite unrelated dirty files.
2. Before cutover, verify the authoritative DNS still matches the documented current phase; after cutover both user and admin hosts must resolve to `118.194.235.34`.
3. The target uses Better Auth with exact user/admin origins; migrated users must sign in again by OTP.
4. After deployment, verify `/login`, logged-out `/api/account` = `401`, internal `/api/health` = `200`, and `swisseph_available = true`.
5. Never expose port `5200`, `SUPABASE_SERVICE_ROLE_KEY`, model keys, user JWTs, passwords, or SSH private keys.
6. Production deployment is manual-only in Gitea. It consumes the exact staging-gate image digests, requires matching `main`/`staging`/public-staging SHA plus the manual release gate, and never changes DNS or imports production data. GitHub production deployment is retired.
# Part A · 代码与文档工作
## 1. High-Rigor Override
## 1. 生产与环境真相
- Production domain: `https://jyotisha.chat`;staging: `https://staging.jyotisha.chat`
- Primary source and the only CI/CD control plane: `https://git.copse.top/root/Jyotisha.git`(Gitea)。GitHub `https://github.com/jesse-ux/Jyotisha.git` 是只读镜像:无 workflow、Actions 已关闭,不得用它验证交付状态,也没有 GitHub Issues 流程。
- Production host: Ubuntu VPS `118.194.235.34`,专用 `deploy` 用户,SSH 端口是部署变量;2 vCPU / 4 GB RAM,只跑 digest 固定镜像,不在主机构建。
- Runtime: `/opt/jyotisha-production`,Compose project `jyotisha-production`,Compose 文件 `deploy/docker-compose.server.yml`。
- Secrets: `/opt/jyotisha-production/.env.production` 与 `.env.production.database`(`0600`);never print, copy into chat, or commit。
- Public edge: Caddy only;Next.js `3000` 与 Python API `5200` 仅 Docker 内网。
- Persistence: 同主机私有 PostgreSQL 17 + Better Auth。从 Supabase 的迁移已切换完成;旧 VPS 不再是部署目标,Supabase 项目按 `docs/operations/production-server-migration-2026-08.md` 作为回滚资产保留到最终对账。
- API 容器有命名卷 `api_scratch`(chart 缓存与异步任务态);重计算端点受 `JYOTISH_HEAVY_COMPUTE_CONCURRENCY`(默认 2)限流,饱和返回 429。
部署安全规则:
1. 打包前 `git status --short --branch`;不得覆盖无关的脏文件。
2. 部署后验证 `/login`、未登录 `/api/account` = `401`、内部 `/api/health` = `200` 且 `swisseph_available = true`;`deployment.gitCommit` 必须等于预期 SHA。
3. 不得暴露端口 `5200`、模型 key、数据库口令、用户 JWT、SSH 私钥。
4. 生产部署只走 Gitea 手动流程(先 `release-quality-gate`,再 dispatch `deploy-production`),复用 staging 已验收的镜像 digest;不改 DNS、不导入生产数据。
## 2. 分支与交付
分支模型:`staging` 是测试环境,`main` 是生产控制分支。所有改动先经 `staging` 验收,再提升到 `main`;不存在直接改 `main` 的路径。
1. 动手前 `git fetch origin --prune`,以远端 **`origin/staging`** 为基线。本地 `staging` / `main` 经常落后远端上百个提交,不得作为基线。
2. 在独立 worktree 开发:路径 `.worktrees/<主题>-<日期>`,分支 `codex/<主题>-<日期>`(见 §3)。
3. 交付到 staging 用快进推送 `git push origin HEAD:staging`。这会触发 Gitea `backend-quality-gate`;它的 `paths:` 过滤与 `deploy/gated-paths.txt` 逐行一致。改动**全部**落在清单之外的纯文档推送(`docs/**`、根目录 `BLOCKED.md` / `CHANGELOG*.md` / `CONTEXT.md` / `AGENTS.md` / `CLAUDE.md` / `README.md` 等)不触发门禁、不发布镜像、不部署。鼓励把文档与同批代码合并一次推送,避免 staging head 与已部署 SHA 分离。
4. 门禁构建 digest 固定镜像并 dispatch `deploy-staging`;随后在 staging 完成与风险相称的验收。`GET /api/health` 的 `.deployment.gitCommit` 必须等于**最近一次含门禁路径改动的 staging 提交**;其后若只有纯文档提交,`deploy/is-docs-only-range.sh <该 SHA> <staging head>` 必须退出 0,否则视为未部署。
5. 提升到 `main` **必须快进,不得 merge**。`deploy-production.yml` 强制 `main` 与 `staging` 指向同一 SHA,merge commit 会让生产部署失败。
6. 推送后必须核对远端 SHA;远端验证失败时不得声称已交付。
7. 不得自行提升 `main`、不改 `.gitea/workflows/**`、不动 DNS——这三件事只由产品负责人触发。
## 3. 工作树与多会话
同一台机器上经常有多个代理会话并行,主检出 `/workspace/Jyotisha` 可能被别的会话切到别的分支。
1. 任何 git 操作前先看 `git status -sb` 第一行确认分支;不要假设自己还在上次的分支上。
2. 代码工作只在自己的 worktree 里做:`git worktree add -b codex/<主题>-<日期> .worktrees/<主题>-<日期> origin/staging`。
3. 文档/任务书推 staging 时,用专门跟踪 `staging` 的 worktree(例如 `.worktrees/staging-docs`):`git pull --ff-only origin staging` → commit → push;不要在主检出上直接 commit 到 staging。
4. 不得在有未提交修改的工作树上切分支、stash、reset、覆盖或顺带提交别人的变更;不得 reset / rebase 别的会话的分支。误落到别人分支上的提交用 cherry-pick 搬走并告知。
5. 两个同时改 `frontend/src/app/page.tsx` 或同一组件的轮次必须串行,任务书里写明先后。
## 4. 记录文件放哪
| 内容 | 位置 | 规则 |
| --- | --- | --- |
| 任务书、执行进度 | `docs/tasks/TASK-<主题>-<日期>.md`、`docs/tasks/PROGRESS-<主题>-<日期>.md` | 新文件只写这里,不再放仓库根目录;索引在 `docs/tasks/README.md` |
| 被环境/依赖挡住的事项 | `BLOCKED.md`(根目录) | 写清缺什么、替代证据是什么;解除后划掉而不是删除 |
| Bug 事实、根因、防复发 | `docs/BUG_HISTORY.md` | 见 §5;编号连续,开工时核对当前最大号 |
| 用户可感知的行为与 Skill 变化 | `CHANGELOG.md` | 日期 + 一句话标题 + 变更要点;Skill 版本是否 bump 写明 |
| 视觉、动效、等待态、间距 | `frontend/DESIGN.md` | 改 UI 的同一提交内更新;`CLAUDE_DESIGN.md` 是上游参照不改 |
| 文案口径 | `frontend/docs/VOICE.md` | 新文案先对照 |
| 真人验收清单 | `docs/testing/` | 自动化做不了的浏览器级验收写成可照做的条目 |
| 领域术语 | `CONTEXT.md` | 新术语先加到 glossary 再用 |
`progress.md`、`findings.md`、`task_plan.md` 是早期实现日志,不是运行或部署说明,不再追加。
## 5. Bug History Workflow Hard Constraint
任何包含"Bug、报错、失败、异常、回归、无法保存、无法删除、状态码错误、线上故障"等现象的任务,开始诊断前必须用报错原文、接口路径、状态码、模块名和用户操作强制检索,并完整读完命中的记录。该文件体量已不允许通读全文,但检索不是可选步骤,命中记录的防复发措施是否仍然存在必须逐条确认:
- `docs/BUG_HISTORY.md`
这份文件是产品与代码 Bug 的长期历史入口;`docs/research/pre_work_error_ledger.md` 负责基础设施、外部引擎、碎片目录与预检风险,两者不得互相替代。
1. 修复前必须用报错原文、接口路径、状态码、模块名和用户操作搜索历史记录,优先检查相同模块的根因与防复发措施。
2. 若历史问题复发,必须关联原 `BUG-NNN`,说明旧测试、约束或发布门禁为何未拦住;不得把复发伪装成无关的新问题。
3. Bug 修复必须在同一变更中更新 `docs/BUG_HISTORY.md`:补充现有记录或新增连续编号,并记录状态、现象、触发条件、根因、修复、验证、防复发、关联记录和修复版本。
4. 若当轮只能诊断或被阻塞,也要把已确认事实写成 `investigating` 或 `blocked`,不得编造根因或提前标记 `resolved`。
5. `resolved` 必须有与风险相称的证据:至少一个针对性回归测试;生产问题还必须有脱敏后的迁移、部署、健康检查或 smoke 证据。
6. Bug 历史严禁写入姓名、出生资料、邮箱、用户/案例 ID、Cookie、JWT、密码、密钥、完整请求体或模型原文。
## 6. 代码增长冻结
- `scripts/jyotish_api_server.py` must not grow. New endpoints and features go in dedicated modules under `scripts/` and are thinly registered from the main file. Do not add new handler bodies, workflows, or feature branches to this file. The cap is enforced by `tests/test_api_server_growth_contract.py`(冻结时行数 + 300 行 bugfix 余量)。
- `frontend/src/app/page.tsx` 已从 4,766 行拆到 2,000 行以下,**不得再增长**:新逻辑进 `frontend/src/hooks/`、`frontend/src/lib/` 或组件;参数式 hook 内部保持 0 个 React hook 的既定模式。
- 不得再手写第二个聊天输入框(一律 `ChatComposer`,自有草稿走 `value`)、第二套滚动跟随(一律 `useConversationScrollAnchor` + `JumpToLatestButton`)、第二套加载动画(揭幕后不得出现 spinner / 骨架 / "正在加载",流式生成中除外)。
## 7. 前端红线
1. `./node_modules/.bin/tsc --noEmit` 通过;`npm run lint` **0 error**(react-hooks 编译器规则会拦 effect 内同步 setState、render 写 ref 等)。
2. `next build` 后 `/` 保持 `○ Static`;首屏 gzip 变化在 ±2% 内,超出要在进度记录里给出原因。
3. 测试总数不得低于开工时 `origin/staging` 的实测;改任何既有断言必须写"原值 / 新值 / 原因"三栏说明,不得静默弱化。
4. 合同测试的 fixture 必须来自真实引擎响应(golden),不得手造形状。
5. 改 UI 的提交同时更新 `frontend/DESIGN.md`;新文案对照 `frontend/docs/VOICE.md`。
6. 不改数据库结构的轮次不得顺带动迁移;动表的轮次必须真跑 `npm run test:db`。
7. 不得顺手升级依赖、不得顺手修不在任务书里的 warning;发现了写进 `BLOCKED.md` 或进度记录。
## 8. 隐私与安全
1. 真实用户出生资料、姓名、邮箱、会话内容、JWT、Cookie、密钥,不得进入 skill 文件、测试、CHANGELOG、Bug 历史、任务书、进度记录或任何提交。示例只用公开名人或明确虚构数据。
2. 不得读取、猜测或借用他人的凭据与账号做验收;没有受控账号就把该项写进 `BLOCKED.md`。
3. 供应商地址必须经服务端 SSRF 防护;不得把任何 key 放进前端。
4. 不得放宽置信度或验证边界,除非有外部 benchmark 证据。
## 9. 开工预检(引擎 / 基础设施 / 发布类任务)
为避免多窗口、多镜像、碎片目录导致重复误判,涉及运行入口、镜像边界、外部 oracle、远端同步、适配器、发布或大规模资料治理的任务,开工前必须读取:
- `docs/research/pre_work_error_ledger.md`
若还涉及碎片目录或镜像仓,再读:
- `docs/research/whole_machine_fragment_sweep_2026_07_05.md`
- `docs/research/whole_machine_fragment_sweep_round25_2026_06_25.md`
并运行:
- `python3 scripts/pre_work_check.py --remote-timeout 8 --command-timeout 45`(包含 `scripts/diagnose_external_engine_adapters.py --json`)
要求:不得把 `.workbuddy` 镜像当作运行主仓;不得在 `git ls-remote` / fetch / push 失败时声称云端已同步;新发现的重复错误、阻塞、碎片目录、远端验证失败追加到错误台账。
纯前端文案或组件改动不要求跑这条预检,但 §2、§3 照常。
## 10. 测试分层与环境缺口
| 层 | 命令 | 何时必跑 |
| --- | --- | --- |
| Python 快速门 | `.venv/bin/python scripts/run_quality_gate.py --profile quick` | 任何 Python 改动 |
| Python 定向 | `.venv/bin/python -m pytest tests/<file>.py` | 改了对应模块 |
| 前端 | `tsc --noEmit`、`npm run lint`、`npm test`、`npm run build` | 任何前端改动 |
| 数据库 | `npm run test:db --prefix frontend`(需 Docker) | 动表 |
| 发布前 | `run_quality_gate.py --profile release` | 提升 `main` 前 |
已知环境缺口,遇到时如实写进 `BLOCKED.md` 而不是宣称通过:无 Docker(DB/部署套件阻塞,用与基线逐条一致的失败清单代替);无登录态与 Chrome(浏览器级验收留给 `docs/testing/` 清单);无模型凭据(真实模型输出留待部署后复核)。
---
# Part B · 解盘类任务硬约束(只在输出占星解读时生效)
以下规则不替代 `SKILL.md` 与 `references/strict-workflow-router.md`,而是把其中最容易被省略的高严谨要求单独钉死。纯计算、纯代码、纯项目维护任务不适用。
## B1. High-Rigor Override
当用户明确要求以下任一项时,必须进入高严谨模式:
@@ -40,137 +165,31 @@ Deployment safety rules:
1. 必须尝试交叉参照 `PyJHora`、`VedAstro`、`jyotishganit`,并保持许可证边界。
2. 必须优先调用本仓原生实现,不得只用轻量包装脚本代替主链代码。
3. 涉及 timing / event / outcome,不得只看 `Vimshottari`,至少需要 `Vimshottari + Narayana Dasha` 双轨交叉。
4. 必须按问题域强制调取相关分盘:
- 事业:`D10 + A10`
- 财富:`D2 / D11`
- 婚恋:`D9 + UL`
4. 必须按问题域强制调取相关分盘:事业 `D10 + A10`;财富 `D2 / D11`;婚恋 `D9 + UL`。
5. 必须交付原始数据依据:度数、Dasha 边界、Shadbala / Ashtakavarga、Yoga 名称、Ayanamsa / Node mode、外部证据路径。
## 2. Functional Benefic/Malefic Hard Constraint
## B2. Functional Benefic/Malefic Hard Constraint
**强制调取 Functional Benefic / Malefic 判定(功能性吉凶星判定)。**
这条约束与 Dasha / 分盘 / 原始数据交付同级,不得省略。
执行要求:
**强制调取 Functional Benefic / Malefic 判定(功能性吉凶星判定)。** 这条约束与 Dasha / 分盘 / 原始数据交付同级,不得省略。
1. 每次进入高严谨模式,必须显式判定当前 Lagna 下的 `functional benefics` 与 `functional malefics`。
2. 任何关于事业、财富、婚恋、健康、障碍、回报、应期的结论,都不得只依据自然吉凶星(natural benefic/malefic)下判断,必须叠加功能性吉凶星层。
2. 任何关于事业、财富、婚恋、健康、障碍、回报、应期的结论,都不得只依据自然吉凶星下判断,必须叠加功能性吉凶星层。
3. 若某颗星在自然属性与功能属性之间冲突,必须在输出中说明冲突来源,并降低置信度或标记 `blocked`。
4. 若未调用功能性吉凶星判定,不得声称该次解读完成了高严谨模式。
5. Technique Audit Table 中必须出现 `Functional Benefic/Malefic` 一行,说明:
- `Used / not used / blocked`
- 关键功能吉星
- 关键功能凶星
- 对结论置信度的影响
5. Technique Audit Table 中必须出现 `Functional Benefic/Malefic` 一行,说明 `Used / not used / blocked`、关键功能吉星、关键功能凶星、对结论置信度的影响。
## 3. Existing MEVG Invocation Hard Constraint
## B3. Existing MEVG Invocation Hard Constraint
**强制执行既有 MEVG 规则,不得把它当成可选增强项。**
本节不是新增一套验证系统,而是把 `SKILL.md` 与
`references/mandatory-verification-gate-protocol.md` 中已经存在的 MEVG
外部验证门控提升为协作代理硬约束。
执行要求:
**强制执行既有 MEVG 规则,不得把它当成可选增强项。** 本节不是新增一套验证系统,而是把 `SKILL.md` 与 `references/mandatory-verification-gate-protocol.md` 中已经存在的 MEVG 外部验证门控提升为协作代理硬约束。
1. 对用户提出的 **所有星盘运势类问题**、**所有有关印度占星推运的问题**,包括命盘解读、事业、财富、婚恋、健康、流年、流月、应期、事件预测、出生时间校正辅助和技法可靠性判断,必须执行 MEVG。
2. MEVG 必须包含:
- 全球 / 全网外部资料采集
- 真实案例参考
- 来源分级
- 冲突仲裁
- 未验证声明降级
3. 输出的 Technique Audit Table 必须出现以下两行:
- `MEVG / Global Web Evidence`
- `Real Case Calibration`
2. MEVG 必须包含:全球 / 全网外部资料采集、真实案例参考、来源分级、冲突仲裁、未验证声明降级。
3. 输出的 Technique Audit Table 必须出现 `MEVG / Global Web Evidence` 与 `Real Case Calibration` 两行。
4. 若无法完成外部资料采集、无法找到真实案例、网络/工具不可用、或来源之间出现重大冲突,必须写成 `blocked` 或降级置信度,不得静默跳过。
5. 只有 **纯计算 / 纯代码 / 纯项目维护** 可以豁免 MEVG,例如运行测试、检查 Git 状态、修复代码、输出未解释的原始度数或 Dasha 边界。一旦开始解释“这代表什么运势”,豁免立即失效。
5. 只有 **纯计算 / 纯代码 / 纯项目维护** 可以豁免 MEVG(运行测试、检查 Git 状态、修复代码、输出未解释的原始度数或 Dasha 边界)。一旦开始解释"这代表什么运势",豁免立即失效。
## 4. Honesty Boundary
## B4. Honesty Boundary
以下情况必须明确写成 `blocked` 或降级置信度:
以下情况必须明确写成 `blocked` 或降级置信度:外部 oracle 尚未闭环;三大外部参照引擎中有一层无法合法或稳定调用;缺少分盘、Ayanamsa、Node mode 或出生精度;功能性吉凶星层未完成;双重大运或多系统结果发生实质冲突;MEVG / Global Web Evidence 或 Real Case Calibration 未完成。
- 外部 oracle 尚未闭环
- 三大外部参照引擎中有一层无法合法或稳定调用
- 缺少分盘、Ayanamsa、Node mode 或出生精度
- 功能性吉凶星层未完成
- 双重大运或多系统结果发生实质冲突
- MEVG / Global Web Evidence 或 Real Case Calibration 未完成
禁止把内部一致性伪装成“已经全球顶级精度”。
## 5. Pre-Work Error Ledger Hard Constraint
为避免多窗口、多应用、多文件夹碎片导致重复误判,开工前 / 进行任何实质项目工作前必须读取:
- `docs/research/pre_work_error_ledger.md`
若任务涉及运行入口、镜像边界、外部 oracle、远端同步、适配器、测试验收或大规模资料治理,还必须读取:
- `docs/research/whole_machine_fragment_sweep_2026_07_05.md`
- `docs/research/whole_machine_fragment_sweep_round25_2026_06_25.md`
同时必须运行:
- `python3 scripts/pre_work_check.py --remote-timeout 8 --command-timeout 45`
该预检必须包含:
- `scripts/diagnose_external_engine_adapters.py --json`
执行要求:
1. 不得把 `.workbuddy` 镜像当作运行主仓。
2. 不得在 `git ls-remote` / fetch / push 等远端验证失败时声称云端已同步。
3. 不得在未查看当前 `git status --short --branch` 时覆盖或重置本地变更。
4. 新发现的重复错误、阻塞、碎片目录、远端验证失败,必须追加到错误台账或当轮 sweep 文档。
## 6. Git Branch Delivery Hard Constraint
分支模型:`staging` 是测试环境,`main` 是生产控制分支。所有改动必须先经
`staging` 验收,再提升到 `main`;不存在直接改 `main` 的交付路径。
1. 动手前必须 `git fetch origin --prune`,并以远端 **`origin/staging`** 为基线。不得基于本地 `staging` 或本地 `main`:这两个本地引用经常落后远端上百个提交,基于它们做出的分析和补丁会对不上真实代码。
2. 在独立 worktree 中开发,路径 `.worktrees/<主题>-<日期>`,分支 `codex/<主题>-<日期>`。不得在存在未提交修改的工作树上切换分支、stash、reset、覆盖或顺带提交用户变更。
3. 交付到 staging 用快进推送(`git push origin HEAD:staging`)。这会触发 Gitea `backend-quality-gate`;该工作流的 `push:` 触发带有与 `deploy/gated-paths.txt` 逐行一致的 `paths:` 过滤:改动**全部**落在该清单之外的纯文档推送(`docs/**`、根目录 `TASK-*.md` / `PROGRESS-*.md` / `CHANGELOG*.md` / `progress.md` / `task_plan.md` / `findings.md` / `BLOCKED.md` / `CONTEXT.md`、`AGENTS.md` 等记录文件)不触发门禁、不发布镜像、不部署;任何触及清单内路径的推送都会跑完整构建与部署。仍鼓励把文档与同批代码合并一次推送——文档单独推送虽不再取消正在运行的代码门禁,但会让 staging head 与已部署 SHA 分离,增加核对成本。
4. 由 quality gate 构建 digest 固定镜像并 dispatch `deploy-staging`,随后在 `https://staging.jyotisha.chat` 完成与风险相称的验收。`GET /api/health` 的 `.deployment.gitCommit` 必须等于**最近一次含门禁路径改动的 staging 提交**,而不再是 staging head:若其后只有纯文档提交,`deploy/is-docs-only-range.sh <该 SHA> <staging head>` 必须退出 0(publish 与 deploy-staging 对分叉、落后或含门禁路径的 head 仍会拒绝发布);否则视为未部署。
5. 提升到 `main` **必须快进,不得 merge**。`.gitea/workflows/deploy-production.yml` 强制 `main` 与 `staging` 指向同一个 commit SHA;任何 merge commit 都会让生产部署以 `main and staging must identify the same reviewed release` 失败。
6. 生产部署手动执行:先跑 `release-quality-gate`,再 dispatch `deploy-production`。它复用 staging 已验收的镜像 digest,不重新构建。
7. 推送后必须核对远端 SHA,确认 `origin/staging`(以及提升后的 `origin/main`)确实包含目标提交;远端验证失败时不得声称已交付。
8. GitHub `upstream` 仅为镜像:其工作流文件已从仓库删除,GitHub Actions 已在仓库设置中关闭,不得用它验证交付状态。
## 7. Bug History Workflow Hard Constraint
任何包含“Bug、报错、失败、异常、回归、无法保存、无法删除、状态码错误、线上故障”等现象的任务,开始诊断前必须用报错原文、接口路径、状态码、模块名和用户操作强制检索,并完整读完命中的记录。该文件体量已不允许通读全文,但检索不是可选步骤,命中记录的防复发措施是否仍然存在必须逐条确认:
- `docs/BUG_HISTORY.md`
这份文件是产品与代码 Bug 的长期历史入口;`docs/research/pre_work_error_ledger.md` 继续负责基础设施、外部引擎、碎片目录与预检风险,两者不得互相替代。
执行要求:
1. 修复前必须用报错原文、接口路径、状态码、模块名和用户操作搜索历史记录,优先检查相同模块的根因与防复发措施。
2. 若历史问题复发,必须关联原 `BUG-NNN`,说明旧测试、约束或发布门禁为何未拦住;不得把复发伪装成无关的新问题。
3. Bug 修复必须在同一变更中更新 `docs/BUG_HISTORY.md`:补充现有记录或新增连续编号,并记录状态、现象、触发条件、根因、修复、验证、防复发、关联记录和修复版本。
4. 若当轮只能诊断或被阻塞,也要把已确认事实写成 `investigating` 或 `blocked`,不得编造根因或提前标记 `resolved`。
5. `resolved` 必须有与风险相称的证据:至少一个针对性回归测试;生产问题还必须有脱敏后的迁移、部署、健康检查或 smoke 证据。
6. Bug 历史严禁写入姓名、出生资料、邮箱、用户/案例 ID、Cookie、JWT、密码、密钥、完整请求体或模型原文。
## Agent skills
### Issue tracker
Issues and PRDs are tracked in this repository's GitHub Issues using the `gh` CLI. See `docs/agents/issue-tracker.md`.
### Triage labels
Triage uses the canonical `needs-triage`, `needs-info`, `ready-for-agent`, `ready-for-human`, and `wontfix` labels. See `docs/agents/triage-labels.md`.
### Domain docs
Domain documentation uses the single-context layout. See `docs/agents/domain.md`.
## 8. API Server Growth Freeze
`scripts/jyotish_api_server.py` must not grow. New endpoints and features go in dedicated modules under `scripts/` and are thinly registered from the main file. Do not add new handler bodies, workflows, or feature branches to this file. The line-count cap is enforced by `tests/test_api_server_growth_contract.py` (live count at freeze plus 300 lines of bugfix slack).
禁止把内部一致性伪装成"已经全球顶级精度"。候选出生时间不得写成 confirmed;医疗、法律、投资、安全关键结论及确定性死亡/诊断/妊娠预测禁止。
+37
View File
@@ -0,0 +1,37 @@
@AGENTS.md
# Claude 会话分工(CLAUDE.md)
`AGENTS.md` 是所有代理的硬约束,上面已整体导入。本文件只写 Claude Code 会话在这个仓库里的角色、默认工作模式和验收口径。
## 角色
- **产品负责人(用户)**:非程序员。做产品决策、在真实环境实测、触发 `main` 提升与生产发布。用中文沟通;结论先行,数字进表,不要让他读代码。
- **Claude**:产品经理 + 架构 + 验收。读代码做诊断、定方案、写任务书、事后逐项验收;只有在用户明说"直接执行 / 用 subagent 做"时才亲自改代码。
- **coding agent(Cursor / Codex / Claude subagent)**:按任务书执行,写进度记录与 Bug 历史,推 staging。
## 三种工作模式
1. **任务书模式(默认)**:修复或改造类需求 → Claude 写 `docs/tasks/TASK-<主题>-<日期>.md` 并推到 `staging`(纯文档推送不触发门禁)→ 执行方在 `codex/<主题>-<日期>` 分支实现 → Claude 拉最新代码验收。
2. **直接执行模式**:用户明确说"直接开始执行"或"用 subagent"。Claude 自己(或派 fork 子代理)在独立 worktree 上实现,仍然写 `docs/tasks/PROGRESS-*.md`、`docs/BUG_HISTORY.md`,验收由 Claude 独立再做一遍。
3. **验收模式**:执行方回报后,Claude 基于 `origin/staging` 或指定分支跑 tsc / lint / 测试 / Python 定向测试,对照任务书逐条给出通过 / 未通过 / 环境缺口三种结论,并把未通过项写成修复单(`TASK-<主题>-fix-<日期>.md`)。
## 任务书必须有的段落
基线 commit → 事故实证(行号按符号定位)→ 根因 → **决策记录**(产品授权了什么;若推翻既有任务书或 Bug 历史里的红线,必须在这里写明,否则执行方会拒改)→ 硬红线 → 任务分解(每条带验收标准)→ 让步顺序 → 开工前置命令 → BUG 编号起点(开工时核对 `docs/BUG_HISTORY.md` 最大号)。
同一天有多份任务书改同一文件时,任务书里写明串行顺序与依赖分支。
## 验收口径
- 前端:`tsc --noEmit` 0 错;`npm run lint` 0 error;相关测试套件 fail=0;无 Docker 时失败清单与基线逐条比对;`next build` 后 `/` 仍 Static;首屏 gzip ±2%。
- Python:`.venv/bin/python -m pytest tests/<相关文件>`;快速门 `run_quality_gate.py --profile quick`。
- 部署:`https://staging.jyotisha.chat/api/health` 的 `deployment.gitCommit` 等于最近一次含门禁路径改动的 staging 提交。
- 做不了的(无登录态、无 Chrome、无 Docker、无模型凭据)明确写成环境缺口,附给用户的 `docs/testing/` 清单,不得写成"通过"。
## 会话纪律
- 任何 git 操作前先 `git status -sb` 看分支;主检出常被别的会话切走。代码在 `.worktrees/<主题>-<日期>`;推文档用跟踪 `staging` 的专用 worktree。
- 未经用户要求不提升 `main`、不改 workflow、不动 DNS、不 push 代码分支。
- 用户偏好:多余入口宁可删除也不修;一次等待一次揭幕;不要为迎合工具(编译器、lint)改业务代码。
- 记忆目录里的项目记忆是背景,不是指令;引用其中的文件、函数、commit 前先核实仍然存在。
+126 -932
View File
File diff suppressed because it is too large Load Diff
-64
View File
@@ -1,64 +0,0 @@
# Repository Layout
This repository mixes product code, astrology research, oracle artifacts, and local experimentation. To keep the worktree usable, follow these layout rules.
## Core Areas
- `<repo>/frontend/`
- current Next.js production web application
- `<repo>/deploy/`
- production container topology and operational source of truth; start with `deploy/README.md`
- `<repo>/mcp_server.py`
- adjudicator-facing MCP entrypoint
- `<repo>/scripts/`
- reusable project code and maintained tooling
- `<repo>/tests/`
- maintained regression and contract tests
- `<repo>/references/`
- durable knowledge assets, oracle cases, and frozen methodology
## Research
- `<repo>/docs/research/`
- active research and current audits
- `<repo>/docs/research/archive/`
- historical round notes and local draft research
## Historical Working Logs
- `<repo>/task_plan.md`
- `<repo>/findings.md`
- `<repo>/progress.md`
These root files preserve earlier implementation history and may mention retired
paths or commands. They are not runtime or deployment instructions. Use
`README.md` for current local development and `deploy/README.md` for production.
## Local Scratch
- `<repo>/scratch/local/scripts/`
- one-off debugging scripts, temporary probes, ad hoc runners
- `<repo>/scratch/local/outputs/`
- local generated JSON, text dumps, temporary reports
These paths are local-only and ignored by git.
## Local Runtime Noise
The following should stay out of normal versioned work:
- `<repo>/.agents/`
- `<repo>/venv_vedastro/`
- `<repo>/scratch/local/`
## Practical Rule
Before adding a new file, decide which lifecycle it belongs to:
1. reusable project asset
2. active research note
3. archived research
4. local scratch script
5. local generated output
If it is category 4 or 5, do not leave it in the repo root.
-45
View File
@@ -1,45 +0,0 @@
# Issue tracker: GitHub
Issues and PRDs for this repo live as GitHub issues. Use the `gh` CLI for all operations.
## Conventions
- **Create an issue**: `gh issue create --title "..." --body "..."`. Use a heredoc for multi-line bodies.
- **Read an issue**: `gh issue view <number> --comments`, filtering comments by `jq` and also fetching labels.
- **List issues**: `gh issue list --state open --json number,title,body,labels,comments --jq '[.[] | {number, title, body, labels: [.labels[].name], comments: [.comments[].body]}]'` with appropriate `--label` and `--state` filters.
- **Comment on an issue**: `gh issue comment <number> --body "..."`
- **Apply / remove labels**: `gh issue edit <number> --add-label "..."` / `--remove-label "..."`
- **Close**: `gh issue close <number> --comment "..."`
Infer the repo from `git remote -v` — `gh` does this automatically when run inside a clone.
## Pull requests as a triage surface
**PRs as a request surface: no.** _(Set to `yes` if this repo treats external PRs as feature requests; `/triage` reads this flag.)_
When set to `yes`, PRs run through the same labels and states as issues, using the `gh pr` equivalents:
- **Read a PR**: `gh pr view <number> --comments` and `gh pr diff <number>` for the diff.
- **List external PRs for triage**: `gh pr list --state open --json number,title,body,labels,author,authorAssociation,comments` then keep only `authorAssociation` of `CONTRIBUTOR`, `FIRST_TIME_CONTRIBUTOR`, or `NONE` (drop `OWNER`/`MEMBER`/`COLLABORATOR`).
- **Comment / label / close**: `gh pr comment`, `gh pr edit --add-label`/`--remove-label`, `gh pr close`.
GitHub shares one number space across issues and PRs, so a bare `#42` may be either — resolve with `gh pr view 42` and fall back to `gh issue view 42`.
## When a skill says "publish to the issue tracker"
Create a GitHub issue.
## When a skill says "fetch the relevant ticket"
Run `gh issue view <number> --comments`.
## Wayfinding operations
Used by `/wayfinder`. The **map** is a single issue with **child** issues as tickets.
- **Map**: a single issue labelled `wayfinder:map`, holding the Notes / Decisions-so-far / Fog body. `gh issue create --label wayfinder:map`.
- **Child ticket**: an issue linked to the map as a GitHub sub-issue (`gh api` on the sub-issues endpoint). Where sub-issues aren't enabled, add the child to a task list in the map body and put `Part of #<map>` at the top of the child body. Labels: `wayfinder:<type>` (`research`/`prototype`/`grilling`/`task`). Once claimed, the ticket is assigned to the driving dev.
- **Blocking**: GitHub's **native issue dependencies** — the canonical, UI-visible representation. Add an edge with `gh api --method POST repos/<owner>/<repo>/issues/<child>/dependencies/blocked_by -F issue_id=<blocker-db-id>`, where `<blocker-db-id>` is the blocker's numeric **database id** (`gh api repos/<owner>/<repo>/issues/<n> --jq .id`, _not_ the `#number` or `node_id`). GitHub reports `issue_dependencies_summary.blocked_by` (open blockers only — the live gate). Where dependencies aren't available, fall back to a `Blocked by: #<n>, #<n>` line at the top of the child body. A ticket is unblocked when every blocker is closed.
- **Frontier query**: list the map's open children (`gh issue list --state open`, scoped to the map's sub-issues / task list), drop any with an open blocker (`issue_dependencies_summary.blocked_by > 0`, or an open issue in the `Blocked by` line) or an assignee; first in map order wins.
- **Claim**: `gh issue edit <n> --add-assignee @me` — the session's first write.
- **Resolve**: `gh issue comment <n> --body "<answer>"`, then `gh issue close <n>`, then append a context pointer (gist + link) to the map's Decisions-so-far.
-15
View File
@@ -1,15 +0,0 @@
# Triage Labels
The skills speak in terms of five canonical triage roles. This file maps those roles to the actual label strings used in this repo's issue tracker.
| Label in mattpocock/skills | Label in our tracker | Meaning |
| -------------------------- | -------------------- | ---------------------------------------- |
| `needs-triage` | `needs-triage` | Maintainer needs to evaluate this issue |
| `needs-info` | `needs-info` | Waiting on reporter for more information |
| `ready-for-agent` | `ready-for-agent` | Fully specified, ready for an AFK agent |
| `ready-for-human` | `ready-for-human` | Requires human implementation |
| `wontfix` | `wontfix` | Will not be actioned |
When a skill mentions a role (e.g. "apply the AFK-ready triage label"), use the corresponding label string from this table.
Edit the right-hand column to match whatever vocabulary you actually use.
+260
View File
@@ -0,0 +1,260 @@
# 准确率基线、外部 Oracle 闭环与 Benchmark 看板
> 本文从根 README 拆出(2026-09-03),内容原样保留。这里是所有"本机现在能跑什么、哪些指标可测、哪些能力还缺外部 oracle 证据"的命令入口;看板产物就在本目录。所有看板固定输出 `can_claim_global_first: false` 与 `production_tuning_allowed: false`,直到外部样本达到生产调参标准。
### 真实案例复验与准确率边界
一条命令查看本机当前技能覆盖与准确率基线:
```bash
python3 scripts/local_accuracy_report.py --format markdown
```
如需给副手、CI 或后续自动化读取,使用 JSON:
```bash
python3 scripts/local_accuracy_report.py --format json
```
当前总控报告会聚合 technique registry、BPHS invariants、公开人物真实案例复验、Yoga precision/recall/F1、Dasha/Shadbala oracle readiness、Ashtakoot API parity。它用于回答“本机现在能跑什么、哪些指标已经可测、哪些能力还缺外部 oracle 证据”;它不把本地回归测试包装成最终人生事件预测准确率。
公开人物样本复验命令:`python3 tests/run_real_case_revalidation.py`。
当前复验口径是公开人物样本的出生盘星座级一致率,并对部分带有来源矛盾、时区争议或边界度数的参考行标记为 controversial_reference。这个指标用于验证排盘计算是否稳定,不等同于人生事件预测准确率,也不应被当作个人命运判断的命中率。
### Dasha 参考差异审计
对照外部 PDF 或第三方软件时,先运行 Dasha 参考差异审计,而不是直接改生产常数:
```bash
python3 scripts/dasha_reference_audit.py \
--year YYYY --month MM --day DD \
--hour HH --minute mm --second ss \
--lat LAT --lon LON --tz TZ \
--target-start-date 1986-05-18 \
--target-source third_party_chart.pdf
```
该工具会输出当前 Vimshottari 起点、秒级出生时间敏感性、年长常数敏感性,以及对齐目标日期所需的 Moon sidereal longitude 偏移量。不要为单份 PDF 直接调生产常数;应先建立更大的 oracle 样本集,比较 ayanamsa、Moon sidereal longitude、Nakshatra 边界与 Vimshottari 起算口径。
也可以运行合并版外部 oracle 边界审计,同时查看 Dasha、外部黄经与 Shadbala 的校准状态:
```bash
python3 scripts/oracle_boundary_audit.py \
--oracle-file references/oracle/dasha_shadbala_oracle_cases.json
```
该报告会明确标出 `production_tuning_recommended: false`:当前目标集已有外部验证行,但差异审计仍会拒绝单样本或全局倍率调参;VedAstro SDK 黄经样本已纳入 `longitude_cases`,用户盘最大差异约 26.23 角秒、D1/D9 落点一致,但这只能说明基础黄经接近,不能把当前目标集闭合夸大成生产级全局校准。
三方官方/外部 oracle sanity 总控命令:
```bash
python3 scripts/external_oracle_sanity_closure.py --format markdown
```
该报告同时检查 VedAstro official precision sanity、PyJHora black-box artifacts、jyotishganit MIT reference layer。默认命令为非阻塞 sanity,总控质量门可运行;需要真实触发 VedAstro official full snapshot 细算时,加 `--live-official-full-snapshot`。当前允许声明的是“高严谨带 blocked 行”:PyJHora 黑盒证据与 jyotishganit 参考层可审计;VedAstro 黄经 sanity 通过但 official full snapshot 细算仍需显式 live probe 且可能因前台预算或官方快照合同 blocked,不能声称三方 fully closed。
外部真值采集队列用于把缺失目标值拆成可执行任务,而不是直接调生产参数:
```bash
python3 scripts/oracle_collection_queue.py \
--oracle-file references/oracle/dasha_shadbala_oracle_cases.json \
--format markdown
```
如需给自动化或副手读取,可改用 JSON 输出:
```bash
python3 scripts/oracle_collection_queue.py \
--oracle-file references/oracle/dasha_shadbala_oracle_cases.json \
--format json
```
如需让真人或 Antigravity AI 副手直接填写证据包,可一次性导出每个 case 的 draft JSON:
```bash
python3 scripts/prepare_oracle_capture_packets.py \
--oracle-file references/oracle/dasha_shadbala_oracle_cases.json \
--output-dir references/oracle/artifacts/pending_packets
```
该命令会生成 `capture_manifest.json`、`OPERATOR_NEXT_STEPS.md` 和 5 个 `external_*.json`。这些导出包只是人工复核/再采集入口;当前主 oracle 文件的目标集状态以 closure dashboard 和 validator 输出为准。
如果只想优先准备当前最短闭环链路的三条首包,而不是一次性导出整批 pending packets,可直接生成统一 blank kit:
```bash
python3 scripts/generate_blank_oracle.py \
--output-dir references/oracle/artifacts/first_packet_blank_kit
```
该命令会按当前推荐顺序导出 `dasha`、`tajika_sahams`、`shadbala` 三条 front 的首包草稿、`blank_oracle_kit_manifest.json` 和 `BLANK_ORACLE_KIT_NEXT_STEPS.md`。它只复制当前首包模板,不会猜测真值,也不会把本地引擎输出伪装成 external oracle。
填完某个 `external_*.json` 后,必须把 `status` 改为 `external_verified`,补齐 metadata、具体 `source_artifact` 文件路径以及所有 `target_placeholders`。再把该包合并回 oracle 文件:
```bash
python3 scripts/oracle_collection_queue.py \
--oracle-file references/oracle/dasha_shadbala_oracle_cases.json \
--apply-packet references/oracle/artifacts/pending_packets/external_template_steve_jobs_dasha_lahiri.json \
--format json
```
这一步只负责把人工填写的外部证据写回 `template_cases`;它不会自动认可证据,也不会允许生产调参。合并后仍必须重新生成 queue 并运行 validator。
该 JSON 的 scope 是 `external_oracle_collection_queue`。当前目标集可以出现 `external_verified` 与 `ready_for_calibration` 已闭合的状态,但 `production_tuning_allowed` 仍保持 `false`;这表示只能把外部黑盒目标值作为审计证据,不能直接用这些样本做 Dasha/Shadbala 生产调参。
Ashtakoot 外部合婚 oracle 使用同一个队列生成器,但独立样本文件是 `references/oracle/ashtakoot_oracle_cases.json`:
```bash
python3 scripts/oracle_collection_queue.py \
--oracle-file references/oracle/ashtakoot_oracle_cases.json \
--format json
```
该队列同样保持 `ready_for_calibration: 0`,用于采集 `ashtakoot_36_point` 外部合婚目标值,而不是重写现有 `scripts/ashtakoot.py` 算法。每条样本要补齐 `target.total_score`、`target.varna`、`target.vashya`、`target.tara`、`target.yoni`、`target.graha_maitri`、`target.gana`、`target.bhakoot`、`target.nadi`、`target.kuja_status`,并保留 JHora/VedAstro/AstroSage 等外部截图或 API artifact。
每个队列任务还包含 `evidence_packet.capture_id` 草稿证据包。人工或副手录入外部真值时,必须至少填写 `tool_name`、`tool_version_or_url`、`capture_date`、`source_artifact`、`ayanamsa`、`node_mode`、`timezone`、`operator_note`,并保留截图、API 响应或 stdout 等外部 artifact;不得把本仓库本地计算输出当作 `source_artifact`。
外部截图和 stdout 片段统一存入 `references/oracle/artifacts/`,证据包里的 `source_artifact` 必须使用该目录下的 repo-relative 路径或明确标注的外部审阅位置。所有私人截图必须打码;不得提交私人 PDF 原件、不得提交完整出生报告,也不得提交浏览器 scratch 目录或含账号会话/cookie/token/桌面通知的截图。
第一条 JHora/PyJHora 黑盒证据采集按 `docs/user_jhora_capture_guide.md` 执行:优先使用 Steve Jobs 或合成样本,采集 Moon sidereal longitude、Vimshottari start date 与 Shadbala 七曜六分量,保存到 `references/oracle/artifacts/` 后再运行 evidence validator。
外部目标字段采用 `target_fields` + `target_placeholders` 双层结构:`target_fields` 固定记录该案例需要校验的目标,例如 `target.moon_sidereal_longitude_deg`、`target.vimshottari_start_date`、`target.shadbala_components`;当这些字段被真实外部来源填入并且证据包状态升为 `external_verified` 后,队列生成器会保留这些值,不会再把它们降级成 `draft`。这保证了“人工/JHora/PyJHora/VedAstro 采集 → JSON 填写 → 队列生成 → validator 复核”的路径可复验。
当外部证据包被填写回队列 JSON 后,用证据验证器做第二层防线:
```bash
python3 scripts/oracle_evidence_validator.py \
--queue-file /path/to/filled_external_oracle_collection_queue.json
```
该验证器输出 `external_oracle_evidence_validation`,会检查 `evidence_packet` 必填元数据、`target_placeholders` 是否已填、是否覆盖 `target_fields`、是否包含外部 artifact,以及是否错误使用本仓库本地引擎输出。只有状态为 `external_verified` 且证据完整的包才会进入可复核状态;通过 validator 不等于允许生产调参。
证据包通过 validator 之后,再运行边界差异审计,比较本地引擎与外部 Dasha/Shadbala 目标值:
```bash
python3 scripts/oracle_boundary_audit.py \
--oracle-file references/oracle/dasha_shadbala_oracle_cases.json
```
审计报告中的 `template_comparisons` 会列出 external-verified template 的 Dasha 起点差异、Shadbala 七曜分量/总分差异、每个分量的 Rupa 容差、单位说明和 `global_scaling_check.recommendation: reject_global_scaling`,并继续保持 `production_tuning_recommended: false`,防止用单个样本或全局倍率调生产常数。
公开 benchmark 看板用于长期展示能力状态、oracle readiness 和“是否可宣称全球第一”的诚实边界:
```bash
python3 scripts/public_benchmark_dashboard.py \
--oracle-file references/oracle/dasha_shadbala_oracle_cases.json \
--format markdown \
--output docs/benchmark/public_jyotish_benchmark_dashboard.md
```
当前看板固定输出 `can_claim_global_first: false`,直到外部 oracle 样本、差异审计和长期公开 benchmark 都达到生产调参标准。
外部 oracle 总控 closure 看板会合并 Dasha、Shadbala 与 Tajika/Sahams 三条硬闭环战线,给出总任务数、已验证数、第一优先级和下一条执行命令:
```bash
python3 scripts/oracle_closure_master_dashboard.py \
--dasha-oracle-file references/oracle/dasha_shadbala_oracle_cases.json \
--tajika-oracle-file references/oracle/tajika_annual_oracle_cases.json \
--format markdown \
--output docs/benchmark/jyotish_external_oracle_closure_master_dashboard.md
```
当前总控看板输出 `total_tasks: 12`、`external_verified_tasks: 12`、`can_claim_current_target_set_closure: true`,但 `can_claim_global_oracle_closure: false` 与 `production_tuning_allowed: false` 仍保持锁定。含义是当前目标集已闭合,不能夸大成全球 oracle、预测准确率或生产调参闭环。
Dasha 外部 oracle 最短闭环状态板用于把“大运外部真值”从 Shadbala 绝对值大包中拆出来,优先推进第一条可验证边界日期:
```bash
python3 scripts/dasha_oracle_closure_status.py \
--oracle-file references/oracle/dasha_shadbala_oracle_cases.json \
--format markdown \
--output docs/benchmark/dasha_external_oracle_closure_status.md
```
当前第一优先级是 `external_template_steve_jobs_dasha_lahiri`。该状态板只要求 `target.vimshottari_start_date` 和外部证据 metadata,不要求同时填完 Shadbala 七曜六分量;这样可以先完成 Dasha oracle 的第一条闭环,再单独推进 Shadbala 绝对值闭环。
第一条外部证据包的交互辅助命令:
```bash
python3 scripts/first_oracle_packet_assistant.py \
--front dasha \
--format markdown \
--output docs/benchmark/first_dasha_oracle_packet_assistant.md
```
同一个助手也支持:
```bash
python3 scripts/first_oracle_packet_assistant.py --front tajika_sahams --format markdown --output docs/benchmark/first_tajika_oracle_packet_assistant.md
python3 scripts/first_oracle_packet_assistant.py --front shadbala --format markdown --output docs/benchmark/first_shadbala_oracle_packet_assistant.md
```
该助手不会生成或猜测 JHora/PyJHora 真值,只会列出当前 packet 还缺哪些字段、可用外部来源、apply 命令和 validator 命令。
如需先看三条硬闭环 front 的统一排序入口,而不是分别运行三个助手:
```bash
python3 scripts/oracle_packet_assistant_index.py \
--format markdown \
--output docs/benchmark/first_oracle_packet_assistant_index.md
```
该索引会固定列出 `dasha`、`tajika_sahams`、`shadbala` 三条 front 的首包 case、缺失字段数、operator card 与推荐执行顺序,方便直接判断当前最短闭环路径。
Shadbala 外部绝对值闭环使用独立状态板,专门追踪七曜的六分量与总 Rupa:
```bash
python3 scripts/shadbala_oracle_closure_status.py \
--oracle-file references/oracle/dasha_shadbala_oracle_cases.json \
--format markdown \
--output docs/benchmark/shadbala_external_absolute_value_closure_status.md
```
当前第一优先级是 `external_template_synthetic_north_china_shadbala_raman`。除了同一 oracle 行里的 `target.moon_sidereal_longitude_deg`,还必须填写 Sun/Moon/Mars/Mercury/Jupiter/Venus/Saturn 的 `sthana`、`dig`、`kala`、`chesta`、`naisargika`、`drik`、`total_rupa`;验证器会检查分量和总分,不允许用一个全局倍率把本地输出硬缩放成外部值。
Tajika/Sahams 年运系统使用独立的外部 oracle 队列,专门追踪 Varshaphala、太阳回归、Muntha、Year Lord、Mudda Dasha、Sahams 与 Tajika Yogas 的外部验证状态:
```bash
python3 scripts/tajika_annual_oracle_queue.py \
--oracle-file references/oracle/tajika_annual_oracle_cases.json \
--format markdown
```
公开年运看板可这样生成:
```bash
python3 scripts/tajika_annual_benchmark_dashboard.py \
--oracle-file references/oracle/tajika_annual_oracle_cases.json \
--format markdown \
--output docs/benchmark/tajika_sahams_annual_benchmark_dashboard.md
```
当前 Tajika/Sahams 看板固定输出 `can_claim_tajika_sahams_closure: false`:本地 skill 已有年运计算与解释骨架,但太阳回归精确时刻、Varsha Lagna、Muntha、Mudda Dasha、Punya/Rajya/Vivah Saham 和 Tajika Yogas 仍需 JHora/PyJHora/书例级外部证据后,才能宣称年运闭环。
年运第一条最短闭环状态板:
```bash
python3 scripts/tajika_annual_closure_status.py \
--oracle-file references/oracle/tajika_annual_oracle_cases.json \
--format markdown \
--output docs/benchmark/tajika_sahams_annual_closure_status.md
```
如需导出可填写的年运证据包:
```bash
python3 scripts/tajika_annual_oracle_queue.py \
--oracle-file references/oracle/tajika_annual_oracle_cases.json \
--write-packet-dir references/oracle/artifacts/pending_packets \
--format json
```
填完 `external_template_steve_jobs_varshaphala_1984_lahiri.json` 后,可合并回年运 oracle:
```bash
python3 scripts/tajika_annual_oracle_queue.py \
--oracle-file references/oracle/tajika_annual_oracle_cases.json \
--apply-packet references/oracle/artifacts/pending_packets/external_template_steve_jobs_varshaphala_1984_lahiri.json \
--format json
```
`full-reading` 也会输出 `ai_prompt_pack`:这是给网页/app、skill 或后端 AI 代理使用的结构化 Prompt/RAG 上下文包。它不会硬编码断语,而是携带 D1/D9/Dasha/Shadbala/Ashtakavarga 的证据快照、推荐检索文档和边界提示,要求大模型基于计算证据交叉验证,避免单一配置下结论。
+322
View File
@@ -0,0 +1,322 @@
# Jyotish 计算引擎与解读流水线(引擎层文档)
> 本文从 2026-09-03 之前的根 README 拆出,描述 Python 引擎(`scripts/`、`references/`、`SKILL.md`)的定位、流水线、技法覆盖与诚实边界。产品层(网页、部署、协作流程)见根目录 `README.md`。正文保留原文,"Project Status"一节反映 v6.9.14 时期的状态,仅作历史参考。
## What Is This
This is a **Vedic (Jyotish) astrology analysis system** designed for deep, auditable full-chart readings. It is NOT a simple ephemeris calculator — it is a multi-stage interpretive pipeline that:
1. **Computes** divisional charts (D1/D9/D10/...) via Swiss Ephemeris
2. **Routes** 89 capability entries as a backend evidence pool (Dashas, Yogas, Shadbala, Ashtakavarga, Transits...)
3. **Routes** the analysis through strict workflow paths depending on question type (career / relationship / wealth / timing)
4. **Audits** every technique used — declaring what was called, what is complete/covered, and which limitations affect confidence
5. **Degrades gracefully** — limitations are labeled, not silently over-promising
### Key Differentiators (vs. PyJHora / VedAstro / Maitreya)
| Feature | This Project | PyJHora | VedAstro | Maitreya |
|---------|-------------|----------|----------|----------|
| Full-reading pipeline (one command) | ✅ | ❌ | ❌ | ❌ |
| Strict workflow router (per-question-type) | ✅ | ❌ | ❌ | ❌ |
| Technique Audit Table (confidence labeling) | ✅ | ❌ | ❌ | ❌ |
| Capability degradation (limits are explicit) | ✅ | ❌ | ❌ | ❌ |
| MEVG external verification gates | ✅ | ❌ | ❌ | ❌ |
| 89 capability entries routed as a backend evidence pool | ✅ | ✅ (50+) | ✅ (200+) | ✅ |
| Traditional algorithm benchmarked | ✅ mixed depth | ✅ | ✅ | ✅ |
| Docker / MCP Server | ✅ | ❌ | ✅ | ❌ |
| English docs / PyPI package | ✅ in progress | ✅ | ✅ | ✅ |
---
### Prerequisites
- Python 3.11+
- Swiss Ephemeris (`pyswisseph` or `ephem`)
- Optional: `pypdf`, `pdfplumber` (for PDF chart input)
### Install
```bash
# Clone the repository
git clone https://github.com/732642856/yinduzhanxing.git
cd yinduzhanxing
# Install Python dependencies
pip install -r requirements.txt
# Verify installation
python3 scripts/audit_capabilities.py --mode validate
# Expected: valid=true, problem_count=0
```
### Minimal Full Reading (5 minutes)
```bash
python3 scripts/jyotish_engine.py full-reading \
--year 1990 --month 6 --day 15 \
--hour 10 --minute 30 \
--lat 28.6139 --lon 77.2090 --tz 5.5 \
--age 36 \
--transit-date 2026-06-04
```
**Output:** ~45 computed modules, zero errors, complete structured reading with technique audit table.
### Sample Output (abbreviated)
```
═══ FULL READING ═══
Birth Data: 1990-06-15 10:30 (+5.5) 28.61°N 77.21°E
Lagna: Gemini Sun: Taurus Moon: Leo
── Static Analysis ──
[✓] D1 Rashi Chart
[✓] D9 Navamsa
[✓] D10 Dasamsa
[✓] Vimshottari Dasha (120 years)
[✓] Ashtakavarga (8-point system)
[✓] Shadbala (covered — absolute Rupa totals, component invariants verified)
[✓] Yogas & Doshas
[✓] Argala (planetary interventions)
[✓] Nakshatra Advanced (Chandra Bala / Tara Bala)
── Dynamic Timing ──
[✓] Vimshottari Dasha breakdown
[✓] Dasha Sandhi detection
[✓] Transit (true positions)
[✓] Double Transit analysis
[✓] Narayana Dasha
[✓] Solar Return / Varshaphala
[✓] Nakshatra Dasha (Ashtottari)
── Technique Audit Table ──
✓ Vimshottari Dasha covered high confidence
✓ Ashtakavarga covered high confidence
✓ Shadbala covered absolute Rupa output; total_virupas component invariant passed
✓ Chara Dasha covered KN Rao benchmark 95.83% overall match
✓ KP Sub-Lord covered SubLord/SubSubLord + ABCD significator workflow
```
## Core Workflow
### Three Input Paths
| Path | Input | Behavior |
|------|-------|----------|
| **A: Precise birth data** | Date + time + coordinates | Full `full-reading` engine |
| **B: PDF / text chart** | Scanned chart or description | Extract → Quality Gate → route to A |
| **C: Uncertain birth time** | "Don't know my birth time" | Interactive birth time rectification |
### Eight-Stage Pipeline
```
Stage -1: Question-type routing (career / relationship / wealth / timing)
Stage 0: Input routing (A / B / C)
Stage 1: (B only) PDF extraction + Quality Gate
Stage 2: Intent recognition → target house routing
Stage 3: Static analysis (10 steps)
Stage 4: Dynamic timing (7 steps)
Stage 5: Timing output (5-layer verification)
Stage 6: Remedial measures (optional)
Stage 7: Modern language packaging
Stage 8: Technique Audit Table (mandatory)
```
**Strict Workflow Router** (`references/strict-workflow-router.md`):
- Career questions → `career-timing-strict`
- Relationship questions → `relationship-timing-strict`
- Wealth questions → `wealth-timing-strict`
- Event timing → `event-timing-strict`
- Historical verification → `event-verification-strict`
The AI does NOT require the user to name techniques (e.g., "Chara Dasha"). It auto-selects based on question type.
---
## Technique Coverage
Current registry count: **89 capability entries** (79 covered, 10 complete, 0 partial, 0 missing).
These entries are a **backend evidence pool**, not a flat list of 89 user-facing
prediction sources. Ordinary users see topic-level conclusions and evidence
summaries. The question-domain router selects a small primary chain, then uses
supporting indicators only to raise/lower confidence. Audit-only and alias
entries cannot affect astrological conclusions.
The table below lists representative high-value entries. Treat
`references/technique_registry.json` as the source of truth for the full
machine-readable registry.
| Technique | Status | Notes |
|-----------|--------|-------|
| D1 Rashi Chart | ✅ covered | Swiss Eph base |
| D9 Navamsa | ✅ covered | |
| D10 Dasamsa | ✅ covered | |
| Vimshottari Dasha | ✅ covered | |
| Dasha Sandhi | ✅ covered | |
| Ashtakavarga | ✅ covered | BPHS/PVR calibrated |
| Argala | ✅ covered | |
| Vargottama | ✅ covered | |
| Pushkara | ✅ covered | |
| A10 / Karma Pada | ✅ covered | |
| UL / Upapada | ✅ covered | |
| Transit (true positions) | ✅ covered | |
| Double Transit | ✅ covered | |
| Nakshatra Advanced | ✅ covered | Tara Bala / Chandra Bala / Sub-Lord workflow |
| Narayana Dasha | ✅ covered | CLI and full-reading integration |
| Solar Return / Varshaphala | ✅ covered | Tajika annual-chart workflow |
| **Shadbala** | ✅ covered | **absolute Rupa component-sum output; internal invariants pass; external absolute-value oracle expansion remains open** |
| **Chara Dasha** | ✅ covered | **KN Rao benchmark: sign 100%, duration 91.67%, overall 95.83%** |
| KP Sub-Lord | ✅ covered | SubLord/SubSubLord + ABCD significator workflow |
| Bhava Chalit | ✅ covered | Sripati/Porphyry/Equal/Whole Sign/Placidus/Koch |
| Sudarshana Chakra | ✅ covered | Asc/Moon/Sun reference charts + convergence scoring |
| Tajika Yogas | ✅ complete | Annual-chart yoga set |
| Raj Yoga | ✅ covered | Rule-based detection |
| Dhana Yoga | ✅ covered | Rule-based detection |
| Pancha Mahapurusha | ✅ covered | Complete detection |
| Neecha Bhanga | ✅ complete | Debilitation cancellation workflow |
| Sade Sati | ✅ covered | Saturn pressure timing |
| Tithi Lord | ✅ complete | Lunar-day ruler workflow |
| Pancha Pakshi | ✅ complete | Five-bird system |
| Rashi Tulya Navamsa | ✅ covered | D1/D9 mapping |
| Trimshamsa D30 | ✅ covered | D30 varga support |
| Marriage Counting | ✅ complete | Bhrigu Pada marriage-counting method |
| Prashna Integration | ✅ complete | Prashna workflow integrated |
| Bhrigu Pada Dasha | ✅ complete | Pada progression workflow |
| Muhurta | ✅ covered | Panchanga / auspicious timing workflow |
**Legend:**
- ✅ `covered` — implemented and benchmarked against authoritative sources
- ✅ `complete` — implemented with integrated workflow and validation hooks
- ✅ `covered` — implemented and available in the engine, sometimes with explicit confidence caps
- 🔶 `partial` — reserved for implemented-but-insufficiently-integrated techniques; current registry count is 0
- ❌ `missing` — not currently present in the registry; current registry count is 0
---
## Why This Exists (Competitive Context)
### The Landscape
| Project | Type | Strength | Weakness |
|---------|------|----------|-----------|
| **PyJHora** | Calculation library | Strongest traditional algorithm coverage (50+ Dashas, 284 Yogas) | No interpretive pipeline; user must interpret results themselves |
| **VedAstro** | API / Web platform | 200+ endpoints, Docker, MCP Server, MIT license | Interpretive audit & confidence labeling weaker |
| **Maitreya** | Desktop software | Mature cross-platform GUI | Jyotish depth not as deep as specialized projects |
| **jyotisha** | Panchanga / calendar | Excellent Panchanga accuracy | Not a full reading system |
| **This project** | AI-native analysis system | Full pipeline + audit + degradation | Pure calculation accuracy still being benchmarked |
### Our Position
> **PyJHora is the calculator. VedAstro is the API platform. Maitreya is the desktop software. This project is the "AI-native Jyotish research analyst."**
We are NOT trying to out-calculate PyJHora (it has years of lead). Our value is in:
1. Organizing calculations into a **reproducible interpretive workflow**
2. **Auditing** every technique used and declaring confidence
3. **Degrading gracefully** — confidence caps and limitations are labeled, not silently over-promising
4. Being **AI-native** — designed for integration with LLM-based analysis
---
## Honest Assessment
We believe in transparency about limitations. This is NOT a "99% accurate" system, and anyone claiming that about Jyotish is over-selling.
### Current Accuracy Estimates (self-evaluated)
| Dimension | Score | Notes |
|-----------|-------|-------|
| Astronomical foundation (Swiss Eph) | 8.5/10 | Depends on ayanamsa, node mode, house system |
| Traditional algorithm accuracy | 8.4/10 | Chara Dasha benchmark passed; Shadbala absolute Rupa invariants now pass; Dasha oracle expansion remains open |
| Technique coverage breadth | 9.1/10 | 65 registered techniques; broad and increasingly benchmarked |
| Reading detail depth | 9.6/10 | Possibly best among open-source projects |
| Prediction workflow rigor | 8.8/10 | Strict routing + audit table |
| Verification system | 8.2/10 | Has registry, benchmark, degradation; some verification still internal |
| Engineering maturity | 7.6/10 | Docker, PyPI config and CI exist; release artifacts still need cleanup |
| Open-source influence | 5.5/10 | Currently more of a "private high-density toolkit" |
### What Confidence Caps Mean (Important)
Even when a technique is labeled `covered`, it may carry a confidence or validation boundary:
- It CAN produce output
- Some components may still need broader external oracle expansion against PyJHora / JHora / canonical texts
- It should be interpreted together with cross-technique evidence
- It must NOT be the sole basis for high-confidence predictions when its limitation says so
Examples:
- `Shadbala` (covered): absolute Rupa totals are reported directly from six component sums; internal component invariants pass and `total_rupas = total_virupas / 60`, while external absolute-value oracle expansion remains open.
- `Chara Dasha` (covered): KN Rao benchmark passes at 95.83% overall; remaining differences are documented around Aquarius/Scorpio co-lord strength arbitration.
---
## Project Status
**Current version:** `v6.9.14`
### Recently Completed
- `v6.9.14` — Sudarshana Chakra complete + 475 pytest cases + 65-technique registry audit PASS.
- `v6.9.13` — Bhava Chalit complete + transit trigger output normalization + Nakshatra test calibration.
- `v6.9.12` — Shadbala precision upgrade + Ashtakoot 36-point compatibility + expanded subcommands.
- `v6.9.6` — Field mapping fixes (degree→degree_in_sign + toFixed null safety); PyPI publishing config.
- `v6.9.5` — birth_info null safety + API field mapping fixes.
- `v6.9.4` — AI interpretation integration; current browser build disables direct model API keys and routes AI through server-side `/api/chat` or a backend proxy.
- `v6.9.3` — 35 Dasha systems, 405+ Yoga rules, KP complete system, Prashna, 16-factor synastry, Remedies, Sahams 36, Sudarshana, PMC, Tajika.
- `v6.1.12` — Chara Dasha KN Rao Method rewrite, PyJHora benchmark 95.83% PASS.
- `v6.1.10` — Darakaraka deep reader wired into `full-reading.modules.jaimini.darakaraka`; thematic reports now consume real DK and Rashi Tulya Navamsa evidence.
- `v6.1.9` — Public/sanitized benchmark suite, competitive research, coverage roadmap and PDF validation methodology added.
- `v6.1.8` — Yoga validation reached F1=95.22% (FP=36, FN=63); thematic reports consume real `full-reading.modules` evidence.
- `v6.1.6` — Five-system Dasha convergence wired into full-reading (Vimshottari + Chara + Yogini + Ashtottari + Kalachakra).
- `v6.0.11` — Shadbala 1200/1200 internal invariants pass; later upgraded to absolute Rupa component-sum output.
### Actively Working On (P0)
1. **Release hygiene** — run the release profile, keep product-critical files tracked, rebuild wheel/sdist, and align GitHub tags with source version
2. **README / package metadata sync** — keep public docs, registry counts and distribution artifacts consistent
3. **Dasha oracle expansion** — add external cases for Vimshottari start/end boundaries and configurable year-length/ayanamsa comparisons
4. **Benchmark expansion** — add more oracle cases for Shadbala, KP and annual-chart modules
5. **Frontend verification** — keep the Next.js API contracts aligned with the Python engine output
### Next (P1)
- Production image publishing and smoke-test docs
- English documentation examples and API tutorials
- Multi-Ayanamsa UX polish and benchmark examples(计算层已可验证切换;网页设置展示和更多外部样本仍需补齐)
---
## Engine-level development checks
### Running the Test Suite
```bash
# Syntax check all scripts
python3 -m py_compile scripts/*.py
# Capability audit (must pass with 0 problems, 0 warnings)
python3 scripts/audit_capabilities.py --mode validate
# Next.js unit tests, lint, and production build
npm test --prefix frontend
npm run lint --prefix frontend
npm run build --prefix frontend
# Full-reading regression test (use FICTIONAL data only)
python3 scripts/jyotish_engine.py full-reading \
--year 1990 --month 6 --day 15 \
--hour 10 --minute 30 \
--lat 39.9042 --lon 116.4074 --tz 8 \
--age 36 \
--transit-date 2026-06-04
```
### Important Rules
1. **NEVER** put real user birth data into skill files, tests, CHANGELOG, or public repos
2. Use only: (a) public AA-rated celebrity data, (b) explicitly fictional smoke tests, (c) current-session data (never persisted)
3. Always run `git status --short --branch` before starting work
4. Always run `py_compile` + `audit_capabilities.py` + full-reading regression after modifications
5. Do NOT remove a confidence or validation boundary without external benchmark evidence
6. Do NOT refactor arbitrarily; make minimal verifiable changes
+201
View File
@@ -0,0 +1,201 @@
# VedAstro Gateway、用户级入口与 Codex 插件
> 本文从根 README 拆出(2026-09-03),内容原样保留:VedAstro 官方/自建/本地回退三种模式的配置、中国大陆 Gateway 部署边界、`scripts/vedastro_user_entrypoint.py` 用户级入口,以及把本仓装成 Codex 本地插件的步骤。
### VedAstro:聊天产品推荐配置
项目当前固定使用官方 Python SDK `vedastro==1.23.25`。首次安装依赖时必须安装到项目虚拟环境,并用同一个解释器启动后端,避免子进程落到系统 Python 后出现 `No module named vedastro`:
```bash
.venv/bin/pip install -r requirements.txt
.venv/bin/python scripts/jyotish_api_server.py --host 127.0.0.1 --port 5200
```
在仓库根目录创建本机私有配置文件 `.env.local`。聊天场景推荐先使用下面的快速官方证据模式:
```dotenv
VEDASTRO_API_ENDPOINT=https://api.vedastro.org/api
VEDASTRO_ENABLE_NETWORK=1
VEDASTRO_TIMEOUT_SECONDS=20
VEDASTRO_GATEWAY_REQUIRE_OFFICIAL_RAW_RESPONSE=1
# 聊天快速模式:保留 Dasha / Chara Dasha / Shadbala / Ashtakavarga,
# 不执行 10 行星 + 12 宫位的逐项 fan-out。
VEDASTRO_FULL_SNAPSHOT_FANOUT_ENABLED=0
# 免费公共模式下 SearchEvents 范围扫描耗时长且容易限流,
# 聊天请求中默认关闭,避免同步阻塞流式回复。
VEDASTRO_RANGE_SCAN_NETWORK_ENABLED=0
VEDASTRO_CACHE_TTL_SECONDS=604800
VEDASTRO_OFFICIAL_FULL_SNAPSHOT_CACHE_TTL_SECONDS=604800
VEDASTRO_GATEWAY_QUEUE_ENABLED=1
VEDASTRO_FREE_TIER_QUEUE=1
VEDASTRO_FAIL_OPEN_LOCAL=1
VEDASTRO_FULL_CATALOG_SAMPLE_LIMIT=0
# 没有 key 时可先使用官方公共/免费模式;不要把 key 放到前端。
# VEDASTRO_API_KEY=your_vedastro_key
```
该文件已被 `.gitignore` 忽略;`scripts/jyotish_api_server.py`、`scripts/vedastro_service_adapter.py`、`scripts/run_quality_gate.py` 会自动加载它。VedAstro 子进程默认复用启动后端的 `sys.executable`;如需指定独立解释器,可设置 `VEDASTRO_PYTHON_BIN=/absolute/path/to/python`。
快速模式仍会取得 VedAstro 官方原始响应,并让 Gateway 在存在 `official_raw_response` 时闭合为 `official_verified`;D1/D9 等基础盘继续由本地 Swiss Ephemeris 负责。它只关闭高延迟 fan-out 与 `SearchEvents` 范围扫描,不等于关闭 VedAstro。
获得稳定 API key,或把 Gateway 指向自建 VedAstro 服务后,可开启完整模式:
```dotenv
VEDASTRO_API_KEY=your_vedastro_key
VEDASTRO_FULL_SNAPSHOT_FANOUT_ENABLED=1
VEDASTRO_RANGE_SCAN_NETWORK_ENABLED=1
```
完整模式会增加外部请求数量和首包等待时间,更适合后台任务、预计算或非实时专业解盘,不建议直接放在聊天首轮的同步关键路径。运行 `.venv/bin/python scripts/diagnose_vedastro_mode.py` 可检查当前模式;通过 `/api/vedastro_gateway/status` 查看 Gateway 的实际配置和 readiness。
AI/vibe coding 推荐入口:Cline 接本仓 MCP,Aider 负责低成本小改,Dyad 只做前端原型。运行 `python3 scripts/print_cline_mcp_config.py` 生成 Cline MCP 配置;详情见 `docs/vibe_coding_setup.md`。
### 中国大陆用户:VedAstro Gateway 模式
普通中国大陆用户不需要、也不应该让浏览器直连 VedAstro。推荐部署方式是:网页只访问你自己的本地或云端后端;后端通过 `VedAstro Gateway` 统一管理 self-host、official upstream、TTL/cache、free-tier queue 和 local fallback。
最短配置:
```bash
cp .env.cn.example .env.local
.venv/bin/python scripts/jyotish_api_server.py --host 127.0.0.1 --port 5200
npm ci --prefix frontend
npm run dev --prefix frontend
```
网页侧使用:
- `Trust Center -> Web Professional Reading v1`
- `/api/vedastro_gateway/status` 查看当前后端策略
- `/api/vedastro_gateway/run` 生成 VedAstro-compatible evidence packet
- `/api/professional_reading` 生成网页专业解盘包
关键边界:
- 不要让浏览器直连 VedAstro,也不要把 `VEDASTRO_API_KEY` 放进前端。
- `VEDASTRO_CACHE_TTL_SECONDS` 和 `VEDASTRO_OFFICIAL_FULL_SNAPSHOT_CACHE_TTL_SECONDS` 用于缓存官方或自建服务结果。
- `VEDASTRO_GATEWAY_QUEUE_ENABLED=1` / `VEDASTRO_FREE_TIER_QUEUE=1` 用于把昂贵或被限流的外部请求排队。
- 如果 VedAstro 官方或自建服务不可达,`VEDASTRO_FAIL_OPEN_LOCAL=1` 会保持本地 Jyotish 引擎继续输出,并在 Technique Audit Table 里降级标注。
- Gateway 不会默认声称跑完 641 项;它只把 capability catalog、dynamic selection、cache/queue/fallback 状态作为证据边界交给 strict workflow。
### Codex 用户级 VedAstro + strict workflow 入口
如果用户在 Codex 窗口从云端 Git 仓库拉取本项目,推荐先走这一条稳定入口,而不是手动拼多个底层脚本:
```bash
python3 scripts/vedastro_user_entrypoint.py \
--year YYYY --month MM --day DD --hour HH --minute mm \
--lat LAT --lon LON --tz TZ \
--question "事业机会什么时候出现" \
--themes career,marriage,wealth \
--reference-date 2026-07-02 \
--format markdown
```
机器读取或交给后续 agent 处理时使用 JSON:
```bash
python3 scripts/vedastro_user_entrypoint.py \
--year YYYY --month MM --day DD --hour HH --minute mm \
--lat LAT --lon LON --tz TZ \
--question "事业机会什么时候出现" \
--themes career,health,education,property,children,migration,prashna \
--reference-date 2026-07-02 \
--format json
```
这个入口会自动做四件事:
1. 读取 `.env.local` 并诊断当前是 `official_extended` 还是 `fast_local_fallback`。
2. 启动 `official_full_capability_catalog`,给 VedAstro 官方能力目录生成 `domain / execution_policy / adjudicator_use / confidence_role / blocked_reason`。
3. 按 `--themes` 做动态选择,避免把健康、教育、房产、子女、迁移、Prashna 等非三大主题塞进 `general`。
4. 触发 strict workflow 合同摘要,输出 primary route、可用 route、cache/TTL/free-tier queue 策略和 honesty boundary。
边界必须保留:这个入口**不会把 641 项全部当作已执行**。它先做官方能力目录分类和主题选择;能自动执行的进入证据层,需要第二人资料、用户文本、校时画像或官方网络预算的方法会保持 `needs_user_context`、`needs_user_text`、`needs_rectification_profile` 或 `blocked`。
#### 作为 Codex 本地插件安装
本仓现在带了最小插件包装:`.codex-plugin/plugin.json`。它复用现有 `skills/` 与根目录 `mcp_server.py`,适合你把当前仓直接装进 Codex 本机环境。
1. 先把本仓登记到个人 marketplace:
```bash
python3 <home>/.codex/skills/.system/plugin-creator/scripts/create_basic_plugin.py \
jyotish-vedic-astrology \
--path ~/.codex/plugins \
--marketplace-path ~/.agents/plugins/marketplace.json \
--marketplace-name personal \
--with-marketplace
```
上面是 Codex 官方脚本的标准 marketplace 流。如果你要让 **当前仓本身** 被安装,关键不是用 scaffold 目录跑能力,而是让 `~/.agents/plugins/marketplace.json` 里的 `jyotish-vedic-astrology` 条目最终指向当前仓路径。
最少要确认这一条存在:
```json
{
"name": "jyotish-vedic-astrology",
"source": {
"source": "local",
"path": "<repo>"
}
}
```
2. 若本机还没把 personal marketplace 接进 Codex:
```bash
codex plugin marketplace add ~/.agents/plugins/marketplace.json
```
3. 安装插件:
```bash
codex plugin add jyotish-vedic-astrology@personal
```
4. 检查是否已被识别:
```bash
codex plugin list
```
5. 开一个**新线程**再测试。Codex 只会在新线程里重新拾取新装的 skills / MCP。
#### 本地更新 / 重装
当你改了 `.codex-plugin/plugin.json`、`skills/` 或 `mcp_server.py`:
```bash
python3 <home>/.codex/skills/.system/plugin-creator/scripts/update_plugin_cachebuster.py \
<repo>
codex plugin add jyotish-vedic-astrology@personal
```
然后重新开新线程验证。
推荐的 official extended `.env.local` 示例:
```bash
VEDASTRO_API_ENDPOINT=https://api.vedastro.org/api
VEDASTRO_ENABLE_NETWORK=1
VEDASTRO_TIMEOUT_SECONDS=20
VEDASTRO_CACHE_TTL_SECONDS=600
VEDASTRO_OFFICIAL_FULL_SNAPSHOT_CACHE_TTL_SECONDS=600
VEDASTRO_FREE_TIER_QUEUE=1
# 可选
# VEDASTRO_API_KEY=sk_live_xxx
```
先运行:
```bash
python3 scripts/diagnose_vedastro_mode.py
```
若仍显示 `fast_local_fallback`,用户级入口仍可运行,但解盘必须把 VedAstro official 证据写成 blocked/降级,不能声称 official extended 已闭环。
+72
View File
@@ -0,0 +1,72 @@
# 任务书与进度记录(docs/tasks/)
这里存放每一轮协作的**任务书**(`TASK-<主题>-<日期>.md`)和执行方的**进度记录**(`PROGRESS-<主题>-<日期>.md`)。2026-09-03 之前它们堆在仓库根目录,已整体搬到这里;新文件一律直接写在本目录。
- 任务书由产品/架构侧(通常是 Claude)写,包含:基线 commit、事故实证、根因、决策记录、硬红线、任务分解、验收标准。
- 进度记录由执行方(coding agent)写:做了什么、测试数字、偏离与原因。
- 被环境或依赖挡住的事项写进根目录 `BLOCKED.md`;Bug 事实写进 `docs/BUG_HISTORY.md`;两者不在这里重复。
- 纯文档改动不触发 staging 门禁(见 `deploy/gated-paths.txt`)。
## 索引(按主题)
### 生时校正(rectification)
| 任务书 | 进度 | 主题 |
| --- | --- | --- |
| `TASK-rectification-convergence-20260830.md` | `PROGRESS-rectification-convergence-20260830.md` | 收敛重构 v2 |
| `TASK-rectification-decision-authority-20260831.md` | `PROGRESS-rectification-decision-authority-20260831.md` | 决策权威归一与停止语义 |
| `TASK-rectification-billing-20260831.md` | — | run_failed 与开场问题槽为空 |
| `TASK-round2-cost-and-delivery-20260831.md` | — | 第二轮真实成本与交付物 |
| `TASK-rectification-provisional-adopt-20260901.md` | — | provisional 采用成为一等成功出口 |
| `TASK-rectification-engine-convergence-20260901.md` | — | 引擎侧相邻分钟可区分 |
| `TASK-rectification-nonterminal-exit-20260901.md` | — | 非终态轮出口统一 |
| `TASK-rectification-tails-20260901.md` | — | Round A/2 收尾 |
| `TASK-rectification-question-in-message-20260902.md` | — | 题目进消息、删问题槽 |
| `TASK-rectification-question-ownership-fix-20260902.md` | — | 选项回归服务端、fail-closed |
| `TASK-rectification-adopt-flow-20260902.md` | — | 采用流程整治 |
| `TASK-rectification-adopt-flow-fix-20260903.md` | — | 采用流程修复单(含删「用这个时间看盘」) |
| `TASK-rectification-uncertainty-stop-20260903.md` | — | 不确定度停止规则加样本下限(BUG-503) |
| `TASK-rectification-walkthrough-polish-20260902.md` | — | 首次真实走查抛光(服务端) |
| `TASK-rectification-ux-20260902.md` | — | 会话面空白假死与交互摩擦(09-03 已在新基线重启) |
| `TASK-consultation-birth-accuracy-20260901.md` | — | 咨询侧出生时间精度真值传递 |
### 聊天主链路与首页
| 任务书 | 进度 | 主题 |
| --- | --- | --- |
| `TASK-chat-message-authority-20260901.md` | — | 消息服务端权威化(BUG-464) |
| `TASK-session-url-20260901.md` | — | 会话 URL 化 |
| `TASK-cloud-truth-convergence-20260901.md` | — | 本地/云端双份真相收敛 |
| `TASK-home-split-20260901.md` | `PROGRESS-home-split-20260901.md` | 拆分首页巨石组件·第一批 |
| `TASK-contract-repairs-20260901.md` | `PROGRESS-contract-repairs-20260901.md` | 孤儿契约红修复(先于第二批) |
| `TASK-home-split-batch2-20260901.md` | `PROGRESS-home-split-batch2-20260901.md` | 拆页第二批:聊天主链路 |
| `TASK-home-split-batch3-20260901.md` | `PROGRESS-home-split-batch3-20260901.md` | 拆页第三批:onboarding/profile |
| `TASK-chat-streaming-ux-20260901.md` | `PROGRESS-chat-streaming-ux-20260901.md` | 流式体验与双会话面统一 |
| `TASK-unified-loading-20260902.md` | `PROGRESS-unified-loading-20260902.md` | 首页一次等待一次揭幕(BUG-479) |
| `TASK-agent-voice-20260901.md` | — | Agent 输出语气 |
### 个人报告
| 任务书 | 进度 | 主题 |
| --- | --- | --- |
| `TASK-report-sectioned-generation-20260830.md` | `PROGRESS-report-sectioned-20260830.md` | 分章节生成 |
| `TASK-report-skill-parity-20260901.md` | `PROGRESS-report-skill-parity-20260901.md` | 内容对齐 skill 解读深度 |
| `TASK-report-blocked-repairs-20260902.md` | `PROGRESS-report-blocked-repairs-20260902.md` | 全主题 blocked 修复 |
| `TASK-report-section-writer-failure-20260902.md` | `PROGRESS-report-writer-failure-20260902.md` | 写作阶段 report_schema_invalid |
### 前端基础与工程
| 任务书 | 进度 | 主题 |
| --- | --- | --- |
| `TASK-frontend-optimization-20260828.md` | `PROGRESS-frontend-optimization-20260828.md` | 前端优化九条 |
| `TASK-frontend-followup-20260829.md` | `PROGRESS-frontend-followup-20260829.md` | 九条收尾 |
| `TASK-frontend-interaction-20260830.md` | `PROGRESS-frontend-interaction-20260830.md` | 交互与 UI 收尾 |
| — | `PROGRESS-react-compiler-20260817.md` | React Compiler 尝试(已回滚,结论见 BLOCKED.md) |
| `TASK-engine-runtime-hygiene-20260901.md` | `PROGRESS-engine-runtime-hygiene-20260901.md` | Python 引擎运行时治理 |
| `TASK-billing-pricing-20260830.md` | `PROGRESS-billing-pricing-20260830.md` | 计费闭环与功能级定价 |
## 命名与归档
- 文件名:`TASK-<kebab-主题>-<YYYYMMDD>.md`;同主题的修复单加 `-fix`;进度记录同名换前缀。
- 一轮结束后不删除文件;结论沉淀到 `docs/BUG_HISTORY.md`(Bug)、`CHANGELOG.md`(行为/skill 变化)、`frontend/DESIGN.md`(视觉与交互合同)。
- 任务书里的行号会随代码漂移,定位以符号名为准。
@@ -0,0 +1,291 @@
# 任务书 · 前端优化九条的收尾(2026-08-29)
复核对象:`origin/staging` @ `3198fb6b`("perf(frontend): split chat streaming, load Inter, isolate admin CSS")。
上一轮交付基本属实,我逐条实测过:`tsc --noEmit` exit 0、`eslint` 0 error、`next build` exit 0、路由模式(`/` `○ Static`、`/login` `/admin/**` 仍 `ƒ`)、admin 路由确实不再引用含 `.message-list` 的 216 KB globals chunk、`public/` 只剩 logo、Inter 走 `next/font` 并生成独立 `@font-face` chunk、星盘库 effect 已合并成单 effect 三分支。**本轮不重做这些,只收三个尾巴。**
---
## 硬红线
1. **不得修改任何既有测试断言。** 本轮三条任务都不需要改断言 —— 如果你发现"必须改断言才能过",那是方案错了,停下来登记 `BLOCKED.md`,不要动断言。
2. **不得让 `error.tsx` / `not-found.tsx` 重新 import `globals.css` 或 `site-styles`。** 这两页与 admin 共享根布局段,一旦 import,admin 每条路由会重新背上约 33 KB gzip —— 上一轮 −32 KB 的成果会当场归零。`tests/site-style-isolation-contract.test.ts` 已锁这条,它必须保持绿灯且不被修改。
3. 不得手写 `useCallback` / `useMemo`。
4. 不得为迎合 React Compiler 改写代码;本轮不重开 React Compiler(理由见 `BLOCKED.md` 2026-08-17 记录)。
5. 推 staging 前必须 `./node_modules/.bin/tsc --noEmit` 通过(BUG-409 防复发)。**不要用 `npx tsc`**,本仓库环境下会装到空包 `tsc@2.0.4`。
6. 测试数不得低于基线 **2205**,且 `fail=0`、`skipped=0`(在有 Docker 的环境里跑)。
7. 不得改 `.gitea/workflows/**`。不得在有未提交改动的工作树上切分支。不得自行把 staging 提升到 main。
让步顺序:功能与测试不回归 > 可验证的修复 > 代码整洁。
## 开工前置
```bash
git fetch origin --prune
git worktree add -b codex/frontend-followup-20260829 \
../.worktrees/frontend-followup-20260829 origin/staging
```
基线必须是 `origin/staging`,不是任何本地 ref。读 `pre_work_error_ledger.md`,跑 `scripts/pre_work_check.py`,读 `frontend/AGENTS.md`(Next.js 版本与你训练数据不同,写代码前先看 `node_modules/next/dist/docs/`)。改前先在 `docs/BUG_HISTORY.md` 里检索是否有同类记录。
---
## 任务 A(P0)· 根 404 / 错误页现在完全没有样式
### 事实
`src/app/not-found.tsx` 和 `src/app/error.tsx` 的 markup 是纯 Tailwind 工具类,但上一轮把 globals 从根布局段摘掉后,这两页**一条 CSS 都不加载**。构建产物实证:
```
.next/server/app/_not-found.html
→ 只引用 3b67syn08d_z3.css(2,146 B,纯 Inter @font-face)
`min-h-svh` / `text-muted-foreground` 的定义只在 0grkt280n67e_.css(216 KB),该页不加载它
```
用户看到的是浏览器默认裸 HTML:不居中、无配色、无间距,`<Button>` 塌成一行光秃秃的链接文字。这是真实的用户可见回归,不是可接受的取舍。
`BLOCKED.md` 把唯一出路写成"必须另开一条不与 admin 共享的布局链"—— **这个判断是错的**,请一并订正该条记录。
### 做法
**照抄仓库里已有的同类模式**,不要发明新方案:`src/app/global-error.tsx` 和 `src/app/forbidden.tsx` 早就是内联 `style={{...}}` 写法,正是为了应付同一个约束。
具体:
- 模块级常量沿用 `global-error.tsx` 的形式:`const canvas = "var(--color-canvas, #fbfaf7)"` 等。**注意:这两页上 globals 不加载,CSS 变量取不到值,实际生效的是括号里的 fallback。** 这是预期行为,fallback 值必须和 `globals.css` 里的 token 真实值一致(`--color-canvas: #fbfaf7`、`--color-ink: #1d1d1f`、`--color-ink-secondary: #5f5f59`、`--color-border: #d8d6cf`、`--color-action: #85432f`、`--color-danger: #9a2f2f`),改前去 `globals.css` 核一遍,不要照抄我这里的数字。
- 移除 `import { Button } from "@/components/ui/button"` —— 它是 Tailwind 组件,在这两页上等于无样式。改用原生 `<button>`(error 页的"重试")和 `<Link>`("返回对话"),各自带内联 style。`next/link` 保留,别退化成 `<a href>`,会丢客户端导航。
- `error.tsx` 的 `TriangleAlert` 可以留,但把 `className="size-8 text-destructive"` 换成 lucide 的 props:`size={32}` + `color={danger}`,`aria-hidden="true"` 保留。
- `error.tsx` 保留 `"use client"` 和现有的 `useEffect(() => console.error(...))`,不要动错误上报逻辑。
### 无障碍合同(`frontend/DESIGN.md`,不得降级)
- 可点区域 `minHeight: 44px`、`minWidth: 88px`
- `error.tsx` 的错误块保留 `role="alert"`
- focus-visible 可见描边:沿用 `global-error.tsx` 的做法,页面内嵌一个作用域 `<style>` 写 `.xxx-action:focus-visible { outline: 3px solid ...; outline-offset: 2px; }`
- 文案一字不改
### 验收(必须逐条给出证据,不接受"看起来好了")
```bash
./node_modules/.bin/next build
# 1) 根 404 的 body 里不得再出现 Tailwind 工具类
python3 -c "
import re;h=open('.next/server/app/_not-found.html').read()
print(re.search(r'<body.*?</body>',h,re.S).group(0)[:1200])"
# 2) admin 仍不得引用 globals chunk(这条是 P0 的守门条件)
grep -rho '[a-z0-9_-]\{8,\}\.css' .next/server/app/admin/ | sort -u
# 期望:只有 antd/admin 那个 chunk + Inter chunk 两个,
# 绝不能出现含 .message-list 的那个 216 KB chunk
grep -l 'message-list' $(find .next/static -name '*.css')
# 3) 站点路由 CSS 不变
grep -o 'rel="stylesheet"[^>]*href="[^"]*"' .next/server/app/index.html
```
另外:`next start` 后人工看一眼 `/一个不存在的路径`,确认是居中的暖白页而不是裸 HTML,截图或描述写进 PROGRESS。
### 测试
`tests/site-style-isolation-contract.test.ts` 的既有断言**保持原样不动**(它锁的正是"这两页不许 import globals",我们的方案让它继续为真)。在同文件**新增**断言:这两页不含 Tailwind 工具类特征(例如不出现 `className="flex`、`min-h-svh`、`text-muted-foreground`),且不再 import `@/components/ui/button`。
### 建档
`docs/BUG_HISTORY.md` 追加一条(用户可见回归,必须建档)。**编号前先重新确认远端最大号**(当前本地最大 BUG-430),别抢号:
```bash
git fetch origin --prune && git show origin/staging:docs/BUG_HISTORY.md | grep -o '^## BUG-[0-9]*' | sort -t- -k2 -n | tail -3
```
防复发条写清楚:根布局段(`error.tsx` / `not-found.tsx` / `forbidden.tsx` / `global-error.tsx`)的页面只能用内联样式,不得依赖任何工具类或 `globals.css`。
### 止损
改动超过 250 行,或发现必须动布局链 / 移动 `app/page.tsx` 才能完成 —— 停下,把实际卡点写进 `BLOCKED.md`,不要硬推。
---
## 任务 B(P1)· 一条时区依赖的脆测试
### 事实
`frontend/tests/onboarding-presentation.test.ts:43` 用绝对时刻构造:
```ts
const noon = new Date("2026-07-19T12:00:00+08:00");
```
而 `src/lib/onboarding-client.ts:112` 读的是 `now.getHours()`(**运行机器的本地时区**)。在 UTC 环境下该时刻是 04:00,落进"夜深了"分支,断言 `中午好,周宁。` 必红。
实测:`TZ=Asia/Shanghai` → 3 pass / 0 fail;默认 UTC → 1 fail。跟本轮和上一轮改动都无关,是既有问题。
### 做法
改成本地时区构造 —— **同一个测试文件末尾已经在用这个正确写法**(`new Date(2026, 6, 19, hour)`),照它改:
```ts
const noon = new Date(2026, 6, 19, 12);
```
**断言的期望值一个字都不许改**(`中午好,周宁。` / `现在最想理清哪件事?` 等全部原样保留)。这不是改断言,是修夹具构造。
同文件第 27 行的 `new Date("2026-07-19T08:00:00+08:00")` 只被断言了名字、不涉及时段,可改可不改;若改,断言同样不许动。
顺手扫一遍是否还有同类:
```bash
grep -rn '+08:00' frontend/tests/ | grep -iv 'iso\|timestamp\|askedAt\|resolvedAt'
```
凡是"绝对时刻 + 断言时段文案"的组合都按同一方式修;只做时间戳比较的不要动。
### 验收
```bash
TZ=UTC ./node_modules/.bin/tsx --test tests/onboarding-presentation.test.ts
TZ=Asia/Shanghai ./node_modules/.bin/tsx --test tests/onboarding-presentation.test.ts
TZ=America/New_York ./node_modules/.bin/tsx --test tests/onboarding-presentation.test.ts
```
三个时区必须全绿。不建档 BUG_HISTORY(测试夹具问题,非产品缺陷),在 PROGRESS 里记一句即可。
---
## 任务 C(P2,可止损)· 绕开 readonly 的类型夹具
### 事实
上一轮为了让 `tsc` 变绿,在两个测试里把直接赋值改成了 `Object.assign` 绕 readonly:
```ts
// frontend/tests/rectification-answer-choice.test.ts
Object.assign(refreshed, { latestResult: { ... } });
Object.assign(refreshed.conversationSummary, { activeFocus: { ... } });
```
行为没变,但 `Object.assign` 会把真实的类型不匹配一起吞掉,将来这里改坏了 `tsc` 也不会报。
### 做法
按真实类型修:让夹具**一次性构造出正确形状的对象**,而不是先解析再改字段。例如把 `parseV9CaseDossier(...)` 的结果解构后重建一个新对象,或给局部变量一个显式的可变结构类型。
- 禁止 `as any` / `@ts-expect-error` / `@ts-ignore`
- 禁止改任何断言
- 禁止为此修改 `src/**` 的类型定义(那是产品类型,不该为测试让路)
### 止损
如果不改断言、不动产品类型就做不到,**保留现状**,只在 `Object.assign` 上方加一行注释说明为什么(哪个字段是 readonly、为什么夹具需要改它),并在 `BLOCKED.md` 记一条。这条不值得为它冒回归风险。
---
## 任务 D(P1)· 等待动效有七套,同一个视觉被实现了三遍
### 事实
全仓(不含 admin,antd 是独立设计系统,不在范围)现有等待动效清单,均已实测:
| 视觉 | keyframes | 时长 / 曲线 | 出现位置 |
| --- | --- | --- | --- |
| 轨道环 | `app-loading-orbit` | 1.4s linear | `AppLoadingIndicator` → `page.tsx:3707` 载入账户、`page.tsx:4103` 正在准备问题、`birth-time-assessment-overlay` |
| 打字光标 | `onboarding-caret` | 700ms steps(1,end) | `globals.css:657` 引导语打字流 |
| 文字微光 | `agent-activity-shimmer` | 1.6s linear + `background-clip:text` | `globals.css:322` Agent 活动状态 |
| 圆圈旋转 ① | `birth-place-spin` | **0.8s** linear | `globals.css:369` ← `birth-place-picker.tsx:291` `<LoaderCircle className="is-spinning">` |
| 圆圈旋转 ② | `consultation-run-spin` | **0.8s** linear | `globals.css:999` ← `consultation-run-timeline.tsx:60` `<LoaderCircle>` |
| 圆圈旋转 ③ | Tailwind `animate-spin` | **1s** linear | `personal-report-page.tsx:209`、`personal-report-center.tsx:78/168/178`、`reports/[reportId]/loading.tsx:7` |
| 透明度呼吸 | `daily-starlanguage-pending` | 1.6s ease-in-out | `globals.css:1780` ← 今日星语卡 `aria-busy` |
**①②③ 是同一个视觉(旋转的 lucide `LoaderCircle`)、三套实现、两种时长。**
用户说的"初始化结束有三种加载动画"能在 `page.tsx` 同一段 render 里定位到,是连着出现的三种:
- `page.tsx:4028` `<OnboardingChatMessage streaming>` → 打字光标闪
- `page.tsx:4100-4103` `onboardingPending` → 轨道环"正在准备问题"
- `page.tsx:4123` 附近 `aria-busy={dailyStarlanguageBusy}` → 今日星语卡开始透明度呼吸
三个不同节奏(700ms / 1.4s / 1.6s)、三种不同形态,在几秒内依次闪过。这是用户投诉的直接来源。
另有死代码:`globals.css:395` 的 `@keyframes pulse` 全仓 0 引用。
### 做法
**目标不是"全部统一成一个"**,而是按"等待的语义"分层,最多留三类,同类必须同实现:
1. **整页 / 整块阻塞等待**(载入账户、正在准备问题、生时评估浮层)→ 继续用轨道环 `AppLoadingIndicator`。**保持现状不动**,这是品牌感的来源。
2. **行内 / 局部等待**(出生地、运行时间线、个人报告)→ **收敛成唯一一个 `<InlineSpinner>` 组件**:一套 keyframes、一个时长、一处尺寸约定。上表 ①②③ 全部改用它,删掉 `birth-place-spin` 和 `consultation-run-spin` 两套 keyframes,清掉所有 `animate-spin` 类名。
3. **流式生成中**(打字光标、文字微光)→ **保持**。它们表达的是"内容正在到达",语义与"在等待"不同,不要一并统一掉。
透明度呼吸(今日星语卡)归入第 2 类的语义但形态不同 —— 由你判断:要么并入 `InlineSpinner`,要么保留但必须说明它为什么不能是 spinner。
**初始化结束那一刻,不得让用户连续看到三种形态。** 轨道环消失后今日星语卡立刻开始呼吸,等于换了个动效继续等。要求二选一:让星语的首次拉取在轨道环期间就完成(轨道环消失时卡片已是终态),或卡片首次渲染直接给静态占位文案、不加动效。改完必须按帧说明用户实际看到几种。
### 约束
- 不得引入任何第三方动画库
- 不得修改 `AppLoadingIndicator` 的 DOM 结构(`birth-time-assessment-overlay` 依赖它)
- 所有等待容器现有的 `role="status"` / `aria-live="polite"` / `aria-busy` 一律保留,不得因为换组件丢掉
- **reduced-motion 要特别处理**:`globals.css:443` 有全局 `*` 规则 `animation-iteration-count: 1 !important`,旋转类动效在该模式下转一圈就停 —— 视觉上像卡死。新 `InlineSpinner` 在 `prefers-reduced-motion: reduce` 下必须退化成静态但语义明确的形态(静止圆点 + 文案),不要留一个停在半途的圆弧
- 顺手删 `globals.css:395` 的死 `@keyframes pulse`
- admin 的 antd `<Spin>` 不在范围,不要动
### 交付前必须写进 `frontend/DESIGN.md`
新增一节"等待与加载",把三类词汇表写死:每一类叫什么、用在什么语义、用哪个组件、时长多少、reduced-motion 下退化成什么。**这一步不能省** —— 不写进 DESIGN.md,下一个人还会再造第四套。
### 验收
```bash
# 行内旋转应只剩一处实现
grep -rn 'animate-spin' frontend/src/ # 期望 0 命中
grep -n 'birth-place-spin\|consultation-run-spin' frontend/src/app/globals.css # 期望 0
grep -c '@keyframes' frontend/src/app/globals.css # 应比现在的 13 少
```
外加:
- 改后动效清单表(每处等待 → 归哪一类 → keyframes → 时长),对照上面那张表
- 完整走一遍初始化:新账号 → 填姓名 → 填出生资料 → 初始化结束 → 落到首页。**按帧描述用户依次看到几种动效**,录屏更好。这是本条唯一真正的验收标准
- 出生地选择器、运行时间线、个人报告三处各自截图或描述,确认视觉一致
- 系统开启"减少动态效果"后再走一遍,确认没有停住的半圈
不建 `BUG_HISTORY`(这是设计收敛,不是缺陷),在 PROGRESS 里单列一节。
### 止损
收敛行内 spinner 若需改动超过 8 个文件,或需要触碰生时校正外壳 —— 只做"三个圆圈旋转合一 + DESIGN.md 词汇表",初始化流程的时序调整登记 `BLOCKED.md` 留下一轮。
---
## 不在本轮范围
- **`page.tsx:1209` 的 `visibleSessions`**(每次 render 重算 filter+filter+sort):没有基准证明它是热点,且红线禁止手写 `useMemo`。留到下一轮,届时先出基准。
- **深色主题**:产品决策,等人拍板,不得自行开工。
- **继续拆 `Home`**:上一轮只切了第一刀(`useState` 61→60),剩余切片单独立项。
- **打字光标与文字微光的形态本身**:任务 D 只收敛"等待"类,"内容正在到达"类不动。
- **`web/*.html`**:确认不删,Python API 仍在用。
---
## 收尾
- PROGRESS 文件名写 `PROGRESS-frontend-followup-20260829.md`。**不要写成 `PROGRESS.md`** —— 根目录已有受版本控制的 `progress.md`,大小写不敏感文件系统上会互相覆盖。
- 订正 `BLOCKED.md` 里"`error.tsx`/`not-found.tsx` 只能另开布局链"那条 —— 实际用内联样式即可,两全。
- 三条任务合成**一次** staging 推送(staging push 会触发全量构建+部署,没有路径过滤,不要分多次推)。
- 推送后核对 `https://staging.jyotisha.chat/api/health` 的 `.deployment.gitCommit` 等于新 SHA。
- 不自行提升 main。
## 交付物清单
1. `src/app/not-found.tsx`、`src/app/error.tsx` 改为内联样式,无 Tailwind 依赖
2. `_not-found.html` body 无工具类的构建产物证据
3. admin 路由 CSS chunk 清单证据(仍为 antd/admin + Inter 两个)
4. `site-style-isolation-contract.test.ts` **新增**断言(既有断言未改)
5. `onboarding-presentation.test.ts` 三时区全绿证据
6. 任务 C:修好,或保留 + 注释 + BLOCKED 记录
7. `InlineSpinner` 组件,①②③ 三处旋转全部改用它,`animate-spin` 与两套旧 keyframes 清零
8. `frontend/DESIGN.md` 新增"等待与加载"一节(三类词汇表 + reduced-motion 退化约定)
9. 初始化全流程按帧的动效说明(含 reduced-motion 一遍)
10. `docs/BUG_HISTORY.md` 新条目(任务 A,编号已对远端确认)
11. `BLOCKED.md` 订正(任务 A 那条判断有误)
12. `PROGRESS-frontend-followup-20260829.md`
13. `tsc --noEmit` / `eslint` / `tsx --test`(≥2205,fail=0,skipped=0)/ `next build` 四条命令的实际输出
@@ -0,0 +1,249 @@
# 任务书 · 客户端交互与 UI 收尾(2026-08-30)
基线:`origin/staging` @ `ea0fbd44`。
本轮四条任务全部来自一次对着代码实测的审计,每条都附了实测数据。**先读完「硬红线」再动手。**
---
## 硬红线
1. **不得改变任何元素的视觉尺寸。** 任务 1 是扩大热区,不是把按钮画大。改完截图对比,图标和留白必须和改前一模一样。
2. **不得手写 `useCallback` / `useMemo`。**
3. **不得修改既有测试断言** —— 除非该断言锁住的正是本轮要修的缺陷本身;那种情况下必须在断言上方写注释说明「原值是什么、为什么它是错的」,并在 PROGRESS 里单列。
4. 推 staging 前必须 `./node_modules/.bin/tsc --noEmit` 通过。**不要用 `npx tsc`**,本仓库环境下会装到空包 `tsc@2.0.4`。
5. 测试数不得低于基线,且 `fail=0`、`skipped=0`(在有 Docker 的环境里跑)。本机没有 Docker 时会有 23 条数据库/部署类失败 + 10 条 skipped,那是既有环境缺口,不是你引入的 —— 但**必须逐条比对失败清单,确认没有新增**。
6. **浅色和深色两套都要验。** 本仓库已有深色主题(`prefers-color-scheme` + `data-theme`),任何配色改动必须同时在两套下检查对比度。
7. 不得改 `.gitea/workflows/**`。不得在有未提交改动的工作树上切分支。不得自行把 staging 提升到 main。
让步顺序:功能与测试不回归 > 可验证的修复 > 视觉一致 > 代码整洁。
## 开工前置
```bash
git fetch origin --prune
git worktree add -b codex/interaction-20260830 \
../.worktrees/interaction-20260830 origin/staging
```
基线必须是 `origin/staging`,不是任何本地 ref。读 `pre_work_error_ledger.md`,跑 `scripts/pre_work_check.py`,读 `frontend/AGENTS.md`(Next.js 版本与训练数据不同,写代码前先看 `node_modules/next/dist/docs/`)。改前先在 `docs/BUG_HISTORY.md` 检索同类记录。
**下面所有行号只是线索,请按选择器定位**,`origin/staging` 上的行号可能有偏移。
---
## 任务 0(P0)· 深色下两处对比度不达标
### 事实
深色调色板的字色逐个对底色实测,两组低于 WCAG AA 4.5:1:
| 组合 | 实测 |
| --- | ---: |
| `--color-ink-tertiary` `#928e84` on `--color-canvas-muted` `#30302d` | **4.05:1** ✗ |
| `--color-action` `#d4785a` on `--color-canvas-muted` `#30302d` | **4.18:1** ✗ |
`frontend/tests/dark-theme-contract.test.ts` 现有的对比度断言**只验了「字色 vs `--color-canvas`」**,漏掉了卡片底 `--color-canvas-muted`,所以这两组没被拦住。代码块的语言标签(`.markdown-code-language`)正是 `ink-tertiary` 落在 `.markdown-code` 的暖卡片底上,是已在线上的实例。
### 做法
两个深色块(`@media (prefers-color-scheme: dark)` 内的 `:root:not([data-theme="light"])`,以及 `:root[data-theme="dark"]`)**各改一处**,共两处:
```
--color-ink-tertiary: #928e84 → #9c988e
--color-action: #d4785a → #d78064
```
`#d78064` 与原值**色相 15°、饱和度均不变**,只提亮 2.5% 明度 —— 观感仍是同一个黏土橙,不要顺手换色相。
`#d4785a` 在仓库里共 **15 处**,四个根边界页(`error.tsx` / `not-found.tsx` / `forbidden.tsx` / `global-error.tsx`,它们各自内联了一份深色 token)和 `DESIGN.md` 的深色对照表里都有,**必须一起换**,否则边界页的行动色会和主站不一致:
```bash
grep -rn '#d4785a' frontend/src frontend/DESIGN.md
```
`--color-focus` 在深色块里跟随 `--color-action`,一并确认。
### 测试
把 `dark-theme-contract.test.ts` 里那条对比度断言从「1 种底色」扩成 **8 种字色 × 4 种底色**:
- 字色:`color-ink`、`color-ink-strong`、`color-ink-secondary`、`color-ink-tertiary`、`color-action`、`color-danger`、`color-success`、`color-warning`
- 底色:`color-canvas`、`color-canvas-soft`、`color-canvas-muted`、`color-sidebar-solid`
全部 32 组必须 ≥ 4.5:1,失败信息里要打印出具体是哪一对、实际多少。**不要放宽阈值来让测试通过。**
### 验收
```bash
./node_modules/.bin/tsx --test tests/dark-theme-contract.test.ts
grep -rc '#d4785a' frontend/src frontend/DESIGN.md # 期望全 0
```
反向验证:把 `--color-ink-tertiary` 改回 `#928e84`,测试必须变红。
### 建档
`docs/BUG_HISTORY.md` 新增一条(用户可见的可读性缺陷)。**编号前先确认远端最大号**,别抢号:
```bash
git fetch origin --prune && git show origin/staging:docs/BUG_HISTORY.md \
| grep -o '^## BUG-[0-9]*' | sort -t- -k2 -n | tail -3
```
防复发条写清楚:新增字色/底色 token 时必须同时进这张 32 组矩阵,不得只验阅读面。
---
## 任务 1(P0)· 触达尺寸普遍低于文档承诺的 44px
### 事实
`frontend/DESIGN.md:165` 写着 *"Touch targets are at least 44px"*。实测违反:
| 选择器 | 实际 | 位置 |
| --- | ---: | --- |
| **`.message-actions button`**(globals.css:1253 附近) | **26×26px,`padding: 0`** | 每条回答下方的赞/踩/复制/重新生成 |
| `.chart-nav-chip`(:732) | 32px | 侧栏星盘 chip |
| `.auth-links button`(:1657) | 32px,`padding: 0` | 登录页链接按钮 |
| `.select-item`(:2507) | 40px | 模型选择器每一项 |
| `.birth-time-window-details .birth-time-skip-button`(:2450) | 40px | |
| `.report-center-section-heading button` | 40px | |
**26px 那条优先级最高** —— 它是全产品点得最勤的控件,出现在每一条回答下方,且完全没有 padding 撑开热区。
### 做法
**扩大热区,不改视觉尺寸。** 用透明的伪元素把可点区域撑到 44px:
```css
.message-actions button { position: relative; }
.message-actions button::after {
position: absolute;
content: "";
inset: 50% 50% 50% 50%;
translate: -50% -50%;
width: 44px;
height: 44px;
}
```
(上面是示意,具体写法自己定,但必须满足:视觉尺寸不变、热区 ≥44px、不影响相邻元素布局、不遮挡兄弟元素的点击。)
对 40px 那几个,直接把 `min-height` 提到 44px 更简单 —— **但前提是不撑破所在容器**。`.select-item` 在下拉里有 `max-height` 限制,改高之后一屏能显示的条目变少,需要目视确认下拉不会变得难用;如果变差,改用伪元素方案。
`.chart-nav-chip` 是 inline-flex 的胶囊,直接提高会改变视觉;用伪元素。
### 止损
- 如果某一处用伪元素会造成热区互相重叠(相邻按钮间距小于 44px 时必然发生),**不要硬撑到 44px**:把该处的实际间距和重叠范围写进 `BLOCKED.md`,只做到不重叠的最大值,并说明还差多少。宁可 36px 不重叠,也不要 44px 互相吃点击。
- `.message-actions` 一行有 4 个按钮,请先量一下它们的间距再决定。
### 验收
- 改前改后各截一张图(浅色 + 深色),确认视觉零差异
- 用浏览器 devtools 量出每个按钮的实际命中矩形,列表给出
- 相邻按钮热区不得重叠 —— 给出实测间距
- 新增合同测试:断言这些选择器要么 `min-height ≥ 44px`,要么带扩大热区的伪元素规则
### 建档
同任务 0,另建一条 BUG_HISTORY。防复发:新增可点元素必须满足 44px 命中区,视觉尺寸小于 44px 时用伪元素补。
---
## 任务 2(P1)· 字数上限是静默的
### 事实
| 位置 | 上限 | 反馈 |
| --- | ---: | --- |
| 主对话输入框(`page.tsx` 传给 `chat-composer.tsx`) | 500 | **无** |
| `birth-time-guide-turn.tsx:34` | 500 | **无** |
| `birth-time-choice-question.tsx:113` | 240 | **无** |
| 姓名输入(`page.tsx:909`) | 80 | **无** |
只有 `maxLength` 属性。到顶之后继续打字,浏览器直接不接收,界面**毫无反应** —— 这是最难自我诊断的一类问题,用户只会觉得"键盘坏了"。
### 做法
给这几处加接近上限时才出现的计数提示:
- **平时不显示**,剩余字数低于某个阈值(建议 50,短输入按比例调)才出现,避免常态噪声
- 用 `--color-ink-tertiary`;到达上限时才转 `--color-danger`
- 计数区必须 `aria-live="polite"` 且 `aria-atomic="true"`,但**只在阈值内挂载**,不要让读屏用户每敲一个字都被播报
- 输入框加 `aria-describedby` 指向计数区
主输入框的计数放哪需要判断:`.composer-footer` 已经存在,优先复用,不要新造一层容器把输入框顶高。
### 止损
如果加计数会让移动端输入区高度变化导致布局跳动,**先只做主对话输入框**,其余三处登记 `BLOCKED.md`。布局跳动比没有计数更糟。
### 验收
- 四处(或已做的那几处)各录一段:从阈值外打到上限,说明何时出现、何时变红
- 读屏验证:阈值外不播报,进入阈值后播报一次,不是每字一次
- 移动端确认输入区高度不跳
---
## 任务 3(P1)· 三个输入框的发送键不一致,且无任何提示
### 事实
| 位置 | 发送方式 |
| --- | --- |
| 主对话输入框(`page.tsx:3701`) | **Enter**(Shift+Enter 换行),已正确处理 `isComposing` |
| 生时校正对话(`rectification-agentic-chat.tsx:1233`) | **Enter**,已处理 `isComposing` |
| `birth-time-guide-turn.tsx:39` | **⌘/Ctrl+Enter** |
第三处不但与前两处相反,界面上**没有一个字**告诉用户。它有可见的「整理为经历草稿」按钮所以不会卡死,但用户在主对话养成的 Enter 习惯到这里只会换行。
### 做法
**统一为 Enter 发送、Shift+Enter 换行**,与前两处一致。改 `birth-time-guide-turn.tsx`:
- 必须同时加 `!event.nativeEvent.isComposing` 判断 —— 这是中文输入法的必要条件,前两处都有,第三处因为原本需要修饰键所以没加。**漏了这条会导致中文用户选词时误发送**,比现状严重得多。
- 保留「整理为经历草稿」按钮不动。
那是一个 `rows={3}` 的多行框,改成 Enter 发送后换行只能靠 Shift+Enter。如果你判断这个框的使用场景更需要自由换行(用户在描述一段经历),**可以反过来选择保留 ⌘+Enter 但补上可见提示**(放在既有的 `#birth-time-guide-hint` 里)。两种都可接受,但必须二选一并在 PROGRESS 里写明理由 —— 不允许维持"既不一致又无提示"的现状。
### 验收
- 中文输入法下逐字验证:输入拼音 → 按 Enter 选词 → **不得发送**;选完词再按 Enter → 发送
- 三个输入框的行为写成一张对照表放进 PROGRESS
- 新增合同测试:三处的 `onKeyDown` 必须都带 `isComposing` 判断
---
## 不在本轮范围
- **会话列表虚拟化 / `page.tsx:1212` 的 `visibleSessions` 每次 render 重排**:与已修好的消息列表同类,但会话数通常只有几十。**没有渲染基准之前不得动手** —— 需要先按 `frontend/scripts/home-streaming-render-benchmark.mts` 的模式出一份会话列表基准,证明它是热点。红线也禁止手写 `useMemo`。
- **代码块语法高亮**:产品已明确不做。
- **会话搜索、编辑自己发出的消息**:不在本轮。
- **15 个无 CSS 规则的死类名**:见 `frontend/tests/class-name-definition-contract.test.ts` 的 `knownUnstyled` 白名单,都是有意的空修饰符,不要顺手清理。
---
## 收尾
- PROGRESS 文件名写 `PROGRESS-frontend-interaction-20260830.md`。**不要写成 `PROGRESS.md`** —— 根目录已有受版本控制的 `progress.md`,大小写不敏感文件系统上会互相覆盖。
- 四条任务合成**一次** staging 推送(staging push 触发全量构建+部署,没有路径过滤,不要分多次推)。
- 推送后核对 `https://staging.jyotisha.chat/api/health` 的 `.deployment.gitCommit` 等于新 SHA。**流水线是 `validate` → `publish` → 才派发 `deploy`,全链路约 20 分钟**,不要在十几分钟内就断定部署失败。
- 不自行提升 main。
## 交付物清单
1. 两个深色块各改两处色值,`#d4785a` 全仓 15 处清零
2. `dark-theme-contract.test.ts` 扩成 32 组对比度断言 + 反向验证证据
3. 触达尺寸改动,附改前改后截图(浅色+深色)证明视觉零差异
4. 每个可点元素的实测命中矩形与相邻间距
5. 字数计数提示,附阈值行为录制与读屏播报验证
6. 发送键统一(或补提示)+ 中文输入法选词不误发的逐字验证
7. 三个输入框行为对照表
8. 新增合同测试(触达尺寸、`isComposing`)
9. `docs/BUG_HISTORY.md` 两条新条目(编号已对远端确认)
10. `BLOCKED.md`:任何触发止损的项
11. `PROGRESS-frontend-interaction-20260830.md`
12. `tsc --noEmit` / `eslint`(0 error)/ `tsx --test`(失败清单与基线逐条比对)/ `next build` 四条命令的实际输出
@@ -0,0 +1,241 @@
# 任务书 · 个人报告改为分章节生成(2026-08-30)
基线:`origin/staging` @ `a96df754`。
## 为什么要做
现状:`createPersonalReportAgent` 用**一次**模型调用产出整份叙述(`executiveSummary` + 最多 12 个 `thematicNarrative`),结构化输出 + Zod 校验,失败只允许**一次**修复重试。
两个问题:
1. **没有设输出上限。** 仓库里有现成的 `agentGenerationSettings`(答复预算 16,384 token),`agent-run.ts` 和 `consultation-tools.ts` 都在用,**只有 `src/mastra/personal-report.ts` 没用** —— 它走模型提供方的默认值。而 schema 允许的最坏输出约 224,000 字符(12 章 × 每章上限)。
2. **失败是全有或全无。** 任何一章写坏或被截断 → JSON 不完整 → schema 不过 → 重试一次 → 整份报告 `failed`。用户看到的是"生成失败",不是"少了两个主题"。
**产品已确认:一份缺若干主题、缺失部分明确标注的报告,算合格交付。** 这是本轮降级方案成立的前提。
## 这不是"上下文丢失"问题
`createPersonalReportAgent` 是结构性无状态的 —— 注释原文:*"chat history and skill text are structurally excluded by the agent definition (no skills, no tools, no memory)"*。prompt 是 `(bundle, plan)` 的纯函数,**现在就没有跨调用的对话上下文可丢**。拆开后每次仍拿到完整证据。
真正需要跨章节的只有三件,均在本任务书内解决:摘要要概括全部主题(最后生成)、章节间不重复(传已写标题列表)、断言口径一致(服务端 `claimCards` + `evidenceRefs` 绑定,本就每次相同)。
---
## 硬红线
1. **任务 0 是门控。** 观测必须先上线并收到真实数据,才允许调整输出上限或收紧 schema。**不得凭任务书里的估算直接改参数** —— 那个 224,000 是 schema 上限推算,不是实测。
2. **章节生成先串行,不得并发。** 章节之间无依赖,理论上可并发,但会放大限流风险。先串行拿数据。
3. **`report_document` 的语义不得改变**:它只存最终成品。中间结果一律不写进去,避免半成品被当成完整报告读出。
4. **schema 只可收紧,不可放宽。** 不得为了让截断的输出通过而放松校验。
5. **任务生命周期在 Postgres 函数里**(`claim_personal_report_job` / `heartbeat_personal_report_job` / `complete_personal_report_job` / `fail_personal_report_job`,见 `supabase/migrations/20260814040000_personal_report_jobs_v2.sql`)。章节级状态**必须沿用同一模式加 SQL 函数**,不得把状态机搬进应用层。
6. **不得修改既有测试断言** —— 除非该断言锁的正是本轮要改的缺陷本身;那种情况必须在断言上方注明原值与原因,并在 PROGRESS 单列。
7. 推 staging 前必须 `./node_modules/.bin/tsc --noEmit` 通过。**不要用 `npx tsc`**,本仓库环境下会装到空包 `tsc@2.0.4`。
8. **数据库测试必须真跑。** 本轮动了表结构,`npm run test:db` 需要 Docker。**没有 Docker 就不要推** —— 把环境缺口写进 `BLOCKED.md` 并停下,不允许"本地跑不了所以跳过"。
9. 不得改 `.gitea/workflows/**`。不得在有未提交改动的工作树上切分支。不得自行把 staging 提升到 main。
让步顺序:数据不损坏 > 功能与测试不回归 > 可验证的改进 > 成本 > 代码整洁。
## 开工前置
```bash
git fetch origin --prune
git worktree add -b codex/report-sectioned-20260830 \
../.worktrees/report-sectioned-20260830 origin/staging
```
基线必须是 `origin/staging`。读 `pre_work_error_ledger.md`,跑 `scripts/pre_work_check.py`,读 `frontend/AGENTS.md`。改前在 `docs/BUG_HISTORY.md` 检索同类记录。
**先读这几个文件再动手**,本任务书的判断都基于它们:
- `src/mastra/personal-report.ts` —— agent、prompt、schema、重试
- `src/lib/personal-report-plan.ts` —— `ReportSectionPlanEntry`,注意它**已经有** `disposition`、`evidenceRefs`、`targetCharacters`
- `src/lib/personal-report-contract.ts` —— `claimStatus` 含 `blocked`
- `supabase/migrations/20260814040000_personal_report_jobs_v2.sql` —— 任务表与四个 SQL 函数
- `src/components/personal-report/personal-report-page.tsx` —— 9 个状态与轮询
---
## 任务 0(P0,门控)· 先把截断变成可观测的
### 事实
`src/mastra/personal-report.ts` 的 `logTelemetry` 只记 `resolved` / `failed`,不记 `finishReason` 也不记 token 用量。**现在无法从数据上区分"模型不听话"和"输出被截断"**,也就无法证明后续改动有效。
### 做法
- `logTelemetry` 增加 `finishReason`(`length` 即截断)与 `usage.outputTokens` / `usage.inputTokens`
- 两次尝试(首次与修复重试)各记一条,能区分是哪一次
- 遵守 `AGENTS.md` 的隐私红线:**只记指标名、阶段、数值**,不得记 prompt、bundle、模型原文、用户资料、案例 ID
### 验收
- 人为构造一次会被截断的生成(例如临时把输出上限调到极小),确认日志出现 `finishReason: "length"`
- 上线后至少收集一段真实数据,在 PROGRESS 里给出:失败总数、其中 `length` 占比、`outputTokens` 的 p50/p95
**这一条必须先单独上线并收到数据**,任务 2 的输出上限取值要用这批数据决定,不许拍脑袋。
---
## 任务 1(P0)· 章节中间结果落库
### 做法
新建 `public.personal_report_sections`,**不要**往 `report_document` 里增量写。
字段至少包含:`user_id`、`request_id`、`section_id`、`payload jsonb`(单个 thematicNarrative 条目)、`status`(`pending` / `ready` / `blocked`)、`attempt_count`、`max_attempts`、`last_error_code`、`created_at`、`updated_at`。主键或唯一约束用 `(user_id, request_id, section_id)`。
选这个方案而不是复用 `report_document` 的三个理由,实现时请守住:
1. `report_document` 保持"最终成品"语义
2. **每个章节有自己的重试预算** —— 一个难写的主题不得烧光整个任务的 `max_attempts`
3. 续做只需查"哪些 section 还没有 payload"
### 迁移要求
照 `20260814040000_personal_report_jobs_v2.sql` 的既有写法:
- 整个迁移包在 `begin; ... commit;` 里
- 所有 DDL 用 `if not exists`,可重复执行
- **必须 `enable row level security`**,并给 `authenticated` 只读自己的行的 policy
- 显式 `grant`:`authenticated` 只 `select`;`service_role` 才有写权限
- 章节状态流转写成 SQL 函数(与 `claim/heartbeat/complete/fail_personal_report_job` 同一模式),`security definer` 并显式 `grant execute` 给 `service_role`
- 文件名沿用 `YYYYMMDDHHMMSS_描述.sql` 格式,时间戳要晚于 `20260830010000`
### 验收
```bash
npm run db:migrate:check # 幂等性
npm run test:db # 需要 Docker
```
新增数据库测试,至少覆盖:`authenticated` 读不到别人的章节;`authenticated` 写不进去;`service_role` 能写;同一 `(user_id, request_id, section_id)` 重复插入不产生第二行。
### 止损
如果执行环境没有 Docker,**停在这里**,把缺口写进 `BLOCKED.md`,不要带着未验证的迁移继续做任务 2。
---
## 任务 2(P0)· 把一次生成切成 plan → 章节 → 摘要 → 装配
### 阶段模型
沿用**已存在但基本没用起来**的 `personal_report_jobs.progress_phase`:
```
plan → section:<id> × N → summary → assemble → ready
↑确定性 ↑每章节一次调用 ↑最后一次 ↑确定性
```
### 每个章节一次调用
输入:
- **按该章节 `evidenceRefs` 过滤后的 bundle 子集** —— `ReportSectionPlanEntry.evidenceRefs` 已经有这个字段。**这条是成本关键**:不过滤就是把完整证据包重发 N 次。过滤后既省钱也让模型更聚焦。
- plan 只保留这一个 section
- **已完成章节的标题列表**(只要标题,不要正文)——用于避免重复
- 显式输出上限,用 `agentGenerationSettings`;具体数值由任务 0 的数据决定,并参考该 section 的 `targetCharacters.max`
输出 schema 收成**单个 thematicNarrative 条目**,不再是 12 条数组。
### 摘要最后生成
输入是各已完成章节的**标题 + `claimStatus`**,不是正文全文。这样既概括到全部主题,又不会把 prompt 撑大。
### 装配
确定性合并成 `report_document`,此时才写 `report_document` 并把 `personal_reports.status` 置 `ready`。
### 续做
worker 拿到租约后,按 `progress_phase` 与 `personal_report_sections` 的已有行判断从哪继续,**已完成章节不得重算**。
### 验收
- 单元测试:给定 N 个 write 章节,验证发生 N+1 次调用,且第 k 次的 bundle 只含该章节 `evidenceRefs` 引用到的证据
- 续做测试:模拟在第 3 章后中断,重新领取任务,验证前 3 章不重算、最终文档完整
- 端到端至少跑一份真实报告,PROGRESS 给出:章节数、每章 `outputTokens`、总墙钟时间,与改前单次调用对照
### 止损
- 如果过滤 bundle 导致某类章节缺证据写不出来,**不要退回发全量**:先确认是 plan 的 `evidenceRefs` 不全还是过滤逻辑错了。真是 plan 不全就修 plan,并在 PROGRESS 说明。
- 如果总墙钟时间超过现有 8 分钟轮询预算(`POLL_BUDGET_MS`),**不要顺手调大预算**,先把数据摆出来再决定。
---
## 任务 3(P1)· 章节写不出时降级为 blocked,报告照常交付
### 前提
**产品已确认:缺若干主题、缺失部分明确标注的报告算合格交付。**
`blocked` 已经是一等 `claimStatus`(`personal-report-contract.ts`),文档视图已有「阻塞」标签与渲染路径 —— 复用它,不要新造状态。
### 做法
- 单个章节耗尽自己的 `attempt_count` 后,标记该行 `status = 'blocked'`,记 `last_error_code`,**继续下一章**
- 装配时把 blocked 章节渲染成明确的"本节未能生成",并说明原因类别(截断 / 校验失败 / 证据不足),**不得静默省略**
- 只有当**全部** write 章节都 blocked、或摘要本身失败时,整份报告才 `failed`
### 明确不要做
- 不得因为有 blocked 章节就退积分或改计费 —— 产品已定这算合格交付
- 不得把 blocked 章节伪装成正常内容
- 不得为了凑数让模型"随便写点什么"
### 验收
- 强制某一章连续失败,验证:该章标 blocked、其余章正常、报告 `ready`、页面上该节有明确标注
- 强制全部章节失败,验证报告 `failed` 且失败原因可读
---
## 任务 4(P2)· 等待页显示真进度
### 事实
`personal_report_jobs.progress_percent`(0–100)和 `progress_phase` 都已存在,目前基本没被用起来。等待页只有一个转圈加"已等待 N 分",8 分钟里没有任何进展信号。
### 做法
- 每完成一个章节更新 `progress_percent`(已完成 / 总 write 章节数)与 `progress_phase`
- 等待页显示"正在生成第 3/7 个主题"一类的文案
- 保留既有的 `timed-out` / 「继续等待」/ 「返回报告中心」路径,**不要动那 9 个状态的结构**
### 验收
生成一份多主题报告,录一段等待过程,说明进度是如何推进的。
---
## 不在本轮范围
- **章节并发生成**:红线 2 已禁止。等串行数据出来再单独立项。
- **提示缓存**:先做 `evidenceRefs` 过滤,量完成本再谈。
- **收紧 `thematicNarrative` 的 `max(12)`**:等任务 0 的数据。
- **换模型或改模型选择逻辑**:不在本轮。
- 前端 UI 的其它优化:见 `TASK-frontend-interaction-20260830.md`,两份任务书互不冲突。
## 收尾
- PROGRESS 文件名写 `PROGRESS-report-sectioned-20260830.md`。**不要写成 `PROGRESS.md`** —— 根目录已有受版本控制的 `progress.md`,大小写不敏感文件系统上会互相覆盖。
- **任务 0 单独一次推送并收数据**;任务 1–4 可合成第二次推送。staging push 触发全量构建+部署,没有路径过滤。
- 数据库迁移走既有流程(`.gitea/workflows/migrate-staging-database.yml`),**不要手工连库改表**。
- 推送后核对 `https://staging.jyotisha.chat/api/health` 的 `.deployment.gitCommit`。流水线是 `validate` → `publish` → 才派发 `deploy`,**全链路约 20 分钟**,不要十几分钟就断定失败。
- 不自行提升 main。
## 交付物清单
1. `logTelemetry` 记 `finishReason` 与 token 用量,且不含任何隐私字段
2. 任务 0 上线后的真实数据:失败总数、`length` 占比、`outputTokens` p50/p95
3. `personal_report_sections` 迁移(事务内、幂等、RLS、显式 grant、SQL 状态函数)
4. 数据库测试:越权读、越权写、service_role 可写、重复插入幂等
5. 分章节生成实现:N+1 次调用、按 `evidenceRefs` 过滤 bundle、摘要最后生成
6. 续做测试:中断后不重算已完成章节
7. blocked 降级:单章失败报告仍 `ready` 且有明确标注;全部失败才 `failed`
8. `progress_percent` / `progress_phase` 真实推进 + 等待页文案
9. 改前改后对照:章节数、每章 `outputTokens`、总墙钟时间
10. `docs/BUG_HISTORY.md` 条目(编号先对远端确认)
11. `BLOCKED.md`:任何触发止损的项,尤其是 Docker 缺口
12. `PROGRESS-report-sectioned-20260830.md`
13. `tsc --noEmit` / `eslint`(0 error)/ `tsx --test`(失败清单与基线逐条比对)/ `npm run test:db` / `next build` 的实际输出