@chiimagnus/applebookscli 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,40 +1,39 @@
1
1
  # AppleBooksCLI
2
2
 
3
- [AppleBooksCLI](https://github.com/chiimagnus/AppleBooksCLI) 是一个用于 macOS Apple Books 的命令行工具。你可以直接查询自己的书库、阅读状态、划线与笔记,读取可用的 EPUB/PDF 内容,导出笔记,并在需要时安全地修改笔记或藏书。
3
+ English | [简体中文](README.zh.md)
4
4
 
5
- ## 主要功能
5
+ [AppleBooksCLI](https://github.com/chiimagnus/AppleBooksCLI) is a command-line tool for Apple Books on macOS. It can query your library, reading state, highlights, and notes; read available EPUB/PDF content; export notes; and safely update existing notes or collections when requested.
6
6
 
7
- - 浏览、搜索 Apple Books 书库与阅读状态。
8
- - 查询划线、笔记、最近批注,并按书籍或时间定位。
9
- - 查看单条批注时获得可直接跳回 Apple Books 对应划线位置的链接。
10
- - 读取可用 EPUB 的目录、章节、元数据与批注上下文。
11
- - 提取 PDF 划线与笔记。
12
- - 导出 JSON、CSV、Markdown 或 HTML。
13
- - **安全修改笔记、管理藏书,并在写入前自动备份。**
14
- - 提供标准 `applebookscli` Agent Skill。
7
+ ## Features
15
8
 
16
- ## 系统要求
9
+ - Browse and search the Apple Books library and reading state.
10
+ - Query highlights, notes, and recent annotations, with book- and time-based filtering.
11
+ - Open a single annotation back at its Apple Books location when a deep link is available.
12
+ - Read available EPUB tables of contents, chapters, metadata, and annotation context.
13
+ - Extract PDF highlights and notes.
14
+ - Export JSON, CSV, Markdown, or HTML.
15
+ - **Safely update notes and manage collections, with an automatic backup before writes.**
16
+ - Provide a standard `applebookscli` Agent Skill in English and Chinese.
17
17
 
18
- - 读取 Apple Books 数据时,macOS 可能要求为终端或调用进程授予 Full Disk Access。
19
- - 未下载的 EPUB、DRM 内容或当前系统无法读取的内容会明确提示不可用或能力受限;AppleBooksCLI 不绕过系统保护。
18
+ ## Requirements
20
19
 
21
- ## 安装
20
+ - macOS may require Full Disk Access for the terminal or calling process before Apple Books data can be read.
21
+ - Undownloaded EPUBs, DRM-protected content, or content the current system cannot read are reported as unavailable or capability-limited. AppleBooksCLI does not bypass system protections.
22
+
23
+ ## Install
22
24
 
23
25
  ```sh
24
- # 安装 CLI
25
26
  npm install --global @chiimagnus/applebookscli@latest
26
-
27
- # 安装 SKILL.md;首次安装时由 Agent Skills CLI 选择目标 Agent
28
- CLI_VERSION="$(applebookscli --version)"
29
- npx -y skills@1.5.23 add "chiimagnus/AppleBooksCLI#v${CLI_VERSION}" --skill applebookscli --global
30
-
27
+ npx -y skills@1.5.23 add "chiimagnus/AppleBooksCLI#v$(applebookscli --version)" --skill applebookscli --global
31
28
  ```
32
29
 
33
- 之后通过 npm 升级 CLI 时,若该 Skill 仍由 Agent Skills CLI 管理,npm `postinstall` 会把它自动切到相同的 `v<CLI版本>` tag 并调用官方 updater;没有安装 Skill 的用户不会受到影响。使用 `--ignore-scripts` 会显式关闭这条自动联动。此前手工复制的 Skill 没有 source tracking,只需按上面的标准命令重新安装一次即可接入后续自动更新。
30
+ For the Chinese Skill, replace `applebookscli` with `applebookscli-zh` in the second command.
31
+
32
+ Future npm upgrades keep an Agent Skills CLI-managed Skill on the same CLI release tag automatically. `--ignore-scripts` disables that automatic update.
34
33
 
35
- ## 获取帮助
34
+ ## Help
36
35
 
37
- CLI 自带完整帮助,具体命令与参数以当前安装版本为准:
36
+ The installed CLI is the source of truth for current commands and arguments:
38
37
 
39
38
  ```sh
40
39
  applebookscli --help
@@ -42,68 +41,68 @@ applebookscli <group> --help
42
41
  applebookscli <group> <subcommand> --help
43
42
  ```
44
43
 
45
- ## 快速开始
44
+ ## Quick start
46
45
 
47
46
  ```sh
48
- # 浏览书库
47
+ # Browse the library
49
48
  applebookscli books list
50
49
 
51
- # 查看正在阅读的书
50
+ # Show books currently in progress
52
51
  applebookscli reading in-progress
53
52
 
54
- # 查看最近创建的批注
53
+ # Show recently created annotations
55
54
  applebookscli annotations recent
56
55
 
57
- # 查看书库统计
56
+ # Show library statistics
58
57
  applebookscli stats
59
58
  ```
60
59
 
61
- 需要结构化结果时,大多数查询命令支持 `--json`:
60
+ Most query commands support `--json` when structured output is needed:
62
61
 
63
62
  ```sh
64
63
  applebookscli books list --json
65
64
  applebookscli annotations recent --json
66
65
  ```
67
66
 
68
- ## 笔记、划线与定位
67
+ ## Notes, highlights, and locations
69
68
 
70
- 先找到批注,再用 UUID 查看具体内容:
69
+ Find an annotation first, then inspect it by UUID:
71
70
 
72
71
  ```sh
73
72
  applebookscli annotations recent --json
74
73
  applebookscli annotations get <annotation-uuid>
75
74
  ```
76
75
 
77
- 单条批注结果会包含对应的 `appleBooksURL`,可以直接跳回 Apple Books 中该书或对应划线位置。
76
+ A single-annotation result includes an `appleBooksURL` when available so you can jump back to the book or highlight location in Apple Books.
78
77
 
79
- 如果需要查看划线前后的正文:
78
+ To read text around a highlight:
80
79
 
81
80
  ```sh
82
81
  applebookscli content context <annotation-uuid>
83
82
  ```
84
83
 
85
- 搜索、按书筛选、颜色、时间范围等能力以当前帮助为准:
84
+ Use the current help for search, book filters, colors, and time ranges:
86
85
 
87
86
  ```sh
88
87
  applebookscli annotations --help
89
88
  ```
90
89
 
91
- ## EPUB PDF
90
+ ## EPUB and PDF
92
91
 
93
92
  ```sh
94
- # EPUB 内容相关命令
93
+ # EPUB content commands
95
94
  applebookscli content --help
96
95
 
97
- # 查看 PDF inventory
96
+ # List PDF inventory
98
97
  applebookscli pdf list
99
98
 
100
- # 提取某个 PDF highlights
99
+ # Extract highlights from a PDF
101
100
  applebookscli pdf highlights --help
102
101
  ```
103
102
 
104
- EPUB 在读取正文前会先检查本地 materialization 状态,不主动触发 iCloud hydration,也不会绕过 DRMPDF 只处理当前可解析为可读本地文件的 source;对 iCloud placeholder non-hydrating 行为尚未建立等价保证。
103
+ Before reading EPUB text, AppleBooksCLI checks local materialization state without intentionally triggering iCloud hydration and does not bypass DRM. PDF commands only operate on sources that currently resolve to readable local files; equivalent non-hydrating behavior for iCloud placeholders has not been established.
105
104
 
106
- ## 导出
105
+ ## Export
107
106
 
108
107
  ```sh
109
108
  # Markdown
@@ -113,15 +112,15 @@ applebookscli export --format markdown --output ~/Desktop/apple-books.md
113
112
  applebookscli export --format json --output ~/Desktop/apple-books.json
114
113
  ```
115
114
 
116
- 还支持 CSV、HTML、按书分组、筛选划线/笔记、Obsidian 格式、封面与完整笔记归档等选项。有 CFI EPUB 批注在 HTML/Markdown 中会把 `Location` 本身做成 Apple Books deep link;无 CFI 时退化为书籍级链接。JSON/CSV 保留对应 `appleBooksURL`:
115
+ CSV, HTML, grouping by book, highlight/note filtering, Obsidian formatting, covers, and complete-notes archives are also available. EPUB annotations with a CFI make the `Location` text itself an Apple Books deep link in HTML/Markdown; without a CFI, the link falls back to the book level. JSON/CSV preserve the corresponding `appleBooksURL`:
117
116
 
118
117
  ```sh
119
118
  applebookscli export --help
120
119
  ```
121
120
 
122
- ## 安全写入
121
+ ## Safe writes
123
122
 
124
- AppleBooksCLI 可以修改已有笔记和管理藏书。写入前会自动创建备份,并在写入后验证结果;普通查询不会隐式修改 Apple Books 数据。
123
+ AppleBooksCLI can update existing notes and manage collections. It creates a backup before writing and verifies the result afterward. Ordinary queries do not implicitly modify Apple Books data.
125
124
 
126
125
  ```sh
127
126
  applebookscli annotations update-note --help
@@ -129,13 +128,13 @@ applebookscli collections --help
129
128
  applebookscli backups --help
130
129
  ```
131
130
 
132
- 单条 collection / annotation mutation 可加 `--sync`,在本地 commit + cloud projection 后等待当前 Mac CloudKit acknowledgement:
131
+ A single collection or annotation mutation can add `--sync` to wait for current-Mac CloudKit acknowledgement after the local commit and cloud projection:
133
132
 
134
133
  ```sh
135
134
  applebookscli collections create "My Shelf" --sync --json
136
135
  ```
137
136
 
138
- 连续多条写入时,优先正常提交各 mutation,最后只 flush 一次:
137
+ For several writes, commit the normal mutations first and flush once at the end:
139
138
 
140
139
  ```sh
141
140
  applebookscli collections create "Shelf A" --json
@@ -143,19 +142,19 @@ applebookscli annotations update-note <annotation-uuid> --note "New note" --json
143
142
  applebookscli sync --json
144
143
  ```
145
144
 
146
- `sync` 只处理已存在的 pending collection/member/annotation cloud records;无 pending 时不触发生命周期。acknowledgement 只证明**当前 Mac** 已完成 Apple Books CloudKit upload,不等于另一台设备已经显示。post-commit `cloud_sync_failed` 不能触发自动重试;BKLibrary restore 也不等同于可逐条 flush cloud mutation。
145
+ `sync` only processes already pending collection/member/annotation cloud records and does not trigger the lifecycle when none are pending. Acknowledgement proves only that **this Mac** completed the Apple Books CloudKit upload; it does not prove that another device already displays the change. A post-commit `cloud_sync_failed` must not cause an automatic mutation retry, and restoring a BKLibrary snapshot is not equivalent to replaying individually flushable cloud mutations.
147
146
 
148
- ## 可选配置
147
+ ## Optional configuration
149
148
 
150
- 大多数用户不需要配置文件。只有需要指定额外的 EPUB 目录,或给历史批注补充书名/作者信息时,才需要 `~/.config/applebookscli/config.json`。
149
+ Most users do not need a configuration file. `~/.config/applebookscli/config.json` is only needed for an additional EPUB directory or to supplement title/author metadata for historical annotations.
151
150
 
152
- 示例见 [`Config/applebookscli.example.json`](Config/applebookscli.example.json)
151
+ See [`Config/applebookscli.example.json`](Config/applebookscli.example.json).
153
152
 
154
- ## 开发与维护
153
+ ## Development and maintenance
155
154
 
156
- 架构、CLI contract、写入安全、发布流程和其它维护者文档从 [`docs/index.md`](docs/index.md) 开始。
155
+ Start with [`docs/index.md`](docs/index.md) for architecture, CLI contract, write safety, release workflow, and other maintainer documentation.
157
156
 
158
157
  ## License
159
158
 
160
- AppleBooksCLI 使用 [AGPLv3 LICENSE](LICENSE)
161
- 第三方 notice 与许可证文本见 [`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md) [`ThirdPartyLicenses/`](ThirdPartyLicenses/)
159
+ AppleBooksCLI is licensed under the [AGPLv3 LICENSE](LICENSE).
160
+ Third-party notices and license texts are in [`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md) and [`ThirdPartyLicenses/`](ThirdPartyLicenses/).
package/README.zh.md ADDED
@@ -0,0 +1,160 @@
1
+ # AppleBooksCLI
2
+
3
+ [English](README.md) | 简体中文
4
+
5
+ [AppleBooksCLI](https://github.com/chiimagnus/AppleBooksCLI) 是一个用于 macOS Apple Books 的命令行工具。你可以直接查询自己的书库、阅读状态、划线与笔记,读取可用的 EPUB/PDF 内容,导出笔记,并在需要时安全地修改笔记或藏书。
6
+
7
+ ## 主要功能
8
+
9
+ - 浏览、搜索 Apple Books 书库与阅读状态。
10
+ - 查询划线、笔记、最近批注,并按书籍或时间定位。
11
+ - 查看单条批注时获得可直接跳回 Apple Books 对应划线位置的链接。
12
+ - 读取可用 EPUB 的目录、章节、元数据与批注上下文。
13
+ - 提取 PDF 划线与笔记。
14
+ - 导出 JSON、CSV、Markdown 或 HTML。
15
+ - **安全修改笔记、管理藏书,并在写入前自动备份。**
16
+ - 提供标准 `applebookscli` Agent Skill,并提供英文/中文两个版本。
17
+
18
+ ## 系统要求
19
+
20
+ - 读取 Apple Books 数据时,macOS 可能要求为终端或调用进程授予 Full Disk Access。
21
+ - 未下载的 EPUB、DRM 内容或当前系统无法读取的内容会明确提示不可用或能力受限;AppleBooksCLI 不绕过系统保护。
22
+
23
+ ## 安装
24
+
25
+ ```sh
26
+ npm install --global @chiimagnus/applebookscli@latest
27
+ npx -y skills@1.5.23 add "chiimagnus/AppleBooksCLI#v$(applebookscli --version)" --skill applebookscli-zh --global
28
+ ```
29
+
30
+ 英文 Skill 把第二条命令里的 `applebookscli-zh` 改成 `applebookscli` 即可。
31
+
32
+ 以后通过 npm 升级 CLI 时,由 Agent Skills CLI 管理的 Skill 会自动跟随到相同的 CLI release tag。使用 `--ignore-scripts` 会关闭这项自动更新。
33
+
34
+ ## 获取帮助
35
+
36
+ CLI 自带完整帮助,具体命令与参数以当前安装版本为准:
37
+
38
+ ```sh
39
+ applebookscli --help
40
+ applebookscli <group> --help
41
+ applebookscli <group> <subcommand> --help
42
+ ```
43
+
44
+ ## 快速开始
45
+
46
+ ```sh
47
+ # 浏览书库
48
+ applebookscli books list
49
+
50
+ # 查看正在阅读的书
51
+ applebookscli reading in-progress
52
+
53
+ # 查看最近创建的批注
54
+ applebookscli annotations recent
55
+
56
+ # 查看书库统计
57
+ applebookscli stats
58
+ ```
59
+
60
+ 需要结构化结果时,大多数查询命令支持 `--json`:
61
+
62
+ ```sh
63
+ applebookscli books list --json
64
+ applebookscli annotations recent --json
65
+ ```
66
+
67
+ ## 笔记、划线与定位
68
+
69
+ 先找到批注,再用 UUID 查看具体内容:
70
+
71
+ ```sh
72
+ applebookscli annotations recent --json
73
+ applebookscli annotations get <annotation-uuid>
74
+ ```
75
+
76
+ 单条批注结果会包含对应的 `appleBooksURL`,可以直接跳回 Apple Books 中该书或对应划线位置。
77
+
78
+ 如果需要查看划线前后的正文:
79
+
80
+ ```sh
81
+ applebookscli content context <annotation-uuid>
82
+ ```
83
+
84
+ 搜索、按书筛选、颜色、时间范围等能力以当前帮助为准:
85
+
86
+ ```sh
87
+ applebookscli annotations --help
88
+ ```
89
+
90
+ ## EPUB 与 PDF
91
+
92
+ ```sh
93
+ # EPUB 内容相关命令
94
+ applebookscli content --help
95
+
96
+ # 查看 PDF inventory
97
+ applebookscli pdf list
98
+
99
+ # 提取某个 PDF 的 highlights
100
+ applebookscli pdf highlights --help
101
+ ```
102
+
103
+ EPUB 在读取正文前会先检查本地 materialization 状态,不主动触发 iCloud hydration,也不会绕过 DRM。PDF 只处理当前可解析为可读本地文件的 source;对 iCloud placeholder 的 non-hydrating 行为尚未建立等价保证。
104
+
105
+ ## 导出
106
+
107
+ ```sh
108
+ # Markdown
109
+ applebookscli export --format markdown --output ~/Desktop/apple-books.md
110
+
111
+ # JSON
112
+ applebookscli export --format json --output ~/Desktop/apple-books.json
113
+ ```
114
+
115
+ 还支持 CSV、HTML、按书分组、筛选划线/笔记、Obsidian 格式、封面与完整笔记归档等选项。有 CFI 的 EPUB 批注在 HTML/Markdown 中会把 `Location` 本身做成 Apple Books deep link;无 CFI 时退化为书籍级链接。JSON/CSV 保留对应 `appleBooksURL`:
116
+
117
+ ```sh
118
+ applebookscli export --help
119
+ ```
120
+
121
+ ## 安全写入
122
+
123
+ AppleBooksCLI 可以修改已有笔记和管理藏书。写入前会自动创建备份,并在写入后验证结果;普通查询不会隐式修改 Apple Books 数据。
124
+
125
+ ```sh
126
+ applebookscli annotations update-note --help
127
+ applebookscli collections --help
128
+ applebookscli backups --help
129
+ ```
130
+
131
+ 单条 collection / annotation mutation 可加 `--sync`,在本地 commit + cloud projection 后等待当前 Mac 的 CloudKit acknowledgement:
132
+
133
+ ```sh
134
+ applebookscli collections create "My Shelf" --sync --json
135
+ ```
136
+
137
+ 连续多条写入时,优先正常提交各 mutation,最后只 flush 一次:
138
+
139
+ ```sh
140
+ applebookscli collections create "Shelf A" --json
141
+ applebookscli annotations update-note <annotation-uuid> --note "New note" --json
142
+ applebookscli sync --json
143
+ ```
144
+
145
+ `sync` 只处理已存在的 pending collection/member/annotation cloud records;无 pending 时不触发生命周期。acknowledgement 只证明**当前 Mac** 已完成 Apple Books CloudKit upload,不等于另一台设备已经显示。post-commit `cloud_sync_failed` 不能触发自动重试;BKLibrary restore 也不等同于可逐条 flush 的 cloud mutation。
146
+
147
+ ## 可选配置
148
+
149
+ 大多数用户不需要配置文件。只有需要指定额外的 EPUB 目录,或给历史批注补充书名/作者信息时,才需要 `~/.config/applebookscli/config.json`。
150
+
151
+ 示例见 [`Config/applebookscli.example.json`](Config/applebookscli.example.json)。
152
+
153
+ ## 开发与维护
154
+
155
+ 架构、CLI contract、写入安全、发布流程和其它维护者文档从 [`docs/index.md`](docs/index.md) 开始。
156
+
157
+ ## License
158
+
159
+ AppleBooksCLI 使用 [AGPLv3 LICENSE](LICENSE)。
160
+ 第三方 notice 与许可证文本见 [`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md) 和 [`ThirdPartyLicenses/`](ThirdPartyLicenses/)。
package/bin/applebookscli CHANGED
Binary file
@@ -3,16 +3,16 @@ import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  import { spawn } from "node:child_process";
5
5
 
6
- const skillName = "applebookscli";
6
+ const skillNames = ["applebookscli", "applebookscli-zh"];
7
7
  const source = "chiimagnus/AppleBooksCLI";
8
8
  const sourceURL = "https://github.com/chiimagnus/AppleBooksCLI.git";
9
9
  const skillsVersion = "1.5.23";
10
10
 
11
- async function runUpdater() {
11
+ async function runUpdater(names) {
12
12
  return new Promise((resolve, reject) => {
13
13
  const child = spawn(
14
14
  "npx",
15
- ["-y", `skills@${skillsVersion}`, "update", skillName, "-g", "-y"],
15
+ ["-y", `skills@${skillsVersion}`, "update", ...names, "-g", "-y"],
16
16
  {
17
17
  stdio: "ignore",
18
18
  env: { ...process.env, DISABLE_TELEMETRY: "1" },
@@ -40,25 +40,24 @@ async function main() {
40
40
  }
41
41
 
42
42
  const lock = JSON.parse(rawLock);
43
- const entry = lock.skills?.[skillName];
44
- if (
45
- !entry ||
46
- entry.sourceType !== "github" ||
47
- (entry.source !== source && entry.sourceUrl !== sourceURL)
48
- ) {
49
- return;
50
- }
43
+ const managed = skillNames.filter((name) => {
44
+ const entry = lock.skills?.[name];
45
+ return entry?.sourceType === "github" &&
46
+ (entry.source === source || entry.sourceUrl === sourceURL);
47
+ });
48
+ if (managed.length === 0) return;
51
49
 
52
50
  const targetRef = `v${packageJSON.version}`;
53
- if (entry.ref !== targetRef) {
51
+ const changed = managed.some((name) => lock.skills[name].ref !== targetRef);
52
+ if (changed) {
54
53
  const mode = (await stat(lockPath)).mode & 0o777;
55
54
  const temporary = `${lockPath}.${process.pid}.tmp`;
56
- entry.ref = targetRef;
55
+ for (const name of managed) lock.skills[name].ref = targetRef;
57
56
  await writeFile(temporary, `${JSON.stringify(lock, null, 2)}\n`, { mode });
58
57
  await rename(temporary, lockPath);
59
58
  }
60
59
 
61
- const code = await runUpdater();
60
+ const code = await runUpdater(managed);
62
61
  if (code !== 0) {
63
62
  console.warn(
64
63
  `applebookscli: Skill update to ${targetRef} did not complete; Agent Skills CLI can retry later.`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chiimagnus/applebookscli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Native Apple Books CLI for macOS on Apple Silicon.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
@@ -27,6 +27,7 @@
27
27
  "bin/applebookscli",
28
28
  "libexec/applebookscli/applebookscli-pdf-worker",
29
29
  "libexec/applebookscli/sync-installed-skill.mjs",
30
+ "README.zh.md",
30
31
  "LICENSE",
31
32
  "THIRD_PARTY_NOTICES.md",
32
33
  "ThirdPartyLicenses"