v0.20 alpha skill-driven python core

This commit is contained in:
kai
2026-05-06 16:26:41 +08:00
parent d1169646b8
commit db626f1d58
87 changed files with 5213 additions and 2865 deletions
+58
View File
@@ -0,0 +1,58 @@
---
name: deep-research
description: Use when a user wants to run Deep Research, create a client-ready research report, analyze supplied audit/material files, compare evidence against regulations or best practices, or continue a phase-based research project.
---
# Deep Research
## Principle
Deep Research is driven by the repository Python core, not by chat context. Treat Codex, OpenCode, Claude Code, Antigravity, and Gemini CLI as surface interfaces that call `scripts/dr.py`; all durable state must be written under `projects/<slug>/`.
## Required Flow
1. Work from the repository root.
2. Validate the skill/runtime registry before a serious run:
`uv run python scripts/dr.py skills validate`
3. For user-supplied materials, stop after Phase 0/1 material brief and interview:
`uv run python scripts/dr.py init "<topic>" --slug <slug> --method <method> --input-material <path>`
Review `phase1/material_brief.md` with the user before generating or approving the framework.
4. If model calls will be used, probe the selected profile first:
`uv run python scripts/dr.py models --profile medium --probe`
5. Run Phase 1 and pause for framework review:
`uv run python scripts/dr.py frame <slug> --method <method>`
After user approval: `uv run python scripts/dr.py approve <slug>`
6. Run Phase 2 with file-backed task cards and packets:
`uv run python scripts/dr.py research <slug> --workers 6 --execute-packets --allow-search-fallback`
7. Build briefs and chapters only from persisted packets:
`uv run python scripts/dr.py research <slug> --build-briefs`
`uv run python scripts/dr.py research <slug> --assemble-chapters --workers 4`
8. Review and finalize through Python:
`uv run python scripts/dr.py review <slug>`
`uv run python scripts/dr.py finalize <slug> --report-engine reportlab`
## Research Rules
- Chinese is the formal thinking and writing language by default; English is allowed for search keywords, source titles, abstracts, and raw excerpts.
- Do not invent evidence when model/API access fails. Stop at the last durable artifact and report the exact blocker.
- Phase 2 concurrency must use task cards and packet files, not platform subagents as the default mechanism.
- Search must use the project Python gateway (`scripts/search.py` / `scripts.lib.search_client`) by default. Do not use Tavily MCP, browser MCP, or platform-native web search in subagents unless the user explicitly requests that escape hatch.
- User materials are starting evidence, not final truth. Cross-check against authoritative sources such as NMPA, FDA, EMA, ICH, WHO, pharmacopeias, and recognized best-practice references.
- For GMP/quality/operations diagnosis, prefer `--method gmp_quality_operations_diagnosis`.
- Chapter drafts are not acceptable if they merely summarize principles. Each section must turn evidence into concrete findings, risk implications, and整改动作;otherwise return to Phase 2 enrichment.
## Useful Commands
- Status: `uv run python scripts/dr.py status <slug>`
- List methods: `uv run python scripts/dr.py methods list`
- Show method: `uv run python scripts/dr.py methods show <method>`
- Dry-run task cards: `uv run python scripts/dr.py research <slug> --dry-run`
- Sync adapter skills: `uv run python scripts/dr.py skills sync`
## Common Failures
- If Codex cannot write `~/.codex`, run `uv run python scripts/deploy_adapters.py codex --force` outside sandboxed mode.
- The Codex deploy script does not copy `config.toml` by default; use `--include-config` only when the user explicitly wants the bundled Codex profile.
- If `models --probe` returns subscription/model errors, do not launch packet workers; switch profile/key/provider first.
- If a PDF has little embedded text, Phase 0 should call FireRed OCR. Default endpoint: `http://192.168.50.100:8001`.
- If a subagent asks for MCP/web permissions during research, stop it and reroute the task through `search-gateway`.
+34
View File
@@ -0,0 +1,34 @@
---
name: document-ingest
description: Use when Deep Research starts from user-provided PDFs, scanned audit reports, DOCX/PPTX files, images, or internal notes that must become phase0 persisted inputs.
---
# Document Ingest
## Core Rule
User-provided materials are evidence leads, not final evidence. Always persist the original file, extracted text, OCR status, and limitations under `phase0/` before Phase 1 framing depends on them.
## Required Artifacts
- `phase0/inputs/<original-file>` stores the source file copy.
- `phase0/extracted/<stem>.md` stores direct text extraction plus OCR text when available.
- `phase0/extracted/<stem>.ocr.md` stores OCR-only output for scanned PDFs.
- `manifest.json.material_inventory[]` records `copied_to`, `extracted_to`, `ocr_required`, `ocr_status`, and OCR errors if any.
## PDF Handling
- Text PDFs should use direct extraction first.
- If direct extraction is too sparse, run FireRed OCR through the configured LAN endpoint.
- Default endpoint: `http://192.168.50.100:8001`.
- Override endpoint with `DEEP_RESEARCH_OCR_ENDPOINT`.
- Limit page count with `DEEP_RESEARCH_OCR_MAX_PAGES` when testing or when documents are very long.
## Current Boundary
PDF text extraction and scanned-PDF OCR are supported. DOCX, PPTX, image-only batches, table reconstruction, and layout-aware evidence mapping should remain explicit next-step work unless implemented in Python core.
## Quality Notes
- OCR text may contain spacing or line-break errors. Treat it as internal material evidence and verify formal findings against NMPA, FDA, EMA, ICH, WHO, or other authoritative sources.
- If OCR fails, do not block project initialization. Record the failure and continue Phase 1 with a clear limitation.
+53
View File
@@ -0,0 +1,53 @@
---
name: search-gateway
description: Use when Deep Research agents or subagents need web, scholar, patent, news, regulatory, or source-discovery search without using platform MCP tools or browser search directly.
---
# Search Gateway
## Rule
Use the project Python search gateway as the only default search interface. Do not call Tavily MCP, browser MCP, generic web tools, or platform-native search from a subagent unless the user explicitly asks for that escape hatch.
## Commands
Run searches from the repository root:
```bash
uv run python scripts/search.py "<query>" --route general --json --trace
uv run python scripts/search.py "<query>" --route scholar --year-low 2020 --json --trace
uv run python scripts/search.py "<query>" --route news --time-range y --json --trace
uv run python scripts/search.py "<query>" --route patents --json --trace
uv run python scripts/search.py "<query>" --profile biomed_literature --json --trace
```
If `uv` cannot use the user cache in a sandbox, set a local cache:
```bash
UV_CACHE_DIR=/private/tmp/deep_research_uv_cache uv run python scripts/search.py "<query>" --route general --json --trace
```
## Routing
- `general`: Exa first, Tavily fallback.
- `scholar`: Serper Scholar first; use for papers, guidelines, and technical literature.
- `news`: Serper News first; use for recent industry/current information.
- `patents`: Serper Google Patents first.
- `biomed_literature`: scholar plus general discovery.
API keys are loaded from `secrets.env` by `scripts/search.py`; do not ask the user to authorize MCP calls when the env keys are available.
## Subagent Protocol
For evidence packets:
1. Search through `scripts/search.py`, save or summarize the returned JSON in the packets `raw_quotes_or_notes`.
2. Use search hits only as candidate sources; whenever possible, cite the original regulator, guideline, paper, or official document.
3. Put every used source in `sources` with `id`, `title`, `url`, `tier`, and `score`.
4. Do not write a final chapter during search; produce structured evidence only.
For chapter assembly:
1. Do not search. Use only `phase2/chapter_briefs`, `phase2/packets`, `phase2/sources.jsonl`, `phase0/extracted`, and `phase1/framework.md`.
2. Do not create new `source_id`.
3. If evidence is thin, mark the chapter as needing Phase 2 enrichment instead of filling with generic prose.