@chiimagnus/applebookscli 0.1.6 → 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 +55 -78
- package/README.zh.md +160 -0
- package/bin/applebookscli +0 -0
- package/libexec/applebookscli/applebookscli-pdf-worker +0 -0
- package/libexec/applebookscli/sync-installed-skill.mjs +74 -0
- package/package.json +6 -5
- package/share/applebookscli/skill/applebookscli/SKILL.md +0 -36
package/README.md
CHANGED
|
@@ -1,108 +1,108 @@
|
|
|
1
1
|
# AppleBooksCLI
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
8
|
-
- 查询划线、笔记、最近批注,并按书籍或时间定位。
|
|
9
|
-
- 查看单条批注时获得可直接跳回 Apple Books 对应划线位置的链接。
|
|
10
|
-
- 读取可用 EPUB 的目录、章节、元数据与批注上下文。
|
|
11
|
-
- 提取 PDF 划线与笔记。
|
|
12
|
-
- 导出 JSON、CSV、Markdown 或 HTML。
|
|
13
|
-
- 安全修改笔记、管理藏书,并在写入前自动备份。
|
|
14
|
-
- 安装随 CLI 一起分发的 `applebookscli` Skill,供 Codex/AI 直接使用。
|
|
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
|
-
|
|
19
|
-
- npm 发布的预编译版本目前支持 Apple Silicon(arm64)。
|
|
20
|
-
- 读取 Apple Books 数据时,macOS 可能要求为终端或调用进程授予 Full Disk Access。
|
|
21
|
-
- 未下载的 EPUB、DRM 内容或当前系统无法读取的内容会明确提示不可用或能力受限;AppleBooksCLI 不绕过系统保护。
|
|
18
|
+
## Requirements
|
|
22
19
|
|
|
23
|
-
|
|
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.
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
## Install
|
|
26
24
|
|
|
27
25
|
```sh
|
|
28
|
-
npm install --global @chiimagnus/applebookscli
|
|
29
|
-
applebookscli --version
|
|
26
|
+
npm install --global @chiimagnus/applebookscli@latest
|
|
27
|
+
npx -y skills@1.5.23 add "chiimagnus/AppleBooksCLI#v$(applebookscli --version)" --skill applebookscli --global
|
|
30
28
|
```
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
For the Chinese Skill, replace `applebookscli` with `applebookscli-zh` in the second command.
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
Future npm upgrades keep an Agent Skills CLI-managed Skill on the same CLI release tag automatically. `--ignore-scripts` disables that automatic update.
|
|
33
|
+
|
|
34
|
+
## Help
|
|
37
35
|
|
|
38
|
-
|
|
36
|
+
The installed CLI is the source of truth for current commands and arguments:
|
|
39
37
|
|
|
40
38
|
```sh
|
|
41
|
-
|
|
39
|
+
applebookscli --help
|
|
40
|
+
applebookscli <group> --help
|
|
41
|
+
applebookscli <group> <subcommand> --help
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
##
|
|
44
|
+
## Quick start
|
|
45
45
|
|
|
46
46
|
```sh
|
|
47
|
-
#
|
|
47
|
+
# Browse the library
|
|
48
48
|
applebookscli books list
|
|
49
49
|
|
|
50
|
-
#
|
|
50
|
+
# Show books currently in progress
|
|
51
51
|
applebookscli reading in-progress
|
|
52
52
|
|
|
53
|
-
#
|
|
53
|
+
# Show recently created annotations
|
|
54
54
|
applebookscli annotations recent
|
|
55
55
|
|
|
56
|
-
#
|
|
56
|
+
# Show library statistics
|
|
57
57
|
applebookscli stats
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
Most query commands support `--json` when structured output is needed:
|
|
61
61
|
|
|
62
62
|
```sh
|
|
63
63
|
applebookscli books list --json
|
|
64
64
|
applebookscli annotations recent --json
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
##
|
|
67
|
+
## Notes, highlights, and locations
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
Find an annotation first, then inspect it by UUID:
|
|
70
70
|
|
|
71
71
|
```sh
|
|
72
72
|
applebookscli annotations recent --json
|
|
73
73
|
applebookscli annotations get <annotation-uuid>
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
A single-annotation result includes an `appleBooksURL` when available so you can jump back to the book or highlight location in Apple Books.
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
To read text around a highlight:
|
|
79
79
|
|
|
80
80
|
```sh
|
|
81
81
|
applebookscli content context <annotation-uuid>
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
Use the current help for search, book filters, colors, and time ranges:
|
|
85
85
|
|
|
86
86
|
```sh
|
|
87
87
|
applebookscli annotations --help
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
## EPUB
|
|
90
|
+
## EPUB and PDF
|
|
91
91
|
|
|
92
92
|
```sh
|
|
93
|
-
# EPUB
|
|
93
|
+
# EPUB content commands
|
|
94
94
|
applebookscli content --help
|
|
95
95
|
|
|
96
|
-
#
|
|
96
|
+
# List PDF inventory
|
|
97
97
|
applebookscli pdf list
|
|
98
98
|
|
|
99
|
-
#
|
|
99
|
+
# Extract highlights from a PDF
|
|
100
100
|
applebookscli pdf highlights --help
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
-
EPUB
|
|
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.
|
|
104
104
|
|
|
105
|
-
##
|
|
105
|
+
## Export
|
|
106
106
|
|
|
107
107
|
```sh
|
|
108
108
|
# Markdown
|
|
@@ -112,15 +112,15 @@ applebookscli export --format markdown --output ~/Desktop/apple-books.md
|
|
|
112
112
|
applebookscli export --format json --output ~/Desktop/apple-books.json
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
|
|
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`:
|
|
116
116
|
|
|
117
117
|
```sh
|
|
118
118
|
applebookscli export --help
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
##
|
|
121
|
+
## Safe writes
|
|
122
122
|
|
|
123
|
-
AppleBooksCLI
|
|
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.
|
|
124
124
|
|
|
125
125
|
```sh
|
|
126
126
|
applebookscli annotations update-note --help
|
|
@@ -128,13 +128,13 @@ applebookscli collections --help
|
|
|
128
128
|
applebookscli backups --help
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
A single collection or annotation mutation can add `--sync` to wait for current-Mac CloudKit acknowledgement after the local commit and cloud projection:
|
|
132
132
|
|
|
133
133
|
```sh
|
|
134
134
|
applebookscli collections create "My Shelf" --sync --json
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
For several writes, commit the normal mutations first and flush once at the end:
|
|
138
138
|
|
|
139
139
|
```sh
|
|
140
140
|
applebookscli collections create "Shelf A" --json
|
|
@@ -142,42 +142,19 @@ applebookscli annotations update-note <annotation-uuid> --note "New note" --json
|
|
|
142
142
|
applebookscli sync --json
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
-
`sync`
|
|
146
|
-
|
|
147
|
-
## 安装 AppleBooksCLI Skill
|
|
148
|
-
|
|
149
|
-
npm 包中包含配套的 `applebookscli` Skill:
|
|
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.
|
|
150
146
|
|
|
151
|
-
|
|
152
|
-
applebookscli skill install
|
|
153
|
-
```
|
|
147
|
+
## Optional configuration
|
|
154
148
|
|
|
155
|
-
|
|
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.
|
|
156
150
|
|
|
157
|
-
|
|
158
|
-
applebookscli skill install --force
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
## 可选配置
|
|
162
|
-
|
|
163
|
-
大多数用户不需要配置文件。只有需要指定额外的 EPUB 目录,或给历史批注补充书名/作者信息时,才需要 `~/.config/applebookscli/config.json`。
|
|
164
|
-
|
|
165
|
-
示例见 [`Config/applebookscli.example.json`](Config/applebookscli.example.json)。
|
|
166
|
-
|
|
167
|
-
## 获取帮助
|
|
168
|
-
|
|
169
|
-
CLI 自带完整帮助,具体命令与参数以当前安装版本为准:
|
|
170
|
-
|
|
171
|
-
```sh
|
|
172
|
-
applebookscli --help
|
|
173
|
-
applebookscli <group> --help
|
|
174
|
-
applebookscli <group> <subcommand> --help
|
|
175
|
-
```
|
|
151
|
+
See [`Config/applebookscli.example.json`](Config/applebookscli.example.json).
|
|
176
152
|
|
|
177
|
-
##
|
|
153
|
+
## Development and maintenance
|
|
178
154
|
|
|
179
|
-
|
|
155
|
+
Start with [`docs/index.md`](docs/index.md) for architecture, CLI contract, write safety, release workflow, and other maintainer documentation.
|
|
180
156
|
|
|
181
157
|
## License
|
|
182
158
|
|
|
183
|
-
AppleBooksCLI
|
|
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
|
|
Binary file
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { readFile, rename, stat, writeFile } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
|
|
6
|
+
const skillNames = ["applebookscli", "applebookscli-zh"];
|
|
7
|
+
const source = "chiimagnus/AppleBooksCLI";
|
|
8
|
+
const sourceURL = "https://github.com/chiimagnus/AppleBooksCLI.git";
|
|
9
|
+
const skillsVersion = "1.5.23";
|
|
10
|
+
|
|
11
|
+
async function runUpdater(names) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const child = spawn(
|
|
14
|
+
"npx",
|
|
15
|
+
["-y", `skills@${skillsVersion}`, "update", ...names, "-g", "-y"],
|
|
16
|
+
{
|
|
17
|
+
stdio: "ignore",
|
|
18
|
+
env: { ...process.env, DISABLE_TELEMETRY: "1" },
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
child.once("error", reject);
|
|
22
|
+
child.once("exit", resolve);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function main() {
|
|
27
|
+
const packageJSON = JSON.parse(
|
|
28
|
+
await readFile(new URL("../../package.json", import.meta.url), "utf8"),
|
|
29
|
+
);
|
|
30
|
+
// ponytail: skills@1.5.23 还没有公开的“只重绑 ref”命令;只改它自己的 source ref,target 更新仍完全交给官方 updater。
|
|
31
|
+
const lockPath = process.env.XDG_STATE_HOME
|
|
32
|
+
? join(process.env.XDG_STATE_HOME, "skills", ".skill-lock.json")
|
|
33
|
+
: join(homedir(), ".agents", ".skill-lock.json");
|
|
34
|
+
|
|
35
|
+
let rawLock;
|
|
36
|
+
try {
|
|
37
|
+
rawLock = await readFile(lockPath, "utf8");
|
|
38
|
+
} catch {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const lock = JSON.parse(rawLock);
|
|
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;
|
|
49
|
+
|
|
50
|
+
const targetRef = `v${packageJSON.version}`;
|
|
51
|
+
const changed = managed.some((name) => lock.skills[name].ref !== targetRef);
|
|
52
|
+
if (changed) {
|
|
53
|
+
const mode = (await stat(lockPath)).mode & 0o777;
|
|
54
|
+
const temporary = `${lockPath}.${process.pid}.tmp`;
|
|
55
|
+
for (const name of managed) lock.skills[name].ref = targetRef;
|
|
56
|
+
await writeFile(temporary, `${JSON.stringify(lock, null, 2)}\n`, { mode });
|
|
57
|
+
await rename(temporary, lockPath);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const code = await runUpdater(managed);
|
|
61
|
+
if (code !== 0) {
|
|
62
|
+
console.warn(
|
|
63
|
+
`applebookscli: Skill update to ${targetRef} did not complete; Agent Skills CLI can retry later.`,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
await main();
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.warn(
|
|
72
|
+
`applebookscli: optional Skill update skipped: ${error instanceof Error ? error.message : String(error)}`,
|
|
73
|
+
);
|
|
74
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chiimagnus/applebookscli",
|
|
3
|
-
"version": "0.1
|
|
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": {
|
|
@@ -17,16 +17,17 @@
|
|
|
17
17
|
"cpu": [
|
|
18
18
|
"arm64"
|
|
19
19
|
],
|
|
20
|
-
"publishConfig": {
|
|
21
|
-
"access": "public"
|
|
22
|
-
},
|
|
23
20
|
"bin": {
|
|
24
21
|
"applebookscli": "bin/applebookscli"
|
|
25
22
|
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"postinstall": "node libexec/applebookscli/sync-installed-skill.mjs"
|
|
25
|
+
},
|
|
26
26
|
"files": [
|
|
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"
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: applebookscli
|
|
3
|
-
description: 通过 `applebookscli` 查询、定位、导出或受保护地修改 Apple Books 图书、阅读状态、EPUB/PDF、批注笔记与藏书,以及执行云同步、备份恢复或访问诊断时使用。
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# AppleBooksCLI
|
|
7
|
-
|
|
8
|
-
使用已安装的 `applebookscli` 作为 Apple Books 数据操作入口。用户询问自己的数据时,实际查询后再回答,不用能力说明代替结果。
|
|
9
|
-
|
|
10
|
-
## 命令与 identity
|
|
11
|
-
|
|
12
|
-
命令、参数和枚举以当前 `--help` 为准;需要机器结果时优先 `--json`,`export` 使用 `--format json`。`doctor` 只用于诊断实际的 permission / unavailable / schema 问题。
|
|
13
|
-
|
|
14
|
-
优先使用稳定 identity:book asset ID、annotation UUID、collection ID、backup handle。标题/作者/名称先 search/list 并确认唯一;local PK 只在用户明确指定或没有稳定 identity 时使用。不要静默选择多候选中的第一项。
|
|
15
|
-
|
|
16
|
-
## Annotation 与写入
|
|
17
|
-
|
|
18
|
-
“最新笔记”只在 nonempty note 中比较;“最新”默认按创建时间,“最近修改”按修改时间。具体 annotation 优先返回高亮、note、必要时间与 `appleBooksURL`;需要前后正文时才用 `content context`。
|
|
19
|
-
|
|
20
|
-
`annotations update-note --note` 是整段替换。用户要求追加时先读原 note,再构造完整新值。`annotations delete` soft-delete 整条 annotation,不用于清空 note。
|
|
21
|
-
|
|
22
|
-
只有用户明确要求修改或 restore 时才写。不要直接读写 Apple Books SQLite,也不要额外手工 quit/launch Books;guarded mutation rail 已负责 backup、Books lifecycle、事务、read-back 与 cloud projection。
|
|
23
|
-
|
|
24
|
-
`committed=true` 后出现 warning 不能自动重试;结果未知时先做最窄只读确认。单条 mutation 只有在用户要求立即确认上传时才加 `--sync`。连续多条写入先正常执行,最后一次 `applebookscli sync --json`,避免每条都触发 lifecycle。
|
|
25
|
-
|
|
26
|
-
`--sync` / `sync` 成功只证明当前 Mac 的 Apple Books cloud records 获得 CloudKit acknowledgement;没有 second-device 证据时不要声称另一设备已经显示。`cloud_sync_failed` 是 post-commit warning。`backups restore` 是 BKLibrary snapshot replacement,不要把 restore 后的 `sync` 解释成 snapshot diff 已逐条上传。
|
|
27
|
-
|
|
28
|
-
## EPUB、PDF 与导出
|
|
29
|
-
|
|
30
|
-
EPUB 不可用时按需要用 `content status --json` 解释原因;不绕过 DRM,也不主动 hydration。PDF 只处理当前可解析的本地 source;不要把 PDF 命令当作已证明 non-hydrating 的 iCloud placeholder probe。
|
|
31
|
-
|
|
32
|
-
完整笔记归档使用 `--complete-notes` 的 fail-closed 路径;失败时不能降级成普通 export 后声称完整。普通导出遵守用户给定的输出与 overwrite 策略。
|
|
33
|
-
|
|
34
|
-
## 完成判断
|
|
35
|
-
|
|
36
|
-
不要把 exit 0 当成目标完成;以返回数据证明结果,并区分 empty、not found、unavailable、degraded、warning 与 CloudKit acknowledgement。
|