codex-to-im 0.1.0

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) 2024-2025 op7418
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,163 @@
1
+ # Codex-to-IM
2
+
3
+ `codex-to-im` is a local bridge app that connects Codex desktop sessions to IM channels such as Feishu/Lark and Weixin.
4
+
5
+ The product is no longer centered around a Codex skill. The main path is:
6
+
7
+ 1. Install `codex-to-im`
8
+ 2. Open the local web workbench
9
+ 3. Configure IM channels
10
+ 4. Start the bridge in the background
11
+ 5. Bind real desktop Codex threads to Feishu or Weixin chats
12
+
13
+ `SKILL.md` is still kept in the repo, but only as an optional Codex integration entry.
14
+
15
+ ## Project Origin
16
+
17
+ The current codebase is a consolidated continuation of two earlier repositories:
18
+
19
+ - `Claude-to-IM`
20
+ - `Claude-to-IM-skill`
21
+
22
+ `codex-to-im` is based on those two projects and has been reworked toward a single-package local app, shared-thread workflow, and optional Codex integration model.
23
+
24
+ Windows host installation guide: [docs/install-windows.md](D:/codex/Claude-to-IM-skill/docs/install-windows.md)
25
+
26
+ ## What It Includes
27
+
28
+ - Local background bridge service
29
+ - Local web workbench for configuration, testing, logs, and bindings
30
+ - Feishu credential setup and connectivity testing
31
+ - Weixin QR login flow
32
+ - Desktop session discovery from `~/.codex/sessions`
33
+ - Web-side binding updates for IM chats
34
+ - Optional Codex integration for opening `codex-to-im` or entering the Feishu handoff flow
35
+
36
+ ## Install
37
+
38
+ ### Prerequisites
39
+
40
+ - Node.js 20+
41
+ - If you use the `codex` or `auto` runtime, install Codex CLI first
42
+
43
+ ```bash
44
+ npm install -g @openai/codex
45
+ codex auth login
46
+ ```
47
+
48
+ ### Global install
49
+
50
+ ```bash
51
+ npm install -g codex-to-im
52
+ ```
53
+
54
+ ### Local development
55
+
56
+ ```bash
57
+ npm install
58
+ npm run build
59
+ ```
60
+
61
+ ## Run
62
+
63
+ Start the local app:
64
+
65
+ ```bash
66
+ codex-to-im
67
+ ```
68
+
69
+ This launches the local workbench and opens it in your browser.
70
+
71
+ By default the workbench runs at:
72
+
73
+ ```text
74
+ http://127.0.0.1:4781
75
+ ```
76
+
77
+ If that port is already occupied, the app automatically finds an available local port and prints the actual address to the terminal when starting.
78
+
79
+ If you forget the current address, run:
80
+
81
+ ```bash
82
+ codex-to-im url
83
+ ```
84
+
85
+ ## Main Workflow
86
+
87
+ 1. Open the workbench
88
+ 2. Fill in Feishu credentials or trigger Weixin QR login
89
+ 3. Save config and test connectivity
90
+ 4. Start the bridge
91
+ 5. Open the desktop sessions section
92
+ 6. Bind a Feishu or Weixin chat to the target thread
93
+ 7. Continue the same Codex thread from IM
94
+
95
+ Useful command:
96
+
97
+ - `/history` shows the latest N messages of the current session
98
+ - N is configurable in the web workbench under the basic settings panel
99
+
100
+ If you enable Feishu streaming response cards, the Feishu app must have the required permissions published first, at minimum:
101
+
102
+ - `cardkit:card:write`
103
+ - `cardkit:card:read`
104
+ - `im:message:update`
105
+
106
+ If those permissions are missing, the bridge log will usually show `99991672` with `cardkit:card:write`, and the bridge falls back to a final-result message.
107
+
108
+ Also note that under the current `codex` runtime, the `Codex CLI / SDK` typically emits the assistant text only when the `agent_message` item is completed, not as token-level deltas. In practice that means Feishu "streaming cards" currently behave more like:
109
+
110
+ - early `Thinking / Tool Progress` updates
111
+ - final response text written into the card at completion
112
+
113
+ So character-by-character text streaming is not guaranteed in the current implementation.
114
+
115
+ If creating a new session fails with `Not inside a trusted directory`, either:
116
+
117
+ - change the default working directory to a trusted Git repo, or
118
+ - enable `Allow Codex outside trusted Git repos` in the basic settings and restart the bridge
119
+
120
+ ## Optional Codex Integration
121
+
122
+ The repo still includes a lightweight optional integration under `SKILL.md`.
123
+
124
+ It is not required for the product to work.
125
+
126
+ If installed into `~/.codex/skills/codex-to-im`, it should only be used for two actions:
127
+
128
+ - Open `codex-to-im`
129
+ - Open the Feishu session-sharing entry for the current workflow
130
+
131
+ You can install that optional integration from the web UI, or with:
132
+
133
+ ```bash
134
+ bash scripts/install-codex.sh --link
135
+ ```
136
+
137
+ ## Repo Layout
138
+
139
+ - `src/ui-server.ts` — local workbench UI and HTTP API
140
+ - `src/service-manager.ts` — bridge and UI lifecycle management
141
+ - `src/desktop-sessions.ts` — desktop thread discovery from Codex session files
142
+ - `src/session-bindings.ts` — binding summaries and web-side binding updates
143
+ - `src/lib/bridge/` — bridge runtime and IM channel routing
144
+ - `SKILL.md` — optional Codex integration only
145
+ - `docs/` — PRD and shared-thread design docs
146
+
147
+ ## Development
148
+
149
+ ```bash
150
+ npm run typecheck
151
+ npm run build
152
+ ```
153
+
154
+ ## Status
155
+
156
+ Current product direction:
157
+
158
+ - Standalone local app first
159
+ - Web workbench first
160
+ - Shared Codex thread model first
161
+ - Codex integration is optional, not the primary installation path
162
+
163
+ [中文文档](README_CN.md)
package/README_CN.md ADDED
@@ -0,0 +1,161 @@
1
+ # Codex-to-IM
2
+
3
+ `codex-to-im` 是一个本地桥接应用,用来把 Codex 桌面会话接到飞书、微信等 IM 渠道。
4
+
5
+ 这个项目现在不再以 Skill 为中心。主路径是:
6
+
7
+ 1. 安装 `codex-to-im`
8
+ 2. 打开本地 Web 工作台
9
+ 3. 配置 IM 渠道
10
+ 4. 在后台启动 bridge
11
+ 5. 把真实的桌面 Codex thread 绑定到飞书或微信聊天
12
+
13
+ 仓库里仍然保留了 `SKILL.md`,但它只是一个可选的 Codex 集成入口,不再是产品本体。
14
+
15
+ ## 项目来源
16
+
17
+ 当前这套代码是在两个早期仓库的基础上整理和改造出来的:
18
+
19
+ - `Claude-to-IM`
20
+ - `Claude-to-IM-skill`
21
+
22
+ 现在的 `codex-to-im` 是在这两个工程基础上继续演进的单包版本,重点调整成了本地应用、共享 thread 和可选 Codex 集成的形态。
23
+
24
+ Windows 主机安装说明见:[docs/install-windows.md](D:/codex/Claude-to-IM-skill/docs/install-windows.md)
25
+
26
+ ## 现在包含什么
27
+
28
+ - 本地后台 bridge 服务
29
+ - 本地 Web 工作台,用于配置、测试、日志和绑定管理
30
+ - 飞书凭据配置与连通性测试
31
+ - 微信扫码登录
32
+ - 从 `~/.codex/sessions` 发现桌面会话
33
+ - 在网页中查看和切换 IM 绑定
34
+ - 可选的 Codex 集成,仅用于打开 `codex-to-im` 或进入飞书共享入口
35
+
36
+ ## 安装
37
+
38
+ ### 依赖
39
+
40
+ - Node.js 20+
41
+ - 如果使用 `codex` 或 `auto` 运行时:先安装 Codex CLI
42
+
43
+ ```bash
44
+ npm install -g @openai/codex
45
+ codex auth login
46
+ ```
47
+
48
+ ### 全局安装
49
+
50
+ ```bash
51
+ npm install -g codex-to-im
52
+ ```
53
+
54
+ ### 本地开发
55
+
56
+ ```bash
57
+ npm install
58
+ npm run build
59
+ ```
60
+
61
+ ## 启动
62
+
63
+ 启动本地应用:
64
+
65
+ ```bash
66
+ codex-to-im
67
+ ```
68
+
69
+ 它会拉起本地工作台并在浏览器中打开。
70
+
71
+ 默认地址:
72
+
73
+ ```text
74
+ http://127.0.0.1:4781
75
+ ```
76
+
77
+ 如果默认端口已被占用,应用会自动选择一个可用端口,并在启动时把实际地址打印到命令行。
78
+
79
+ 如果你忘了当前地址,可以执行:
80
+
81
+ ```bash
82
+ codex-to-im url
83
+ ```
84
+
85
+ ## 主流程
86
+
87
+ 1. 打开工作台
88
+ 2. 填写飞书配置,或触发微信扫码
89
+ 3. 保存配置并测试连通性
90
+ 4. 启动 bridge
91
+ 5. 打开“最近桌面会话”
92
+ 6. 把飞书或微信聊天绑定到目标 thread
93
+ 7. 在 IM 中继续同一条 Codex 会话
94
+
95
+ 常用命令补充:
96
+
97
+ - `/history` 查看当前会话最近 N 条消息
98
+ - N 可在 Web 工作台的“基础配置”里调整
99
+
100
+ 如果你启用了飞书流式响应卡片,需要先在飞书应用侧开通并发布相关权限,至少包括:
101
+
102
+ - `cardkit:card:write`
103
+ - `cardkit:card:read`
104
+ - `im:message:update`
105
+
106
+ 如果缺少这些权限,Bridge 日志里通常会看到 `99991672` 和 `cardkit:card:write`,系统会自动退回到最终结果消息。
107
+
108
+ 另外要注意:当前 `codex` runtime 下,`Codex CLI / SDK` 实际返回的正文文本事件通常只在 `item.completed` 时出现,不是 token 级逐字输出。所以“飞书流式响应卡片”在当前版本里更准确的含义是:
109
+
110
+ - 可以先显示 `Thinking / Tool Progress`
111
+ - 正文通常会在回答完成时一次性落到卡片里
112
+
113
+ 也就是说,飞书侧当前不保证像聊天模型网页那样逐字冒字。
114
+
115
+ 如果新建会话时报 `Not inside a trusted directory`,可以:
116
+
117
+ - 把默认工作目录改成一个你已经信任的 Git 仓库
118
+ - 或在基础配置里打开“允许在未信任 Git 目录运行 Codex”,然后重启 Bridge
119
+
120
+ ## 可选 Codex 集成
121
+
122
+ 仓库里仍然保留了一个很薄的可选集成,定义在 `SKILL.md`。
123
+
124
+ 它不是必需的。
125
+
126
+ 如果你把它装到 `~/.codex/skills/codex-to-im`,它只保留两个动作:
127
+
128
+ - 打开 `codex-to-im`
129
+ - 打开“共享当前会话到飞书”的入口
130
+
131
+ 你可以在 Web UI 中安装这层可选集成,也可以手动执行:
132
+
133
+ ```bash
134
+ bash scripts/install-codex.sh --link
135
+ ```
136
+
137
+ ## 仓库结构
138
+
139
+ - `src/ui-server.ts` — 本地工作台 UI 和 HTTP API
140
+ - `src/service-manager.ts` — bridge 与 UI 的生命周期管理
141
+ - `src/desktop-sessions.ts` — 从 Codex 会话文件发现桌面 thread
142
+ - `src/session-bindings.ts` — 绑定摘要与网页侧切换
143
+ - `src/lib/bridge/` — bridge 运行时与 IM 路由
144
+ - `SKILL.md` — 可选 Codex 集成,不是主产品
145
+ - `docs/` — PRD 与共享 thread 技术设计
146
+
147
+ ## 开发
148
+
149
+ ```bash
150
+ npm run typecheck
151
+ npm run build
152
+ ```
153
+
154
+ ## 当前方向
155
+
156
+ - 先做独立本地应用
157
+ - 先做 Web 工作台
158
+ - 先做共享 Codex thread
159
+ - Codex 集成是可选增强,不是主安装路径
160
+
161
+ [English](README.md)
package/SECURITY.md ADDED
@@ -0,0 +1,38 @@
1
+ # Security
2
+
3
+ ## Credential Storage
4
+
5
+ Credentials are stored in `~/.codex-to-im/config.env` and the local runtime data under `~/.codex-to-im/`.
6
+
7
+ The app still falls back to `~/.claude-to-im/` on machines that already have legacy data, but new installs should treat `~/.codex-to-im/` as the primary home.
8
+
9
+ This repository never stores secrets in source control.
10
+
11
+ ## Log Redaction
12
+
13
+ Tokens and secrets should be masked in logs and workbench output. Only short tail fragments of secrets should ever be shown for confirmation or diagnosis.
14
+
15
+ ## Operational Model
16
+
17
+ `codex-to-im` is a local single-user bridge:
18
+
19
+ - The bridge runs on the user's machine
20
+ - The web workbench is local-only
21
+ - IM authentication is delegated to each IM platform
22
+ - Access control is enforced through configured allowlists and channel bindings
23
+
24
+ ## Rotation Guidance
25
+
26
+ If a token is rotated or suspected to be exposed:
27
+
28
+ 1. Revoke the old credential on the IM platform
29
+ 2. Update the value in the local `codex-to-im` workbench
30
+ 3. Restart the bridge from the workbench
31
+ 4. Review recent logs under `~/.codex-to-im/logs/`
32
+
33
+ ## Legacy Data
34
+
35
+ If you upgraded from an older `claude-to-im` install, check both of these locations during diagnosis:
36
+
37
+ - `~/.codex-to-im/`
38
+ - `~/.claude-to-im/`
package/SKILL.md ADDED
@@ -0,0 +1,79 @@
1
+ ---
2
+ name: codex-to-im
3
+ description: |
4
+ Optional Codex integration for the codex-to-im local app. Use only when the
5
+ user wants to open codex-to-im from Codex or enter the Feishu session-sharing
6
+ flow. Do not use this skill as the main setup, config, logs, or daemon
7
+ management path.
8
+ argument-hint: "open | share-feishu"
9
+ allowed-tools:
10
+ - Bash
11
+ - Read
12
+ - Grep
13
+ - Glob
14
+ ---
15
+
16
+ # Codex-to-IM Optional Integration
17
+
18
+ `codex-to-im` is a standalone local app with a background bridge and web workbench.
19
+
20
+ This optional integration is intentionally thin. It exists only for two actions:
21
+
22
+ - `open`
23
+ - `share-feishu`
24
+
25
+ If the user asks to configure channels, start or stop the bridge, inspect logs, or diagnose issues, do not treat this integration as the main workflow. Open the local app instead.
26
+
27
+ ## Resolve the repo / install root
28
+
29
+ Prefer these locations:
30
+
31
+ - `~/.codex/skills/codex-to-im`
32
+ - `~/.claude/skills/codex-to-im`
33
+
34
+ If neither exists, fall back to globbing `**/skills/**/codex-to-im/SKILL.md` and derive the root from that match.
35
+
36
+ ## Command mapping
37
+
38
+ Map user intent to one of these two actions:
39
+
40
+ | User says | Action |
41
+ |---|---|
42
+ | `open codex-to-im`, `打开 codex-to-im`, `open bridge workbench`, `打开工作台` | `open` |
43
+ | `share current session to feishu`, `共享当前会话到飞书`, `把当前会话发到飞书`, `open feishu handoff` | `share-feishu` |
44
+
45
+ ## Execution
46
+
47
+ ### `open`
48
+
49
+ Prefer:
50
+
51
+ ```bash
52
+ codex-to-im open
53
+ ```
54
+
55
+ If the `codex-to-im` command is unavailable, fall back to:
56
+
57
+ ```bash
58
+ node dist/cli.mjs open
59
+ ```
60
+
61
+ Run from the repo / install root.
62
+
63
+ ### `share-feishu`
64
+
65
+ Prefer:
66
+
67
+ ```bash
68
+ codex-to-im share-feishu
69
+ ```
70
+
71
+ If the `codex-to-im` command is unavailable, fall back to:
72
+
73
+ ```bash
74
+ node dist/cli.mjs share-feishu
75
+ ```
76
+
77
+ Run from the repo / install root.
78
+
79
+ After opening the workbench, tell the user to use the desktop sessions panel or the IM binding panel to finish binding the target thread to Feishu.
@@ -0,0 +1,106 @@
1
+ # Codex-to-IM Configuration
2
+ # Copy to ~/.codex-to-im/config.env and edit
3
+
4
+ # Runtime backend: claude | codex | auto
5
+ # claude (default) — uses Claude Code CLI + @anthropic-ai/claude-agent-sdk
6
+ # codex — uses @openai/codex-sdk (auth: codex auth login, or OPENAI_API_KEY)
7
+ # auto — tries Claude first, falls back to Codex if CLI not found
8
+ # If you plan to use the codex runtime, install Codex CLI first:
9
+ # npm install -g @openai/codex
10
+ # codex auth login
11
+ CTI_RUNTIME=claude
12
+
13
+ # Enabled channels (comma-separated: telegram,discord,feishu,qq,weixin)
14
+ CTI_ENABLED_CHANNELS=telegram
15
+
16
+ # Default working directory for Codex / bridge sessions
17
+ CTI_DEFAULT_WORKDIR=/path/to/your/project
18
+
19
+ # Default model (optional — inherits from runtime's own default if not set)
20
+ # CTI_DEFAULT_MODEL=
21
+
22
+ # Default mode (code, plan, ask)
23
+ CTI_DEFAULT_MODE=code
24
+
25
+ # Number of recent messages returned by /history
26
+ # CTI_HISTORY_MESSAGE_LIMIT=8
27
+
28
+ # ── Claude CLI path (optional) ──
29
+ # Override if you have multiple `claude` versions in PATH, or the daemon
30
+ # picks the wrong one (e.g. an npm-installed 1.x instead of the native 2.x).
31
+ # CTI_CLAUDE_CODE_EXECUTABLE=/path/to/claude
32
+
33
+ # ── Third-party API provider (optional) ──
34
+ # If you use Claude through a third-party API provider (not the default
35
+ # Anthropic API), set these so the daemon forwards them to the CLI subprocess.
36
+ # They are automatically passed through in both inherit and strict env modes.
37
+ # All ANTHROPIC_* vars in this file are forwarded to the launchd/setsid daemon.
38
+ # ANTHROPIC_API_KEY=your-third-party-api-key
39
+ # ANTHROPIC_BASE_URL=https://your-api-provider.com/v1
40
+ # ANTHROPIC_AUTH_TOKEN=your-auth-token
41
+
42
+ # ── Codex auth (optional — only if not using `codex auth login`) ──
43
+ # Priority: CTI_CODEX_API_KEY > CODEX_API_KEY > OPENAI_API_KEY
44
+ # CTI_CODEX_API_KEY=
45
+ # CTI_CODEX_BASE_URL=
46
+ # Allow Codex to run when CTI_DEFAULT_WORKDIR is not inside a trusted Git repo.
47
+ # Keep this off unless you intentionally want Codex to work in arbitrary folders.
48
+ # CTI_CODEX_SKIP_GIT_REPO_CHECK=true
49
+
50
+ # ── Telegram ──
51
+ CTI_TG_BOT_TOKEN=your-telegram-bot-token
52
+ # Chat ID for authorization (at least one of CHAT_ID or ALLOWED_USERS is required)
53
+ # Get it: send a message to the bot, then visit https://api.telegram.org/botYOUR_TOKEN/getUpdates
54
+ CTI_TG_CHAT_ID=your-chat-id
55
+ # CTI_TG_ALLOWED_USERS=user_id_1,user_id_2
56
+
57
+ # ── Discord ──
58
+ # CTI_DISCORD_BOT_TOKEN=your-discord-bot-token
59
+ # CTI_DISCORD_ALLOWED_USERS=user_id_1,user_id_2
60
+ # CTI_DISCORD_ALLOWED_CHANNELS=channel_id_1
61
+ # CTI_DISCORD_ALLOWED_GUILDS=guild_id_1
62
+
63
+ # ── Feishu / Lark ──
64
+ # CTI_FEISHU_APP_ID=your-app-id
65
+ # CTI_FEISHU_APP_SECRET=your-app-secret
66
+ # CTI_FEISHU_DOMAIN=https://open.feishu.cn
67
+ # CTI_FEISHU_ALLOWED_USERS=user_id_1,user_id_2
68
+ # Enable streaming response cards in Feishu (default true).
69
+ # Requires published Feishu permissions such as:
70
+ # - cardkit:card:write
71
+ # - cardkit:card:read
72
+ # - im:message:update
73
+ # Current Codex runtime note: thinking/progress can update live, but
74
+ # assistant body text may still arrive only at completion.
75
+ # CTI_FEISHU_STREAMING_ENABLED=true
76
+
77
+ # ── QQ ──
78
+ # Required: obtain from https://q.qq.com/qqbot/openclaw
79
+ # CTI_QQ_APP_ID=your-qq-app-id
80
+ # CTI_QQ_APP_SECRET=your-qq-app-secret
81
+ # Allowed users — comma-separated user_openid values (NOT QQ numbers)
82
+ # CTI_QQ_ALLOWED_USERS=openid_1,openid_2
83
+ # Image input — set to false if the underlying provider doesn't support image input
84
+ # CTI_QQ_IMAGE_ENABLED=true
85
+ # Max image size in MB (default 20)
86
+ # CTI_QQ_MAX_IMAGE_SIZE=20
87
+
88
+ # ── WeChat / 微信 ──
89
+ # No static token is required here. Use the QR login helper to add accounts:
90
+ # npm run weixin:login
91
+ # Optional protocol overrides (normally leave unset)
92
+ # CTI_WEIXIN_BASE_URL=https://ilinkai.weixin.qq.com
93
+ # CTI_WEIXIN_CDN_BASE_URL=https://novac2c.cdn.weixin.qq.com/c2c
94
+ # Enable inbound media download/processing for image/file/video messages.
95
+ # Voice messages do not use raw audio download/transcription here: the bridge
96
+ # only accepts WeChat-provided speech-to-text text and otherwise returns an error.
97
+ # (default false for safety in CLI setups)
98
+ # CTI_WEIXIN_MEDIA_ENABLED=false
99
+
100
+ # ── Permission ──
101
+ # Auto-approve all tool permission requests without user confirmation.
102
+ # Useful for channels that lack interactive permission UI (e.g. Feishu
103
+ # WebSocket long-connection mode, where there is no HTTP webhook to
104
+ # render clickable approve/deny buttons).
105
+ # ⚠️ Only enable this in trusted, access-controlled environments.
106
+ # CTI_AUTO_APPROVE=true