Metadata-Version: 2.5
Name: horosa-skill
Version: 0.53.1
Summary: GitHub-first Horosa AI skill distribution with CLI, MCP, and local structured memory.
License-Expression: AGPL-3.0-only
License-File: LICENSE
Requires-Python: >=3.12
Requires-Dist: cryptography>=45.0.0
Requires-Dist: httpx>=0.28.0
Requires-Dist: markdown-it-py<5,>=3.0.0
Requires-Dist: mcp[cli]<3,>=2.3.0
Requires-Dist: pydantic>=2.12.0
Requires-Dist: python-docx>=1.1.2
Requires-Dist: reportlab>=4.4.3
Requires-Dist: svglib<3,>=2.4.0
Requires-Dist: tomlkit>=0.12.0
Requires-Dist: typer>=0.27.3
Requires-Dist: tzdata>=2025.2
Provides-Extra: dev
Requires-Dist: numpy>=1.26; extra == 'dev'
Requires-Dist: pytest>=8.3.0; extra == 'dev'
Requires-Dist: ruff==0.16.7; extra == 'dev'
Provides-Extra: vectors
Requires-Dist: numpy>=1.26; extra == 'vectors'
Requires-Dist: onnxruntime>=1.24.2; extra == 'vectors'
Requires-Dist: tokenizers>=0.20; extra == 'vectors'
Description-Content-Type: text/markdown

# Horosa Skill Core

`horosa-skill` 是这个仓库真正可运行的核心子项目。它把星阙 / Horosa 的本地算法、AI 导出协议、离线 runtime、MCP 暴露层和本地数据管理统一进一个 Python 包里。

如果根目录 README 讲的是“这个项目是什么”，这里讲的是“这个包具体能做什么”。

## License / 许可证

这个子项目现在采用 `GNU AGPL-3.0-only` 许可证发布。完整文本见 [LICENSE](LICENSE)。

This subproject is distributed under `GNU AGPL-3.0-only`. See [LICENSE](LICENSE) for the full text.

## 新增工程能力

- ken 后端统一（v0.6.0）：奇门 / 太乙 / 金口诀（及三式合一的奇门 + 太乙）由星阙 `ken` 引擎（`kinqimen` / `kintaiyi` / `kinjinkou`）独占计算，headless JS 仅把 ken 结果重排成 `aiExport.js` section
- headless 引擎对齐（v0.6.2）：统摄法（`tongshefa.js`）与十年大运（`engine/decennials.py`）已与星阙逐值对齐（京房八宫五行、`Math.round`/`Math.ceil` 一致），对照星阙 `decennials.test.js` 金标
- tracing：本地 JSONL trace、`trace_id`、`group_id`
- benchmark：`HorosaBench` 本地评测集
- provenance：知识库与导出协议都带来源字段
- release metadata：`server.json`、SBOM、GitHub release workflow

## 四条命令（v0.38.x）

- `uv run horosa-skill setup --client <claude-code|claude-desktop|cursor|vscode|codex|gemini|windsurf|cline|zed>`（`windsurf` = Devin Desktop，原 Windsurf，key 保留兼容） —— 探网 → 装离线 runtime → 写该客户端配置 → doctor → 回读 → 真起一次 stdio
- `uv run horosa-skill client config --format <client>` —— 只生成（不落盘）该客户端的配置块 / 注册命令
- `uv run horosa-skill client check` —— 体检本机各客户端**实际写着什么**（占位符、超时、路径、版本漂移）
- `uv run horosa-skill doctor --explain` —— 机器可读体检 + 6–10 行人话；`selfcheck` 起一张盘 → 存 → 读回

零安装（无 checkout）把 `uv run horosa-skill` 换成 `uvx --from "<发布页 wheel URL>" horosa-skill`（见根 README「快速开始」）。

## 其它常用命令

- `uv run horosa-skill benchmark run`
- `uv run horosa-skill benchmark run --skip-runtime`
- `uv run horosa-skill trace latest`
- `uv run horosa-skill client openclaw-config --format mcporter`
- `uv run horosa-skill client openclaw-check --workspace ~/.openclaw/workspace`

## 这个子项目包含什么

- 离线 runtime 安装与诊断
  - `install`
  - `doctor`
  - `serve`
  - `stop`
- MCP 服务层
  - Streamable HTTP
  - stdio
- JSON-first CLI
  - `tool run`
  - `tool list`，包含每个工具的 `input_contract`
  - `dispatch`
  - `ask`
  - `export registry`
  - `export parse`
  - `knowledge registry`
  - `knowledge read`
- 本地数据管理
  - SQLite
  - JSON artifacts
  - run manifest
  - AI answer write-back
- 结构化报告导出
  - report template
  - JSON / DOCX / PDF artifacts
  - `style=chart` 完整排盘报告（不经 AI，全部盘面段落 + 盘图 + 目录 / 书签 / 页码）
- 自备知识库
  - `knowledge mine / add / remove / trash / restore`（删除与覆盖先进回收站；读不了的文件在 `problems` 里写明原因）
  - 计算时 `knowledge=[条目名 / #标签 / auto]` → `data.knowledge_context`
  - report artifact 回写本地 manifest
- 星阙 AI 导出协议机器建模
  - export registry
  - export snapshot parsing
  - per-tool `export_snapshot`
  - per-tool `export_format`

## 运行层示例（非全表，全表见根 README）

完整双语能力矩阵请看根目录 [README.md](../README.md) 和 [README_EN.md](../README_EN.md)。这里保留运行层视角，强调“你在这个子项目里具体能调什么”。

### 核心星盘与派生盘

- `chart`：标准星盘
- `chart13`：13 宫扩展盘
- `hellen_chart`：希腊星盘
- `guolao_chart`：七政四余盘
- `india_chart`：印度盘
- `relative`：合盘 / 关系盘
- `germany`：量化盘 / 中点盘

### 推运与时运

- `solarreturn`：太阳返照
- `lunarreturn`：月返
- `solararc`：太阳弧推运
- `givenyear`：指定年推运
- `profection`：小限
- `pd`：主限 / 本初方向
- `pdchart`：主限盘
- `zr`：黄道释放
- `firdaria`：法达星限
- `decennials`：十年大运 / 十年星限

推运工具必须带目标输入，不允许只用本命资料直接调用：

- `solarreturn` / `lunarreturn`：本命资料 + `datetime` + `dirZone` + `dirLat` + `dirLon`，输出本命盘和返照盘。
- `givenyear`：本命资料 + 指定年/目标时间 `datetime` + `dir*`，输出本命盘和流年盘。
- `solararc` / `profection`：本命资料 + `datetime` + `dirZone`，输出本命盘和推运盘。
- `pd`：本命资料 + `pdtype` + `pdMethod` + `pdTimeKey` + `pdaspects`，输出真实主限表格。
- `pdchart`：本命资料 + `datetime` + `dirZone` + 主限方法字段，输出主限法盘星体表格和相位。
- `zr` / `firdaria` / `decennials`：本命资料 + 用户是否接受星阙默认时间轴设置，输出对应时间轴。

完整说明见根目录 [`docs/INPUT_CONTRACTS.md`](../docs/INPUT_CONTRACTS.md)。审计推运类输出时不要只看短预览，因为正文通常先写本命盘，返照盘、推运盘、流年盘或主限表格在后续 section；按 `export_format.sections` 或 [`docs/EXPORT_AUDIT_GUIDE.md`](../docs/EXPORT_AUDIT_GUIDE.md) 检查完整内容。Agent 应先用 `uv run horosa-skill agent guidance --tool <tool>` 或 MCP `horosa_agent_guidance` 检查必问项，再调用真实工具。

### 中文术数与扩展技法

- `ziwei_birth`：紫微斗数命盘
- `ziwei_rules`：紫微规则库
- `bazi_birth`：八字命盘
- `bazi_direct`：八字直断
- `liureng_gods`：大六壬起课
- `liureng_runyear`：大六壬行年
- `qimen`：奇门遁甲（由星阙 `ken` 后端 `kinqimen` 计算）
- `taiyi`：太乙神数（由星阙 `ken` 后端 `kintaiyi` 计算）
- `jinkou`：金口诀（由星阙 `ken` 后端 `kinjinkou` 计算）
- `tongshefa`：统摄法
- `sanshiunited`：三式合一（聚合 ken 的奇门 + 太乙与大六壬）
- `suzhan`：宿占 / 宿盘
- `sixyao`：六爻 / 易卦
- `otherbu`：西洋游戏 / 占星骰子
- `geomancy`：天文地占（4 母卦 → 16 图形，十二宫图形入宫 + 判官/见证，以起卦时刻确定性起卦）
- `tarot`：塔罗（韦特 78 牌，确定性抽牌 + 牌阵直断 / 细论 / 综合建议）
- `jieqi_year`：全年节气盘
- `nongli_time`：农历换算
- `gua_desc`：卦义说明
- `gua_meiyi`：梅易卦义

### 导出与调度

- `export_registry`：星阙 AI 导出协议注册表
- `export_parse`：星阙 AI 导出正文解析器
- `horosa_dispatch`：自然语言总调度器

### 星阙悬浮知识库

- `knowledge_registry`：悬浮知识目录
- `knowledge_read`：悬浮知识读取器

已接入 31 个域 = 3 个悬浮域（星盘 `planet`/`sign`/`house`/`lot`/`aspect`、大六壬 `shen`/`house`、奇门 `stem`/`door`/`star`/`god`）
+ 27 个技法方法论手册域（上游 HelpDoc 收割，逐条带出处）+ 八字口诀库 `bazi_pithy`（21 类 173 条）；`knowledge_read {"query": …}` 跨域检索。

明确排除：

- `fengshui`

## 快速开始

```bash
cd horosa-skill
uv sync
uv run horosa-skill setup --client cursor   # 换成你的客户端；一条命令装 runtime + 写配置 + 体检 + 真起一次
uv run horosa-skill selfcheck               # 活体：起一张盘 → 存 → 读回
uv run horosa-skill client check            # 之后任何时候：看各客户端实际写着什么
```

只想手动分步：`install` → `doctor` → `serve`（HTTP）或 `client config --format <client>`（stdio）。

## 最短工作流

### 1. 安装 runtime

```bash
uv run horosa-skill install
uv run horosa-skill doctor
```

如果你主要是接 OpenClaw / mcporter，也可以直接生成当前路径版配置并做一次最小联通检查：

```bash
uv run horosa-skill client openclaw-config --format mcporter
uv run horosa-skill client openclaw-check --workspace ~/.openclaw/workspace
```

### 2. 直接让调度器选技法

```bash
echo '{
  "agent_confirmed_settings": true,
  "clarification_notes": "用户确认：1990-01-01 12:00 上海出生；此刻 2026-11-12 16:40 在上海；按星阙默认。",
  "query": "请用奇门和六壬看看我现在的状况",
  "birth": {"date": "1990-01-01", "time": "12:00", "place": "上海"},
  "context": {"date": "2026-11-12", "time": "16:40", "place": "上海"}
}' | uv run horosa-skill ask --stdin
```

奇门、六壬这类起课技法按 `context` 里的「此刻」起盘（出生数据代替不了），缺了会被拦下并说明缺什么；结果的 `time_basis` 写明每个技法用了哪个时刻。`agent_confirmed_settings` 只在用户真的确认过设置之后才带。

### 3. 查看某一次完整记录

```bash
uv run horosa-skill memory show <run_id>
```

### 4. 回写 AI 最终回答

```bash
echo '{
  "run_id":"<run_id>",
  "user_question":"我接下来事业走势如何？",
  "ai_answer_text":"先稳后升，宜先整理资源再扩张。",
  "ai_answer_structured":{"trend":"up_later"}
}' | uv run horosa-skill memory answer --stdin
```

### 5. 生成结构化报告

AI 客户端推荐先读取模板，再把自己的分析写回，最后让 Horosa Skill 本地渲染文件：

```bash
uv run horosa-skill report template --run-id <run_id> --tool chart
uv run horosa-skill report render --run-id <run_id> --tool chart --format docx
uv run horosa-skill report render --run-id <run_id> --tool chart --format pdf
```

也可以一次性调用某个技法并直接生成报告：

```bash
echo '{"date":"2028-04-06","time":"09:33","place":"上海","question":"这次签约顺不顺","agent_confirmed_settings":true,"clarification_notes":"用户确认：此刻与地点、所问之事；奇门设置按星阙默认。"}' \
  | uv run horosa-skill report from-tool qimen --stdin --format pdf --style chart
```

`--style chart` 出不含 AI 解读的完整排盘报告；要解读报告就用 `--ai-answer-file` / `--ai-report-file` 把写好的解读一起传进来。

## 常用命令

### 列出工具

```bash
uv run horosa-skill tool list
```

### 直接运行单个方法

```bash
echo '{"date":"1990-01-01","time":"12:00","zone":"8","lat":"31n14","lon":"121e28","defaults_accepted":true,"clarification_notes":"用户接受星阙默认（Alcabitus 宫制、回归黄道）。"}' \
  | uv run horosa-skill tool run chart --stdin
```

没带确认、又有会改结果的设置没回答时，命令以退出码 2 结束，stderr 的 JSON 是 `agent_guidance.required` 与可直接转给用户的追问。

### 运行本地 Phase 2 技法

```bash
echo '{"taiyin":"巽","taiyang":"坤","shaoyang":"震","shaoyin":"震"}' \
  | uv run horosa-skill tool run tongshefa --stdin
```

### 导出 registry

```bash
uv run horosa-skill export registry --technique qimen
```

### 解析星阙 AI 导出正文

```bash
echo '{
  "technique":"qimen",
  "content":"[起盘信息]\n参数\n\n[八宫]\n八宫内容\n\n[演卦]\n演卦内容"
}' | uv run horosa-skill export parse --stdin
```

### 读取星阙悬浮知识

```bash
echo '{"domain":"astro","category":"planet","key":"Sun"}' \
  | uv run horosa-skill knowledge read --stdin
```

## 本地记录系统会保存什么

每次 run 会持久化：

- run 元信息
- tool call 记录
- entity 索引
- JSON artifact
- run manifest
- query_text
- user_question
- ai_answer_text
- ai_answer_structured
- report_json / report_docx / report_pdf artifact
- artifact `exists` / `file_size` / `sha256` 元信息，方便确认文件仍可用
- 每条 run 的 `artifact_summary` 会汇总报告数量、类型计数和最新报告路径，AI 客户端不用自己遍历文件列表
- `report render` / `report from-tool` 入参里的 AI 分析会自动写回 `ai_answer_text` / `ai_answer_structured`，后续可按关键词检索

对应管理命令：

- `uv run horosa-skill memory query`
- `uv run horosa-skill memory query --text "事业走势" --artifact-kind report_pdf`
- `uv run horosa-skill memory show <run_id>`
- `uv run horosa-skill memory answer --stdin`（再写一次不会盖掉上一次，旧答案留在 `answer_history`）
- `uv run horosa-skill memory delete --entity 妈妈`（也可 `--run-id` / `--before`；默认只列出，`--yes` 才删，已交付的报告文件只列不删）
- `uv run horosa-skill memory export --entity 妈妈 --out <空文件夹>`（导出成人能直接读的文件夹）
- `uv run horosa-skill memory rebuild`（照 `runs/` 里的产物重建检索库，只增不删）
- `uv run horosa-skill report template --run-id <run_id>`
- `uv run horosa-skill report render --run-id <run_id> --format pdf`

## 环境变量

可以复制 `.env.example` 再按需覆盖：

```bash
cp .env.example .env
```

全部变量（含档位与说明）见 [docs/ENV_VARS.md](../docs/ENV_VARS.md)（由注册表生成）。常见项：

- `HOROSA_SERVER_ROOT`
- `HOROSA_CHART_SERVER_ROOT`
- `HOROSA_SKILL_DATA_DIR`
- `HOROSA_SKILL_DB_PATH`
- `HOROSA_SKILL_OUTPUT_DIR`
- `HOROSA_RUNTIME_ROOT`
- `HOROSA_RUNTIME_MANIFEST_URL`
- `HOROSA_RUNTIME_RELEASE_REPO`
- `HOROSA_RUNTIME_PLATFORM`
- `HOROSA_RUNTIME_START_TIMEOUT_SECONDS`
- `HOROSA_SKILL_HOST`
- `HOROSA_SKILL_PORT`
- `HOROSA_MCP_COMPACT`（=1 精简面 14 个工具）/ `HOROSA_TOOLSETS`（按域裁剪全量面）
- `HOROSA_MCP_RESULT_VIEW`（MCP 结果缺省视图，缺省 `reading` 阅读视图；`full` = 完整信封）/ `HOROSA_MCP_RESULT_MAX_CHARS` / `HOROSA_MCP_RESULT_MAX_TOKENS`（单次结果预算）
- `HOROSA_MCP_TOKEN` / `HOROSA_MCP_ALLOWED_HOSTS`（streamable-http 的 Bearer 与 Host 白名单）
- `HOROSA_REPORT_OUTPUT_ROOTS`（报告 `output_path` 允许写入的目录白名单）
- `HOROSA_RUNTIME_MIRROR`（离线 runtime 下载镜像）
- `HOROSA_CLARIFY`（澄清闸档位）/ `HOROSA_JEV*`（可选云端决策层，缺省关；密钥永不回显）

## 相关文档

- [根目录中文首页](../README.md)
- [Root English README](../README_EN.md)
- [客户端配置示例](./examples/clients)
- [Runtime 发布说明](../docs/OFFLINE_RUNTIME_RELEASES.md)
- [算法覆盖矩阵](../docs/ALGORITHM_COVERAGE.md)
