Commit Graph

350 Commits

Author SHA1 Message Date
starmen1265 9c8ac34138 fix(kb_workflow): resolve module/package naming conflict
PR Test / lint (pull_request) Successful in 1s
Rename kb_workflow.py to cli.py to avoid conflict with kb_workflow/ package.
Add __main__.py to support `python -m kb_workflow` execution.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 10:35:33 +08:00
starmen1265 9d2433322a fix(crawler): set proxy_required=False by default
PR Test / lint (pull_request) Successful in 2s
旁路由 (192.168.1.200) provides automatic system-level proxy.
No explicit HTTP_PROXY/HTTPS_PROXY configuration needed.
2026-03-18 00:04:48 +08:00
starmen1265 e1d3218a44 Merge branch 'fix/ci-deploy-reset' 2026-03-18 00:03:43 +08:00
starmen1265 c09c8588f0 fix(crawler): resolve circular import in zhihu_crawler
Circular import chain:
  zhihu_crawler -> pipeline.config -> pipeline.platforms -> zhihu_crawler

Fix: Lazy import get_settings() inside _get_cookie() method instead of
module-level import.
2026-03-18 00:03:02 +08:00
starmen1265 d88f1a3b8d Merge pull request 'docs(skill): update kb_workflow SKILL.md to reflect current implementation' (#28) from fix/ci-deploy-reset into main
Deploy kb-skills / deploy (push) Successful in 2s
Reviewed-on: http://192.168.1.22:8418/starmen1265/kb-skills/pulls/28
2026-03-17 23:52:57 +08:00
starmen1265 6a819b6c80 docs(skill): update kb_workflow SKILL.md to reflect current implementation
PR Test / lint (pull_request) Successful in 2s
- Fix CLI path: kb-workflow -> kb_workflow
- Add login command documentation for Zhihu
- Update directory structure to match actual paths
- Add environment variable checks section
- Document strict failure handling principle
- Update technical architecture diagram
2026-03-17 23:50:42 +08:00
starmen1265 5ccabec3e4 Merge pull request 'fix(ci): correct skill directory names in deploy.yml' (#27) from fix/ci-deploy-reset into main
Deploy kb-skills / deploy (push) Successful in 1s
Reviewed-on: http://192.168.1.22:8418/starmen1265/kb-skills/pulls/27
2026-03-17 23:41:51 +08:00
starmen1265 228cd1cf8c fix(ci): correct skill directory names in deploy.yml
PR Test / lint (pull_request) Successful in 2s
- Fix kb-workflow -> kb_workflow (underscore not hyphen)
- Remove non-existent skill directories from the list
- Only include skills that actually exist in the repo
2026-03-17 23:40:12 +08:00
starmen1265 289be86fc6 Merge pull request 'fix/ci-deploy-reset' (#26) from fix/ci-deploy-reset into main
Deploy kb-skills / deploy (push) Successful in 1s
Reviewed-on: http://192.168.1.22:8418/starmen1265/kb-skills/pulls/26
2026-03-17 23:28:17 +08:00
starmen1265 7744f7ac1d docs(phase-09): complete phase execution - pipeline integration verified
PR Test / lint (pull_request) Successful in 2s
2026-03-17 23:25:08 +08:00
starmen1265 248a1f2b8c docs(09-01): complete ZhihuAdapter integration plan
- Integrated ZhihuCrawler into ZhihuAdapter
- Added comment crawling and formatting
- Implemented cookie auto-login flow
- Added idempotent execution via IdempotencyChecker

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 23:17:39 +08:00
starmen1265 76f06c330b feat(09-01): integrate ZhihuCrawler into ZhihuAdapter
- Replace ZhihuPlaywrightExtractor with ZhihuCrawler
- Add comment crawling with include_comments=True by default
- Implement cookie expiration detection and QR code login trigger
- Add idempotency check via IdempotencyChecker
- Add comment formatting with "## 热门评论" section
- Convert HTML content to Markdown using html2text

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 23:14:22 +08:00
starmen1265 22ed60a5ab docs(09-00): complete Wave 0 test scaffolding plan
- Added 5 mock fixtures for ZhihuCrawler integration testing
- Added 6 test skeletons (marked skip) for Wave 1 implementation
- Updated STATE.md with Phase 9 position
- Updated ROADMAP.md with plan progress

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 23:02:40 +08:00
starmen1265 95218c18cd test(09-00): add Wave 0 test scaffolding for Pipeline integration
- Add mock fixtures for ZhihuCrawler CrawlResult models:
  - mock_crawl_answer_result: simulates answer crawl with comments
  - mock_crawl_article_result: simulates zhuanlan article crawl
  - mock_comments_list: test data for comment formatting
  - mock_zhihu_login_result: simulates QR code login success
  - mock_crawl_failed_result: for error handling tests

- Add test skeletons (marked skip) for Wave 1 implementation:
  - test_fetch_metadata_answer
  - test_fetch_metadata_article
  - test_fetch_content_with_comments
  - test_cookie_expired_triggers_login
  - test_idempotent_execution
  - test_comment_formatting

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 22:59:07 +08:00
starmen1265 bee696b96d docs(09): complete phase 9 planning with 2 plans in 2 waves 2026-03-17 22:54:48 +08:00
starmen1265 1c42443dce fix(09): revise plans based on checker feedback 2026-03-17 22:53:00 +08:00
starmen1265 ec18ea9197 docs(09): create phase 9 plans 2026-03-17 22:46:21 +08:00
starmen1265 45ba9c973f docs(09): research phase 9 domain 2026-03-17 22:37:38 +08:00
starmen1265 b3c7386098 docs(state): record phase 9 context session 2026-03-17 22:32:56 +08:00
starmen1265 e6b62f42e7 docs(09): capture phase context 2026-03-17 22:32:44 +08:00
starmen1265 007b0d70ef docs(08): complete phase 08 - Zhihu Crawler
Phase 08: Crawler - All 3 plans complete

Verification: 7/7 must-haves passed
Tests: 44 passed

Requirements completed:
- CONT-01: Crawl Zhihu answers
- CONT-02: Crawl Zhihu articles
- CONT-03: Crawl comments (optional)
- CONT-04: Metadata extraction
- NET-01: Proxy configuration
- NET-02: Mandatory proxy
- NET-03: Rate limiting & retry

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 22:23:56 +08:00
starmen1265 123e307522 docs(08-03): complete anti-crawl measures plan
- Proxy configuration from HTTP_PROXY/HTTPS_PROXY
- Random delay (1-3s) between requests
- Exponential backoff retry (3 attempts)
- x-zse-96 signature handled by browser

All 44 crawler tests passing

Requirements: NET-01, NET-02, NET-03 completed

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 22:20:38 +08:00
starmen1265 9e1452d2a9 feat(08-03): integrate proxy, delay, and retry into ZhihuCrawler
- Add CrawlerConfig with ProxyConfig, delay, and retry settings
- Integrate proxy configuration via _start_browser_with_proxy()
- Add random delay via _apply_random_delay()
- Add retry logic via _crawl_with_retry using tenacity
- Add ZhihuApiInterceptor tests for x-zse-96 handling
- All tests pass
2026-03-17 22:14:47 +08:00
starmen1265 6a4f13b2f6 docs(08-02): complete comment crawler plan
- Add 08-02-SUMMARY.md with execution details
- Update STATE.md with decisions and metrics
- Mark CONT-03 requirement complete

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 21:59:49 +08:00
starmen1265 626fb73a58 feat(08-03): create CrawlerConfig for proxy and rate limiting
- Add CrawlerConfig with ProxyConfig, delay, and retry settings
- Support HTTP_PROXY/HTTPS_PROXY environment variable parsing
- Add proxy_required validation with clear error message
- Add get_crawler_config singleton for configuration access

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 21:57:09 +08:00
starmen1265 f41e75a1b2 feat(08-02): implement crawl_comments method with hot sorting
- Add COMMENT_API_TEMPLATE for comment API URL
- Implement crawl_comments() returning CommentsResult
- Use order=hot for popular comments sorting
- Only fetch first-level comments (no nested replies)
- Add include_comments parameter to crawl_answer()
- Export CommentAuthor, CommentData, CommentsResult in __init__.py

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 21:56:47 +08:00
starmen1265 8cc46965c1 test(08-02): add failing tests for comment crawling
- Test crawl_comments returns CommentsResult
- Test comments use hot sorting (order=hot)
- Test comment has required fields (content, author, like_count)
- Test no nested replies (first-level only)
- Test include_comments parameter control

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 21:54:42 +08:00
starmen1265 b1f57922da feat(08-02): add CommentData models for comment crawling
- Add CommentAuthor model for comment author info
- Add CommentData model with content, author, likes, child_count
- Add CommentsResult model for crawl operation result
- Update CrawlResult to include optional comments field

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 21:53:17 +08:00
starmen1265 f0ee4ca5e2 docs(08-01): complete zhihu content crawler plan
- ZhihuCrawler class with API interception
- AnswerData, ArticleData models
- 15 tests passing

Requirements: CONT-01, CONT-02, CONT-04 completed

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 21:51:56 +08:00
starmen1265 aa96bc963c feat(08-01): implement ZhihuCrawler with API interception
- Add ZhihuCrawler class with crawl_answer() and crawl_article() methods
- Implement ZhihuApiInterceptor for capturing /api/v4/ responses
- Add _parse_author(), _parse_metadata(), _parse_answer_data(), _parse_article_data() helpers
- Support DOM parsing fallback for zhuanlan articles
- Export ZhihuCrawler and ZhihuApiInterceptor from __init__.py

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 21:10:10 +08:00
starmen1265 912773fc65 test(08-01): add failing tests for ZhihuCrawler
- Add test_answer_crawler.py with tests for crawl_answer()
- Add test_article_crawler.py with tests for crawl_article()
- Add test_metadata_extraction.py with tests for author/metadata parsing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 21:08:13 +08:00
starmen1265 a102a75b28 feat(08-01): create crawler data models and test scaffolding
- Add Pydantic models: AnswerData, ArticleData, ContentMetadata, AuthorInfo, CrawlResult
- Create test fixtures in conftest.py with mock browser and sample API responses
- Set up crawler module with __init__.py exports

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 21:06:33 +08:00
starmen1265 334aac87c7 fix(08): resolve Wave 1 file conflict - move 08-02 to Wave 2 2026-03-17 21:02:17 +08:00
starmen1265 6d2d6b26e9 docs(08): create phase 8 plans for crawler implementation 2026-03-17 20:56:51 +08:00
starmen1265 c93237abde docs(08): add validation strategy 2026-03-17 20:49:01 +08:00
starmen1265 1464c9b707 docs(08): research crawler implementation domain 2026-03-17 20:47:12 +08:00
starmen1265 ba33e0e518 docs(state): record phase 08 context session 2026-03-17 18:57:06 +08:00
starmen1265 87adf8aca6 docs(08): capture phase context for crawler implementation 2026-03-17 18:56:56 +08:00
starmen1265 e8eaca519f docs(07-03): complete Login CLI Subcommand plan
- Cookie validation via /api/v4/me endpoint
- login CLI subcommand with 3 modes: scan, import, status
- AUTH-04 requirement complete: Cookie expiry detection
- Phase 7 Login Auth complete, ready for Phase 8 Crawler

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 18:24:32 +08:00
starmen1265 d9861aa6c3 feat(07-03): implement login CLI subcommand
- Add login_command function with QR code login, cookie import, and status check
- Add login subcommand with --import-cookie and --status options
- Update CLI help text with login examples
- Fix mock paths in tests to match actual import locations

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 18:10:43 +08:00
starmen1265 94c85baac9 test(07-03): add failing tests for login CLI subcommand
- Test login_default_mode - default QR code login flow
- Test login_import_cookie - --import-cookie JSON import
- Test login_status - --status cookie validation
- Test login_integration - successful login saves cookie
- Test login_error_handling - exception handling

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 18:01:53 +08:00
starmen1265 919a4673e6 feat(07-03): implement cookie validation functionality
- Add CookieValidationResult Pydantic model with valid, username, user_id, reason fields
- Add validate_cookie async method to ZhihuLogin class
- Validate cookie via Zhihu /api/v4/me endpoint
- Handle 200, 401, and other status codes appropriately
- Handle network errors gracefully

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 18:00:37 +08:00
starmen1265 32bb22008b test(07-03): add failing tests for cookie validation
- Test validate_cookie_valid - valid cookie returns user info
- Test validate_cookie_expired - expired cookie returns False
- Test validate_cookie_empty - empty cookie returns False
- Test validate_cookie_malformed - network error handling
- Test validate_cookie_other_status_code - non-200/401 handling

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 17:59:28 +08:00
starmen1265 4228b1e3a1 docs(07-01): complete QR Code Login Core plan 2026-03-17 17:57:28 +08:00
starmen1265 799bf09acc docs(07-02): add self-check verification to summary
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 17:54:12 +08:00
starmen1265 072d83da35 feat(07-01): implement ZhihuLogin QR code login class
TDD GREEN phase - implementation passes all 8 tests:

- ZhihuLoginResult: Pydantic model for login results
- ZhihuLogin: Main class with QR code login flow
  - LOGIN_URL: https://www.zhihu.com/signin
  - CANVAS_SELECTORS: Multiple fallback selectors for QR canvas
  - _find_qrcode_canvas(): Find canvas with fallback selectors
  - _save_qrcode_image(): Save QR code to intermediate directory
  - check_login_cookie(): Detect z_c0 cookie for login state
  - get_cookies_str(): Extract cookie string from context
  - _wait_for_login(): Poll with configurable timeout (tenacity)
  - login_by_qrcode(): Main entry point for login flow

Key design decisions:
- Uses tenacity Retrying for configurable timeout
- QR code saved to intermediate_path with timestamp
- Multiple canvas selectors for robustness
- Proper browser lifecycle management

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 17:54:06 +08:00
starmen1265 771ca554b3 docs(07-02): complete cookie import & persistence plan 2026-03-17 17:53:38 +08:00
starmen1265 00245c58cc feat(07-02): implement CookieManager class
- CookieManager saves cookies to ~/.kb_env file
- Updates existing ZHIHU_COOKIE line or appends new
- Preserves other configuration lines
- Sets file permissions to 600 for security
- Loads cookies from env file
- Clears get_settings cache after saving

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 17:50:39 +08:00
starmen1265 fb9bc2d1ed test(07-01): add failing tests for ZhihuLogin QR code login
TDD RED phase - tests expect ZhihuLogin class that doesn't exist yet:

- test_login_page_access: verify correct login URL
- test_qrcode_screenshot: verify QR code capture and save
- test_cookie_detection_with_z_c0: verify login detection
- test_cookie_detection_without_z_c0: verify no login when missing z_c0
- test_cookie_extraction: verify cookie string format
- test_login_timeout: verify timeout after 60s polling
- test_result_model_success: verify success result model
- test_result_model_failure: verify failure result model

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 17:50:26 +08:00
starmen1265 19c377ef65 test(07-02): add failing tests for Cookie persistence
- Test save_cookie creates env file
- Test save_cookie updates existing line
- Test save_cookie appends new line
- Test save_cookie preserves other lines
- Test save_cookie sets file permissions to 600
- Test load_cookie returns saved value
- Test load_cookie returns empty if file not exists

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 17:49:47 +08:00