Skip to content
cocoafunPublic

About

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

PaperClaw 高保真复刻版

基于 Next.js App Router + TypeScript + Tailwind + PostgreSQL + Drizzle ORM 的单体实现,覆盖 PaperClaw 核心页面、公共 API、登录态 API、Token 态 API、RSS 抓取与本地可运行数据链路。

现在额外包含一套面向 Agent / OpenClaw 的 workspace discovery、远程 /SKILL.md 文档和本地 companion skill。

1. 本地启动

pnpm install
pnpm db:migrate
pnpm db:seed
pnpm dev

打开:http://localhost:3000/

2. 默认环境变量

复制并编辑:

cp .env.example .env

关键变量:

  • DATABASE_URL="postgresql://postgres:[email protected]:5432/paperclaw"
  • DIRECT_DATABASE_URL="postgresql://postgres:[email protected]:5432/paperclaw"(可选,推荐生产环境用于 Drizzle 迁移直连)
  • NEXT_PUBLIC_BASE_URL="http://localhost:3000"
  • SILICONFLOW_API_KEY=""(可选,空值时使用离线规则摘要)
  • SILICONFLOW_BASE_URL="https://api.siliconflow.cn/v1"
  • SILICONFLOW_MODEL="deepseek-ai/DeepSeek-V3.2"
  • RSS_FETCH_TIMEOUT_MS="20000"(可选,单个 RSS 拉取超时毫秒数)
  • RSS_FETCH_RETRY_COUNT="2"(可选,RSS 临时错误重试次数)
  • RSS_FETCH_RETRY_DELAY_MS="700"(可选,重试基础等待毫秒,按线性退避增长)
  • RSS_FETCH_FEED_CONCURRENCY="6"(可选,feed 抓取并发度)
  • CRON_SECRET 或 SYNC_CRON_SECRET(可选,定时同步鉴权)
  • ADMIN_EMAILS="[email protected],[email protected]"(可选,逗号分隔;这些账号可访问后台管理员页)
  • GITHUB_CLIENT_ID/GITHUB_CLIENT_SECRET(可选,配置后启用 GitHub 登录)
  • GITHUB_PROXY_URL(可选,GitHub 不可直连时使用,如 ClashX 的 http://127.0.0.1:7890)
  • GITHUB_OAUTH_TIMEOUT_MS(可选,默认 20000)

数据库说明:

  • 当前默认数据库为 PostgreSQL。
  • Drizzle schema 位于 lib/db/schema.ts。
  • 初始迁移已提交到 drizzle/。
  • 开发时可使用 pnpm db:migrate 应用迁移,pnpm db:studio 打开 Drizzle Studio。

如果你本地用 Homebrew 管理 PostgreSQL,可直接按下面操作:

brew install postgresql@17
brew services start postgresql@17
createuser -h 127.0.0.1 -p 5432 -s postgres
createdb -h 127.0.0.1 -p 5432 -U postgres paperclaw
pnpm db:migrate
pnpm db:seed

常用数据库服务命令:

brew services start postgresql@17
brew services stop postgresql@17
brew services list | rg postgresql

GitHub OAuth 配置步骤:

  1. 在 GitHub 创建 OAuth App。
  2. Homepage URL 填 http://localhost:3000(或你的部署域名)。
  3. Authorization callback URL 填 http://localhost:3000/api/auth/github/callback(或对应线上地址)。
  4. 将 Client ID/Secret 写入 .env 后重启 pnpm dev。

如果 GitHub 登录报网络错误:

  1. 配置 GITHUB_PROXY_URL=http://127.0.0.1:7890(按你的 ClashX 端口调整)。
  2. 保留 NO_PROXY=localhost,127.0.0.1(避免本地回调被代理)。
  3. 重启服务后再试。

3. 复刻页面

  • /
  • /insights
  • /article/[id]
  • /articles/[date]
  • /favorites
  • /feeds
  • /about
  • /auth/login
  • /subscriptions
  • /subscriptions/settings
  • /admin(仅 ADMIN_EMAILS 白名单用户可访问)
  • /marketplace
  • /pricing

4. 复刻 API

公共:

  • GET /api/workspaces
  • GET /api/workspaces/[workspace]
  • GET /api/workspaces/[workspace]/archive
  • GET /api/workspaces/[workspace]/tags
  • GET /api/workspaces/[workspace]/feeds
  • GET /api/workspaces/[workspace]/search?q=...
  • GET /api/workspaces/[workspace]/articles/latest?ack=&rationale=&pstate=&token=
  • GET /api/workspaces/[workspace]/articles/[date]?ack=&rationale=&pstate=&token=
  • GET /api/workspaces/[workspace]/content/[id]?ack=
  • GET /api/workspaces/[workspace]/content?ids=id1,id2&ack=
  • GET /api/archive
  • GET /api/tags
  • GET /api/feeds
  • GET /api/search?q=...(至少 2 字符)
  • GET /api/articles/latest?tags=&ack=&rationale=&pstate=&token=
  • GET /api/articles/[date]?tags=&ack=&rationale=&pstate=&token=
  • GET /api/content/[id]?ack=
  • GET /api/content?ids=id1,id2&ack=
  • GET /llms-full.txt?ack=
  • GET /SKILL.md
  • GET /api/workspaces/[workspace]
  • GET /.well-known/ai-plugin.json

登录态:

  • GET/POST/DELETE /api/user/feeds
  • GET/POST/DELETE /api/user/workspaces
  • GET/POST /api/user/notes
  • GET/POST/DELETE /api/user/token
  • GET/POST/DELETE /api/user/favorites
  • POST /api/user/favorites/import
  • GET/POST /api/user/settings
  • POST /api/insights/tasks
  • POST /api/admin/sync(仅 ADMIN_EMAILS 白名单用户;手动触发指定订阅的内容同步)

Token 态:

  • GET /api/agent/feeds?ack=&token=

说明:

  • /api/workspaces/[workspace]/* 是 Agent 的规范入口。
  • 根级 /api/* 保留为默认 workspace 的兼容别名。
  • /SKILL.md 是站点级索引 skill,/api/workspaces/[workspace] 提供 workspace 专属元数据与链接。

5. 行为约束(已实现)

  • ack 缺失:403 Skill acknowledgment required
  • rationale 缺失:400
  • pstate 缺失或非法:400
  • pstate=has_token 但无 token:400
  • ack 当前值见 /SKILL.md(当前实现为 paperclaw-v1)
  • search 关键字 <2:400
  • user/* 未登录:401
  • 匿名收藏存 localStorage,登录后自动迁移到云端
  • 标签过滤支持前缀匹配(例如 AI 匹配 AI/LLM/Agent)
  • Pro 功能(notes/settings 保存)已做权限 gating
  • /api/workspaces 返回多 workspace discovery 元数据,供 Agent 先做选择再进入具体 skill

6. 数据与抓取

  • 工作区注册表:data/workspaces/registry.ts
  • 每个类别的配置:data/workspaces/<slug>/manifest.json
  • 每个类别的源清单:data/workspaces/<slug>/sources.json
  • 每个类别现在还包含 manifest.json 里的 agent 配置块,用来生成 workspace skill 和 discovery 元数据
  • 本地 companion skill:skills/paperclaw-remote/
  • 默认源抓取口径(对齐 reference):
    • 仅保留相对当前执行时刻向前 48 小时内的文章
    • 不做“每源限量”,按全局文章池执行 48h 过滤
    • 若 48 小时窗口内无文章,回退为全局最新 50 篇
    • 所有文章都严格按文章发布时间分桶;缺失发布时间时进入 unknown
    • 缺失发布时间的文章允许入库,published_at 在 API 中返回空字符串
    • 48h 窗口锚点为同步任务执行时刻(与 reference pipeline 一致)
    • --date=YYYY-MM-DD 仅控制本次同步锚点和 run 记录,不改变文章按发布时间分组的规则
    • 每次抓取都会与历史已入库文章做去重;重复文章不会再次走摘要/打标/快照更新
  • 用户订阅源抓取保持原行为(不应用上面的默认源 48h 过滤)
  • 种子数据:data/seed-articles.json
  • 抓取脚本:
    • pnpm sync:feeds(默认 92 源)
    • pnpm sync:feeds -- --workspace=management
    • pnpm sync:feeds -- --workspace=economics
    • pnpm sync:feeds -- --date=2026-03-07(按指定同步锚点抓取,文章仍按发布时间分组)
    • pnpm sync:feeds -- --date=2026-03-07 --reset-date(强制重新处理本轮抓到的已存在文章,并重置该同步锚点对应 run)
    • pnpm sync:user-feeds(用户订阅源)
  • 自动抓取(每日):
    • 内部接口:/api/internal/sync/default
    • 鉴权:Authorization: Bearer <CRON_SECRET>
    • 未传 workspace 时,入口只负责分发后台任务;传 ?workspace=<slug> 时只同步指定 workspace
    • 分发后会按 workspace 拆成多个独立函数执行,避免单个请求卡满 5 分钟
    • 同步 curated source 后,会自动补齐已订阅该 workspace 的用户 source 关联
    • 已提供 vercel.json cron:每天 UTC 16:00 触发一次,对应北京时间次日 00:00
    • 同步不会自动生成洞察;洞察需要在 /insights 页面手动创建任务

说明:无 SILICONFLOW_API_KEY 时,摘要/标签走离线规则;有 key 时自动增强。

工作区/社区扩展说明见:

  • docs/community-workspaces.md

OpenClaw / Agent 使用说明:

  • 远程入口先读 /SKILL.md
  • 发现 workspace 用 /api/workspaces
  • 选择后读 /api/workspaces/<workspace>
  • 本地可安装的 companion skill 在 skills/paperclaw-remote/

7. 测试

类型与构建:

pnpm typecheck
pnpm lint
pnpm build

E2E(Playwright):

pnpm exec playwright install
pnpm test:e2e

已包含:

  • API 合约测试:tests/e2e/api-contract.spec.ts
  • 登录到阅读收藏主链路:tests/e2e/user-journey.spec.ts

8. 备注

  • Magic Link 在本地模式直接返回登录链接,便于开发测试。
  • Pro 支付链路暂未接入真实支付,当前为权限模型与 UI 占位。

参考站点: 站点:https://www.dailybit.cc/

站点构建背景、思路:https://zhuanlan.zhihu.com/p/2007846824799658367

About

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages