feishu-docs-cli 0.1.0-beta.10

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.
Files changed (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +403 -0
  3. package/README.zh.md +402 -0
  4. package/bin/feishu-docs.js +8 -0
  5. package/dist/auth.d.ts +76 -0
  6. package/dist/auth.js +512 -0
  7. package/dist/auth.js.map +1 -0
  8. package/dist/cli.d.ts +5 -0
  9. package/dist/cli.js +197 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/client.d.ts +28 -0
  12. package/dist/client.js +256 -0
  13. package/dist/client.js.map +1 -0
  14. package/dist/commands/authorize.d.ts +12 -0
  15. package/dist/commands/authorize.js +73 -0
  16. package/dist/commands/authorize.js.map +1 -0
  17. package/dist/commands/cat.d.ts +6 -0
  18. package/dist/commands/cat.js +159 -0
  19. package/dist/commands/cat.js.map +1 -0
  20. package/dist/commands/cp.d.ts +9 -0
  21. package/dist/commands/cp.js +70 -0
  22. package/dist/commands/cp.js.map +1 -0
  23. package/dist/commands/create.d.ts +6 -0
  24. package/dist/commands/create.js +120 -0
  25. package/dist/commands/create.js.map +1 -0
  26. package/dist/commands/delete.d.ts +6 -0
  27. package/dist/commands/delete.js +91 -0
  28. package/dist/commands/delete.js.map +1 -0
  29. package/dist/commands/info.d.ts +6 -0
  30. package/dist/commands/info.js +69 -0
  31. package/dist/commands/info.js.map +1 -0
  32. package/dist/commands/install-skill.d.ts +5 -0
  33. package/dist/commands/install-skill.js +28 -0
  34. package/dist/commands/install-skill.js.map +1 -0
  35. package/dist/commands/login.d.ts +10 -0
  36. package/dist/commands/login.js +93 -0
  37. package/dist/commands/login.js.map +1 -0
  38. package/dist/commands/ls.d.ts +6 -0
  39. package/dist/commands/ls.js +79 -0
  40. package/dist/commands/ls.js.map +1 -0
  41. package/dist/commands/mkdir.d.ts +6 -0
  42. package/dist/commands/mkdir.js +49 -0
  43. package/dist/commands/mkdir.js.map +1 -0
  44. package/dist/commands/mv.d.ts +9 -0
  45. package/dist/commands/mv.js +72 -0
  46. package/dist/commands/mv.js.map +1 -0
  47. package/dist/commands/read.d.ts +6 -0
  48. package/dist/commands/read.js +439 -0
  49. package/dist/commands/read.js.map +1 -0
  50. package/dist/commands/search.d.ts +7 -0
  51. package/dist/commands/search.js +92 -0
  52. package/dist/commands/search.js.map +1 -0
  53. package/dist/commands/share.d.ts +13 -0
  54. package/dist/commands/share.js +266 -0
  55. package/dist/commands/share.js.map +1 -0
  56. package/dist/commands/spaces.d.ts +6 -0
  57. package/dist/commands/spaces.js +43 -0
  58. package/dist/commands/spaces.js.map +1 -0
  59. package/dist/commands/tree.d.ts +6 -0
  60. package/dist/commands/tree.js +101 -0
  61. package/dist/commands/tree.js.map +1 -0
  62. package/dist/commands/update.d.ts +9 -0
  63. package/dist/commands/update.js +217 -0
  64. package/dist/commands/update.js.map +1 -0
  65. package/dist/commands/wiki.d.ts +6 -0
  66. package/dist/commands/wiki.js +286 -0
  67. package/dist/commands/wiki.js.map +1 -0
  68. package/dist/parser/block-types.d.ts +141 -0
  69. package/dist/parser/block-types.js +167 -0
  70. package/dist/parser/block-types.js.map +1 -0
  71. package/dist/parser/blocks-to-md.d.ts +26 -0
  72. package/dist/parser/blocks-to-md.js +666 -0
  73. package/dist/parser/blocks-to-md.js.map +1 -0
  74. package/dist/parser/text-elements.d.ts +13 -0
  75. package/dist/parser/text-elements.js +91 -0
  76. package/dist/parser/text-elements.js.map +1 -0
  77. package/dist/scopes.d.ts +21 -0
  78. package/dist/scopes.js +48 -0
  79. package/dist/scopes.js.map +1 -0
  80. package/dist/services/block-writer.d.ts +29 -0
  81. package/dist/services/block-writer.js +131 -0
  82. package/dist/services/block-writer.js.map +1 -0
  83. package/dist/services/doc-blocks.d.ts +8 -0
  84. package/dist/services/doc-blocks.js +26 -0
  85. package/dist/services/doc-blocks.js.map +1 -0
  86. package/dist/services/markdown-convert.d.ts +68 -0
  87. package/dist/services/markdown-convert.js +217 -0
  88. package/dist/services/markdown-convert.js.map +1 -0
  89. package/dist/services/wiki-nodes.d.ts +20 -0
  90. package/dist/services/wiki-nodes.js +46 -0
  91. package/dist/services/wiki-nodes.js.map +1 -0
  92. package/dist/types/index.d.ts +236 -0
  93. package/dist/types/index.js +5 -0
  94. package/dist/types/index.js.map +1 -0
  95. package/dist/utils/document-resolver.d.ts +26 -0
  96. package/dist/utils/document-resolver.js +46 -0
  97. package/dist/utils/document-resolver.js.map +1 -0
  98. package/dist/utils/drive-types.d.ts +4 -0
  99. package/dist/utils/drive-types.js +16 -0
  100. package/dist/utils/drive-types.js.map +1 -0
  101. package/dist/utils/errors.d.ts +23 -0
  102. package/dist/utils/errors.js +114 -0
  103. package/dist/utils/errors.js.map +1 -0
  104. package/dist/utils/member.d.ts +11 -0
  105. package/dist/utils/member.js +30 -0
  106. package/dist/utils/member.js.map +1 -0
  107. package/dist/utils/scope-prompt.d.ts +39 -0
  108. package/dist/utils/scope-prompt.js +134 -0
  109. package/dist/utils/scope-prompt.js.map +1 -0
  110. package/dist/utils/url-parser.d.ts +5 -0
  111. package/dist/utils/url-parser.js +55 -0
  112. package/dist/utils/url-parser.js.map +1 -0
  113. package/dist/utils/validate.d.ts +8 -0
  114. package/dist/utils/validate.js +15 -0
  115. package/dist/utils/validate.js.map +1 -0
  116. package/dist/utils/version.d.ts +12 -0
  117. package/dist/utils/version.js +128 -0
  118. package/dist/utils/version.js.map +1 -0
  119. package/package.json +53 -0
  120. package/skills/feishu-docs/SKILL.md +194 -0
@@ -0,0 +1,194 @@
1
+ ---
2
+ name: feishu-docs
3
+ description: Read, write, search, and manage Feishu (Lark) cloud documents and knowledge bases via the feishu-docs CLI. Use this skill whenever the user mentions Feishu docs, Lark docs, knowledge bases (wiki spaces), or wants to interact with Feishu cloud documents in any way — reading, creating, updating, deleting, searching, sharing, or browsing wiki structure. Also trigger when the user pastes a Feishu or Lark URL, or mentions feishu-docs-cli. This skill covers both Chinese (飞书) and international (Lark) platforms.
4
+ ---
5
+
6
+ # Feishu Docs CLI
7
+
8
+ `feishu-docs` is a CLI tool that lets you read and write Feishu (Lark) cloud documents directly from the terminal. All output goes to stdout as plain text or JSON — designed for agent consumption.
9
+
10
+ ## Prerequisites
11
+
12
+ Before using any command, verify the environment is ready:
13
+
14
+ ```bash
15
+ feishu-docs whoami
16
+ ```
17
+
18
+ If this fails with an auth error:
19
+ - Ensure `FEISHU_APP_ID` and `FEISHU_APP_SECRET` environment variables are set
20
+ - For user-level features (search, personal docs), the user needs to run `feishu-docs login` interactively in their terminal — you cannot do this for them
21
+ - Tenant (app) mode works without login but only accesses docs the app has been granted permission to
22
+
23
+ ## Reading Documents
24
+
25
+ Read a document by URL or token. Output is Markdown by default.
26
+
27
+ ```bash
28
+ feishu-docs read <url|token>
29
+ feishu-docs read <url> --blocks # Lossless Block JSON
30
+ feishu-docs read <url> --raw # Plain text
31
+ feishu-docs read <url> --with-meta # Prepend title/URL/revision metadata
32
+ ```
33
+
34
+ Accepts full Feishu/Lark URLs or raw tokens (e.g., `wikcnXXX`, `doxcnXXX`). The URL format is automatically detected — wiki pages, docx, sheets, and bitable links all work.
35
+
36
+ Markdown conversion is lossy (colors, merged cells, complex layouts are dropped). When fidelity matters, use `--blocks` to get the raw Block JSON.
37
+
38
+ ## Browsing Knowledge Bases
39
+
40
+ Discover what's available before reading:
41
+
42
+ ```bash
43
+ feishu-docs spaces # List all accessible wiki spaces
44
+ feishu-docs tree <space_id> --depth 3 # Show document tree structure
45
+ feishu-docs cat <space_id> --max-docs 20 # Read all docs recursively
46
+ feishu-docs cat <space_id> --title-only # Just list titles
47
+ feishu-docs cat <space_id> --node <token> # Start from a specific node
48
+ ```
49
+
50
+ `spaces` returns space IDs and names. Use a space_id with `tree` to understand the structure, then `read` individual documents or `cat` to batch-read.
51
+
52
+ ## Searching
53
+
54
+ ```bash
55
+ feishu-docs search "keyword" --type docx --limit 10
56
+ ```
57
+
58
+ Search requires a user access token (`feishu-docs login`). It will not work with tenant-only auth.
59
+
60
+ ## Creating Documents
61
+
62
+ ```bash
63
+ # Create in a wiki space
64
+ feishu-docs create "Title" --wiki <space_id> --body ./content.md
65
+
66
+ # Create in a cloud folder
67
+ feishu-docs create "Title" --folder <folder_token> --body ./content.md
68
+
69
+ # Create empty document (returns URL)
70
+ feishu-docs create "Title"
71
+
72
+ # Pipe content from stdin
73
+ echo "# Hello" | feishu-docs create "Title" --wiki <space_id> --body -
74
+ ```
75
+
76
+ The `--body` flag accepts a file path or `-` for stdin. Content is Markdown — the API converts it to Feishu blocks server-side.
77
+
78
+ When creating under a wiki node, use `--wiki <space_id> --parent <node_token>` to place it under a specific parent.
79
+
80
+ ## Updating Documents
81
+
82
+ ```bash
83
+ # Overwrite entire document (auto-backs up first)
84
+ feishu-docs update <url> --body ./updated.md
85
+
86
+ # Append to end of document
87
+ feishu-docs update <url> --body ./extra.md --append
88
+
89
+ # Pipe from stdin
90
+ echo "## New Section" | feishu-docs update <url> --body - --append
91
+ ```
92
+
93
+ Overwrite mode automatically backs up the current document to `~/.feishu-docs/backups/` before writing. If the write fails, it auto-recovers from the backup.
94
+
95
+ To restore a previous version:
96
+ ```bash
97
+ feishu-docs update <url> --restore ~/.feishu-docs/backups/<backup-file>.json
98
+ ```
99
+
100
+ ## Deleting Documents
101
+
102
+ ```bash
103
+ feishu-docs delete <url> --confirm
104
+ ```
105
+
106
+ Moves to recycle bin (recoverable for 30 days). The `--confirm` flag is required.
107
+
108
+ ## Document Info
109
+
110
+ ```bash
111
+ feishu-docs info <url|token> # Human-readable metadata
112
+ feishu-docs info <url> --json # Structured JSON output
113
+ ```
114
+
115
+ Returns title, document type, URL, owner, creation time, and revision number.
116
+
117
+ ## Listing Cloud Files
118
+
119
+ ```bash
120
+ feishu-docs ls # Root folder
121
+ feishu-docs ls <folder_token> # Specific folder
122
+ feishu-docs ls --type docx --limit 20 # Filter by type
123
+ ```
124
+
125
+ ## File Operations
126
+
127
+ ```bash
128
+ feishu-docs mv <url|token> <target_folder_token> # Move file
129
+ feishu-docs cp <url|token> <target_folder_token> # Copy file (auto-named)
130
+ feishu-docs cp <url|token> <target_folder> --name "My Copy"
131
+ feishu-docs mkdir "Folder Name" --parent <folder_token> # Create folder
132
+ ```
133
+
134
+ `mv` is asynchronous — it polls the task until complete (max 30s). `cp` without `--name` automatically appends " - 副本" to the original title.
135
+
136
+ ## Sharing & Permissions
137
+
138
+ ```bash
139
+ feishu-docs share list <url> # View collaborators
140
+ feishu-docs share add <url> user@example.com --role view
141
+ feishu-docs share add <url> ou_xxx --role edit
142
+ feishu-docs share remove <url> user@example.com # Remove collaborator
143
+ feishu-docs share update <url> ou_xxx --role manage # Change role
144
+ feishu-docs share set <url> --public tenant # Org-wide readable
145
+ feishu-docs share set <url> --public tenant:edit # Org-wide editable
146
+ feishu-docs share set <url> --public open # Internet-accessible
147
+ feishu-docs share set <url> --public closed # Disable link sharing
148
+ ```
149
+
150
+ Roles: `view`, `edit`, `manage`. Member types (email, openid, unionid, userid) are auto-detected.
151
+
152
+ ## Wiki Management
153
+
154
+ ```bash
155
+ feishu-docs wiki create-space <name>
156
+ feishu-docs wiki add-member <space_id> <member>
157
+ feishu-docs wiki remove-member <space_id> <member>
158
+ feishu-docs wiki rename <url> --title <new_title>
159
+ feishu-docs wiki move <url> --to <space_id>
160
+ feishu-docs wiki copy <url> --to <space_id>
161
+ ```
162
+
163
+ ## Global Options
164
+
165
+ Every command accepts these flags:
166
+
167
+ | Flag | Effect |
168
+ |------|--------|
169
+ | `--auth user` | Force user token (personal docs, search) |
170
+ | `--auth tenant` | Force app token (CI/CD, shared docs) |
171
+ | `--json` | Output structured JSON instead of text |
172
+ | `--lark` | Use Lark (international) domain |
173
+
174
+ Default auth mode is `auto` — tries user token first, falls back to tenant.
175
+
176
+ ## Common Workflows
177
+
178
+ **Research a wiki space**: `spaces` → pick a space_id → `tree <space_id>` → `read` specific docs
179
+
180
+ **Write a report to wiki**: Write markdown locally → `create "Title" --wiki <space_id> --body ./report.md`
181
+
182
+ **Update existing doc**: `read <url>` to see current content → edit locally → `update <url> --body ./updated.md`
183
+
184
+ **Batch extract**: `cat <space_id> --max-docs 50` to dump all docs as markdown for analysis
185
+
186
+ **Organize files**: `mkdir "Reports" --parent <folder>` → `mv <doc> <new_folder>` to organize documents into folders
187
+
188
+ ## Limitations
189
+
190
+ - Only `docx` (new document format) is fully supported for read/write
191
+ - Legacy `doc` format is not supported
192
+ - Images cannot be written; read returns temporary URLs valid ~24 hours
193
+ - Markdown conversion is lossy — use `--blocks` for lossless JSON when precision matters
194
+ - Search requires user-level auth (run `feishu-docs login` first)