diff --git a/PRIVACY.md b/PRIVACY.md index 95d14b4d..7651cd6e 100644 --- a/PRIVACY.md +++ b/PRIVACY.md @@ -7,6 +7,7 @@ MoonDigest 的隐私政策。适用于 Chrome 应用商店版和 GitHub 发布 - B站 和 YouTube 视频页上的网页脚本(包括你用的 AI agent)可以向插件要这个视频的信息、字幕、章节和热门评论,这些都是网站本来就给这个页面的数据。 - 设置 → MCP 的「允许 Agent 使用我的 B站和 YouTube 账号」默认关闭。打开后,插件会连本机 `127.0.0.1:47823` 上的 MCP 服务(`mcp/`),你在本机运行的 AI 工具就能通过它用你的登录读和改下面这些。见 README 的「给 AI agent 用」。 - 能读:B站 和 YouTube 的视频搜索结果;视频的信息、字幕、章节、热门评论和画面;你 B站 的收藏夹和里面的视频、稍后再看、关注和分组、观看历史,连同分拣台的标签、备注、AI 判断和判断标准;你 YouTube 的稍后观看、赞过的视频、订阅、历史记录和 YouTube 播放列表。 + - 你允许读取网页以后,还能读 B站 和 YouTube 之外的任意网页:页面上主视频的标准字幕和画面,没有视频时是网页正文(最多 10 万字)。网页在插件自己开的标签页里打开,用的是你浏览器里的登录,所以登录后才看得到的网页也读得到。 - 能改:在 B站 移动、复制、取消收藏视频,清理失效视频,新建、改名、删除收藏夹,改收藏夹的公开或私密;把视频加进或移出 B站稍后再看、YouTube 稍后观看和你的 YouTube 播放列表;分拣台的 AI 判断、保留、备注、标签、判断标准,以及勾选哪些收藏夹。 - 修改直接执行,不逐次问你。对 B站收藏夹、稍后再看、YouTube 播放列表、分拣台结果和分拣范围的每次修改都记在浏览器本地(B站和 YouTube 上的修改留最近 100 次,本地的修改另留最近 100 次),可以在设置 → MCP 的「Agent 最近的修改」或分拣台里撤销。撤销有做不到的情况(如已删除的收藏夹),见 [mcp/README.md](mcp/README.md) 的「安全模型」。 - 这些数据只交给本机的 MCP 服务,再由它交给你运行的 AI 工具,MoonDigest 不把它们发往别处。AI 工具之后把内容发给哪个模型服务,由那个工具决定。API Key 和 AI 对话不会交出去。开关关着时插件不连 MCP 服务。 diff --git a/docs/AGENT.md b/docs/AGENT.md index 4311ab3f..40b3dec6 100644 --- a/docs/AGENT.md +++ b/docs/AGENT.md @@ -2,7 +2,7 @@ How AI agents use MoonDigest: page messages for agents that drive the browser (the skill, `skills/moondigest/SKILL.md`), and a local MCP server (`mcp/`) for any MCP client. The page messages read the video of the page they run in and nothing else: no search, nothing of the user's account, no write. Everything else goes through the MCP server, behind one switch (§2): a video search (`search`), the user's own Bilibili favorites, follows and watch history with their 分拣 tags, notes and AI verdicts (`favorites` / `follows` / `history`), the user's collections on other sites (`collection`), and the writes: Bilibili's favorites (`favWrite`), the 分拣台's local results and 判断标准 (`triage`, `triageSettings`), which folders the 分拣台 keeps a copy of (`sync`), and the collections (`collectionWrite`). No write asks the user first. Safety is undo: every `favWrite`, `collectionWrite`, `triage`, 判断标准 change and untick is journaled and reversed by `undo`, from the tool, the 分拣台 (U) or 设置 → MCP. Never API keys or AI conversations. For sites beyond the Bilibili 分拣台 MoonDigest has no pages of its own: the agent is the UI. -Supported pages: Bilibili video pages (`www.bilibili.com/video/…`, `/bangumi/play/…`, `/list/…`, `/festival/…`) and YouTube watch pages (`www.youtube.com/watch?v=…`). The MCP server reads the sites registered in `extension/agent-sites/` (§5); the page messages only these two. +Supported pages: Bilibili video pages (`www.bilibili.com/video/…`, `/bangumi/play/…`, `/list/…`, `/festival/…`) and YouTube watch pages (`www.youtube.com/watch?v=…`). The MCP server reads the sites registered in `extension/agent-sites/` (§5), among them `web`: any other http(s) page, once the user has allowed reading web pages; the page messages only these two. ## 1. Page messages (what the skill uses) @@ -84,7 +84,9 @@ Server → extension: `{ id, method, params }`. Extension → server: `{ id, ok: `get` on a Bilibili URL that names its video (`/video/BV…`, `/video/av…`, `/list/…?bvid=`) opens no tab (`extension/agent-video.js`): the service worker asks Bilibili through the 分拣台's channel with the functions the 细看 reads with, about a second a video, so the result is always the requested video's. Its `data` is `moondigest-get`'s with `url` the requested one, plus `zone` (Bilibili's 分区 name, may be `""`) and `tags` (the video's tags). `brief: true` is for judging many videos cheaply: `subtitle.segments` only those starting in the first 120 s, `chapters: []`, `comments: []` (up to 5 hot comments when there is no subtitle), and `brief: true` in `data`; a `get` that goes through a tab ignores `brief`. These reads run one at a time, 300 ms apart; one still queued at the deadline is `TIMEOUT`, Bilibili's risk control is `THROTTLED`. A subtitle listed by Bilibili's old `x/player/v2` (asked only when `x/player/wbi/v2` fails; it can hand out another video's) is used only when it fits the video's length, else `subtitle.missing` says so. -Every other `get` (`/bangumi/`, `/festival/`, `/list/` without `bvid`, YouTube) and every `frame` find a tab already showing that video (same site and video id; Bilibili `/video/` also the part `p`, default 1; `/list/` and `/festival/` match on the `bvid` query, else the path; `/bangumi/` on its ep/ss id). A discarded tab (no content script until shown) is never picked. Else they load `url` in the extension's own tab: at most one, opened muted with `active: false` on first need and navigated to the next video afterwards, so calls never pile up tabs. Calls that need it run one at a time, and a call still queued when the server has given up (55 s after it arrived) is dropped with `TIMEOUT` instead of loading anything. A tab that no call has answered in yet counts as the requested video only while it is still loading. The extension waits up to 50 s for that tab's content script to answer (a missing reply or one without `ok` means not loaded yet), then fails with `TIMEOUT`, before the server's own 60 s. The extension rejects any `url` that is not a supported page with code `BAD_URL`. Then they run the same handler the page messages run, in that tab's content script (`chrome.tabs.sendMessage`), so both paths return identical results. A `get` whose URL names a BV id or YouTube id is not answered with another video's data: when the page's `videoId` differs (the tab's URL changed before its page did) the page is asked again every 500 ms, until the deadline (`TIMEOUT`). A `frame` that comes back `TAB_HIDDEN` (Chrome loads no media in a tab never shown) is asked again with that tab in front, and the tab that was in front of its window is brought back afterwards, unless the user switched tabs meanwhile; `get` never switches tabs. Timeout: 60 s per call, code `TIMEOUT`. +Every other `get` (`/bangumi/`, `/festival/`, `/list/` without `bvid`, YouTube) and every `frame` find a tab already showing that video (same site and video id; Bilibili `/video/` also the part `p`, default 1; `/list/` and `/festival/` match on the `bvid` query, else the path; `/bangumi/` on its ep/ss id). A discarded tab (no content script until shown) is never picked. Else they load `url` in the extension's own tab: at most one, opened muted with `active: false` on first need and navigated to the next video afterwards, so calls never pile up tabs. Calls that need it run one at a time, and a call still queued when the server has given up (55 s after it arrived) is dropped with `TIMEOUT` instead of loading anything. A tab that no call has answered in yet counts as the requested video only while it is still loading. The extension waits up to 50 s for that tab's content script to answer (a missing reply or one without `ok` means not loaded yet), then fails with `TIMEOUT`, before the server's own 60 s. The extension rejects any `url` no site reads with code `BAD_URL`: one that is not http(s), or a Bilibili or YouTube page other than those above. Then they run the same handler the page messages run, in that tab's content script (`chrome.tabs.sendMessage`), so both paths return identical results. A `get` whose URL names a BV id or YouTube id is not answered with another video's data: when the page's `videoId` differs (the tab's URL changed before its page did) the page is asked again every 500 ms, until the deadline (`TIMEOUT`). A `frame` that comes back `TAB_HIDDEN` (Chrome loads no media in a tab never shown) is asked again with that tab in front, and the tab that was in front of its window is brought back afterwards, unless the user switched tabs meanwhile; `get` never switches tabs. Timeout: 60 s per call, code `TIMEOUT`. + +A site whose adapter reads the page itself (§5, `read` a function) is read only in the extension's own tab: the user's tabs are never used. It fails with `NO_ACCESS` until the user has allowed the site's origins. Its `get` `data` is what `read` returned, with `site` set to the site's id. Its `frame` injects `agent-page.js` into the tab's isolated world and runs the same frame as above (`MdgAgentPage.frame`). `search` opens no tab: the service worker fetches with the user's cookies. Bilibili: the WBI-signed `api.bilibili.com/x/web-interface/wbi/search/type?search_type=video` through the same channel as 分拣台 (`triageBiliGet`). YouTube: the `www.youtube.com/results?search_query=…` page, read from its `ytInitialData`; only the result list's own videos, no shorts, ads, channels, playlists or shelves. YouTube has page 1 only (about 20 videos); a `page` above 1 is an error. Searches run one at a time, at least 2 s apart; one still queued at the call's deadline is dropped with `TIMEOUT`. HTTP 412, B站's risk-control codes and YouTube's 429 are `THROTTLED`. No results is `items: []`, not an error. @@ -160,7 +162,8 @@ MdgAgentSites.register({ const m = /^\/v\/(\w+)$/.exec(u.pathname); return u.hostname === "www.demo.com" && m ? `${m[1]}:` : null; }, - read: "content", // the content script (agent-page.js) answers in the page + read: "content", // the content script (agent-page.js) answers in the page; or a function, see below + fallback: false, // optional: true for the one site the registry asks last (web) search: async (query, page) => [], // optional: §2's search items, throw an Error with code THROTTLED when rate-limited // optional, all four together: the user's collections (§2 collection / collectionWrite) collections: { saved: ["add", "remove"], history: [] }, // kind → the writes it takes ([] read only) @@ -174,4 +177,7 @@ MdgAgentSites.register({ - `key`: the registry prefixes the id, so two URLs of one video must give the same `itemId:part`. Two keys equal means the same video for tab reuse. - `read: "content"`: a content script (`agent-page.js`) answers in the page. It needs a manifest entry and host access, which the manifest grants for Bilibili and YouTube. - `list`, `has`, `write`: agent-collections.js has checked the kind, the op and the items before; the adapter writes one item per `write` and never batches, retries or skips (the rules in §2 are agent-collections.js's). Throw an Error with code `THROTTLED` or `NOT_LOGGED_IN` to stop a batch. To run in the site's page, `MdgAgentBridge.inSitePage(site, url, ready, func, args, deadline)` runs `func(...args)` once in the MAIN world of the bridge's own tab on a page of `site` (loading `url` there when it shows another site), after `ready()` there returns `{ ok: true }`. Both are serialized (`chrome.scripting.executeScript`): no closures, no extension globals; write them as arrows, since a method shorthand's source does not compile there. One that does not settle by the deadline is `TIMEOUT`, and the own tab goes to `about:blank`. `func` runs once even when it fails, so it should catch and return its errors. +- `read` a function: `chrome.scripting.executeScript({ func: read, args: [url] })` in the bridge's own tab, in the page's isolated world: it reads the DOM, not the page's globals, and the page cannot change what it runs with. It is serialized: no closures, no extension globals, and its source must compile alone, so a function expression (`read: async function read(url) {}`), not the method shorthand. It returns §1's `get` data (missing fields read as unknown), or a falsy value while the page is not ready, and is asked again every 0.5 s for up to 50 s. A throw counts as not ready. +- Host access: the manifest grants only Bilibili and YouTube; other sites are in `optional_host_permissions` (every http(s) site), so a new site needs no manifest change. Until the user allows its origins the site answers `NO_ACCESS`. Today the only way to allow them is the side panel's grant for reading web pages, which allows every site at once; a per-site 允许 in 设置 is not built yet. +- `web` (`agent-sites/web.js`) is the fallback: any http(s) page no other site claims, keyed by its whole URL (the hash too: it may be the route). It declines `bilibili.com`, `b23.tv`, `youtube.com` and `youtu.be` hosts, so a page there that their adapters do not read stays `BAD_URL`. Its `read` returns `kind: "video"` with the largest `