---
name: feishu-token-updater
description: 更新飞书技能 feishu-docx-yashu 的 tenant_access_token 字段。激活条件：用户消息包含「更新/设置飞书 token」。
metadata:
  author: "AI Assistant"
  updated: "2026-08-07 19:19:00"
  version: "2.4.0"
title: feishu-token-updater
canonical_url: https://skilld.dev/gh/steelan9199/wechat-publisher/feishu-token-updater
last_updated: 2026-10-07T07:20:50.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [update.js](https://skilld.dev/api/skills-raw/steelan9199/wechat-publisher/feishu-token-updater/update.js).
>
> If the user asked to install this Skill, run `npx skilld install steelan9199/wechat-publisher/feishu-token-updater`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/feishu-token-updater`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/steelan9199/wechat-publisher/feishu-token-updater) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/feishu-token-updater`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/feishu-token-updater --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/feishu-token-updater --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# 飞书 tenant_access_token 更新器

## 用途

只做一件事：把用户**剪贴板**里的飞书访问令牌（`tenant_access_token`）写入配置文件：

`C:\Users\Administrator\.skills-manager\skills\feishu-docx-yashu\config.default.json`

- 只改 `tenant_access_token` 的**值**，键名永远不动。
- 不碰 `appId`、`appSecret`、`member_id`、`custom` 等其它任何字段。

## 环境说明

| 项目         | 说明                                                    |
| ------------ | ------------------------------------------------------- |
| `$SKILL_DIR` | 当前 Skill 所在的绝对目录，即 SKILL.md 文件所在的文件夹 |
| 校验脚本     | `$SKILL_DIR/update.js`（JWT 校验 + 配置写入）           |
| 临时文件     | `$SKILL_DIR/_tmp_token.txt`（剪贴板内容中转，用后即删） |
| 命令外壳     | **Bash（Git Bash / MSYS2）优先**，尽量不使用 PowerShell  |
| 剪贴板读取   | 经 Git Bash 伪文件 `/dev/clipboard` 直接读系统剪贴板      |
| Node.js 版本 | `>=18`（推荐用托管版 node 绝对路径）                    |

> **⚠️ `$SKILL_DIR` 仅为文档占位符，不是环境变量**，执行命令时必须替换为技能目录的实际绝对路径。在 bash 中若未替换，`$SKILL_DIR` 会被当作环境变量展开为空字符串，导致路径错误。

## 核心原则：Token 与脚本代码都不进上下文

token 极长（数百~数千字符）且是敏感凭证，放进聊天框纯属浪费 token 和泄露风险。因此：

- **用户禁止把 token 粘贴到聊天消息里**，只需复制到剪贴板。
- 完整 token 只允许出现在「剪贴板 → 临时文件 → Node.js 脚本内部变量」这条链路里。
- AI 与用户只接触 token 的前 ~20 字符前缀。
- 仅当剪贴板内容**未通过校验**时，额外显示其前 10 与后 10 字符（换行/制表符转为 `\n`、`\r`、`\t` 形式）及总长度 `len`，供用户确认复制的到底是不是 token。

**校验脚本 `update.js` 持久驻留技能目录，AI 直接 `node` 运行、不读取、不重写、不删除，脚本代码不进入对话上下文。**

## 流程

1. 用户把 token 复制到剪贴板，然后发「更新飞书 token」（不要粘贴 token 到聊天框）。
2. 执行「第二步：读取剪贴板」（token 不进上下文）。
3. 执行「第三步：运行校验脚本」（脚本内检测，只输出结果与前缀）。
4. 执行「第四步：清理临时文件」。
5. 执行「第五步：回执」。

## 第一步：触发

用户消息含「更新/设置飞书 token」即触发，**不要等用户粘贴 token**，直接执行第二步。token 是否有效由第三步的代码判断。

## 第二步：读取剪贴板 → 临时文件（内容不进上下文）

用 Bash（Git Bash / MSYS2）把剪贴板原样写入技能目录下的临时文件。Git Bash 提供 `/dev/clipboard` 伪文件，可直接读取系统剪贴板，**无需 PowerShell、也不回显剪贴板内容**（`$SKILL_DIR` 替换为实际路径）：

```bash
printf '%s' "$(cat /dev/clipboard)" > "$SKILL_DIR/_tmp_token.txt"
```

要点：

- `cat /dev/clipboard` 读取系统剪贴板全文；`printf '%s'` 不追加额外换行（等价于 PowerShell 的 `-Raw -NoNewline`）。
- 剪贴板为空时临时文件为空，属正常，交由第三步判为无效。
- 此命令输出为空，不会把 token 打到终端。

## 第三步：运行校验脚本（代码不进上下文）

直接运行本技能目录下的校验脚本 `update.js`（`$SKILL_DIR` 替换为实际路径）。脚本内含 JWT 特征校验与配置写入逻辑，AI **无需读取、无需重写**脚本内容，脚本代码不进入对话上下文：

```bash
node "$SKILL_DIR/update.js"
```

脚本行为说明（供 AI 理解输出，无需查看源码）：

- 读取第二步写入的 `_tmp_token.txt`（脚本用 `__dirname` 自动定位同目录文件），校验 JWT 特征（`eyJ` 开头、三段点分隔）并解码 payload 确认 token 类型为 `access_token`。
- 校验通过：将 token 写入配置文件的 `tenant_access_token` 字段，打印 `UPDATED old=<旧前缀> new=<新前缀>`（各 20 字符）。
- 校验失败：打印 `NO_VALID_TOKEN_IN_CLIPBOARD head=<前10字符> tail=<后10字符> len=<总长度>`，换行/制表符以 `\n`、`\r`、`\t` 形式显示；用户可据此判断复制内容是否为完整 token、是否复制错内容、或 token 是否真的无效。
- 路径用 `/`，Windows 下 Node 可直接识别，避免反斜杠转义问题。

## 第四步：清理临时文件

删除第二步产生的临时 token 文件（`$SKILL_DIR` 替换为实际路径；校验脚本 `update.js` 不得删除）：

```bash
rm -f "$SKILL_DIR/_tmp_token.txt"
```

## 第五步：回执

- 输出 `UPDATED`：告知用户已更新，只显示新 token 前 ~20 字符（如 `eyJhbGciOiJF...`）供核对。**完整 token 不要回显。**
- 输出 `NO_VALID_TOKEN_IN_CLIPBOARD`：说明剪贴板里没有符合特征的 token，并**原样展示 `head=`、`tail=`、`len=` 三个字段**（剪贴板内容前 10 / 后 10 字符与总长度），供用户确认复制内容是否为完整 token、是否复制错内容；随后引导走「兜底：发链接」。

## 兜底：发链接引导（剪贴板无有效 token 时）

把链接原样发给用户（不要自己打开、不要代填）：

`https://open.feishu.cn/api-explorer/cli_a74fda9e3ad8901c?apiName=create&project=docx&resource=document&version=v1`

并附引导：

> 打开上面的飞书 API Explorer 链接，授权/操作后从请求头复制 `tenant_access_token`（一长串字符），**复制到剪贴板即可，不要粘贴到聊天框**，然后回复「更新飞书 token」，我会自动读取剪贴板并写入配置。

## 硬性约束

- 配置文件路径固定为 `C:\Users\Administrator\.skills-manager\skills\feishu-docx-yashu\config.default.json`，不要写到其它位置。
- 只改 `tenant_access_token` 这一个字段的值；键名永不修改。
- token 属敏感凭证：完整值不回显、不落盘到日志/无关文件；临时 token 文件用后即删。
- `update.js` 为持久脚本，AI 不得在对话中读取、重写、内联或删除其代码，只能通过 `node` 运行。
- 命令尽量用 Bash（Git Bash / MSYS2）编写，剪贴板经 `/dev/clipboard` 读取；仅当确实无 bash 等价能力时才退回 PowerShell。
