feishu-codex-connector 0.1.6

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 feishu-codex-bridge contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # Feishu Codex Connector
2
+
3
+ Feishu Codex Connector is an unofficial Feishu/Lark bot and local bridge for OpenAI Codex. It lets you send coding tasks from Feishu or Lark chat, run Codex in a controlled local workspace, and stream the result back through rich cards, messages, and document comments.
4
+
5
+ Use it when you want a personal AI coding agent in Feishu/Lark that can work with local repositories, preserve Codex sessions, switch workspaces, and keep app secrets and OpenAI API keys in a profile-local encrypted keystore.
6
+
7
+ ## At A Glance
8
+
9
+ | Item | Value |
10
+ | --- | --- |
11
+ | npm package | `feishu-codex-connector` |
12
+ | CLI command | `feishu-codex` |
13
+ | Runtime | Node.js `>=20.12.0` |
14
+ | Chat platforms | Feishu and Lark |
15
+ | Codex auth | OpenAI API key, local Codex state, or inherited user auth |
16
+ | Local state | `~/.feishu-codex` |
17
+
18
+ ## Features
19
+
20
+ - Run OpenAI Codex from Feishu/Lark direct messages, groups, and document comments.
21
+ - Bootstrap a Feishu/Lark PersonalAgent app with a terminal QR-code wizard.
22
+ - Receive events through Feishu/Lark persistent connection mode.
23
+ - Stream Codex progress and command completion through rich interactive cards.
24
+ - Manage workspace aliases, session reset/resume, timeouts, diagnostics, and process lifecycle from chat.
25
+ - Store app secrets and Codex API keys as profile-scoped secret references instead of plaintext config.
26
+ - Restrict access with owner, admin, user, and group allow lists.
27
+
28
+ ## Install
29
+
30
+ Install from npm:
31
+
32
+ ```bash
33
+ npm install -g feishu-codex-connector
34
+ feishu-codex run
35
+ ```
36
+
37
+ Or run from a local checkout:
38
+
39
+ ```bash
40
+ pnpm install
41
+ pnpm build
42
+ node bin/feishu-codex.mjs run
43
+ ```
44
+
45
+ ## First Run
46
+
47
+ The first run starts a PersonalAgent bootstrap wizard:
48
+
49
+ 1. The terminal renders a QR code.
50
+ 2. Scan it with the Feishu/Lark app.
51
+ 3. Pick or create a PersonalAgent app.
52
+ 4. The connector initializes a Codex agent profile.
53
+ 5. Config is written to `~/.feishu-codex/config.json`; profile state is written under `~/.feishu-codex/profiles/<profile>/`.
54
+
55
+ If `OPENAI_API_KEY` is present, the wizard uses API-key auth. Otherwise it tries to reuse local Codex state when available.
56
+
57
+ If you already have a PersonalAgent app, skip QR creation:
58
+
59
+ ```bash
60
+ feishu-codex run \
61
+ --app-id cli_xxx \
62
+ --app-secret "$FEISHU_APP_SECRET"
63
+ ```
64
+
65
+ ## Manual Profile
66
+
67
+ Create a profile explicitly when you already know the Feishu/Lark app credentials and target workspace:
68
+
69
+ ```bash
70
+ feishu-codex profile create default \
71
+ --tenant feishu \
72
+ --app-id cli_xxx \
73
+ --app-secret "$FEISHU_APP_SECRET" \
74
+ --codex-auth api-key \
75
+ --codex-api-key "$OPENAI_API_KEY" \
76
+ --workspace /absolute/project/path
77
+
78
+ feishu-codex run --profile default
79
+ ```
80
+
81
+ Normal profile config stores only secret references. App secrets and Codex API keys are stored in the profile-local encrypted keystore under `~/.feishu-codex/profiles/<name>/`.
82
+
83
+ ## Feishu/Lark Events
84
+
85
+ The default runtime uses the Feishu/Lark persistent connection:
86
+
87
+ ```bash
88
+ feishu-codex run --profile default
89
+ ```
90
+
91
+ When startup succeeds, the terminal should show `ws client ready`. Send `/status` in the bot DM or an authorized group to verify message delivery.
92
+
93
+ If the WebSocket connects but messages do not arrive, check the app's Events & Callbacks settings in Feishu/Lark Open Platform:
94
+
95
+ 1. Event subscription mode is set to persistent connection.
96
+ 2. `im.message.receive_v1` is subscribed.
97
+ 3. Callback subscription mode is set to persistent connection.
98
+ 4. `card.action.trigger` is subscribed if card buttons are used.
99
+
100
+ `--poll-chat <chat_id>` is only a diagnostic fallback for apps whose event subscription is not configured yet.
101
+
102
+ ## CLI Commands
103
+
104
+ ```bash
105
+ feishu-codex profile list
106
+ feishu-codex profile export default
107
+ feishu-codex run --profile default
108
+ feishu-codex start --profile default
109
+ feishu-codex status --profile default
110
+ feishu-codex stop --profile default
111
+ feishu-codex ps
112
+ feishu-codex doctor --profile default --json
113
+ ```
114
+
115
+ ## Chat Commands
116
+
117
+ | Command | Purpose |
118
+ | --- | --- |
119
+ | `/help` | Show the help card |
120
+ | `/status` | Show profile, workspace, session, and queue status |
121
+ | `/new`, `/reset` | Reset the current scope's Codex session |
122
+ | `/new group [name]` | Create a new Feishu/Lark group and inherit the current workspace |
123
+ | `/resume`, `/resume use <nonce>` | List and restore recent sessions for the current workspace |
124
+ | `/cd <path>` | Switch the current scope workspace |
125
+ | `/ws list` | List workspace aliases |
126
+ | `/ws save <name>` | Save the current workspace as an alias |
127
+ | `/ws add <name> <path>` | Save a specific path as a workspace alias |
128
+ | `/ws use <name>` | Switch to a workspace alias |
129
+ | `/ws remove <name>` | Remove a workspace alias |
130
+ | `/stop` | Stop the current run |
131
+ | `/timeout <minutes\|off\|default>` | Set the current scope idle timeout |
132
+ | `/config`, `/config show` | Edit or inspect profile settings |
133
+ | `/invite`, `/remove` | Manage access lists |
134
+ | `/doctor`, `/doctor detail` | Run diagnostics |
135
+ | `/ps`, `/exit <id>`, `/reconnect` | Manage the local connector process |
136
+
137
+ ## Security
138
+
139
+ - Secrets are not written as plaintext in normal profile config.
140
+ - App secrets and OpenAI API keys are resolved through profile-scoped secret references.
141
+ - Rendered run output is redacted for common API-key and app-secret patterns.
142
+ - Codex receives an explicit prompt rule not to inspect or reveal bridge secret files.
143
+ - The connector is designed for personal local operation; review workspace permissions before granting group access.
144
+
145
+ ## FAQ
146
+
147
+ **Is this an official Feishu, Lark, or OpenAI project?**
148
+ No. This is an independent connector for Feishu/Lark and OpenAI Codex.
149
+
150
+ **Does it work with both Feishu and Lark?**
151
+ Yes. Use `--tenant feishu` or `--tenant lark` when creating a profile.
152
+
153
+ **Do I need an OpenAI API key?**
154
+ API-key auth is the most predictable remote mode. The connector can also use local Codex state or inherited user auth when configured.
155
+
156
+ **Where are local files stored?**
157
+ The default state directory is `~/.feishu-codex`.
158
+
159
+ ## Documentation
160
+
161
+ - [Architecture](./docs/ARCHITECTURE.md)
162
+ - [Functional Specification](./docs/SPEC.md)
163
+ - [Feature Parity Specification](./docs/FEATURE_PARITY_SPEC.md)
164
+ - [Command Completion Specification](./docs/COMMAND_COMPLETION_SPEC.md)
165
+ - [Feishu/Lark Permissions](./docs/FEISHU_PERMISSIONS.md)
166
+
167
+ ## License
168
+
169
+ MIT
package/README.zh.md ADDED
@@ -0,0 +1,170 @@
1
+ # Feishu Codex Connector
2
+
3
+ Feishu Codex Connector 是一个非官方的飞书 / Lark 机器人和本地桥接服务,用来在飞书或 Lark 聊天里运行 OpenAI Codex。你可以从私聊、群聊或文档评论发送编程任务,让 Codex 在本机受控工作区执行,并把进度和结果通过富文本卡片、消息和文档评论回传。
4
+
5
+ 适合这些场景:给自己搭建飞书 Codex 机器人、把 OpenAI Codex 接入 Lark、远程驱动本地代码仓库、保留 Codex session、切换 workspace,并把飞书 App Secret 和 OpenAI API Key 放在 profile 级加密 keystore 中。
6
+
7
+ ## 快速信息
8
+
9
+ | 项目 | 内容 |
10
+ | --- | --- |
11
+ | npm 包 | `feishu-codex-connector` |
12
+ | CLI 命令 | `feishu-codex` |
13
+ | Node.js | `>=20.12.0` |
14
+ | 平台 | 飞书、Lark |
15
+ | Codex 认证 | OpenAI API Key、本机 Codex 状态、继承用户认证 |
16
+ | 本地状态目录 | `~/.feishu-codex` |
17
+
18
+ ## 主要功能
19
+
20
+ - 从飞书 / Lark 私聊、群聊、文档评论里运行 OpenAI Codex。
21
+ - 首次运行提供 PersonalAgent 扫码向导,在终端显示二维码创建或绑定应用。
22
+ - 使用飞书 / Lark 开放平台长连接接收消息和卡片回调。
23
+ - 用富文本交互卡片展示 Codex 运行进度、命令完成状态和操作按钮。
24
+ - 在聊天里管理 workspace alias、session reset/resume、timeout、doctor 诊断和本机进程。
25
+ - App Secret 和 Codex API Key 以 profile-scoped secret reference 保存,不明文写入普通配置。
26
+ - 支持 owner、admin、user、group allow list 控制访问范围。
27
+
28
+ ## 安装
29
+
30
+ 通过 npm 安装:
31
+
32
+ ```bash
33
+ npm install -g feishu-codex-connector
34
+ feishu-codex run
35
+ ```
36
+
37
+ 从源码运行:
38
+
39
+ ```bash
40
+ pnpm install
41
+ pnpm build
42
+ node bin/feishu-codex.mjs run
43
+ ```
44
+
45
+ ## 首次启动
46
+
47
+ 第一次运行会进入 PersonalAgent 扫码向导:
48
+
49
+ 1. 终端渲染二维码。
50
+ 2. 用飞书 / Lark App 扫码。
51
+ 3. 选择或创建 PersonalAgent 应用。
52
+ 4. connector 初始化 Codex agent profile。
53
+ 5. 配置写入 `~/.feishu-codex/config.json`,profile 状态写入 `~/.feishu-codex/profiles/<profile>/`。
54
+
55
+ 如果环境里有 `OPENAI_API_KEY`,首次初始化会使用 API key 模式;否则会优先复用本机 Codex 登录状态。
56
+
57
+ 如果已有 PersonalAgent app,可以跳过扫码:
58
+
59
+ ```bash
60
+ feishu-codex run \
61
+ --app-id cli_xxx \
62
+ --app-secret "$FEISHU_APP_SECRET"
63
+ ```
64
+
65
+ ## 手动创建 Profile
66
+
67
+ 如果已经知道飞书 / Lark 应用凭证和目标代码目录,可以直接创建 profile:
68
+
69
+ ```bash
70
+ feishu-codex profile create default \
71
+ --tenant feishu \
72
+ --app-id cli_xxx \
73
+ --app-secret "$FEISHU_APP_SECRET" \
74
+ --codex-auth api-key \
75
+ --codex-api-key "$OPENAI_API_KEY" \
76
+ --workspace /absolute/project/path
77
+
78
+ feishu-codex run --profile default
79
+ ```
80
+
81
+ 普通 profile config 只保存 secret 引用。App Secret 和 Codex API Key 会写入 profile-local encrypted keystore,不会明文写进 `config.json`。
82
+
83
+ ## 飞书 / Lark 长连接
84
+
85
+ 默认运行方式使用飞书 / Lark 开放平台长连接:
86
+
87
+ ```bash
88
+ feishu-codex run --profile default
89
+ ```
90
+
91
+ 启动成功后,终端会看到 `ws client ready`。然后在机器人私聊或已授权群聊里发送 `/status` 测试消息接收。
92
+
93
+ 如果 WebSocket 已连接但收不到消息,请在飞书 / Lark 开放平台检查当前应用的「事件与回调」:
94
+
95
+ 1. 事件配置的订阅方式为「使用长连接接收事件」。
96
+ 2. 已订阅 `im.message.receive_v1`。
97
+ 3. 回调配置的订阅方式为「使用长连接接收回调」。
98
+ 4. 如需卡片按钮,已订阅 `card.action.trigger`。
99
+
100
+ `--poll-chat <chat_id>` 只作为诊断或事件订阅尚未配置时的兜底方式。
101
+
102
+ ## CLI 命令
103
+
104
+ ```bash
105
+ feishu-codex profile list
106
+ feishu-codex profile export default
107
+ feishu-codex run --profile default
108
+ feishu-codex start --profile default
109
+ feishu-codex status --profile default
110
+ feishu-codex stop --profile default
111
+ feishu-codex ps
112
+ feishu-codex doctor --profile default --json
113
+ ```
114
+
115
+ ## 飞书内命令
116
+
117
+ | 命令 | 作用 |
118
+ | --- | --- |
119
+ | `/help` | 查看帮助卡片 |
120
+ | `/status` | 查看当前 profile、workspace、session、队列 |
121
+ | `/new`, `/reset` | 重置当前 scope 的 Codex session |
122
+ | `/new group [name]` | 创建新的飞书 / Lark 群聊并继承当前 workspace |
123
+ | `/resume`, `/resume use <nonce>` | 列出并恢复当前 workspace 下的历史 session |
124
+ | `/cd <path>` | 切换当前 scope 的 workspace |
125
+ | `/ws list` | 查看 workspace 别名 |
126
+ | `/ws save <name>` | 保存当前 workspace 为别名 |
127
+ | `/ws add <name> <path>` | 保存指定路径为 workspace 别名 |
128
+ | `/ws use <name>` | 切换到 workspace 别名 |
129
+ | `/ws remove <name>` | 删除 workspace 别名 |
130
+ | `/stop` | 停止当前 scope 的运行 |
131
+ | `/timeout <minutes\|off\|default>` | 设置当前 scope 的 idle timeout |
132
+ | `/config`, `/config show` | 修改或查看配置 |
133
+ | `/invite user @name`, `/invite admin @name`, `/invite group` | 管理访问控制 |
134
+ | `/remove user @name`, `/remove admin @name`, `/remove group` | 移除访问控制 |
135
+ | `/doctor`, `/doctor detail` | 诊断当前 connector 状态 |
136
+ | `/ps`, `/exit <id>`, `/reconnect` | 查看、停止或重连本机 connector 进程 |
137
+
138
+ ## 安全说明
139
+
140
+ - 普通 profile 配置不会明文保存 App Secret 或 OpenAI API Key。
141
+ - 敏感信息通过 profile-scoped secret reference 解析。
142
+ - 输出渲染会对常见 API key 和 app secret 模式做脱敏。
143
+ - connector 会显式提示 Codex 不要读取或泄露桥接服务的 secret 文件。
144
+ - 当前设计以个人本地运行为主;给群聊授权前,请确认 workspace 权限和 allow list。
145
+
146
+ ## 常见问题
147
+
148
+ **这是飞书、Lark 或 OpenAI 官方项目吗?**
149
+ 不是。这是一个独立的 Feishu/Lark + OpenAI Codex connector。
150
+
151
+ **同时支持飞书和 Lark 吗?**
152
+ 支持。创建 profile 时使用 `--tenant feishu` 或 `--tenant lark`。
153
+
154
+ **必须使用 OpenAI API Key 吗?**
155
+ API-key 模式最适合稳定远程运行。也可以按配置使用本机 Codex 状态或继承用户认证。
156
+
157
+ **本地文件存在哪里?**
158
+ 默认状态目录是 `~/.feishu-codex`。
159
+
160
+ ## 文档
161
+
162
+ - [Architecture](./docs/ARCHITECTURE.md)
163
+ - [Functional Specification](./docs/SPEC.md)
164
+ - [Feature Parity Specification](./docs/FEATURE_PARITY_SPEC.md)
165
+ - [Command Completion Specification](./docs/COMMAND_COMPLETION_SPEC.md)
166
+ - [Feishu/Lark Permissions](./docs/FEISHU_PERMISSIONS.md)
167
+
168
+ ## License
169
+
170
+ MIT
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import { main } from '../dist/cli.js';
3
+
4
+ main(process.argv).catch((error) => {
5
+ const message = error instanceof Error ? error.message : String(error);
6
+ console.error(message);
7
+ process.exitCode = 1;
8
+ });