docs(07): capture phase context
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
# Phase 7: 登录认证体系 - Context
|
||||
|
||||
**Gathered:** 2026-03-17
|
||||
**Status:** Ready for planning
|
||||
|
||||
<domain>
|
||||
## Phase Boundary
|
||||
|
||||
建立知乎登录认证机制,支持二维码扫码和手动 Cookie 两种方式,实现 Cookie 持久化和过期检测。
|
||||
|
||||
此阶段不涉及内容爬取(Phase 8),只处理登录认证和 Cookie 管理。
|
||||
|
||||
</domain>
|
||||
|
||||
<decisions>
|
||||
## Implementation Decisions
|
||||
|
||||
### 二维码显示方式
|
||||
- **显示方式**: 保存为图片文件,作为标准 step 输出(让 AI 代理能够获取并展示)
|
||||
- **存储位置**: 中间目录(与现有中间文件存放位置一致)
|
||||
- **等待超时**: 60 秒
|
||||
- **超时行为**: 轮询检测,超时退出(不自动重试)
|
||||
|
||||
### Cookie 存储策略
|
||||
- **存储位置**: `~/.kb_env` 文件(与现有配置文件一致)
|
||||
- **输入格式**: 支持 JSON 导入(Chrome Cookie 导出插件格式),内部存储为字符串
|
||||
- **存储格式**: 原始 Cookie 字符串,例如 `ZHIHU_COOKIE="name1=value1; name2=value2"`
|
||||
- **加密**: 不加密,用户需自行保护 `~/.kb_env` 文件权限
|
||||
|
||||
### 过期检测机制
|
||||
- **检测时机**: 每次使用前检测 Cookie 有效性
|
||||
- **检测方法**: 请求知乎用户信息接口,检查返回状态
|
||||
- **过期处理**: 自动触发扫码重新登录
|
||||
|
||||
### 命令行交互流程
|
||||
- **登录命令**: `python3 kb-workflow/kb_workflow.py login`
|
||||
- **默认模式**: 扫码模式(弹出二维码让用户扫码)
|
||||
- **手动设置**: `--import-cookie cookies.json` 从文件导入 JSON 格式 Cookie
|
||||
- **状态查看**: `login --status` 检查当前 Cookie 是否有效
|
||||
|
||||
### Claude's Discretion
|
||||
- 二维码图片的具体文件名格式
|
||||
- 用户信息接口的具体 URL 和返回格式
|
||||
- JSON Cookie 解析的具体实现
|
||||
- 错误提示信息的具体文案
|
||||
|
||||
</decisions>
|
||||
|
||||
<code_context>
|
||||
## Existing Code Insights
|
||||
|
||||
### Reusable Assets
|
||||
- `kb_workflow/metadata/zhihu_extractor.py` — PlaywrightBrowser 类,已支持 Cookie 设置
|
||||
- `kb_workflow/pipeline/config.py` — KBSettings 配置类,支持环境变量加载
|
||||
- `kb_workflow/pipeline/schemas.py` — StepInput/StepOutput 基类,可扩展登录相关 Schema
|
||||
- `~/.kb_env` — 现有配置文件,已存储 ZHIHU_COOKIE
|
||||
|
||||
### Established Patterns
|
||||
- 配置管理: pydantic-settings BaseSettings + Field + 环境变量
|
||||
- 处理器模式: BaseProcessor + process(input) -> output
|
||||
- CLI 设计: argparse subparsers
|
||||
- 用户确认: rich.prompt 或 input() fallback
|
||||
|
||||
### Integration Points
|
||||
- CLI 入口: `kb_workflow.py` 添加 `login` 子命令
|
||||
- 配置类: KBSettings 添加 ZHIHU_COOKIE 相关逻辑
|
||||
- 浏览器管理: 扩展 PlaywrightBrowser 支持二维码生成和 Cookie 提取
|
||||
|
||||
</code_context>
|
||||
|
||||
<specifics>
|
||||
## Specific Ideas
|
||||
|
||||
- 二维码图片路径: `~/work/intermediate/zhihu_qrcode_{timestamp}.png`
|
||||
- Cookie 环境变量: `ZHIHU_COOKIE="name1=value1; name2=value2"`
|
||||
- JSON 导入格式: Chrome Cookie Editor 导出的 JSON 数组格式
|
||||
- 用户信息接口: `https://www.zhihu.com/api/v4/me` 或类似
|
||||
|
||||
</specifics>
|
||||
|
||||
<deferred>
|
||||
## Deferred Ideas
|
||||
|
||||
None — discussion stayed within phase scope
|
||||
|
||||
</deferred>
|
||||
|
||||
---
|
||||
|
||||
*Phase: 07-login-auth*
|
||||
*Context gathered: 2026-03-17*
|
||||
Reference in New Issue
Block a user