Skip to main content
Glama
yzyx
by BerBai
README.md
# yzyx — 有知有行网页版工具(CLI + MCP,读 + 新增记录,禁删除)

有知有行没有官方 API / CLI / MCP。本工具走 2026-11-29 实测定案的通道:
网页版是 Phoenix LiveView 服务端渲染,带上登录 session Cookie 直接 GET
页面 HTML 就能读到账本数据,不需要浏览器、不需要 websocket。

## 能读什么

| 命令 / 工具 | 内容 |
|---|---|
| `status` / `yzyx_status` | 检查 Cookie 是否有效 |
| `overview` / `yzyx_overview` | 家庭总览:总资产、更新日期、月度资产/负债变化、投资年化、今年净投入、本月现金流、财务晴雨表六项比率、心理账户 5 个目标 |
| `inventory` / `yzyx_inventory` | 资产盘点:五大分类小计 + 全部账户(cid、名称、金额、日期),可 `-c <分类>` 只看一类 |
| `cell <cid>` / `yzyx_cell` | 单个盘点账户的当前金额与最近记录 |
| `groups` / `yzyx_groups` | 投资记账分组汇总:每组总资产、累计收益、年化收益率 |
| `update <cid> <金额>` / `yzyx_update_cell` | **【写】**给盘点账户新增一条记录(日期/备注可选),写后自动读回验证 |

**删除:全面禁止**(设计要求)。写入通道在代码层只白名单放行
`create_cell_record` 一个事件,含 delete/remove 的事件名直接抛错;
CLI 没有删除命令,MCP 没有删除工具。

**已知边界**:单个投资账户的列表与详情是页面连上 websocket 后才加载的,
静态 GET 拿不到,所以只做到分组汇总。投资记账的新增记录表单也在
websocket 侧,本期未做;资产盘点的更新已走同一协议打通(见下)。

分类 key:`liquid_assets` 流动资金 / `fixed_assets` 固定资产 /
`investment` 投资理财 / `receivables` 应收款 / `liabilities` 负债。

## 安装(Mac)

```bash
cd youzhiyouxing-tool
python3 -m venv .venv
.venv/bin/pip install -e .
```

## Cookie(登录凭证,只存本地文件)

工具按顺序找 Cookie:环境变量 `YZYX_COOKIE`(整串,仅临时调试)→
`YZYX_COOKIE_FILE` 指向的文件 → 默认 `~/.config/yzyx/cookie.txt`。

首次设置:

```bash
mkdir -p ~/.config/yzyx
printf '_weasley_key=<值>; _weasley_web_user_remember_me=<值>\n' > ~/.config/yzyx/cookie.txt
chmod 600 ~/.config/yzyx/cookie.txt
```

两个值从浏览器 DevTools → Application → Cookies → `yx.youzhiyouxing.cn` 取。
**不要把 Cookie 贴到聊天里**——它等同登录凭证。Cookie 失效(工具报
「登录态问题」)时,重新登录网页版、按上面刷新文件即可;在网页端点
「退出」会立刻让现有 Cookie 作废。

## CLI 用法

```bash
.venv/bin/yzyx status
.venv/bin/yzyx overview
.venv/bin/yzyx inventory            # 全部五类(逐类抓取,约 5 个请求)
.venv/bin/yzyx inventory -c investment
.venv/bin/yzyx cell 1234567         # cid 来自 inventory 输出
.venv/bin/yzyx groups
.venv/bin/yzyx update 1234567 12345.67 --comment 月度盘点   # 写:先确认,--yes 跳过
# 全部命令支持 --json
```

## MCP 用法

stdio server:`.venv/bin/yzyx-mcp`。给 MCP 客户端(Claude Code / Codex 等)
的配置示例:

```json
{
  "mcpServers": {
    "yzyx": {
      "command": "/绝对路径/youzhiyouxing-tool/.venv/bin/yzyx-mcp"
    }
  }
}
```

工具读默认 Cookie 文件;如需指定,在配置里加
`"env": {"YZYX_COOKIE_FILE": "/路径/cookie.txt"}`。

## 实现要点(踩过的坑)

- HTTP 用 httpx,但**不能** `trust_env=True` 自动解析环境代理:某些环境的
  `no_proxy` 含 `[IPv6]` 条目会让 httpx 解析崩溃。client.py 的做法是显式读
  `HTTPS_PROXY` 等变量传 `proxy=`,并用系统 CA 存储验签(受管网络的出口
  代理会换证书,certifi 包不认,系统存储认)。Mac 上无代理变量时即直连。
- Python urllib 在本环境会超时,不要用它直连本站。
- 读操作不发任何写请求。写操作只有 `update` 一条路径(新增记录):
  走 Phoenix Channels 协议(wss + vsn 2.0.0 数组消息)推
  `create_cell_record` 事件。三个实测坑:①握手 Cookie 必须用 GET 响应
  刚轮换的 `_weasley_key`(服务端每次响应都轮换,旧值 join 回 stale,
  客户端已做自动吸收+回写 Cookie 文件);②表单 value 必须 urlencoded
  字符串,传 JSON 对象会让服务端通道崩溃;③事件 payload 用 `cid`
  (组件号,从页面表单 phx-target 动态读),不是 `target`。

TDQS

A3.6/5.0

Scored across 6 tools

Disambiguation4/5

Each tool targets a distinct layer: auth status, household summary, category-level inventory, single-account detail, and investment grouping. The only mild overlaps are yzyx_overview vs yzyx_groups (both report investment returns) and yzyx_inventory vs yzyx_cell (list vs single account), but the descriptions make the cid-based relationship explicit.

Naming Consistency4/5

All tools share the yzyx_ prefix and snake_case, with resource-noun names (status, overview, inventory, cell, groups). The one deviation is yzyx_update_cell, which switches to a verb_noun form, but this actually usefully signals the sole write operation.

Tool Count5/5

Six tools is well-scoped for a read-mostly personal finance surface, with no redundant entries. Each tool maps to a distinct view or the single write path.

Completeness3/5

Read coverage is solid (auth, overview, inventory, account detail, investment groups) plus an append-only write, but there is no way to create or edit accounts, query historical ranges/time series per account, or remove records (removal is deliberately forbidden). These gaps are partly documented, but agents needing trends or corrections will hit dead ends.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues